# POC deploy stack — global step 8 (deploy/spec.md, architecture.md §12).
# Three containers only: pds-keycloak (the PDS's own IdP), web-platform-stub, pds.
# The Angular SPA runs on the host via `ng serve`; Outil Local + Claude Desktop are
# native-Windows processes (architecture.md §12.0) reaching this stack over `localhost`
# (WSL2 port-forwarding) — neither belongs in this file.
#
# Address matrix: deploy/spec.md §3. Run `./gen-keys.sh` once before the first `up`.

services:
  pds-keycloak:
    image: quay.io/keycloak/keycloak:26.0
    command: start-dev --import-realm
    ports:
      - "8080:8080"
    environment:
      KEYCLOAK_ADMIN: admin
      KEYCLOAK_ADMIN_PASSWORD: admin
      KC_DB: dev-mem
      KC_HEALTH_ENABLED: "true"
      # Pins the issued-token `iss` to the container-network name regardless of whether a
      # client reaches this container via `localhost:8080` (host) or `pds-keycloak:8080`
      # (compose network) — resolves deploy/spec.md's D-4 issuer-uri mismatch without
      # needing `podman compose exec` for demo step 1's curl. KC_HOSTNAME_PORT is pinned
      # explicitly — Keycloak's hostname-v2 provider otherwise derives the default port from
      # the scheme (80/443), which would silently drop `:8080` from the issuer and break the
      # match against KC_ISSUER_URI below.
      KC_HOSTNAME: pds-keycloak
      KC_HOSTNAME_PORT: "8080"
      KC_HOSTNAME_STRICT_HTTPS: "false"
    volumes:
      - ../pds/docker/realm-export.json:/opt/keycloak/data/import/bqt-realm.json:ro
    healthcheck:
      # Keycloak 26 serves health/metrics on its separate "management interface" (port 9000
      # by default, see the boot log's own "Management interface listening on :9000" line),
      # not on the main :8080 HTTP port — and this image has no `curl`/`wget` at all (a
      # stripped-down base, confirmed live: `which curl` -> "executable file not found"), so
      # an HTTP-based probe isn't an option. A hand-built raw HTTP/1.1 GET against :9000 via
      # bash's /dev/tcp got a 400 from Quarkus's HTTP parser for reasons not visible from
      # outside (confirmed live, both with and without a matching Host header) — rather than
      # keep guessing at request formatting, this just checks the management port accepts a
      # TCP connection at all (bash's /dev/tcp, since kc.sh itself needs bash so it's always
      # present). Weaker than a true readiness probe, but sufficient to gate `pds`'s startup
      # for this POC's purposes — the import/boot sequence (~11s per a live boot log) is well
      # inside this healthcheck's own start_period before the port even opens.
      test: ["CMD", "bash", "-c", "exec 3<>/dev/tcp/127.0.0.1/9000"]
      interval: 10s
      timeout: 5s
      retries: 12
      start_period: 60s

  web-platform-stub:
    build: ../platform/stub
    ports:
      - "3000:3000"
    environment:
      PLATFORM_ISSUER: https://veritia.eu
      PDS_MCP_URI: http://localhost:8081/mcp
      PDS_DISCOVERY_URI: http://pds:8081/mcp
      SIGNING_KEY_PATH: /keys/platform-signing.jwk.json
      PDS_ASSERT_URI: http://pds:8081/account-link/assert
      PDS_ASSERTION_JWKS_URI: http://pds:8081/pds-jwks.json
      PDS_ASSERT_DEV_SECRET: poc-dev-secret
    volumes:
      - ./keys:/keys:ro

  pds:
    build: ../pds
    ports:
      - "8081:8081"
    environment:
      KC_ISSUER_URI: http://pds-keycloak:8080/realms/bqt
      MCP_CANONICAL_URI: http://localhost:8081/mcp

      PLATFORM_JWKS_URI: http://web-platform-stub:3000/jwks.json
      PLATFORM_INTROSPECT_BASE: http://web-platform-stub:3000/introspect
      PLATFORM_EXPECTED_ISS: https://veritia.eu
      PDS_PROVIDER_ID: 9b7c1e40-2f6a-4c11-9e2a-000000000bqt
      PDS_ASSERT_DEV_SECRET: poc-dev-secret
    volumes:
      - ./data:/app/data
    depends_on:
      pds-keycloak:
        condition: service_healthy
