# Test harness: pull the published BACKEND image and run it (+ a throwaway TimescaleDB)
# so the frontend's integration tests exercise the real HTTP contract instead of
# importing backend source. Used by scripts/backend-for-tests.sh; not a deploy file.
# The frontend itself is NOT a service here — the tests run the SSR app in-process
# (TestClient) with api_client pointed at this backend. DB data is tmpfs (ephemeral).
services:
  db:
    image: timescale/timescaledb:${TIMESCALEDB_TAG:-latest-pg18}
    environment:
      POSTGRES_USER: thermograph
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-testing}
      POSTGRES_DB: thermograph
    tmpfs:
      # pg18 places PGDATA in a version subdir under the mount — mount at /var/lib/postgresql.
      - /var/lib/postgresql
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U thermograph -d thermograph"]
      interval: 3s
      timeout: 5s
      retries: 20

  backend:
    # The published backend image is pulled (no local build). Default a published tag;
    # override THERMOGRAPH_BACKEND_TEST_TAG to pin a specific backend build (e.g. a sha).
    image: ${REGISTRY_HOST:-git.thermograph.org}/${BACKEND_IMAGE_PATH:-emi/thermograph-backend/app}:${THERMOGRAPH_BACKEND_TEST_TAG:-v0.0.2-split-ci}
    depends_on:
      db:
        condition: service_healthy
    environment:
      THERMOGRAPH_DATABASE_URL: postgresql+asyncpg://thermograph:${POSTGRES_PASSWORD:-testing}@db:5432/thermograph
      # Required at import; the frontend tests never drive the backend's reverse proxy,
      # so an unreachable placeholder is fine.
      THERMOGRAPH_FRONTEND_BASE_INTERNAL: http://127.0.0.1:1
      THERMOGRAPH_BASE: "/"
      THERMOGRAPH_ENABLE_NOTIFIER: "0"
      PORT: "8137"
      WORKERS: "1"
    ports:
      # Host port defaults to 18137 to avoid a dev server on 8137.
      - "127.0.0.1:${BACKEND_TEST_HOST_PORT:-18137}:8137"
