# Staging stack — isolated from local docker-compose.yml (8080 / 3306)
# and from other apps on the server (unique project name + host ports).
#
# Local:
#   docker compose --env-file .env.staging -f docker-compose.staging.yml up -d --build
#
# CI (image already in registry):
#   APP_IMAGE=git.koppkb.com/KoPKB/api_arrahn IMAGE_TAG=<sha> \
#     docker compose --env-file .env.staging -f docker-compose.staging.yml up -d --no-build
#
# Host nginx reverse-proxies the public domain to 127.0.0.1:${HTTP_PORT}.
# See docker/nginx/host-proxy.example.conf
#
# If 8090 or 3308 is already taken, set HTTP_PORT / MYSQL_PUBLISH_PORT in .env.staging.

name: api_arrahn_staging

services:
  app:
    image: ${APP_IMAGE:-api_arrahn}:${IMAGE_TAG:-staging}
    build:
      context: .
      dockerfile: docker/php/Dockerfile
      target: staging
    container_name: api_arrahn_staging_app
    working_dir: /var/www/html
    volumes:
      - storage_staging:/var/www/html/storage
      - ./.env.staging:/var/www/html/.env.staging:ro
    env_file:
      - .env.staging
    environment:
      APP_ENV: staging
      USE_STAGING_ENV: "true"
    extra_hosts:
      - "host.docker.internal:host-gateway"
    depends_on:
      mysql:
        condition: service_healthy
    restart: unless-stopped

  web:
    image: nginx:1.25-alpine
    container_name: api_arrahn_staging_web
    ports:
      - "${HTTP_PORT:-8090}:80"
    volumes:
      - ./docker/nginx/default.conf:/etc/nginx/conf.d/default.conf:ro
    depends_on:
      - app
    restart: unless-stopped

  mysql:
    image: mysql:8.0
    container_name: api_arrahn_staging_mysql
    command: --default-authentication-plugin=mysql_native_password
    ports:
      - "127.0.0.1:${MYSQL_PUBLISH_PORT:-3308}:3306"
    environment:
      MYSQL_DATABASE: erahn_xtra
      MYSQL_USER: xtrauser
      MYSQL_PASSWORD: password
      MYSQL_ROOT_PASSWORD: root
    volumes:
      - mysql_staging_data:/var/lib/mysql
      - ./docker/mysql/init:/docker-entrypoint-initdb.d:ro
    healthcheck:
      test: ["CMD", "mysqladmin", "ping", "-h", "127.0.0.1", "-uroot", "-proot"]
      interval: 5s
      timeout: 5s
      retries: 30
      start_period: 20s
    restart: unless-stopped

volumes:
  mysql_staging_data:
  storage_staging:
