Skip to content

Deploy workflows: preflight the settings load before replacing the site - #1465

Merged
jonfroehlich merged 2 commits into
masterfrom
1460-deploy-preflight
Nov 22, 2026
Merged

jonfroehlich merged 2 commits into
masterfrom
1460-deploy-preflight

Conversation

@jonfroehlich

@jonfroehlich jonfroehlich commented Nov 21, 2026 •

Copy link
Copy Markdown
Member

Part of #1460. Follow-up to #1464.

What changed

Both deploy workflows get one step between docker compose build website and docker compose up -d:

docker compose run --rm --no-deps -T website python scripts/preflight_settings.py

It loads the Django settings in a throwaway container using the host's real config.ini mount, environment and container user. Since 2.35.3, settings refuse to load on test/prod without a readable config.ini that sets SECRET_KEY and ALLOWED_HOSTS. Before this change that refusal was invisible: up -d returns before the app boots, so the job went green and the site answered 502/503. Now a bad config fails the job at this step with the reason in the Actions log.

  • --no-deps keeps it from starting or touching the database.
  • The log is public, so nothing from config.ini is ever printed. configparser quotes the bad line or value in its own errors, so settings.py now reads the file only through a guarded read and safe_config_get(), which report the error type alone. The script prints no tracebacks.
  • Bypass: setting the repository variable SKIP_DEPLOY_PREFLIGHT to true skips the step without a commit, in case the step itself ever misfires.

What a failure means

The running container is not replaced and normally keeps answering. It is, however, already running on top of the new checkout (/code is bind-mounted), so it can go down at its next worker respawn or restart. Fix the config or revert promptly.

Verification

Run in a container against the project image:

Config Exit Output
valid SECRET_KEY + ALLOWED_HOSTS 0 PREFLIGHT OK
no SECRET_KEY 1 names the missing setting
bare % in the key 1 error type only, no value
no [Django] header 1 error type only, no file contents
bad % in a [Postgres] password 1 error type only, no value

The first three were also run through docker compose run itself under a separate project. Not verifiable before merge: the step on the CSE self-hosted runners. PR CI does not run the deploy workflows, so the first real run is the -test deploy when this merges.

Review

An independent review (Opus 5.5, claude-opus-5-5) led to the second commit: the value-safe config reads and script, corrected failure-mode wording, the bypass variable, and doc updates. Left as follow-ups: widening the preflight to django.setup(), and making a missing CONFIG_PATH a compose error instead of an auto-created directory.

No version bump: no change in site behaviour.

🤖 Generated with Claude Code — Fable 5.2, claude-fable-5-2

Adds a step between `docker compose build` and `up -d` in both deploy
workflows that imports makeabilitylab.settings in a throwaway container
(--no-deps, real mounts/env/user). A config.ini that the 2.35.3 guard
rejects now fails the job with the reason in the log and leaves the
running container alone, instead of a green deploy and a 502.

Tested locally against the built image: valid config exits 0; a config
without SECRET_KEY exits 1 with the ImproperlyConfigured message; a
missing config path exits 1.

Part of #1460.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…ocs; bypass

From an independent review of this branch:
- configparser errors quote the offending line/value, and the preflight
  prints to a public Actions log. config.ini is now read only through a
  guarded read and safe_config_get(), which re-raise ImproperlyConfigured
  with the error type only (`from None`). Covers SECRET_KEY, ALLOWED_HOSTS
  and the optional [Postgres] credentials. 3 new tests.
- The step runs scripts/preflight_settings.py instead of a bare import: it
  prints the exception type, the message only for ImproperlyConfigured, and
  never a traceback.
- Docs/comments no longer claim the site simply "stays up": the old
  container keeps running but on the new checkout.
- SKIP_DEPLOY_PREFLIGHT repository variable bypasses the step without a commit.
- Docs: deploys are GitHub Actions workflows, not webhooks/deploy emails.

Verified in a container against five configs (valid, no key, bare % in key,
no section header, bad % in Postgres password): correct exit codes, no
config text in any output.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@jonfroehlich
jonfroehlich merged commit 04dfc55 into master Nov 22, 2026
5 of 6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant