services:
  laravel.test:
    container_name: 'services_api_php'
    build:
      context: ./docker/8.3
      dockerfile: Dockerfile
      args:
        WWWGROUP: '${WWWGROUP}'
        MYSQL_CLIENT: mariadb-client
    image: sail-8.3/app
    extra_hosts:
      - 'host.docker.internal:host-gateway'
      #ports:
      #- '${APP_PORT:-80}:80' #commented out to use caddy
      #- '${VITE_PORT:-5173}:${VITE_PORT:-5173}' We do not use vite for this project
    environment:
      WWWUSER: '${WWWUSER}'
      LARAVEL_SAIL: 1
      XDEBUG_MODE: '${SAIL_XDEBUG_MODE:-off}'
      XDEBUG_CONFIG: '${SAIL_XDEBUG_CONFIG:-client_host=host.docker.internal}'
      IGNITION_LOCAL_SITES_PATH: '${PWD}'
    volumes:
      - '.:/var/www/html'
    networks:
      - sail
      - shared_network
    depends_on:
      - mariadb
      - redis
  mariadb:
    container_name: 'services-api-mariadb'
    image: 'mariadb:11'
    ports:
      - '${FORWARD_DB_PORT:-3307}:3306'
    environment:
      MYSQL_ROOT_PASSWORD: '${DB_PASSWORD}'
      MYSQL_ROOT_HOST: '%'
      MYSQL_DATABASE: '${DB_DATABASE}'
      MYSQL_USER: '${DB_USERNAME}'
      MYSQL_PASSWORD: '${DB_PASSWORD}'
      MYSQL_ALLOW_EMPTY_PASSWORD: 'yes'
    volumes:
      - 'sail-mariadb:/var/lib/mysql'
      - './docker/mariadb/create-testing-database.sh:/docker-entrypoint-initdb.d/10-create-testing-database.sh'
    networks:
      - sail
    healthcheck:
      test: ["CMD", "healthcheck.sh", "--connect", "--innodb_initialized"]
      retries: 3
      timeout: 5s
  redis:
    container_name: 'servcices_api_redis'
    image: 'redis:alpine'
    ports:
      - '${FORWARD_REDIS_PORT:-6380}:6379'
    volumes:
      - 'sail-redis:/data'
    networks:
      - sail
    healthcheck:
      test: ["CMD", "redis-cli", "ping"]
      retries: 3
      timeout: 5s
  caddy:
    container_name: 'servcices_api_caddy'
    build:
      context: "./docker/caddy"
      dockerfile: Dockerfile
      args:
        WWWGROUP: "${WWWGROUP}"
    restart: unless-stopped
    ports:
      - "${APP_SSL_PORT:-8080}:443"
    environment:
      LARAVEL_SAIL: 1
      HOST_DOMAIN: laravel.test
    volumes:
      - "./docker/caddy/Caddyfile:/etc/caddy/Caddyfile"
      - ".:/srv:cache"
      - "./docker/caddy/certificates:/data/caddy/certificates/local"
      - "./docker/caddy/authorities:/data/caddy/pki/authorities/local"
      - "sailcaddy:/data:cache"
      - "sailcaddyconfig:/config:cache"
    networks:
      - sail
    depends_on:
      - laravel.test
networks:
  sail:
    driver: bridge
  shared_network:
    external: true
volumes:
  sail-mariadb:
    driver: local
  sail-redis:
    driver: local
  sailcaddy:
    driver: local
  sailcaddyconfig:
    driver: local
