services:
  laravel.test:
    build:
      context: ./vendor/laravel/sail/runtimes/8.2
      dockerfile: Dockerfile
      args:
        WWWGROUP: '${WWWGROUP:-1000}'
    image: sail-8.2/app
    ports:
      - '${APP_PORT:-8000}:80'
    environment:
      WWWUSER: '${WWWUSER:-1000}'
      LARAVEL_SAIL: 1
    volumes:
      - '.:/var/www/html'
    networks:
      - sail
    depends_on:
      - redis
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost"] 
      interval: 10s
      timeout: 5s
      retries: 5

  mysql:
    image: 'mysql:8.0'
    ports:
      - '${FORWARD_DB_PORT:-3306}:3306'
    profiles:
      - db
    environment:
      MYSQL_ROOT_PASSWORD: '${DB_PASSWORD:-password}'
      MYSQL_DATABASE: '${DB_DATABASE:-laravel}'
      MYSQL_USER: '${DB_USERNAME:-sail}'
      MYSQL_PASSWORD: '${DB_PASSWORD:-password}'
    volumes:
      - 'sail-mysql:/var/lib/mysql'
    networks:
      - sail

  redis:
    image: 'redis:alpine'
    ports:
      - '6379:6379'
    networks:
      - sail
    healthcheck:
      test: ["CMD", "redis-cli", "ping"]
      interval: 10s
      timeout: 3s
      retries: 5

  nginx:
    image: nginx:alpine
    ports:
      - '8181:80'
    volumes:
      - './docker/nginx/default.conf:/etc/nginx/conf.d/default.conf:ro'
      - '.:/var/www/html:ro'
    networks:
      - sail
    depends_on:
      - laravel.test
    healthcheck:
      test: ["CMD-SHELL", "nginx -t"]
      interval: 10s
      timeout: 5s
      retries: 5

networks:
  sail:
    driver: bridge

volumes:
  sail-mysql:
    driver: local
