Build once, inspect, transfer and release the same artifact
The source commit identifies code and configuration. uv.lock and hash-pinned requirements identify resolved Python dependencies. A Docker image ID identifies the loaded image configuration and its content-addressed layers.
Purpose: replace ad hoc target rebuilding with a traceable release. Prerequisites: local tests pass, the approved target runs the reference stack, backup/restore works and schema compatibility has been reviewed. Environment: a reviewed source checkout on an isolated builder, optional approved GitHub Actions repository, and a separate target host. Inputs: source revision, target architecture, release record, previous image identity and approved maintenance window. Status: the existing local checks are executed evidence; the workflow and target transfer below require installation in the selected repository/host and their own execution receipts.
1. Understand the artifact identities
The source commit identifies code and configuration. uv.lock and hash-pinned requirements identify resolved Python dependencies. A Docker image ID identifies the loaded image configuration and its content-addressed layers. A registry manifest digest identifies the registry's manifest object. A compressed exported archive has its own file checksum. Record all applicable identities rather than assuming they are interchangeable.
This tutorial uses a Docker archive, which can be delivered over SSH without publishing a registry package or giving the deployment host a registry push token. Its checksum detects alteration only when the expected checksum arrives through a trusted release record; an attacker who can replace both archive and checksum can forge that comparison. Preserve build provenance and approval separately. The supplied pytest -q ~/playground/automation-service/test_service.py expects a registry repository@sha256 identity and refuses remote Docker contexts. Use that helper only with an actual reviewed registry digest, not a substituted local image ID.
2. Build and export manually on an approved builder
Run from the VM workspace (`~/playground`) on the builder after verifying that this is the reviewed checkout. Choose the architecture of the actual target. A build made for arm64 is not automatically runnable on an amd64 VM; multi-platform builds require separate testing for each target.
git rev-parse uses the reviewed repository commit when available. A non-Git source archive takes the explicit alternate branch and identifies the packaged manifest by SHA-256 with a bundle prefix. Keep that manifest and the approved archive checksum together; do not describe the bundle identifier as a Git commit. The commands create new .env and .recovery/release-output state exclusively; if those already exist, inspect and use the existing known lab configuration or a fresh builder directory. Do not overwrite existing secrets to repeat a build.
The exported image contains application code and pinned installed dependencies; it must not contain .env, database dumps or signing keys. Review .dockerignore and Dockerfile before building. Run the completed image in staging with the same database/worker flow before promotion. The [Docker save](https://docs.docker.com/reference/cli/docker/image/save/) and [load](https://docs.docker.com/reference/cli/docker/image/load/) references define archive behavior.
Return to the VM workspace (`~/playground`) before continuing. The export block ended in .recovery/release-output, so run:
Before transferring the manually exported archive, run the same blocking vulnerability policy. The archive remains a quarantined candidate until this check passes. This uses the official Trivy container and reads the archive through a read-only mount; it does not receive the Docker socket or deployment credentials. Run from the VM workspace (`~/playground`):
A nonzero result stops promotion. A successful archive export is not approval to transfer/deploy it. The official [Trivy image documentation](https://trivy.dev/latest/docs/target/container_image/) describes archive scanning. Record the actual scanner digest, report and vulnerability database date. An unpatched container base image often reports unfixed HIGH base-system findings; this strict policy therefore blocks it. Do not bypass the gate to finish the exercise. Remediate the base/runtime or obtain a narrowly scoped, time-limited security decision for the actual deployment; no such exception is granted by this tutorial.
3. Add a protected manual build workflow
The following complete example can be saved as .github/workflows/release-artifact.yml in an approved repository. Installing it and starting hosted jobs requires the repository owner's authorization and billing review. It has no host SSH credential and performs no deployment or registry publication. It allows a deliberate manual trigger rather than giving an untrusted pull request production access.
Pins identify retrieved action commits; review upstream code and update them intentionally. The scanner pin corresponds to the official [Trivy action](https://github.com/aquasecurity/trivy-action) release0.35.0. A vulnerability finding or unavailable vulnerability database stops release promotion. Do not turn a failing scan into a success by globally suppressing its exit status. Review findings, update the base/dependencies or record a narrowly justified, time-limited exception through your security process.
Before triggering the workflow, select the reviewed branch/commit in GitHub's Actions interface. After it completes, retain the run URL, commit, scan output, test output and artifact metadata. Download reviewed-server-image; confirm its source_commit equals the approved revision. A successful workflow definition parser is not a hosted execution receipt. Keep deployment authorization in a protected environment or explicit operator approval; this build identity needs no production secrets.
4. Verify and load on the selected target
On the LAPTOP/BUILDER, after approval of this precise candidate and maintenance action, create the remote artifact directory through the verified SSH connection, then transfer the files in order:
On the REMOTE host, enter it, verify the expected record through the trusted approval channel, then validate file bytes and load:
Expected: the loaded image exists by the exact expected ID. The metadata's architecture must match uname -m/the provider machine architecture; use linux/arm64 for a separately tested ARM target. Loading is a local daemon mutation and does not execute the application. If checksum or identity fails, stop before deployment and retrieve the approved artifact again. Do not rebuild on the target and call it the same artifact.
5. Apply a maintenance release and retain rollback
Return to the REMOTE example directory. First finish a verified backup and record schema compatibility. Capture the old API image ID using the existing container before changing anything:
A blank container ID means there is no running prior release; inspect the inventory rather than guessing rollback. Copy the reviewed new schema/code configuration separately as a new source-release directory if it changed; keep .env and database-volume/project ownership consistent with the selected deployment. Never let a new directory accidentally create a different database project and hide the intended dataset.
For this archive route, create compose.artifact.yaml with these exact contents:
Set APP_IMAGE to the verified value from the artifact record, then perform the reviewed maintenance sequence:
This sequence deliberately stops writers before migrations. It can interrupt requests. If migration fails, keep the maintenance state, preserve logs and diagnose; starting old code against an unknown schema is not an automatic repair. The seed step does not un-revoke an old token. Confirm the actual API/worker image IDs equal APP_IMAGE and complete the public authenticated job workflow before accepting the release. Keep the previous image and protected configuration until the rollback window closes.
For a reviewed backward-compatible schema, execute rollback against the existing database without rerunning old migrations:
That expected result belongs to tutorial02's exact public workflow evidence text. Supply that recorded job ID, not an arbitrary job. Repeat a fresh external workflow using a newly issued short-lived test credential and revoke it afterward as in tutorial02. The previous external test token was deliberately revoked and should remain denied. If schema compatibility is not established, stop and use the rehearsed forward fix or separate-host recovery procedure.
Troubleshooting, cleanup and assessment
A failed build is a source/dependency problem before it is a deployment problem. A scan failure is a finding to resolve. A missing loaded image indicates transfer/daemon targeting trouble. A ready process serving wrong data suggests the wrong project/database/configuration. A503 after migration points to schema, connection or privilege state. Diagnose from recorded identities and first errors before changing multiple components.
Retain approved release records and bounded logs under the agreed policy. Remove only explicitly identified obsolete image/archive artifacts after verifying no running or rollback deployment depends on them. Never use docker system prune as the release cleanup procedure. Registry publication is an optional delivery variant requiring its own repository scope, credentials, provenance and retention; this archive path does not silently grant publishing authority.
You pass when you can trace the deployed image back to a reviewed source revision and test/scan run, detect an altered archive, demonstrate intended maintenance, recover a compatible failed release and identify exactly which retained artifact makes rollback possible. Another operator must be able to repeat the release from the approved artifact without rebuilding it or asking where its configuration came from.
Lock in what you just learned (3 quick questions)
git pull on production?