An engineer in a home workshop swaps one of two brass engine cylinders while the other keeps running, behind a rail of green checkpoint lamps; the machine projects a cartoon golf match onto a screen One machine, two copies of the app: one is swapped while the other keeps the show running.

EyeOnMajors replaces its app one container at a time, checks each new one, and puts the old one back in seconds if the new one doesn’t come up. There’s no Kubernetes: it’s a few hundred lines of shell, proved on staging with the logs below. (The short version for players is in the changelog: Site updates no longer take the site down.)

The setup #

EyeOnMajors is a Rails app for a fantasy golf game played during golf’s four majors: you pick a team of six golfers, and your group follows their scores live. It runs at home, on one Mac mini:

flowchart LR
  visitor((Visitor)) --> cf[Cloudflare]
  cf -- "Cloudflare Tunnel<br/>(no open router ports)" --> nginx
  subgraph mini["Mac mini · rootless Podman"]
    nginx[nginx] --> app1[app1 · Rails]
    nginx --> app2[app2 · Rails]
    worker["worker<br/>(background jobs)"]
    app1 --> pg[(Postgres)]
    app2 --> pg
    worker --> pg
    app1 --> redis[(Redis)]
    app2 --> redis
  end

Everything runs on one machine; Cloudflare reaches it through a tunnel.

  • Podman (rootless) runs everything as containers: nginx in front of two identical Rails app containers, a background-job worker, Postgres and Redis. A separate staging copy, with a copy of production’s data, runs on the same machine.
  • A Cloudflare Tunnel carries traffic from Cloudflare to nginx, so nothing on the home router is open to the internet.
  • GitHub Actions runs the deploy on the Mac mini:
    1. A push to the staging branch deploys staging. A push to main deploys production, and only after the change has been checked on staging.
    2. The deploy only runs once CI (tests, linters, security scans, the Android build) has passed for that exact commit, and only if that commit is still the newest on the branch.
    3. Production takes a database backup first.
    4. Then comes the rolling deploy below.

Why #

Before this change, a production deploy built the new version, replaced app1, waited for it, then replaced app2. If app1 didn’t come up, the deploy stopped and left it dead: the site ran on app2 alone, and getting app1 back meant a manual redeploy. The automatic rollback added just before this (off for production) rebuilt the whole previous version and restarted both containers, which could blip the site while it ran. And it decided what “the previous version” was by asking the site once, so it got whichever container answered.

How the rolling deploy works #

bin/rolling-deploy (called by bin/deploy) works in this order:

  1. Recover first. If an earlier deploy was killed half way, it puts back anything that deploy left mid-swap before doing anything else.
  2. Record the starting state. For each app container: is it running and answering, which commit is it on, and which image. A container that is healthy now is its own rollback target.
  3. Build the new images. If the build fails, nothing running has been touched.
  4. Swap app1:
    • stop it and rename it …-old: it’s kept, not deleted;
    • start the new app1, and check it directly, inside the container: it answers, reports the new commit, and runs the image just built;
    • reload nginx so it sends traffic to the new container.

    If the check fails, the script removes the new container, renames the old one back and starts it. That’s the rollback: the exact old code, in seconds, with no rebuild. app2 served the whole time.

  5. Swap app2 the same way. If it fails, it’s put back, and then app1 is put back too, so both end on the same version.
  6. Worker: only after both app containers pass is the background worker swapped, the same way.
  7. Clean up: remove the -old containers and tag the images with the commit.

Some rules it never breaks:

  • It never stops a container unless the other one is answering.
  • :latest always points at the image that is actually running, so a reboot or a manual restart can’t start code that was never checked.
  • A manual deploy of an older commit (the way to roll back by hand) uses the same rolling deploy.
  • The job goes red with a plain message whenever a deploy didn’t go through, saying what is running.

What a commit must pass before it can deploy #

The rolling deploy is the last step. Before it, every change goes through the same checks, and the deploy job refuses any commit that hasn’t passed them: it looks up the CI and Android runs for that exact commit, and stops unless both are green. A change goes to staging first, and is merged for production only after it has been tried there. Each check is there because it catches something the others can’t:

