Skip to content

fix(docker): real multi-stage image with HEALTHCHECK + relocatable config (#73)#80

Merged
JumpTechCode merged 3 commits into
mainfrom
fix/docker-multistage-healthcheck
Jun 16, 2026
Merged

fix(docker): real multi-stage image with HEALTHCHECK + relocatable config (#73)#80
JumpTechCode merged 3 commits into
mainfrom
fix/docker-multistage-healthcheck

Conversation

@JumpTechCode

Copy link
Copy Markdown
Collaborator

Closes #73.

The Dockerfile was the single-stage editable-install skeleton (it said so in its own header) with no HEALTHCHECK, while the project status table marked the production image "Landed." This makes the claim true.

What changed

  • Multi-stage build. Builder compiles a non-editable pip install . into an isolated /opt/venv and pre-downloads the fastembed model; the slim runtime copies only /opt/venv + the model cache (no build tooling, no source tree leaks), runs as the non-root sentinel user, and bakes a HEALTHCHECK hitting /healthz (liveness — /readyz depends on Postgres/Redis/Kafka and would wedge the container as unhealthy before deps connect).
  • Relocatable config (found in review). The non-editable install moves the package into site-packages, which silently broke the per-env YAML loader: Path(__file__).resolve().parents[2]/"config" resolved to site-packages/config/ instead of the COPY'd /app/config. Added a SENTINEL_CONFIG_DIR override (defaults to the in-tree path for local/dev/test) and set it in the image.
  • Tests. CI never builds the app image (it runs the app from a host venv, compose only starts pg/redis/kafka), so tests/unit/test_dockerfile.py is a contract test guarding the structural claims (multistage, COPY --from, HEALTHCHECK, non-root, no editable install). test_config_dir_env_override guards the config-dir resolution regression.

Verification (local, since CI can't build the image)

  • docker build succeeds; runs as sentinel; from sentinel.api.app import build_app; build_app() imports clean (non-editable install + all deps); curl present; /opt/fastembed cache present (1.3G); HEALTHCHECK in image metadata; no /build leakage.
  • load_settings() resolves config inside the container (was a silent no-op before the fix).
  • Full unit suite: 502 passed, 84.76% coverage; ruff + mypy --strict clean.

Review follow-ups (deliberately out of scope)

  • Dependency pinning / lockfile — the build resolves version ranges fresh each time (not reproducible). Pre-existing (ranges predate this PR) and overlaps CI: add dependency-vulnerability and container-image scanning (pip-audit + image scan) #74 (dependency-vuln + image scanning). Left as follow-up.
  • Image-build CI smoke — a job that builds the image and runs load_settings() would be stronger than the unit-level contract test, but adds a slow (~60s model download) job to every PR. Tracked thought, not done here.

🤖 Generated with Claude Code

JumpTechCode and others added 3 commits June 16, 2026 00:51
…nfig (#73)

The Dockerfile was the single-stage editable-install skeleton with no
HEALTHCHECK, while the project status table claimed the production image had
landed. Make the claim true.

- Multi-stage build: the builder compiles a non-editable install into /opt/venv
  and pre-downloads the embedding model; the slim runtime copies only those
  artifacts (no build tooling leaks), runs non-root, and bakes a /healthz
  HEALTHCHECK (liveness — /readyz depends on external deps).
- The non-editable install relocates the package into site-packages, which
  broke the per-env YAML loader's __file__-relative config-dir resolution (it
  resolved to site-packages/config, not the COPY'd /app/config — a silent
  no-op). Add a SENTINEL_CONFIG_DIR override and point the image at /app/config.
- CI never builds the app image, so a contract test guards the structural
  claims (multistage, copy-from-builder, HEALTHCHECK, non-root, no editable
  install); a regression test guards config-dir resolution.

Verified locally: image builds, runs as `sentinel`, imports build_app, model
cache present (1.3G), HEALTHCHECK in metadata, and load_settings() resolves
config inside the container.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@JumpTechCode
JumpTechCode merged commit 751d20f into main Jun 16, 2026
6 checks passed
@JumpTechCode
JumpTechCode deleted the fix/docker-multistage-healthcheck branch June 16, 2026 07:20
JumpTechCode added a commit that referenced this pull request Jun 16, 2026
…ion from #80) (#82)

The multistage image (#80) switched to a non-editable `pip install .`. setuptools
packages only *.py by default, so `sentinel/diagnosis/prompts/v1.md` (+ its
`.sha256` baseline) — read at boot by PromptBundle.load via a package-relative
path — was dropped from the wheel, and the production image crashed on startup:

    FileNotFoundError: .../site-packages/sentinel/diagnosis/prompts/v1.md

The #80 verification used a build_app() import smoke, which doesn't run the
lifespan where PromptBundle.load lives — so the crash only surfaced on a real
container boot.

- Declare the prompts as package-data so the wheel ships them. The eval
  corpus/cassettes are deliberately left out (dev/CI-only, run from source).
- Contract test guards the declaration (CI never builds the wheel).

Verified: `pip wheel .` now contains v1.md + v1.sha256; the rebuilt image boots
healthy and the full webhook → diagnosis demo works end-to-end.

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Docker: single-stage editable-install skeleton, no HEALTHCHECK; status table overstates it

1 participant