From a0175bedca520c0f2b73dfcc092a2691bd4a775c Mon Sep 17 00:00:00 2001 From: Richard Nienaber Date: Mon, 7 Sep 2026 17:11:00 +0100 Subject: [PATCH] publish the pinned environment to GHCR Everything in the Dockerfile is pinned, but a rebuild still produces its own layers: apt indexes move, timestamps differ, and CI's image and a developer's image agree on every version without being the same image. That is enough to make the toolchains match and not enough to name in a bug report, which is what a digest is for. CI pushes to ghcr.io/rjnienaber/prescript-env from main, and only after the suite has passed inside the image it is about to publish: an image nobody has run is not one to hand to anybody, and a pull request's image is a proposal rather than the environment. Two tags go up, because latest answers "what is current" and nothing else, while a run that has to be reproduced needs a name that still means the same image next month. `make pull_image` takes a digest as readily as a tag and gives either the local name the rest of the tooling already uses, so docker/run.sh reports the registry digest in $PRESCRIPT_IMAGE without knowing where the image came from -- which is the half of a repro block the environment file cannot supply. Public packages on GitHub Packages carry no storage or bandwidth charge, and this repository is public, so the image costs nothing to host. Co-Authored-By: Claude Opus 5 Claude-Session: https://claude.ai/code/session_019f9gkZVUEo3jtv51GSb4vJ --- .github/workflows/ci.yaml | 13 ++++++++ Makefile | 19 +++++++++++ README.md | 8 +++-- docker/publish.sh | 67 +++++++++++++++++++++++++++++++++++++++ docs/container.md | 32 +++++++++++++++---- 5 files changed, 130 insertions(+), 9 deletions(-) create mode 100755 docker/publish.sh diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index b6b4b8b..1bd8b35 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -54,6 +54,10 @@ jobs: # only way to know it still builds is to build it on every change. container: runs-on: ubuntu-latest + permissions: + contents: read + # Only to publish the environment below, and only on main. + packages: write steps: - name: checkout code uses: actions/checkout@v7 @@ -64,6 +68,15 @@ jobs: - name: make docker_test run: make docker_test + # Published only after the suite has passed in it, and only from main: + # an image nobody has run is not one to hand to anybody, and a pull + # request's image is a proposal rather than the environment. + - name: publish the image + if: github.event_name == 'push' && github.ref == 'refs/heads/main' + run: make push_image + env: + GHCR_TOKEN: ${{ secrets.GITHUB_TOKEN }} + # Formatting and linting are properties of the repository, not of any one # Go version, so they run once on the newest. checks: diff --git a/Makefile b/Makefile index bb41302..f605d35 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,7 @@ GCI_VERSION := v0.14.0 IMAGE ?= prescript-env:dev +PUBLISHED_IMAGE ?= ghcr.io/rjnienaber/prescript-env +PUBLISHED_REF ?= $(PUBLISHED_IMAGE):latest VINTBAS_RELEASE := vintbas-1.0.3-1 VINTBAS_ASSET := vintbas-$(shell uname -s | tr '[:upper:]' '[:lower:]')-$(shell uname -m) VINTBAS_URL := https://github.com/rjnienaber/prescript/releases/download/$(VINTBAS_RELEASE)/$(VINTBAS_ASSET) @@ -40,6 +42,23 @@ tape: image: docker build --platform linux/amd64 -t $(IMAGE) docker +# Publishing is what turns "the same Dockerfile" into "the same bytes": a +# rebuild pins the same toolchains but produces its own layers, and only a +# digest is a name a bug report can carry. CI pushes on main; this is here so +# the same thing can be done by hand. +.PHONY: push_image +push_image: + ./docker/publish.sh $(IMAGE) $(PUBLISHED_IMAGE) + +# Pulls the published environment and gives it the local name, so `make +# docker_test` and docker/run.sh use it without knowing where it came from. +# PUBLISHED_REF takes a digest as readily as a tag, and a digest is what to use +# when reproducing someone else's run. +.PHONY: pull_image +pull_image: + docker pull --platform linux/amd64 $(PUBLISHED_REF) + docker tag $(PUBLISHED_REF) $(IMAGE) + # The same checks CI runs, run in the same image CI runs them in. .PHONY: docker_test docker_test: diff --git a/README.md b/README.md index d823de5..7867289 100644 --- a/README.md +++ b/README.md @@ -268,7 +268,8 @@ pty takes anything the program started with it. make dependencies # build tooling, plus the vintbas interpreter the examples run against make prepush # format, lint, test, build, examples -make image # the pinned environment +make pull_image # the pinned environment, as published +make image # or build it locally make docker_test # the suite, inside it ``` @@ -288,8 +289,9 @@ Randomness is not the only thing that moves. Interpreter versions, locale, timezone, terminal size, hash seeds and address layout change what a program prints without changing what it does, and a difference between two ports means nothing if the two ran in different worlds. `docker/` holds a pinned -environment that fixes all of them, used by CI and available locally; see -[docs/container.md](docs/container.md). +environment that fixes all of them, published to +`ghcr.io/rjnienaber/prescript-env` so CI and a developer run the same bytes +rather than the same recipe; see [docs/container.md](docs/container.md). ### Get in touch * Slack: Find me as @rjnienaber on https://gophers.slack.com/ diff --git a/docker/publish.sh b/docker/publish.sh new file mode 100755 index 0000000..7cd8257 --- /dev/null +++ b/docker/publish.sh @@ -0,0 +1,67 @@ +#!/usr/bin/env bash +# +# Publishes the pinned environment so everyone runs the same bytes rather than +# their own build of the same Dockerfile. +# +# Everything in the Dockerfile is pinned, but a rebuild still produces its own +# layers: apt indexes move, timestamps differ, and the two images agree on +# every version without being the same image. That is enough for the toolchains +# to match and not enough to name in a bug report, which is what a digest is +# for. +# +# docker/publish.sh [local image] [remote repository] +# +# Set GHCR_TOKEN to log in first; without it the daemon's existing credentials +# are used, which is what a developer pushing by hand already has. +set -euo pipefail + +LOCAL_IMAGE="${1:-prescript-env:dev}" +REMOTE_IMAGE="${2:-ghcr.io/rjnienaber/prescript-env}" + +if ! docker image inspect "$LOCAL_IMAGE" > /dev/null 2>&1; then + echo "$LOCAL_IMAGE has not been built; run 'make image' first" >&2 + exit 1 +fi + +if [ -n "${GHCR_TOKEN:-}" ]; then + echo "$GHCR_TOKEN" | + docker login ghcr.io --username "${GHCR_USER:-${GITHUB_ACTOR:-x}}" --password-stdin +fi + +# A commit tag as well as latest, because latest answers "what is current" and +# nothing else: a run that has to be reproduced needs a name that still means +# the same image next month. +COMMIT="${GITHUB_SHA:-$(git rev-parse HEAD)}" +COMMIT_TAG="git-${COMMIT:0:12}" + +for TAG in latest "$COMMIT_TAG"; do + echo "==> pushing $REMOTE_IMAGE:$TAG" + docker tag "$LOCAL_IMAGE" "$REMOTE_IMAGE:$TAG" + docker push "$REMOTE_IMAGE:$TAG" > /dev/null +done + +# The digest only exists once the registry has the image, so it is read back +# rather than computed. A push that succeeded is not worth failing over if the +# daemon declines to report one, so the tag stands in. +DIGEST="$(docker image inspect \ + --format '{{range .RepoDigests}}{{println .}}{{end}}' "$REMOTE_IMAGE:$COMMIT_TAG" | + grep "^$REMOTE_IMAGE@" | head -n 1 || true)" +if [ -z "$DIGEST" ]; then + DIGEST="$REMOTE_IMAGE:$COMMIT_TAG" +fi +echo "==> published $DIGEST" + +# The digest is the only part of this worth keeping, so it goes somewhere the +# run that produced it can be read from afterwards rather than only into logs +# that age out. +if [ -n "${GITHUB_STEP_SUMMARY:-}" ]; then + { + echo "### Pinned environment published" + echo + echo '```' + echo "$DIGEST" + echo '```' + echo + echo "Pull it with \`make pull_image PUBLISHED_REF=$DIGEST\`." + } >> "$GITHUB_STEP_SUMMARY" +fi diff --git a/docs/container.md b/docs/container.md index d04687c..479567a 100644 --- a/docs/container.md +++ b/docs/container.md @@ -8,7 +8,8 @@ locale, timezone, terminal size, hash seeds and address layout all change what a program prints without changing what it does. ``` -make image # build it +make pull_image # get the published one +make image # or build it yourself make docker_test # run the suite inside it make docker_shell # look around ``` @@ -80,12 +81,31 @@ timezone=UTC Issue #18 folds both into the repro block of a generated bug report. -## What it does not do +## Where it lives + +`ghcr.io/rjnienaber/prescript-env`, pushed by CI from `main` after the suite +has passed inside it. Building from the same pinned Dockerfile makes two +images agree on every version without making them the same image — apt +indexes move, timestamps differ, and the layers come out different. Pulling +removes that last gap, and gives the run a digest to be named by. + +``` +make pull_image # :latest +make pull_image PUBLISHED_REF=ghcr.io/rjnienaber/prescript-env@sha256:... +``` + +Both give the image the local name the rest of the tooling uses, so +`make docker_test` and `docker/run.sh` do not need to know which one was used. +A tag says which build; a digest says which bytes, and a digest is what to use +when reproducing someone else's run — the publishing step prints the one it +pushed, and `$PRESCRIPT_IMAGE` reports the one a run is actually inside. -The image is not published anywhere yet, so CI and a developer each build it -from the same pinned Dockerfile rather than pulling the same bytes. That is -enough to make the toolchains agree and not enough to make the image layers -byte-identical; publishing it is the obvious follow-up. +The package is public. Public packages on GitHub Packages carry no storage or +bandwidth charge; a private one would bill against the account's quota, and +this image is around a gigabyte. If a first publish ever creates it private, +the fix is one setting on the package, not a change here. + +## What it does not do Address-space randomisation is left on by default. Docker's default seccomp profile permits `personality()` with a handful of arguments and