Check What it catches
Tests (Minitest) About 500 tests that models, controllers and pages behave as they should
System tests (headless Chrome) Flows that need a real browser: sign-in, buttons, JavaScript
Every migration, from an empty database Migrations that only work on a developer’s database, or that don’t match the committed schema. strong_migrations refuses changes the previous release couldn’t run against
Brakeman Rails security mistakes found by reading the code: SQL injection, cross-site scripting, unsafe redirects
bundler-audit and importmap audit Ruby gems and JavaScript packages with known security advisories
RuboCop and ESLint Ruby and JavaScript style and common errors
Herb The HTML templates: unsafe raw output, invalid HTML, accessibility rules. It fails on warnings, not just errors
ShellCheck and the deploy scripts’ own tests Shell mistakes in bin/deploy and bin/rolling-deploy, and the failure paths described below
The production image The real container image is built and started the way production starts it, and must answer its health check
Android (lint, unit tests, a build) The native app and the routes it shares with the site

The fast ones also run on the laptop, as git hooks managed by Lefthook, so most problems are caught before they ever reach CI:

Hook What runs
Every commit RuboCop on the changed Ruby files, Herb on the changed templates, and the native app’s checks when its files changed
Every push Brakeman, bundler-audit, importmap audit, and the native-app request tests

The commit hooks check only the changed files, in parallel, so a commit waits a second or two. Hooks can be skipped on a laptop, which is exactly why CI runs every check again: the hooks are for speed, and CI is the gate.

Code is increasingly written and reviewed with AI coding agents now. That makes the guardrails matter more, not less: an agent can write a lot of plausible code quickly, and these checks hold it to the same bar as anything written by hand.

None of this proves a feature is right. That’s what trying it on staging is for. What it does prove is that the commit being deployed is the one that was tested, and that it passed everything above.

Proof: staging, with the logs #

Each run below is a real deploy to staging, with two small tools running on the Mac mini: poll.sh sends a request to the site every half second, like a visitor, and snapshot.sh records every container’s ID, image and commit before and after.

A normal rolling deploy #

[rolling-deploy staging] app1: golfmajors-app1-staging is healthy on 0d47d0c (image 9536368707f6); restore target
[rolling-deploy staging] app2: golfmajors-app2-staging is healthy on 0d47d0c (image baee11dfbb20); restore target
[rolling-deploy staging] deploying 7c2774b Rolling deploy: refuse while nginx depends on app containers; ...
[rolling-deploy staging] building app1-staging app2-staging
[rolling-deploy staging] swapping app1 (golfmajors-app1-staging)
[rolling-deploy staging] app1 is healthy on 7c2774b
[rolling-deploy staging] swapping app2 (golfmajors-app2-staging)
[rolling-deploy staging] app2 is healthy on 7c2774b
[rolling-deploy staging] deployed 7c2774b: app1 app2 healthy
[deploy staging] healthy: http://localhost:9080 serves 7c2774b

app1 fails: it’s put back, and app2 keeps serving #

A staging-only simulate_unhealthy=app1 input makes the new app1 fail its check on purpose:

[rolling-deploy staging] swapping app1 (golfmajors-app1-staging)
[rolling-deploy staging] SIMULATE_UNHEALTHY: treating the new app1 as unhealthy
[rolling-deploy staging] restoring app1 to its old container (de6cc09)
##[error][rolling-deploy staging] app1 failed on 7c2774b; restored to de6cc09; app2 kept serving
##[error][deploy staging] deploy of 7c2774b failed; the old version was put back and is serving

The snapshots show it’s the same container and image as before the deploy, not a rebuild, and app2 was never restarted:

before:  golfmajors-app1-staging 47940905148b 39993baca22f Up 46 seconds (healthy)
         golfmajors-app2-staging 46521e70c074 e86eb95c830c Up 40 seconds (healthy)
after:   golfmajors-app1-staging 47940905148b 39993baca22f Up 15 seconds
         golfmajors-app2-staging 46521e70c074 e86eb95c830c Up About a minute (healthy)

app2 fails: both are put back #

[rolling-deploy staging] swapping app1 (golfmajors-app1-staging)
[rolling-deploy staging] app1 is healthy on 7c2774b
[rolling-deploy staging] swapping app2 (golfmajors-app2-staging)
[rolling-deploy staging] SIMULATE_UNHEALTHY: treating the new app2 as unhealthy
[rolling-deploy staging] restoring app2 to its old container (de6cc09)
[rolling-deploy staging] putting app1 back on its old container too, so both run de6cc09
##[error][rolling-deploy staging] app2 failed on 7c2774b; both app containers restored to de6cc09

