
services:
    laravel.test:
        build:
            context: ./vendor/laravel/sail/runtimes/8.3
            dockerfile: Dockerfile
            args:
                WWWGROUP: '${WWWGROUP}'
        image: sail-8.3/app
        container_name: bagisto_app
        extra_hosts:
            - 'host.docker.internal:host-gateway'
        ports:
            - '${APP_PORT:-80}:80'                # Mapeia porta 80 do host para o container
        environment:
            WWWUSER: '${WWWUSER}'
            LARAVEL_SAIL: 1
        volumes:
            - '.:/var/www/html'                    # Monta o código local (bind mount)
        networks:
            - sail
        depends_on:
            - mysql
            - redis
        restart: always                             # Reinicia automaticamente se cair

    mysql:
        image: mysql:8.0
        container_name: bagisto_mysql
        ports:
            - '${FORWARD_DB_PORT:-3306}:3306'       # Expõe MySQL para acesso externo (opcional)
        environment:
            MYSQL_ROOT_PASSWORD: rootpassword
            MYSQL_ROOT_HOST: '%'
            MYSQL_DATABASE: bagisto_db
            
            
        volumes:
            - 'sail-mysql:/var/lib/mysql'            # Volume persistente
            - './dump.sql:/docker-entrypoint-initdb.d/dump.sql'   # Script de inicialização
        networks:
            - sail
        restart: always
        healthcheck:
            test: ["CMD", "mysqladmin", "ping", "-p${DB_PASSWORD}"]
            retries: 3
            timeout: 5s

    redis:
        image: 'redis:alpine'
        container_name: bagisto_redis
        ports:
            - '${FORWARD_REDIS_PORT:-6379}:6379'
        volumes:
            - 'sail-redis:/data'
        networks:
            - sail
        restart: always

networks:
    sail:
        driver: bridge

volumes:
    sail-mysql:
        driver: local
    sail-redis:
        driver: local