version: '3.8'

services:
  mysql:
    image: mysql:8.0
    container_name: wedding-agency-mysql
    restart: unless-stopped
    environment:
      MYSQL_ROOT_PASSWORD: root
      MYSQL_DATABASE: wedding-agency
      MYSQL_USER: wedding_user
      MYSQL_PASSWORD: wedding_pass
    ports:
      - "3306:3306"
    volumes:
      - mysql_data:/var/lib/mysql
    command: --default-authentication-plugin=mysql_native_password --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
    networks:
      - wedding-network
    healthcheck:
      test: ["CMD", "mysqladmin", "ping", "-h", "localhost", "-u", "root", "-proot"]
      interval: 10s
      timeout: 5s
      retries: 5

  php:
    image: yiisoftware/yii2-php:7.4-apache
    container_name: wedding-agency-php
    restart: unless-stopped
    volumes:
      - ~/.composer-docker/cache:/root/.composer/cache:delegated
      - ./:/app:delegated
    ports:
      - '8000:80'
    depends_on:
      mysql:
        condition: service_healthy
    networks:
      - wedding-network
    environment:
      - YII_ENV=dev
      - DB_HOST=mysql
      - DB_NAME=wedding-agency
      - DB_USER=root
      - DB_PASSWORD=root

volumes:
  mysql_data:
    driver: local

networks:
  wedding-network:
    driver: bridge