Both ended on their original container IDs (47940905148b, 46521e70c074) and images.

A guard that stopped a deploy before it could do harm #

The first staging runs turned up something no fake test could have: staging’s nginx had a compose depends_on on the app containers, which Podman records against the exact containers. The replaced containers could never be removed, and restarting nginx would have started them again. The script now checks for this before touching anything:

##[error][rolling-deploy staging] golfmajors-nginx-staging depends on golfmajors-app2-staging-old (a compose depends_on):
         recreate golfmajors-nginx-staging without it first (...), then remove any '-old' app containers
##[error][deploy staging] deploy of 7c2774b failed before anything changed

Production’s nginx never had that dependency, and staging’s compose file now matches it.

Does the site ever go down? #

Mostly no, but not never. Across the six staging deploys above, the poller sent about 1,800 requests (a page load and a form POST every half second):

Deploy Requests Didn’t answer within 15 s
Normal 256 1
Older commit, by hand 286 1
app1 fails, put back 108 1
app2 fails, both put back 118 2
Cancelled 128 1
Normal again 136 1

Every other request answered normally, typically in under a tenth of a second. The few that hung were sent at the moment a container stopped: nginx still had that container’s address and waited for a connection that would never answer, for up to 60 seconds before trying the other container. So about one visitor per deploy waits much longer than usual, then most likely gets the page from the other container. Rarely, a request already in progress on the stopping container can fail. Deploys had the same window before this change, and nginx only learned the new addresses at the very end.

The fix is known and small: take a container out of nginx’s rotation before stopping it, and use a 2-second connect timeout. It’s parked for now.

What it doesn’t do #

  • Database migrations aren’t undone. A new version’s migration runs when its first container starts. If the deploy is then put back, the old code runs on the newer schema. That works as long as migrations only add things (columns are removed in a later release, once nothing uses them). strong_migrations and a CI step that runs every migration now enforce that rule (the changelog entry has the short version).
  • “It starts but a feature is broken” isn’t caught. The check proves the container starts and serves the right version. Features are covered by the test suite and by trying the change on staging first.
  • Cancelling the GitHub job doesn’t interrupt a deploy. In the staging test the deploy finished, and then the job showed as cancelled. That’s the safe outcome. The script also cleans up after a deploy that really is killed (a reboot mid-deploy) the next time it runs.
  • One Mac mini is one Mac mini. Power, disk and the home connection are still single points of failure.

Why not Kubernetes? #

The goal is a practical, robust setup on one machine. Kubernetes would bring real things: rolling updates that start the new container alongside the old one, readiness checks wired into the load balancer, self-healing, and everything declared in one place. But on one machine it wouldn’t protect against the machine itself, it doesn’t solve database migrations, and it can’t tell that a running feature is broken. It would also add a control plane competing for the Mac mini’s memory, its own upgrades and failure modes, and far more to debug late at night. For one app on one box, a rolling deploy with a direct health check and a kept-around old container gets most of the benefit in a few hundred lines you can read.

How it was tested #

  • test/deploy/rolling_deploy_test.sh runs bin/rolling-deploy against a fake podman and podman-compose that keep containers, images and nginx in a temp directory. It covers 22 scenarios, including each failure path, recovery from a killed deploy, a signal during the build and during a swap, and the lock. Several tests were checked by removing the fix they guard and watching them fail.
  • test/deploy/deploy_test.sh runs bin/deploy (the lock, the exact-commit checkout, the hand-off, the final check) against a throwaway repo and a fake site.
  • Both run in CI with ShellCheck.
  • What the fakes can’t show (container networking after a rename, Podman’s dependency records, podman-compose’s own behaviour, nginx’s real timing) is why the staging proof above exists. It found the depends_on problem and a cleanup bug the fakes had hidden.

The proof tools #

  • poll.sh STOPFILE: every half second, a GET of the home page and a POST without a CSRF token (Rails answers 422). nginx doesn’t retry a POST once it has reached a container, so it shows whether in-flight requests are dropped. It writes one line per request: the time, method, status (000 means no answer) and seconds.
  • snapshot.sh LABEL: every staging container’s name, ID, image and status, each app container’s commit, nginx’s config checksum and the addresses it resolves, and what each :latest tag points at. A restored container keeps its ID and image; Postgres, Redis and nginx keep theirs.

Run the poller during a deploy, take a snapshot before and after, and compare.