Skip to content

Make prod deploys work from a clean checkout of main#66

Merged
aperson30 merged 1 commit into
mainfrom
fix/prod-deploy-hardening
Jul 12, 2026
Merged

Make prod deploys work from a clean checkout of main#66
aperson30 merged 1 commit into
mainfrom
fix/prod-deploy-hardening

Conversation

@aperson30

Copy link
Copy Markdown
Collaborator

Why

Production deploys had stopped taking effect. Root causes, all fixed here so a plain git pull + rebuild + restart of main serves correctly on the server with no manual patching:

  1. Backend wouldn't boot from a clean checkout. api_blueprint.py imports calculate_session_metrics from services.segmentation_metrics, but that module was never committed to the repo — so a fresh clone/checkout crashes on startup. Added a safe module; its only caller already falls back to frontend-supplied metrics, so behavior is unchanged where the file existed locally.

  2. /api/get-segmentations 500'd on the server. It wrote the uint8-converted mask as a sibling inside the dataset's mask_only/, which is read-only on the server (and writing there violates the never write into image_only/mask_only rule). Now caches the converted copy in /tmp instead.

  3. Deploy runbook hardened (README.md): check out main before pulling (prod had drifted onto an old branch), free the gunicorn port reliably on restart, and verify ping + search + segmentations after each deploy.

Testing

  • python -m py_compile passes on both changed Python files.
  • Equivalent changes already applied live on the server: backend boots, /api/search returns cases, and /api/get-segmentations/17.nii.gz returns 200 with masks rendering in the viewer.

Three fixes so a fresh 'git pull' + rebuild + restart of main serves correctly
on the server, without manual patching:

- Add services/segmentation_metrics.py. api_blueprint imported
  calculate_session_metrics from it, but the module was never committed, so the
  backend crashed on boot from any clean checkout. Provide a safe module whose
  only caller already falls back to frontend-supplied metrics.
- get-segmentations: cache the uint8-converted mask in /tmp instead of writing a
  sibling into the read-only mask_only/ data mount. The write 500'd the endpoint
  in production and violated the never-write-into-mask_only rule.
- README deploy steps: check out main before pulling, free the gunicorn port
  reliably on restart, and verify ping + search + segmentations after deploy.
@aperson30 aperson30 merged commit 3a73464 into main Jul 12, 2026
7 checks passed
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.

1 participant