# Production compose for hamkadr.ir — the Gitea deploy job uses THIS file directly
# (docker compose build api / up -d --no-deps api). Local dev DB → docker-compose.dev.yml.
# nginx (host) terminates TLS for hamkadr.ir and reverse-proxies to 127.0.0.1:${HOST_PORT}.
name: hamkadr   # locked so redeploys reuse the same named volume (no orphaned data)

services:

  # ── .NET 10 Razor Pages app ──────────────────────────────────────────────────
  api:
    image: mirror.soroushasadi.com/hamkadr/api:${API_TAG:-latest}
    build:
      context: .
      dockerfile: Dockerfile
    container_name: hamkadr_api
    restart: unless-stopped
    depends_on:
      db:
        condition: service_healthy
    ports:
      # Published on the host so the (containerized) central nginx can reach it at
      # http://171.22.25.73:${HOST_PORT} — same pattern as the other soroush apps.
      - "${HOST_PORT:-2569}:8080"
    environment:
      ASPNETCORE_ENVIRONMENT: "Production"
      ASPNETCORE_URLS: "http://+:8080"
      ConnectionStrings__Default: "Host=db;Port=5432;Database=${POSTGRES_DB:-hamkadr};Username=${POSTGRES_USER:-hamkadr};Password=${POSTGRES_PASSWORD}"
      Auth__AdminPhone: "${ADMIN_PHONE:-}"
      # Ingestion + AI + channel sources are configured at runtime in /Admin/Settings (DB), not here.
    # healthcheck is defined in the Dockerfile (bash /dev/tcp probe) so the deploy
    # job's `docker inspect Health.Status` wait works.

  # ── Xray/V2Ray client — converts a vmess/vless/trojan config into a local SOCKS proxy ──
  # so ingestion can reach Telegram etc. from inside Iran. Behind the "proxy" profile, so it
  # only runs when you opt in: `docker compose --profile proxy up -d xray`. Put YOUR config at
  # deploy/xray/config.json (see deploy/xray/README.md), then in /Admin/Settings set the
  # ingestion proxy to socks5://xray:10808. Not published — only the app reaches it.
  xray:
    image: mirror.soroushasadi.com/teddysun/xray:latest
    container_name: hamkadr_xray
    restart: unless-stopped
    profiles: ["proxy"]
    volumes:
      - ./deploy/xray/config.json:/etc/xray/config.json:ro

  # ── PostgreSQL (internal only — never published) ─────────────────────────────
  db:
    image: mirror.soroushasadi.com/postgres:16-alpine
    container_name: hamkadr_db
    restart: unless-stopped
    environment:
      POSTGRES_DB: ${POSTGRES_DB:-hamkadr}
      POSTGRES_USER: ${POSTGRES_USER:-hamkadr}
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
    volumes:
      - hamkadr_db_data:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER:-hamkadr} -d ${POSTGRES_DB:-hamkadr}"]
      interval: 5s
      timeout: 5s
      retries: 20

volumes:
  hamkadr_db_data:
    name: hamkadr_db_data
