Repository navigation
feat(deploy): blue/green backend deploys without downtime - #406
Merged
Merged
Conversation
- misc/bluegreen.yml: parkour2-django-blue/green from one image (pk2_prod target, code baked in, no bind mount) - nginx reads its upstream from misc/active/backend.conf; X-Pk2-Color header; worker_shutdown_timeout 180s - misc/bg-deploy.sh + make bg-init/bg-deploy/bg-rollback/bg-status/manage: backup, migrate+smoke on idle color, flip with traffic check, drain, retire - migration gate refuses schema-breaking migrations unless --compatible or --breaking (maintenance window) Sessions are DB-backed and SECRET_KEY is shared, so a flip logs nobody out.
check --database alone does not connect: a container with template DB credentials passes as healthy. Add --deploy and compare SECRET_KEY and DATABASE_URL between the live and idle containers before migrating, so a stale misc/parkour.env (dev hosts) fails the deploy instead of breaking sessions on the flip.
The check docker execs into , which the old position stopped first. Now the leftover container is only reported, and the comparison runs right after up --force-recreate.
…d template - bluegreen.yml env_file now points at the real, untracked parkour.env.ignore; make clean restores the tracked parkour.env template after every deploy, so containers created later got placeholder secrets - preflight requires parkour.env.ignore; parity guard also compares READONLY_DATABASE_URL - environment: still overrides env_file (INSTANCE_VERSION), checked on podman
- nginx -s reload only signals the master; the first request can still hit an old worker, which made the first pk2dev flip fail and auto-restore - wait up to 30s for 200 + new X-Pk2-Color, then require 20 consecutive matches
- dev hosts don't run the rsnapshot service; the deploy should not warn on missing container
- new check-not-bluegreen runs before down: if misc/active/backend.conf points at a -blue/-green container, make prod stops with the go-back recipe - without it make prod left nginx on the old color while the new parkour2-django ran unused
- misc/bg-nightly.sh: update code, import the production dump, restore it in one transaction, then bg-deploy - replaces the old nightly import-pgdb + dev-migras on a staging host; refuses to run on a dirty checkout or with a dump older than 60 min
…session) - bg-nightly.sh: pg_restore -l | grep -v django_session -> -L list, so the host's own logins survive the nightly refresh
- go-back test on pk2test showed make prod runs make down, which removes parkour2_pgdb - guard message now says to run make save-postgres first and restore after
- settings hardcode ALLOWED_HOSTS = ["*"] and never read it from the environment, so the comparison was always empty == empty - restore the trailing newline at the end of misc/bg-deploy.sh
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.
Adds an optional, per-host blue/green swap of the Django container. The stop-everything
make prodand theUpdatingwiki page stay valid and are the default; a host only changes aftermake bg-init.Why
make prodstops everything: downtime, dropped requests.SECRET_KEYis shared throughmisc/parkour.env.ignore, so a swap logs nobody out (prod:django_session, 2996 rows, 66 live).What
misc/bluegreen.yml:parkour2-django-blue/green, code baked into the image (pk2_prodtarget), no./backendbind mount. Env comes frommisc/parkour.env.ignore(the real file;misc/parkour.envis a template thatmake cleanrestores).misc/active/backend.conf;X-Pk2-Colorheader;worker_shutdown_timeout 180s.misc/bg-deploy.sh+make bg-init|bg-deploy|bg-rollback|bg-status|manage: backup (rsnapshot skipped if the container is absent), env parity check against the live color, migrate and smoke test on the idle color, flip with a 20-request check (auto-restore on failure), drain, stop the old color.--compatible(zero downtime) or--breaking(maintenance window).make prodrefuses on a host already in blue/green mode (it would leave nginx on the old color). Going back is documented in the wiki.misc/bg-nightly.sh: nightly staging refresh (git, prod dump restore excludingdjango_sessionso host logins survive, bg-deploy).Decisions
Blue-Green-Deployment;Updatingis untouched.docker system prune -a -f --volumesdeletes the stopped (rollback) color; replaced bydocker image prune -a -fon parkour, parkour-dev, parkour-test.Verified
502s in the nginx log,make bg-rollbackworks, env parity check, automatic restore after a failed traffic check.CreateModel): planned operations listed by the gate, applied on the idle color before the flip, new model usable after; rollback to the old image with the extra table stays healthy.RemoveFieldwithout a flag (rc=1, nothing applied, live color unchanged);--compatibleapplies and flips with zero downtime;--breakingstops the live color, migrates, flips (502 window measured < 1 s for two tiny migrations).max_migration.txtfails its healthcheck, the deploy refuses to flip and the live color keeps serving.502s.make prodreturns the legacy stack (documented dump/restore included,make proddeletes theparkour2_pgdbvolume), thenbg-init+bg-deployreturns to blue/green.misc/bg-deploy.shend to end under podman 5.8.2 (deploy, rollback, gate refusal,--compatible), plus the realbluegreen.ymland real nginx configs.Not verified yet
Deploy note
make bg-initonce: nginx now includesmisc/active/backend.conf. It recreates nginx (seconds of downtime).