services:
  backend:
    image: ${BACKEND_IMAGE_REF}
    restart: unless-stopped
    environment:
      APP_NAME: ${APP_NAME}
      APP_ENV: production
      APP_DEBUG: "false"
      APP_URL: ${APP_URL}
      APP_KEY: ${APP_KEY}
      DB_CONNECTION: mysql
      DB_HOST: ${MYSQL_HOST:-host.docker.internal}
      DB_PORT: ${MYSQL_PORT:-3306}
      DB_DATABASE: ${MYSQL_DATABASE}
      DB_USERNAME: ${MYSQL_USER}
      DB_PASSWORD: ${MYSQL_PASSWORD}
      SESSION_DRIVER: ${SESSION_DRIVER:-database}
      CACHE_STORE: ${CACHE_STORE:-database}
      QUEUE_CONNECTION: sync
      FILESYSTEM_DISK: ${FILESYSTEM_DISK:-s3}
      AWS_ACCESS_KEY_ID: ${AWS_ACCESS_KEY_ID:-}
      AWS_SECRET_ACCESS_KEY: ${AWS_SECRET_ACCESS_KEY:-}
      AWS_SESSION_TOKEN: ${AWS_SESSION_TOKEN:-}
      AWS_DEFAULT_REGION: ${AWS_DEFAULT_REGION:-us-east-1}
      AWS_BUCKET: ${AWS_BUCKET:-}
      AWS_URL: ${AWS_URL:-}
      AWS_ENDPOINT: ${AWS_ENDPOINT:-}
      AWS_USE_PATH_STYLE_ENDPOINT: ${AWS_USE_PATH_STYLE_ENDPOINT:-false}
      GOOGLE_CLIENT_ID: ${GOOGLE_CLIENT_ID:-}
      SANCTUM_STATEFUL_DOMAINS: ${SANCTUM_STATEFUL_DOMAINS}
      FRONTEND_URL: ${FRONTEND_URL}
      RUN_MIGRATIONS: ${BACKEND_RUN_MIGRATIONS_ON_START:-false}
      WAIT_FOR_DB: ${BACKEND_WAIT_FOR_DB:-true}
    extra_hosts:
      - "host.docker.internal:host-gateway"
    healthcheck:
      test: ["CMD-SHELL", "php -r \"exit(@file_get_contents('http://127.0.0.1/up') === false ? 1 : 0);\""]
      interval: 10s
      timeout: 5s
      retries: 12
      start_period: 20s

  frontend:
    image: ${FRONTEND_IMAGE_REF}
    restart: unless-stopped
    ports:
      - "${APP_PORT}:80"
    depends_on:
      backend:
        condition: service_healthy
    healthcheck:
      test: ["CMD-SHELL", "wget -q -O /dev/null http://127.0.0.1/ || exit 1"]
      interval: 10s
      timeout: 5s
      retries: 12
      start_period: 20s
