# EIRS Admin - Docker Compose for Production
# Uses external SQL Server - no local database container

version: '3.8'

services:
  # ===========================================
  # EIRS Admin Web Application (Production)
  # ===========================================
  eirs-admin:
    image: ${REGISTRY:-ghcr.io}/eirs-admin:${TAG:-latest}
    build:
      context: .
      dockerfile: Presentation/EIRS.Admin.Core/Dockerfile
    container_name: eirs-admin
    restart: always
    ports:
      - "80:80"
      - "443:443"
    environment:
      - ASPNETCORE_ENVIRONMENT=Production
      - ASPNETCORE_URLS=http://+:80
      # Connection strings from environment/secrets
      - ConnectionStrings__DbEntities=${DB_CONNECTION_STRING}
      - ConnectionStrings__ERASEntities=${ERAS_CONNECTION_STRING}
      - ConnectionStrings__ERASDWEntities=${ERASDW_CONNECTION_STRING}
      - ConnectionStrings__ErrorConnection=${ERROR_CONNECTION_STRING}
      # Application Insights (optional)
      - ApplicationInsights__ConnectionString=${APPINSIGHTS_CONNECTION_STRING}
      # Timezone
      - TZ=Africa/Lagos
    volumes:
      # Persist logs
      - /var/log/eirs:/app/logs
      # Persist data protection keys
      - /var/lib/eirs/keys:/app/keys
      # Persist temp files
      - /var/lib/eirs/temp:/app/temp
    deploy:
      mode: replicated
      replicas: 2
      resources:
        limits:
          cpus: '2'
          memory: 4G
        reservations:
          cpus: '0.5'
          memory: 512M
      restart_policy:
        condition: on-failure
        delay: 5s
        max_attempts: 3
        window: 120s
      update_config:
        parallelism: 1
        delay: 10s
        failure_action: rollback
        monitor: 60s
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:80/health"]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 60s
    logging:
      driver: "json-file"
      options:
        max-size: "100m"
        max-file: "5"
    networks:
      - eirs-network

  # ===========================================
  # Nginx Reverse Proxy (optional)
  # ===========================================
  nginx:
    image: nginx:alpine
    container_name: eirs-nginx
    restart: always
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - ./nginx/nginx.conf:/etc/nginx/nginx.conf:ro
      - ./nginx/ssl:/etc/nginx/ssl:ro
      - /var/log/nginx:/var/log/nginx
    depends_on:
      - eirs-admin
    networks:
      - eirs-network
    profiles:
      - with-nginx

# ===========================================
# Networks
# ===========================================
networks:
  eirs-network:
    driver: bridge
