# svc-study-workspace deployment

ECS Fargate service following the shared `deploy-ecs.yml` conventions (family
`<env>-svc-study-workspace`, log group `/ecs/oshun-<env>/svc-study-workspace`,
image `<ecr>/oshun/svc-study-workspace:<tag>`, built with
`docker/Dockerfile.node`).

**The build works, as of 2026-08-15, and did not before.** That is worth stating
because none of the prerequisites below mentioned it: `nx build` failed with
TS6059 on every experience-plane module the service imports — the `@nx/js:tsc`
executor pins `rootDir` to the app and each of those libraries is a SOURCE
library — so there was no artefact for any of this to deploy. It builds with
`tsup` now, into the **package-local `dist/`** shape `Dockerfile.node` prefers,
with `dist/index.js` as the entrypoint its `CMD` already looks for. Every npm
package the bundle reaches is declared here and held by
`src/packaging/artifact-dependency-closure.spec.ts`, because bundling turns a
library's dependencies into this service's and pnpm will not resolve one that
was never declared.

**Registration is deliberately not wired yet.** Enabling deployment requires, in
order:

1. The YSD-0120/0122 blocking decisions approved
   (`node tools/yemaya-study/check-decision-log.mjs --enforce-rollout` must pass
   — this command is the rollout gate and MUST be a job step in any workflow
   that deploys this service).
2. Adding the service to the `deploy-ecs.yml` resolve case statement:
   `svc-study-workspace) NAME="@yemaya/svc-study-workspace"; PATH_="apps/yemaya/svc-study-workspace" ;;`
3. Terraform service/target-group entries via `infra/terraform/ecs-services`
   (YSD-1010 lands the CI/CD wiring).

## Container contract

- Listens on `PORT` (default 4020), host `0.0.0.0`.
- **Liveness:** `GET /health` → 200 (process identity, version, uptime).
- **Readiness:** `GET /ready` → 200 only when every configured dependency probe
  passes; 503 otherwise. ALB health checks should target `/ready`.
- **Metrics:** `GET /metrics` (Prometheus text format).
- **Shutdown:** SIGTERM → drains in-flight requests for `SHUTDOWN_GRACE_MS`
  (default 10s, hard-capped at 25s to stay inside the ECS 30s stopTimeout),
  closes the Postgres pool, exits 0.
- **Configuration:** validated at startup (`src/config.ts`); the task fails fast
  with a readable report on missing/inconsistent values. Production requires
  `DATABASE_URL` (from Secrets Manager via the task definition) and structured
  JSON logs.
