services:
    web:
        build:
            context: .
            dockerfile: Dockerfile
        container_name: sprint-prod
        restart: always
        volumes:
            # 專案目錄
            - ../..:/var/www/html
            # Apache HTTP 設定
            - ./apache-data/000-default.conf:/etc/apache2/sites-enabled/000-default.conf:ro
            # Apache HTTPS 設定
            - ./apache-data/default-ssl.conf:/etc/apache2/sites-enabled/default-ssl.conf:ro
            # ========== PHP 設定 ==========
            - ./conf/php.ini:/etc/php/8.3/fpm/php.ini:ro
            - ./conf/php.ini:/etc/php/8.3/cli/php.ini:ro
            # Supervisor Workers
            - ./conf/workers.conf:/etc/supervisor/conf.d/workers.conf:ro
            # SSL 憑證（可選，需要時取消註解並設定 SSL_CERT_PATH）
            # - ${SSL_CERT_PATH}/ssl.crt:/etc/ssl/certs/ssl.crt:ro
            # - ${SSL_CERT_PATH}/ssl.key:/etc/ssl/private/ssl.key:ro
        ports:
            - "${HTTP_PORT:-8180}:80"
            - "${HTTPS_PORT:-8143}:443"
        networks:
            - sprint-network
        depends_on:
            mysql:
                condition: service_healthy

    mysql:
        image: mysql:8.0
        container_name: sprint-mysql
        restart: always
        environment:
            MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD:-root123}
            MYSQL_DATABASE: ${MYSQL_DATABASE:-sprint}
            MYSQL_USER: ${MYSQL_USER:-sprint}
            MYSQL_PASSWORD: ${MYSQL_PASSWORD:-sprint123}
        volumes:
            - ./data/mysql:/var/lib/mysql
        networks:
            - sprint-network
        healthcheck:
            test: ["CMD", "mysqladmin", "ping", "-h", "localhost", "-u", "root", "-p${MYSQL_ROOT_PASSWORD:-root123}"]
            interval: 10s
            timeout: 5s
            retries: 5
            start_period: 30s
        command: --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci

networks:
    sprint-network:
        name: sprint-network
        driver: bridge
