Disimula – A Party Game of Secret Missions

Disimula – CI/CD

Path-filtered workflows per component, images in GHCR, automatic deploys to dev on every push and one-click production on a self-hosted runner at home.

CI/CD pipeline

One workflow per component

Each folder of the monorepo has its own workflow, triggered only by changes under its path (and by pull requests, which only check):

WorkflowChecksPublishes
Backend./mvnw verify: unit tests, ArchUnit rules, integration tests against PostgreSQL in Testcontainers; test reports uploaded on failureghcr.io/…-backend
FrontendESLint, then next build inside the image buildghcr.io/…-frontend and ghcr.io/…-automation (a matrix: the app and the AI worker)
Onlinetype checking, the room's rules with Node's test runner, build, wrangler deploy --dry-run(deployed by the deploy workflows)
Landinglint, type check, static build, wrangler deploy --dry-run(deployed by the deploy workflows)
Infratofu fmt -check, tofu validate for every environmentplan on PRs; on main, dev applies by itself and production waits for approval

Images get two tags: sha-<commit> (immutable, for pinning and rollbacks) and latest (only from the default branch). Pull requests build the image to prove it builds, but never push it. Builds use the GitHub Actions cache per image.

Concurrency groups cancel a superseded run of the same branch, but never cancel an OpenTofu apply or a deploy halfway.

Deploy dev: every push, automatically

Deploy dev runs on workflow_run after any of the five workflows completes on main, and on pushes that change the stack definition (deploy/**). It only deploys what a successful push run actually published: workflow_run fires for failures and pull requests too, and those are filtered out. One deploy at a time; builds finishing together queue up.

Deploy production: by hand

Deploy production is workflow_dispatch only, and refuses to run from any branch but main. Once dev looks right, it puts the images dev is running, by digest, in production: it reads them from dev's containers on the same server, so a push to main after dev was checked (which moves latest) never reaches production unseen. The run's summary lists each digest and the commit it was built from; if dev does not run one of the services, the deploy stops. (The Workers and the landing page are still built from main at that moment.) It has a dry-run option that only writes ~/disimula/.env.next and lists the setting names that would appear or disappear: the safe way to check a change of PROD_* secrets.

The reusable deploy

Both call deploy-env.yml with the environment's name, settings prefix and compose project:

1. Stack on the home server (self-hosted runner, label home)

  1. Restore the OpenTofu state (a composite action installs OpenTofu, derives the R2 credentials and runs tofu init).
  2. Write the env file from every <ENV>_* secret and variable plus the state's outputs. It checks that what the compose files require is present before writing anything, and refuses to change the database password or backup passphrase.
  3. Use a Docker config of the job's own, so no other job's docker logout can drop this login mid-pull, and log in to GHCR. Production then pins the images to the digests dev runs.
  4. docker compose pull, then docker compose up -d --build --remove-orphans --wait: the deploy fails if any service is not healthy within 4 minutes, including the backup service when the last backup is too old.
  5. Record every running image's digest in the log, for audits and rollbacks; prune old images.

2. Workers (GitHub-hosted runner)

The server needs no Node.js: the Workers are published from GitHub's runners with Wrangler.

  • Online games Worker: npm ci, build, deploy, then set its PUSH_TOKEN secret from the state (the same value as the backend's ONLINE_TOKEN). The secret goes after the deploy because it needs the Worker to exist.
  • Landing page: built with this environment's app URL, then deployed.
  • A small retry wrapper handles Cloudflare's 10007 error on a Worker's very first deploy ("does not exist on your account", a race right after upload): only that error is retried, with back-off.

3. Observability (production only)

After the app, the observability stack is pulled and validated by deploy/observability/check.sh, which loads Alloy's config and every dashboard and alert rule in a throwaway Grafana. A broken file stops the deploy and leaves the running stack as it was. It is skipped (with a notice) until a Grafana admin password is configured, and warns when the Telegram token or the heartbeat URL are missing.

Reset dev

Reset dev (type reset to confirm) runs the same deploy with docker compose down --volumes first: dev comes back empty with its seed data. The generated database password lives in the state, so the state of an environment whose database you keep is never destroyed.

Rollback

  • App: set PROD_BACKEND_TAG=sha-1a2b3c4 (or FRONTEND_TAG, AUTOMATION_TAG) and run Deploy production: a pin wins over promoting dev's digests. Tags are in GHCR; digests are in each deploy's log.
  • Settings: ~/disimula/.env.previous is the last env file; copy it back and docker compose up -d.
  • Database: deploy/restore.sh, see infrastructure.

Supply chain

  • Every third-party Action is pinned by commit SHA with the version as a comment.
  • Workflows declare least-privilege permissions (contents: read; packages: write only where images are pushed).
  • Third-party images (Postgres, cloudflared) and Dockerfile base images are pinned by digest.
  • Dependabot groups updates per ecosystem (Actions, npm per app, Maven, Docker, compose) to keep the PR count low; majors come one by one.