version: '3.8'

services:
    app:
        build:
            context: .
            dockerfile: docker/php/Dockerfile
        working_dir: /var/www/html
        volumes:
            - '.:/var/www/html'


        depends_on:
            - mysql
            - redis
        networks:
            - sail

    nginx:
        image: nginx:alpine
        ports:
            - '${APP_PORT:-80}:80'
        volumes:
            - '.:/var/www/html'
            - './docker/nginx/conf.d/:/etc/nginx/conf.d/'
        depends_on:
            - app
        networks:
            - sail
    mysql:
        image: 'mysql:8.0'
        container_name: mysql
        restart: always
        environment:
            MYSQL_ROOT_PASSWORD: password
            MYSQL_DATABASE: m3track_testing
            MYSQL_USER: sail
            MYSQL_PASSWORD: password
        ports:
            - '3306:3306'
        volumes:
            - 'sail-mysql:/var/lib/mysql'
            - './docker/mysql/init.sql:/docker-entrypoint-initdb.d/init.sql'
        networks:
            - sail
        healthcheck:
            test: ["CMD", "mysqladmin", "ping", "-p${MYSQL_ROOT_PASSWORD}", "-h", "mysql"]
            retries: 3
            timeout: 5s
    redis:
        image: 'redis:alpine'
        ports:
            - '${FORWARD_REDIS_PORT:-6379}:6379'
        volumes:
            - 'sail-redis:/data'
        networks:
            - sail
        healthcheck:
            test: ["CMD", "redis-cli", "ping"]
            retries: 3
            timeout: 5s
networks:
    sail:
        driver: bridge
volumes:
    sail-mysql:
        driver: local
    sail-redis:
        driver: local
