services:
  nginx:
    build:
      context: .
      dockerfile: Dockerfile.nginx
    ports:
      - "80"
    volumes:
      - app-public:/var/www/html/public:ro
      - app-storage:/var/www/html/storage:ro
    depends_on:
      app:
        condition: service_started

  app:
    build:
      context: .
    volumes:
      - app-public:/var/www/html/public
      - app-storage:/var/www/html/storage
    environment:
      DB_HOST: mysql
      DB_DATABASE: ${DB_DATABASE:-aigo}
      DB_USERNAME: ${DB_USERNAME:-aigo}
      DB_PASSWORD: ${DB_PASSWORD}
    depends_on:
      mysql:
        condition: service_healthy

  mysql:
    image: mysql:8.0
    volumes:
      - mysql-data:/var/lib/mysql
    environment:
      MYSQL_DATABASE: ${DB_DATABASE:-aigo}
      MYSQL_USER: ${DB_USERNAME:-aigo}
      MYSQL_PASSWORD: ${DB_PASSWORD}
      MYSQL_ROOT_PASSWORD: ${DB_ROOT_PASSWORD}
    healthcheck:
      test: ["CMD", "mysqladmin", "ping", "-h", "localhost"]
      interval: 5s
      timeout: 3s
      retries: 10

volumes:
  app-public:
  app-storage:
  mysql-data:
