name: gpros_hub_api

services:
  app:
    build:
      context: .
      dockerfile: Dockerfile
    container_name: gpros_hub_api_app
    depends_on:
      mysql:
        condition: service_healthy
    environment:
      DB_HOST: ${DB_HOST:-mysql}
      DB_PORT: ${DB_PORT:-3306}
      DB_NAME: ${DB_NAME:-gpros_hub_api}
      DB_USER: ${DB_USER:-gpros_hub_api_user}
      DB_PASS: ${DB_PASS:-gpros_hub_api_secret}
    ports:
      - "${APP_PORT:-8080}:80"
    volumes:
      - gpros_hub_api_logs:/var/www/html/storage/logs
    restart: unless-stopped

  mysql:
    image: mysql:8.0
    container_name: gpros_hub_api_mysql
    command: --default-authentication-plugin=mysql_native_password
    environment:
      MYSQL_DATABASE: ${DB_NAME:-gpros_hub_api}
      MYSQL_USER: ${DB_USER:-gpros_hub_api_user}
      MYSQL_PASSWORD: ${DB_PASS:-gpros_hub_api_secret}
      MYSQL_ROOT_PASSWORD: ${DB_ROOT_PASS:-root_secret}
    healthcheck:
      test: ["CMD", "mysqladmin", "ping", "-h", "127.0.0.1", "-uroot", "-p${DB_ROOT_PASS:-root_secret}"]
      interval: 10s
      timeout: 5s
      retries: 10
      start_period: 20s
    ports:
      - "3306:3306"
    volumes:
      - mysql_data:/var/lib/mysql
      - ./storage/schema.sql:/docker-entrypoint-initdb.d/01-schema.sql:ro
    restart: unless-stopped

volumes:
  mysql_data:
  gpros_hub_api_logs:
