Skip to content
Building the Image in CI and Shipping It Over SSH

24 November 2026 · 2 min read

Building the Image in CI and Shipping It Over SSH

ci-cddockerinfrastructure

The server that runs this site has about 3.8 GB of memory and shares it with other apps. A next build wants roughly 1.5 to 2 GB of that. Building on the host meant every deploy competed with the things that were supposed to keep running.

The change#

The host no longer builds anything. The deploy workflow now does three steps:

  1. Build the runtime image on the CI runner, tagged with the commit SHA.
  2. Ship it: docker save, compressed with zstd, piped over SSH into docker load on the host. Production is untouched by this step, so if it fails the job fails and nothing has changed.
  3. Deploy on the host: record the image the running container uses as the rollback target, check the new SHA's image is actually loaded, point latest at it, run the migrations, start the new container, and wait for the health gate. If the gate fails, the script rolls back to the previous image.

Pinning the host key#

Shipping over SSH from a runner makes host authentication matter. The step uses StrictHostKeyChecking=yes with a pinned host key committed in the repository. The key is public, so it is not a secret, and there is no trust on first use. If the server is rebuilt and its key changes, deploys fail closed with a host key error until the file is updated in a reviewed pull request. That is the behaviour I want from a deploy path: an unexpected key stops the deploy instead of being accepted.

Keeping the disk from filling up#

Shipping whole images adds up. After a successful deploy, earlier SHA tags are removed and dangling images pruned, so only latest, previous and the current one remain. A run that fails midway leaves its image until the next successful deploy, which is an acceptable cost for not deleting things during a failure.

The small details that mattered#

  • Only public NEXT_PUBLIC_* values are build arguments. Server secrets are never baked into the image.
  • compose up and the rollback use --no-build, so nothing on the host can quietly start building again.
  • A step checks the image is present before switching, and the runbook says what the "is not loaded" error means.

The result is a deploy that spends the runner's memory instead of production's, and fails in places where failing is harmless.