services:
    php-apache:
        build:
            context: .
            dockerfile: .docker/php/Dockerfile
        container_name: ${PHP_CONTAINER}
        restart: unless-stopped
        volumes:
            - .:/var/www/html
            - ./.docker/apache/vhost.conf:/etc/apache2/sites-available/000-default.conf
        ports:
            - '${APP_PORT:-80}:80'
            - '${VITE_PORT:-5173}:5173' # vite runs on this port
        environment:
            - APACHE_RUN_USER=#1000
            - APACHE_RUN_GROUP=#1000
            - DB_HOST=${DB_CONTAINER}
        depends_on:
            - mariadb
            - mailhog

    mariadb:
        image: mariadb:latest
        container_name: ${DB_CONTAINER}
        restart: unless-stopped
        environment:
            MYSQL_ROOT_PASSWORD: '${DB_PASSWORD}'
            MYSQL_DATABASE: '${DB_DATABASE}'
            MYSQL_USER: '${DB_USERNAME}'
            MYSQL_PASSWORD: '${DB_PASSWORD}'
        ports:
            - '${DB_EXTERNAL_PORT:-3306}:3306'
        command: --default-authentication-plugin=mysql_native_password  --sql-mode=""
        volumes:
            - mariadb_data:/var/lib/mysql
        healthcheck:
            test: ['CMD', 'mysql', '-uroot', '-p${DB_PASSWORD}', '-e', 'SELECT 1;']
            interval: 10s
            timeout: 5s
            retries: 5

    mailhog:
        image: mailhog/mailhog
        container_name: ${MAILHOG_CONTAINER}
        restart: unless-stopped
        ports:
            - '${MAILHOG_WEB_PORT:-8025}:8025' # Web UI
            - '${MAILHOG_SMTP_PORT:-1025}:1025' # SMTP

volumes:
    mariadb_data:
        name: ${DB_CONTAINER}_data
