version: '3.8'

services:
  app:
    build:
      context: .
      dockerfile: Dockerfile
      args:
        VITE_APP_NAME: "Concerto's Leaderboard"
        VITE_REVERB_APP_KEY: "${REVERB_APP_KEY:-jbtinwmulzayyjtghw6z}"
        VITE_REVERB_HOST: "${REVERB_HOST:-localhost}"
        VITE_REVERB_PORT: "${REVERB_PORT:-6001}"
        VITE_REVERB_SCHEME: "${REVERB_SCHEME:-http}"
    container_name: concerto_app
    restart: unless-stopped
    ports:
      - "${APP_PORT:-8088}:80"
      - "${REVERB_PORT:-6001}:6001"
    environment:
      APP_NAME: "Concerto's Leaderboard"
      APP_ENV: "${APP_ENV:-production}"
      APP_KEY: "${APP_KEY}"
      APP_DEBUG: "${APP_DEBUG:-false}"
      APP_URL: "${APP_URL:-http://localhost:8088}"
      
      DB_CONNECTION: mysql
      DB_HOST: db
      DB_PORT: 3306
      DB_DATABASE: "${DB_DATABASE:-concerto_leaderboard}"
      DB_USERNAME: "${DB_USERNAME:-concerto_user}"
      DB_PASSWORD: "${DB_PASSWORD:-secret}"
      
      SESSION_DRIVER: redis
      CACHE_STORE: redis
      QUEUE_CONNECTION: redis
      
      REDIS_CLIENT: phpredis
      REDIS_HOST: redis
      REDIS_PORT: 6379
      REDIS_PASSWORD: null
      
      BROADCAST_CONNECTION: reverb
      REVERB_APP_ID: "${REVERB_APP_ID:-539140}"
      REVERB_APP_KEY: "${REVERB_APP_KEY:-jbtinwmulzayyjtghw6z}"
      REVERB_APP_SECRET: "${REVERB_APP_SECRET:-ntqqjbzfnz2cgpbq3cbo}"
      REVERB_HOST: "${REVERB_HOST:-localhost}"
      REVERB_PORT: "${REVERB_PORT:-6001}"
      REVERB_SCHEME: "${REVERB_SCHEME:-http}"
      REVERB_SERVER_HOST: "0.0.0.0"
      REVERB_SERVER_PORT: "6001"
      
      RUN_MIGRATIONS: "true"
    volumes:
      - storage_data:/var/www/html/storage/app/public
    depends_on:
      db:
        condition: service_healthy
      redis:
        condition: service_healthy
    networks:
      - concerto_network

  db:
    image: mysql:8.0
    container_name: concerto_db
    restart: unless-stopped
    ports:
      - "${FORWARD_DB_PORT:-3306}:3306"
    environment:
      MYSQL_ROOT_PASSWORD: "${DB_PASSWORD:-secret}"
      MYSQL_DATABASE: "${DB_DATABASE:-concerto_leaderboard}"
      MYSQL_USER: "${DB_USERNAME:-concerto_user}"
      MYSQL_PASSWORD: "${DB_PASSWORD:-secret}"
    volumes:
      - db_data:/var/lib/mysql
    healthcheck:
      test: ["CMD", "mysqladmin", "ping", "-h", "localhost", "-u", "root", "-p${DB_PASSWORD:-secret}"]
      interval: 10s
      timeout: 5s
      retries: 5
    networks:
      - concerto_network

  redis:
    image: redis:7-alpine
    container_name: concerto_redis
    restart: unless-stopped
    ports:
      - "${FORWARD_REDIS_PORT:-6379}:6379"
    volumes:
      - redis_data:/data
    healthcheck:
      test: ["CMD", "redis-cli", "ping"]
      interval: 10s
      timeout: 5s
      retries: 5
    networks:
      - concerto_network

volumes:
  db_data:
    name: concerto_db_data
  redis_data:
    name: concerto_redis_data
  storage_data:
    name: concerto_storage_data

networks:
  concerto_network:
    name: concerto_network
    driver: bridge
