chore(deploy): automate alembic migrations across k8s and docker-compose#7
Merged
AdamDiStefanoAI merged 1 commit intomainfrom Apr 8, 2026
Merged
chore(deploy): automate alembic migrations across k8s and docker-compose#7AdamDiStefanoAI merged 1 commit intomainfrom
AdamDiStefanoAI merged 1 commit intomainfrom
Conversation
Schema migrations were a manual step ("run alembic upgrade head before
the gateway") that's easy to forget on deploy. Bake the step into both
deployment surfaces so it can't be skipped.
* scripts/run-migrations.sh — shared entrypoint that resolves the app
root, asserts DATABASE_URL, and runs `alembic upgrade head`. Idempotent
by design (Alembic wraps each migration in a transaction; replicas
racing each other are safe). Used by every surface below.
* Dockerfile — installs the script onto PATH as `run-migrations` in
the runtime image, so the same image services both the gateway
process and the migration job without a second build.
* deploy/k8s/base/gateway-deployment.yaml — adds an `alembic-upgrade`
initContainer that runs `run-migrations` before the gateway container
starts. Inherits the same configmap+secret as the gateway, so the
database URL never drifts. Same hardened securityContext (non-root,
read-only root fs, all caps dropped).
* docker-compose.yml — adds a one-shot `acr-migrate` service that runs
`run-migrations` and exits. The `acr-gateway` service now waits for
it via `service_completed_successfully`, so `docker compose up` will
always apply pending migrations before starting the gateway.
The production default of SCHEMA_BOOTSTRAP_MODE=validate (set by
effective_schema_bootstrap_mode in config.py) means the gateway will
already refuse to start with a missing schema — this PR makes the
"missing schema" failure path impossible to hit by ensuring migrations
are always applied first.
Verified: alembic chain ends at 0012 (head), all 28 identity tests
pass, both YAMLs parse cleanly.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Schema migrations were a manual step ("run `alembic upgrade head` before the gateway") that's easy to forget on deploy. This PR bakes the step into both deployment surfaces so it can't be skipped.
Changes
scripts/run-migrations.shDockerfiledeploy/k8s/base/gateway-deployment.yamldocker-compose.ymlWhy this works
Test plan
🤖 Generated with Claude Code