From d001f7be0f6a3325fcd615b001088bd28d587cfc Mon Sep 17 00:00:00 2001 From: w3cj Date: Sun, 29 Nov 2026 20:21:18 -0700 Subject: [PATCH] build(release): every release builds to the same bytes on any machine The signing design's first phase. The same tag, built by two builders, now gives byte-identical archives, source tarball, install.sh, SHA256SUMS and formulas. - scripts/release.sh builds every file but the signature in one container, release_image (Debian's buildpack-deps:trixie-scm, pinned by its index's digest), under podman or Docker (DEVVM_RELEASE_RUNTIME), on this machine's processor. The image and the code that runs in the build's container (_build) are the built commit's copies, so a tag builds the same from any checkout; a commit whose release.sh pins no release_image is refused. Everything outside the build's container is the checkout's: the tag's checks, the downloads, the modules' container, the checks on what the build wrote, and the signature. - The build has no network (--network none). The Go modules come first, in a container of their own, the only one with the network, which runs only the checkout's code: its release_image, its release.sh _modules and the Go its mise.lock pins, given only the commit's go.mod and go.sum, read-only, and downloading from proxy.golang.org alone (GOVCS=*:off, GOWORK=off). The checkout's Go rather than the commit's, so a commit can't pick an old Go with a known flaw for the step with the network, and rather than refusing a commit whose Go is older than the checkout's, which would refuse every old tag once mise.lock moves on, though rebuilding old tags is what --tag is for; go.sum pins the module files, so the bytes don't depend on which Go downloaded them. A commit whose go.mod needs a newer Go than the checkout's is refused before anything runs. Every module path the commit's go.mod names is looked up on Google's proxy and checksum database, which the docs say. The build reads the modules read-only as a GOPROXY's files (file:///mod). - Every container runs with --cap-drop ALL, --security-opt no-new-privileges, --pids-limit 8192, --memory 8g and --entrypoint bash, so a setuid file in the commit's image gives no privileges under a rootful runtime, root in it can't chown, a fork bomb or a runaway allocation stops at the container's limits, and the image's entrypoint never runs; Go and GoReleaser are unpacked with tar --no-same-owner. Both runtimes take both limits; rootless podman applies them on cgroups v2 with the pids and memory controllers delegated, as systemd does, and CI's runner needs the same. A full build peaked at 330 processes and 1.8 GiB under Docker Desktop on 10 CPUs. Neither runtime can bound a bind mount's disk use, so the docs say that a running build can fill the temp folder's disk until the time limit. - Each container is named for its run (devvm-release--), so no other run's container, even one left over, has the name, and it's removed (rm -f, then its client ended, then rm -f again): after two hours (DEVVM_RELEASE_TIMEOUT seconds) by a watchdog, and as soon as release.sh stops early. The client runs in the background, so Ctrl+C (INT), a closed terminal (HUP) and kill (TERM) run release.sh's traps at once, which exit through the EXIT trap that removes the container; in the foreground, bash would wait for the client, and the client for the container's PID 1, bash, which ignores them. After kill -9, the watchdog, which outlives release.sh and ignores INT and HUP, removes the container and the temp folder. - Go and GoReleaser are the built commit's mise.lock downloads for linux-arm64 or linux-x64, kept in ~/.cache/devvm-release by SHA-256 and checked before each use, as is the modules' Go from the checkout's mise.lock. A URL has to start with https://dl.google.com/go/ or GoReleaser's releases/download/, can't hold .. or %, which curl decodes (so %2e%2e can't be ..), and goes to curl as --url's value (a lock URL of -K was curl options, run on the host); file:// only from the folder that DEVVM_RELEASE_TEST_FILE_URLS names, which only the tests set, and only when it exists and isn't /. curl: HTTPS redirects only, 30 s to connect, 15 minutes, 1 GiB. A lock with two entries for a tool, or two downloads for the platform, is refused. - The build's repository is new (git init --template=), holding only the commit and, for a tag, the tag, fetched into a pack: no other branches, tags or objects of the maintainer's, no hardlinked files the container could write, and origin set to devvm's GitHub URL, which GoReleaser needs and nothing fetches. Go stamps the binary from the tags it finds, so it finds only the release's. - The container runs as root under a rootless runtime and as you under a rootful one, from the runtime's info (podman's Host.Security.Rootless, Docker's security options), never its name; a runtime that doesn't answer stops the build. Inside: umask 022, TZ=UTC, LC_ALL=C.UTF-8, GOTOOLCHAIN=local, -mod=readonly, no git config but safe.directory, and Go's caches in a container-local folder (Docker Desktop's share lost files that parallel module downloads renamed). - The build writes its files to /out, a mount of its own that it can't swap for a link. Before anything is copied, signed or kept, the folder has to be the one release.sh made, not a link, and everything in it a file or a folder, never a link, yours, and neither setuid, setgid, sticky nor world-writable, and 2 GiB at most, counted as read (sparse files whole) and read no further. The files are then copied to dist/, never moved, as yours with mode 0755 or 0644. minisign signs outside, after the containers are gone. - release.sh --commit COMMIT builds any commit as --head does, with its VERSION; release.sh --tag TAG builds a tag as its release, with its checks, unsigned, to compare with a published SHA256SUMS. An unsigned build never replaces a dist/ that holds SHA256SUMS.minisig, and a build signed with a test key never replaces one whose SHA256SUMS verifies with the checkout's packaging/minisign.pub, the release key. - .goreleaser.yaml: builds_info and every file's info set owner and group root, mode 0755/0644 and the commit's time. - scripts/repro-check.sh [COMMIT | TAG] builds twice with the checkout's release.sh, so no commit's code runs on the host directly. Build 2 fetches from a repository with a stray tag, v0.0.0-stray, at the commit, and runs under Docker where build 1 runs under podman when both are installed (root against your user); every platform archive's files have to be root's with mode 0755 or 0644 (tar -tv). A build that leaves no release fails, whatever its exit status. CI's repro job runs it under the runner's podman and Docker, with a 45-minute limit. The docs say that building a commit runs its code, in a container only as isolated as the runtime keeps it, so an outside commit is built only with the maintainer's go-ahead, and that rebuilding an old tag needs proxy.golang.org to still serve its modules. - scripts/bump.sh release-image moves the container's digest, the SHA-256 of the index it fetched, after checking the index lists linux/amd64 and linux/arm64; TestBumpCoversPins finds the pin. - Tests: release_head.txtar, publish.txtar and the new repro_check.txtar run the scripts through podman and docker stubs and a mise.lock of file:// tarballs. New cases: -K, http://, another host, .. and a percent-encoded .. in a lock URL refused before curl runs, file:// refused without the switch, with it set to 1, to a folder that doesn't exist, to / and from another folder, curl's bounds, two go entries, the build's repository's tags, refs, objects, hardlinks and origin, a stray tag kept out, the image and build code taken from the commit, a commit with no release_image, each runtime's user (rootless and rootful podman and Docker, podman behind docker, no answer), both containers' run lines (security options, limits, entrypoint, --network none, mounts), each container's name its run's (the stub checks it against the run's temp folder), the modules' container getting only go.mod, go.sum, Go and the checkout's release.sh, in the checkout's image, with the checkout's Go, a go.mod newer than the checkout's Go refused before any container, and the build reading its modules; refused output: a link in it, the output folder swapped for a link, a mode 4755, 2755 or 0666 file, a mode 1755 or 0777 folder, a sparse file a byte over 2 GiB (a file of another user's needs root to test, which the test says); a mode 0600 file copied as 0644; a build past DEVVM_RELEASE_TIMEOUT removed by name; release.sh sent INT, HUP and TERM mid-build, ending within 10 s through its trap, and kill -9, each leaving no container, process or temp folder; an unsigned --head and --tag refused over a signed dist/, and a test-key build over a release-key one; --commit never running the commit's host code, --tag's unsigned build matching the signed SHA256SUMS, and repro-check catching a build that records its user, archives that aren't root's, and a release.sh that builds nothing; bump.txtar covers the platform check. Each fails with its fix taken out, which was checked for every fix of the third review: the name, the limits, the test-key refusal, %, the folder's existence and /, the size cap, setgid, sticky, the signal traps, the EXIT trap's removal, the watchdog's removal after kill -9, the client in the background (in the foreground, INT took 60 s), the checkout's Go and the Go version check. Proof, with a throwaway commit whose _build probes its container and leaves a mode 4755 copy of bash and a mode 0666 file in /out, built by this release.sh under Docker Desktop on an arm64 Mac, and under rootful Docker and rootless podman on x86_64 Fedora: every build ran with CapEff and CapBnd 0, NoNewPrivs 1 and no network, couldn't write /mod or rename /out, and was refused before anything was kept; rootful Docker refused its chown to root. The same image under the old run line, on Fedora's rootful Docker: CapBnd a80425fb, NoNewPrivs 0, and proxy.golang.org reachable. Real builds of this commit, stopped 20 s into the build's container: under Docker Desktop, INT, TERM and HUP ended release.sh within 3 s (exit 130, 143, 129) with no container left at once, and kill -9 left the container running for the watchdog, which had removed it and the temp folder 5 s later. The same on Fedora under rootless podman (INT, kill -9, TERM, HUP) and rootful Docker (INT, kill -9). Afterwards no devvm-release container or temp folder was left on either machine. repro-check on this commit, a prerelease (no devvm.rb), agreed on all eight files on the Mac (Docker Desktop, both builds) and on Fedora (rootless podman as root, then rootful Docker as cj), and the two machines' printouts were the same. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/ci.yml | 17 + .goreleaser.yaml | 10 + CHANGELOG.md | 1 + docs/content/docs/contributing/_index.md | 4 +- docs/content/docs/contributing/maintaining.md | 53 +- docs/content/docs/contributing/structure.md | 2 +- docs/content/docs/releases/0.2.0.md | 4 + internal/structure/pins_test.go | 2 + scripts/bump.sh | 25 +- scripts/publish.sh | 3 +- scripts/release.sh | 504 +++++++++++++-- scripts/repro-check.sh | 105 ++++ testdata/script/bump.txtar | 37 +- testdata/script/publish.txtar | 96 ++- testdata/script/release_head.txtar | 584 +++++++++++++++++- testdata/script/repro_check.txtar | 200 ++++++ 16 files changed, 1551 insertions(+), 96 deletions(-) create mode 100755 scripts/repro-check.sh create mode 100644 testdata/script/repro_check.txtar diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c6c21493..750d0447 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -77,6 +77,23 @@ jobs: env: MISE_TASK_RUN_AUTO_INSTALL: "false" + # A release builds to the same bytes twice: scripts/repro-check.sh builds + # the commit with scripts/release.sh in the release's pinned container, + # once under the runner's podman, as root, and once under its Docker, as + # the runner's user, from a repository with a stray tag, then compares + # every file and checks that every archive's files are root's. It needs + # no mise: the container gets Go and GoReleaser from mise.lock. The + # containers' process and memory limits need cgroups v2, with the pids + # and memory controllers delegated to the runner's user for podman. + repro: + runs-on: ubuntu-latest + timeout-minutes: 45 + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + - run: scripts/repro-check.sh + # Without cgo, as devvm ships. On Linux the proxy's child confines every # thread of itself through syscall.AllThreadsSyscall, which a build with # cgo, such as the race detector's in the check jobs, refuses: here a diff --git a/.goreleaser.yaml b/.goreleaser.yaml index b67ff9f3..7962b607 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -19,15 +19,25 @@ builds: mod_timestamp: "{{ .CommitTimestamp }}" # One archive per platform: the binary (its own files embedded), the README, changelog and license. +# Every file in it has the same owner, group and mode and the commit's time on every builder, in +# place of the defaults, which copy them from the file on disk. archives: - id: devvm ids: [devvm] formats: [tar.gz] name_template: devvm-{{ .Version }}-{{ .Os }}-{{ .Arch }} wrap_in_directory: true + builds_info: + owner: root + group: root + mode: 0755 + mtime: "{{ .CommitDate }}" files: - src: LICENSE info: &info + owner: root + group: root + mode: 0644 mtime: "{{ .CommitDate }}" - src: README.md info: *info diff --git a/CHANGELOG.md b/CHANGELOG.md index dadd9647..ae3373b1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -261,5 +261,6 @@ These changes are on `main` and go out in the next release.
Internal changes - mise is 2026.11.14 in base and on this machine, the nix layer has Nix 2.36.0, and the docker layer has buildx 0.39.1 and its model plugin 1.2.10 ([details](https://next.devvm.dev/docs/releases/0.2.0/#pins-since-020-rc1)). +- A release now builds to the same bytes on any machine, in one pinned container, so two builders can check each other's archives ([details](https://next.devvm.dev/docs/releases/0.2.0/#reproducible-release-builds)).
diff --git a/docs/content/docs/contributing/_index.md b/docs/content/docs/contributing/_index.md index f20a2f57..836770b6 100644 --- a/docs/content/docs/contributing/_index.md +++ b/docs/content/docs/contributing/_index.md @@ -35,7 +35,7 @@ mise installs every tool at the version pinned in `mise.toml`, checked against ` | gotestsum | running the tests | | govulncheck | checking dependencies for known vulnerabilities | | nilaway | finding where a nil value may be dereferenced | -| goreleaser | release builds ([Maintaining](maintaining.md#releasing)) | +| goreleaser | release builds, which run in their container with the GoReleaser download that `mise.lock` pins ([Reproducible releases](maintaining.md#reproducible-releases)) | | hugo | the docs site | | vale, markdownlint-cli2, lychee | linting the docs | | node | running markdownlint-cli2, and drawing the docs site's diagrams with pele, which `docs/package.json` pins ([diagrams](docs.md#writing-docs)) | @@ -66,7 +66,7 @@ Run the tasks with `mise run `: Before and after every change, `mise run fmt && mise run lint && mise run test` must pass. Before a push to `main`, `mise run nilaway:linux` must pass as well, because CI's `nilaway` job only warns, so a new finding hides in a green run ([Nil checks](#nil-checks)). -CI runs `lint` and `test` on macOS and Linux, and `vuln` and `nilaway` in jobs of their own. Its `nocgo` job runs `internal/landlock`'s and `internal/proxy`'s tests on Linux with `CGO_ENABLED=0`, as devvm ships. The test tasks turn cgo on for the race detector, and with cgo the proxy's child can't confine every thread of itself (`syscall.AllThreadsSyscall`), so only that job runs a child under Landlock and the seccomp filter. A weekly workflow also scans `main` and the binaries of the latest releases ([Known vulnerabilities](maintaining.md#known-vulnerabilities)). A change that touches only the docs and Markdown files skips them: the Docs workflow runs `lint:docs` and builds the site instead, and on every push to `main` it deploys next.devvm.dev ([the docs sites](maintaining.md#the-docs-sites)). +CI runs `lint` and `test` on macOS and Linux, and `vuln` and `nilaway` in jobs of their own. Its `nocgo` job runs `internal/landlock`'s and `internal/proxy`'s tests on Linux with `CGO_ENABLED=0`, as devvm ships. The test tasks turn cgo on for the race detector, and with cgo the proxy's child can't confine every thread of itself (`syscall.AllThreadsSyscall`), so only that job runs a child under Landlock and the seccomp filter. Its `repro` job builds the release twice, under podman and under Docker, and checks that both builds made the same bytes and that every archive's files are root's ([Reproducible releases](maintaining.md#reproducible-releases)). A weekly workflow also scans `main` and the binaries of the latest releases ([Known vulnerabilities](maintaining.md#known-vulnerabilities)). A change that touches only the docs and Markdown files skips them: the Docs workflow runs `lint:docs` and builds the site instead, and on every push to `main` it deploys next.devvm.dev ([the docs sites](maintaining.md#the-docs-sites)). ### Nil checks diff --git a/docs/content/docs/contributing/maintaining.md b/docs/content/docs/contributing/maintaining.md index 9a9aaa5e..411f8689 100644 --- a/docs/content/docs/contributing/maintaining.md +++ b/docs/content/docs/contributing/maintaining.md @@ -4,7 +4,7 @@ explainer: Bump pinned versions, fix known vulnerabilities, release devvm and ru weight: 2 --- -For maintainers: version bumps and releases. Run the scripts with mise, which puts the pinned GoReleaser and minisign on `PATH`: `mise exec -- scripts/release.sh`. +For maintainers: version bumps and releases. Run the scripts with mise, which puts the pinned minisign on `PATH`: `mise exec -- scripts/release.sh`. The release itself builds in a container, so you also need podman or Docker. ## Updating pinned versions @@ -32,16 +32,18 @@ The tools, by group, as `--check` prints them: | `go` | `go`, `go-minor` only when named, `go-mods`, `deadcode` | Go, its modules and the deadcode task | | `dev-tools` | `dev-tools` | `mise.toml`'s tools except Go, with their `mise.lock` entries | | `ci` | `ci-mise`, `actions` | the mise the workflows install, and their actions | +| `release` | `release-image` | the container that every release is built in | | `docs` | `hextra`, `pele` only when named | the docs site's theme, and pele, which draws its diagrams | - `go` moves Go to its newest patch release of the minor that `go.mod` names, from `go.dev/dl`. It edits the `go` lines of `go.mod` and `docs/go.mod`, `mise.toml`'s `go`, and its `mise.lock` entries. `--check` reports a newer minor on the `go-minor` line, and `scripts/bump.sh go-minor` moves the same files to it. - `go-mods` moves `go.mod`'s direct modules, the ones the depguard allowlist allows and the tests' own, to their newest patch or minor release from the Go module proxy, with `go get` and `go mod tidy`. The indirect ones move as `go mod tidy` needs them. A module's next major has a new path, so `--check` reports it and you move it by hand. `deadcode` moves the deadcode task's version in `mise.toml` to golang.org/x/tools' newest release. - `dev-tools` moves each of `mise.toml`'s tools except Go to mise's newest version of it, edits its line and runs `mise lock`, so `mise.lock` keeps every platform's checksum, and markdownlint-cli2's lock folder in `.mise/locks/` moves with it. nilaway has no releases, so its pin is a pseudo-version, which `mise latest` prints nothing for. `dev-tools` moves a Go tool pinned to a pseudo-version to its newest commit's, from the Go module proxy's `@latest` for the module that holds the tool, the longest prefix of its path that the proxy has. A tool with no newest version stops the run with an error, never a change, and so does any failed request to the proxy, except its answer that a prefix isn't a module. - `ci-mise` moves the `version` that the workflows give jdx/mise-action to base's mise, as the run leaves it, so `scripts/bump.sh mise ci-mise` moves both. `actions` moves each workflow's `uses:` to its newest release's tag, as the tag's commit from `gh api`, with the tag in the comment after it, and reports a newer major without applying it. An action in a folder of its repo, such as `actions/cache/restore`, moves with its repo's releases. +- `release-image` moves `release_image` in `scripts/release.sh`, the container that every release is built in, to the digest of Docker Hub's newest index of `buildpack-deps:trixie-scm`. The digest is the SHA-256 of the index it fetched, which every pull checks the registry's index against, and before it records the digest, it checks that the index has a `linux/amd64` and a `linux/arm64` image, the two that builders run. Every release trusts this image, because its git, awk, tar and gzip write the release's files, so read what changed in it before you commit a bump (docker-library's `repo-info` repository lists each image's packages), and run `scripts/repro-check.sh` after it ([Reproducible releases](#reproducible-releases)). - `hextra` moves the docs site's theme in `docs/go.mod`, and it reminds you to compare the copies of Hextra's files in `docs/layouts/` with the new release's. `pele` moves pele only when named, because the diagrams need a look on the built site. It runs `npm install` in `docs/` with the exact version and no install scripts, which writes `docs/package.json` and `docs/package-lock.json`, and then draws the diagrams again with `mise run docs:diagrams`. The drawing script's self-check fails that step when the new pele no longer measures and writes its small text, such as edge labels, as the script expects ([diagrams](docs.md#writing-docs)). - `cursor` moves Cursor's CLI only when named, to the release that Cursor's install script fetches, with each platform's SHA-256 computed from its download, because Cursor publishes no checksums. devvm's login and proxy code was read against the pinned release, so read the new one where that code names it, then run `e2e-tools`. - A hold keeps a pin below a version, and `--check` shows the newest version beside it. Go modules and actions take Dependabot's ignore list in `.github/dependabot.yml`, which keeps pflag below 1.1.0, because pflag 1.1 prints every boolean flag with `[=true|false]` in the help. The other holds are in `bump.sh`'s `holds`, which keeps Node, the one in `mise.toml`, on its major. -- `bump.sh`'s header lists every pin with the tool that moves it, or with `-` and the reason it's left, as `# pin` lines. `TestBumpCoversPins` in `internal/structure` finds the pins in `assets/`, `mise.toml`, both `go.mod` files, the workflows, `tests/e2e-mise.lock`, `tests/e2e`'s consts, `docs/hugo.yaml` and `docs/package.json`'s dependencies, without the network, and fails on a pin that no line covers or on a line that covers nothing, so a new pin gets a tool or a reason. The header also says why the pins outside those files are left as they are, such as the Lima that `install.sh` installs, which is the newest release checked against its `SHA256SUMS`, and the Homebrew formula, whose URLs and checksums `release.sh` fills in. +- `bump.sh`'s header lists every pin with the tool that moves it, or with `-` and the reason it's left, as `# pin` lines. `TestBumpCoversPins` in `internal/structure` finds the pins in `assets/`, `mise.toml`, both `go.mod` files, the workflows, `tests/e2e-mise.lock`, `tests/e2e`'s consts, `scripts/release.sh`'s container, `docs/hugo.yaml` and `docs/package.json`'s dependencies, without the network, and fails on a pin that no line covers or on a line that covers nothing, so a new pin gets a tool or a reason. The header also says why the pins outside those files are left as they are, such as the Lima that `install.sh` installs, which is the newest release checked against its `SHA256SUMS`, and the Homebrew formula, whose URLs and checksums `release.sh` fills in. - base's Ubuntu cloud image and its apt packages have nothing to bump: devvm pins the newest image on each machine at its first build of base, and records the newest packages for each key of base at its first build ([Ubuntu's cloud image](../internals/images.md#ubuntus-cloud-image), [base's packages](../internals/images.md#bases-packages)). `docker` moves Docker's packages (`assets/layers/docker.sh`), read from its repository for base's Ubuntu release, and its signing key. Packages added to `assets/layers/base.sh` or `assets/features/` need no pin of their own: they change base's key, whose first build records them. - `mise` moves base's mise (`assets/layers/base.sh`) and devvm's host mise (`internal/tools/mise.go`) together: the host one writes the lock base's installs from. `TestMisePins` fails when their versions or Linux checksums differ, and base's mise version is in the key of each tool image mise installs, so a bump builds them again. - The shared tools aren't pinned for users, except Cursor's CLI. Holds go in `assets/shared-tools/mise.toml` (`node = "24"` stays on that major). `testdata/mise.lock` is a fixed lock for the tests. @@ -124,11 +126,11 @@ Until a fix ships, users can still build base, because devvm's fallback to the r - **`TestChangelogShape` keeps the shape,** in `internal/cli/docgen/changelog_test.go`, which `mise run lint:docs` and `mise run test` run. For each entry from 0.2.0-rc.1 on, and for Unreleased once it has a line, it checks the groups and their order, three to five Highlights in a release's entry, each collapsed group's `
`, `` and blank lines, each line's 35 words outside What to do, its `details` link to a `releases/` page, and a full link for every issue and pull request. The entries before 0.2.0-rc.1 are history, and the test leaves them as they are. - **The release page holds each change's full story,** and it is `docs/content/docs/releases/..0.md`, such as `releases/0.2.0.md`, which covers the release and its release candidates. Each release candidate adds its changes there, in the same commit as its changelog entry, so the page is written as the release is made. Each change gets a section of its own with its full story, under Breaking changes, Changes, Fixes and Hardening, as [Writing docs](docs.md#writing-docs) describes, and the Releases section's own page lists the page. Every fact a changelog line leaves out is in its section, so a line can stay one sentence. A change that two lines describe, such as a step in What to do and a line in Fixed, can share one section, which both link, and a line that covers several changes links each one's section. - **A prerelease's changelog entry** lists what changed since the version before it, whether that's a release or another prerelease, and it becomes that prerelease's notes on GitHub. When the release itself goes out, its entry, such as `## 0.2.0`, replaces its prereleases' entries and lists everything since the last release, so someone who upgrades from that release reads one entry. Each prerelease's notes stay on its GitHub release. -- **Before it builds,** `scripts/publish.sh` checks what it needs and stops with nothing done when a check fails. The tag `v` has to pass `release.sh`'s own checks, so it exists, is signed, and is signed by a key in `packaging/release-signer`. The tag's commit has to be `main`'s HEAD, and `origin`'s `main` has to be an ancestor of it, so that the push is a fast-forward. If `origin` already has the tag, it has to be the same tag. The working tree has to be clean, `gh` has to be installed and logged in (`gh auth status`), and minisign has to be installed. A published GitHub release for the tag is refused unless it already has every file, which is the case when an earlier run stopped after it, and unless GitHub marks it as a prerelease exactly when the version is one. The refusal names the `gh release edit` command that fixes the mark. The tap's checkout, a clone of `devvmhq/homebrew-tap`, has to exist, be clean and be on `main`, for a prerelease too, and its `origin` has to have no commits that its `main` lacks. The checkout is `DEVVM_TAP_DIR`, or `../homebrew-tap` next to this repo by default. +- **Before it builds,** `scripts/publish.sh` checks what it needs and stops with nothing done when a check fails. The tag `v` has to pass `release.sh`'s own checks, so it exists, is signed, and is signed by a key in `packaging/release-signer`. The tag's commit has to be `main`'s HEAD, and `origin`'s `main` has to be an ancestor of it, so that the push is a fast-forward. If `origin` already has the tag, it has to be the same tag. The working tree has to be clean, `gh` has to be installed and logged in (`gh auth status`), and minisign, curl and podman or Docker have to be installed. A published GitHub release for the tag is refused unless it already has every file, which is the case when an earlier run stopped after it, and unless GitHub marks it as a prerelease exactly when the version is one. The refusal names the `gh release edit` command that fixes the mark. The tap's checkout, a clone of `devvmhq/homebrew-tap`, has to exist, be clean and be on `main`, for a prerelease too, and its `origin` has to have no commits that its `main` lacks. The checkout is `DEVVM_TAP_DIR`, or `../homebrew-tap` next to this repo by default. - **Then it builds and shows the release.** It runs `scripts/release.sh`, which builds `dist/` and signs `SHA256SUMS`, and where minisign asks for the password. It prints the version, the tag's commit, each file with its size and SHA-256, the release notes, which are the `CHANGELOG.md` entry for the version, and the tap's changes as a `git diff` of each formula it writes: `Formula/devvm.rb` for a release, and `Formula/devvm-rc.rb`, with a line saying when a release moves it too, or when it stays on a newer version. It lists the four steps, each marked done or to do, and when nothing in the tap changes, the fourth says so. Then it asks `Publish devvm ? [y/N]` on the terminal, and any answer but y stops it with nothing published. `--dry-run` stops before the question, so it pushes and publishes nothing and makes no commit in the tap, and `--help` describes the script. - **Then it publishes, in this order.** It pushes `main` and then the tag to `origin`. It makes the GitHub release `devvmhq/devvm` `v` with `gh release create --verify-tag`, titled `devvm `, with the release notes and the archives, the source tarball, `SHA256SUMS`, `SHA256SUMS.minisig` and `install.sh`. The release starts as a draft and is published only once every file is uploaded, so nobody sees a release that is missing files. Last, it copies `dist/devvm.rb` to the tap's `Formula/devvm.rb` and `dist/devvm-rc.rb` to its `Formula/devvm-rc.rb`, each only when it's one the tap gets and it differs, commits them in one commit, `devvm ` for a release or `devvm-rc ` for a prerelease, with the tap's own commit signing, and pushes the tap. It uses `gh` for GitHub and never puts a GitHub token on a command line. At the end it prints how to check the release: `brew update && brew upgrade devvm`, or `brew trust --formula devvmhq/tap/devvm` and then `brew install devvmhq/tap/devvm`, with `devvm-rc` in place of `devvm` for a prerelease, and the install script's `curl` line. - **When a step fails,** it says which steps it published and which it didn't. Fix what failed and run it again, because every step skips what's already done: a pushed `main` or tag, a published release whose `SHA256SUMS` matches the new build's, and a tap whose formulas are already this build's. A draft release that an earlier run left gets this build's files again before it's published. A release published from another build, whose `SHA256SUMS` doesn't match, is refused. To finish by hand instead, run the steps it didn't do in order: `git push origin main`, `git push origin v`, the `gh release create` above (or `gh release upload --clobber` to a draft, then `gh release edit v --draft=false`), each with `--prerelease` for a prerelease, and then copy the formulas the printout listed, `dist/devvm.rb` and `dist/devvm-rc.rb`, to the tap's `Formula/`, commit them and push it. -- `scripts/release.sh` checks the tag with `git tag -v` and its signer against this checkout's `packaging/release-signer`, then builds `dist/` from the tagged commit with GoReleaser (`.goreleaser.yaml`), in a clone of its own, so only what's committed goes in, with one `goreleaser release --skip=publish`. It checks that the binary built for this host prints the version, writes `install.sh` and adds its checksum to `SHA256SUMS`, then signs `SHA256SUMS` with `~/.minisign/devvm.key` (or `DEVVM_MINISIGN_KEY`) and verifies it with `packaging/minisign.pub`. Nothing is published, because publishing is `scripts/publish.sh`'s. `scripts/release.sh --check` runs only the tag's checks and the build's preconditions, prints the tag's commit and builds nothing, and `scripts/publish.sh` runs it first. +- `scripts/release.sh` checks the tag with `git tag -v` and its signer against this checkout's `packaging/release-signer`, then builds `dist/` from the tagged commit with GoReleaser (`.goreleaser.yaml`), in a repository of its own that holds only the commit and the tag, so only what's committed goes in, with one `goreleaser release --skip=publish`. The build runs in the release's container, as [Reproducible releases](#reproducible-releases) describes. In the container, it checks that the Linux binary for the container's processor prints the version, writes `install.sh` and adds its checksum to `SHA256SUMS`. Then, outside the container, it signs `SHA256SUMS` with `~/.minisign/devvm.key` (or `DEVVM_MINISIGN_KEY`) and verifies it with `packaging/minisign.pub`. Nothing is published, because publishing is `scripts/publish.sh`'s. `scripts/release.sh --check` runs only the tag's checks and the build's preconditions, prints the tag's commit and builds nothing, and `scripts/publish.sh` runs it first. - `dist/` then holds: | File | What | @@ -140,12 +142,53 @@ Until a fix ships, users can still build base, because devvm's fallback to the r | `devvm-rc.rb` | the Homebrew formula `devvm-rc`, which follows prereleases, set to each platform's archive, its URL and its checksum from `SHA256SUMS` | | `devvm.rb` | for a release, not a prerelease, the Homebrew formula `devvm`, set the same way | -- `scripts/release.sh --head` builds from HEAD's commit instead, for testing, with `VERSION`'s version, a release's or a prerelease's. It's unsigned unless `DEVVM_MINISIGN_KEY` names a test key; `DEVVM_MINISIGN_PUB` names its public key in place of `packaging/minisign.pub`. `DEVVM_RELEASE_URL` points the formula at a test location. A commit without `install.sh` is refused. +- `scripts/release.sh --head` builds from HEAD's commit instead, for testing, with the version in that commit's `VERSION`, a release's or a prerelease's, and `scripts/release.sh --commit COMMIT` does the same for any other commit. It's unsigned unless `DEVVM_MINISIGN_KEY` names a test key; `DEVVM_MINISIGN_PUB` names its public key in place of `packaging/minisign.pub`. A build signed with a test key never replaces a `dist/` whose `SHA256SUMS` verifies with this checkout's `packaging/minisign.pub`, the release key, and stops before it builds anything, so move the release's `dist/` first, or set `DEVVM_RELEASE_DIST`. `DEVVM_RELEASE_URL` points the formula at a test location. A commit without `install.sh` is refused. +- `scripts/release.sh --tag TAG` builds the tag `TAG` as its release is built, with the same checks of the tag and its signer and the tag's version, but doesn't sign it, so another builder can build a release and compare its `SHA256SUMS` with the published one. An unsigned build, such as this one, never replaces a `dist/` that holds `SHA256SUMS.minisig`, and stops before it builds anything, so move the signed build's `dist/` first, or set `DEVVM_RELEASE_DIST` to a folder that doesn't exist yet for the unsigned one. - `scripts/release.sh --formula-from DIR` writes only the formulas, for `VERSION`'s release once it's published, and builds nothing: `dist/devvm-rc.rb`, and `dist/devvm.rb` too when `VERSION` isn't a prerelease. Download the release's `SHA256SUMS` and `SHA256SUMS.minisig` into `DIR` first. The script checks the signature against `packaging/minisign.pub`, and that its trusted comment is `devvm ` for `VERSION`'s version, so it refuses another release's files. Then it fills in the formulas the same way a build does, from that `SHA256SUMS`. - To try `dist/install.sh` on such a build, copy `dist/` to `DIR/releases/download/v/`, then in a throwaway `HOME` with `DEVVM_PREFIX` under it: `DEVVM_INSTALL_TEST=1 source dist/install.sh`, set `repo_url=file://DIR` and `protos='=https,file'` (it downloads over HTTPS only), and run `main --no-deps`. Without `--no-deps` it offers to install what the host lacks: answer no, or run it with no terminal. - Every build sets the version with `-X github.com/devvmhq/devvm/internal/cli.version=`: devvm doesn't read `VERSION`. The formula template (`packaging/homebrew/devvm.rb`) is both formulas' one source, and it builds nothing. It has an archive for each of macOS and Linux on arm64 and Intel, the same archives the install script installs, and it installs the binary alone from the one for this machine. `release.sh` fills in each formula's class, `Devvm` or `DevvmRc`, and the other formula, which it conflicts with by its full name, `devvmhq/tap/devvm-rc` or `devvmhq/tap/devvm`, because both install the `devvm` command. It also fills in each archive's URL and its checksum, which it reads from the `SHA256SUMS` it just wrote, on every line that isn't a comment. Both generated formulas pass `brew audit --strict --online` and `brew style`. - Publishing is the maintainer's call, so an agent asks first and never runs `scripts/publish.sh` without `--dry-run` on its own. The script's tests (`testdata/script/publish.txtar`) run it against a local bare repo as `origin`, a local bare tap and a fake `gh`. +### Reproducible releases + +The same commit or tag, built on any machine, gives byte-identical release files: every archive, the source tarball, `install.sh`, `SHA256SUMS` and the formulas. To check it, build twice and compare: + +```sh +scripts/repro-check.sh # build HEAD twice and compare every file +scripts/repro-check.sh # the same for another commit +scripts/repro-check.sh v # a tag, built as its release is, to compare with its published SHA256SUMS +``` + +`repro-check.sh` runs both builds with this checkout's `scripts/release.sh`, which runs the commit's own code only in the build's container, never on your machine directly. That code still runs, though, and the container is only as isolated as your container runtime keeps it, so building a commit is running its code. A commit from outside the project, such as a pull request's, is built only with the maintainer's go-ahead for that run, as any outside code is. A commit builds as `release.sh --commit` builds it, unsigned. A tag builds as `release.sh --tag` builds it, with the tag's checks and version and without the signature, so its `SHA256SUMS` matches the published one. A commit or tag whose `release.sh` pins no `release_image`, from before reproducible builds, is refused. The second build differs from the first in what the fixes below keep out of the bytes, so that losing one of them shows as a difference: + +- **A stray tag.** Build 2 fetches the commit from a repository with a tag, `v0.0.0-stray`, at the commit, which Go would stamp into the binary as its version if the build saw it. It's a v0 version because Go ignores a tag whose major version the module's path doesn't name. +- **Another user.** When podman and Docker are both installed, build 1 runs under podman, as root, and build 2 under Docker, as you, and the archives would record each. With one of them, both builds run as the same user, and the script says so. +- **The archives' headers.** Every file in each platform's archive has to be root's, with mode 0755 or 0644, as `tar -tv` lists it, whichever user either build ran as. + +It prints each file's SHA-256, says `DIFFERS` beside any file whose two builds differ, and exits 1 when one does or when an archive's headers aren't those. Both builds run on this machine, in the same image and on its processor, so to compare two machines, run it on both and diff the printouts, which list the files in the same order on every machine. CI's `repro` job runs it under the runner's podman and Docker, on every push and pull request that CI runs on, so the runner needs cgroups v2, with the `pids` and `memory` controllers delegated to its user for podman. It needs podman or Docker, git and curl, and no mise. + +What makes the bytes the same: + +- **One container.** `release.sh` runs GoReleaser, writes `install.sh` and the formulas, and adds `install.sh` to `SHA256SUMS` inside one container image, with no network, `release_image` at the top of `release.sh`: Debian's `buildpack-deps:trixie-scm`, pinned by its index's digest, which `scripts/bump.sh release-image` moves. So git, which writes the source tarball, and awk, tar and gzip are the same on every builder. The image and the code that runs in the container, `release.sh`'s build, are the built commit's copies, so a tag builds the same bytes from any checkout, even one whose pin has moved since. It uses podman when it's installed and Docker otherwise, and `DEVVM_RELEASE_RUNTIME` names one. The container runs this machine's processor, `linux/arm64` or `linux/amd64`. +- **Go and GoReleaser from the commit's `mise.lock`.** `release.sh` reads the URL and SHA-256 of the `linux-arm64` or `linux-x64` download of each from the built commit's `mise.lock`, so a tag builds with its own pins. It keeps each download in `${XDG_CACHE_HOME:-~/.cache}/devvm-release`, named by its SHA-256, and checks every copy against `mise.lock` before the build uses it. A copy that doesn't match stops the build and is deleted from the cache, so the next run downloads it again. A Go toolchain cross-compiles to the same bytes on either processor. +- **Go's modules as `go.sum` pins them.** The modules the commit's `go.mod` needs are downloaded before the build, with this checkout's Go, and Go checks each against the commit's `go.sum`, so every builder builds from the same module files, whichever Go downloaded them. They come from Go's module proxy, `proxy.golang.org`, so rebuilding an old tag needs the proxy to still serve its modules, which it does for good unless a module is taken down, for legal reasons for example. +- **The same environment inside.** The build runs with umask 022, `TZ=UTC`, `LC_ALL=C.UTF-8`, `CGO_ENABLED=0`, `GOTOOLCHAIN=local`, `-mod=readonly`, and no git configuration but `safe.directory`. Go's caches, `HOME` and the tools go in a folder of the container's own, because Docker Desktop's shared folders lose files that Go's parallel module downloads rename, and `-trimpath` keeps their paths out of the binaries. +- **Only the tag built from.** The build's repository holds the commit and, for a tag, `v`, and no other tags, because Go stamps the binary with a version from the tags it finds, and every machine holds different ones. +- **Fixed archive headers.** `.goreleaser.yaml` sets each archive file's owner and group to `root`, its mode (0755 for the binary, 0644 for the rest) and its time to the commit's (`builds_info` and each file's `info`), in place of GoReleaser's defaults, which copy them from the files on disk, and `mod_timestamp` sets the binary's own time to the commit's. Without them, a build under Docker on a Mac records your user and group, and a build under podman records root, so the archives differ. + +The signature, `SHA256SUMS.minisig`, is made outside the container, after the build, so it never changes the bytes of the other files. + +What runs on your machine, outside the containers, is this checkout's `release.sh`: the tag's checks, the downloads, the checks on what the build wrote, and the signature. It limits what the commit's code, in the build's container, can reach and leave behind: + +- **Downloads only from their publishers.** Each `mise.lock` URL has to start with `https://dl.google.com/go/` for Go, or `https://github.com/goreleaser/goreleaser/releases/download/` for GoReleaser, and it goes to curl as `--url`'s value, so a lock can't pass curl an option. It can't hold `..`, or a `%`, which curl would decode, so that `%2e%2e` would be `..`. curl follows redirects over HTTPS only, and gives up after 30 seconds connecting, after 15 minutes, or past 1 GiB. A lock with two entries for a tool, or two downloads of one for this platform, is refused. The tests' lock files use `file://` URLs, which `release.sh` allows only from the folder that `DEVVM_RELEASE_TEST_FILE_URLS` names, and only when that folder exists and isn't `/`, so the variable set by mistake reads no other file of yours, and each download is still checked against `mise.lock`. +- **A repository of the build's own.** `release.sh` fetches the commit and the tag into a new repository, which has no hooks, none of this checkout's other branches, tags or objects, and no files it shares with this one, as a local clone's hardlinks would be. Its `origin` is devvm's repository on GitHub, which GoReleaser reads and nothing fetches from. +- **No network for the build.** The Go modules are downloaded first, in a container of their own, which is the only one with the network. Everything it runs is this checkout's, never the commit's: its `release_image`, its `release.sh`, and the Go that its `mise.lock` pins, so the commit can't choose an old Go with a known flaw for the one container with the network. It gets only the commit's `go.mod` and `go.sum`, read-only, and a commit whose `go.mod` needs a newer Go than this checkout's is refused before anything runs, so build it from a checkout at least as new. Go downloads the modules from its module proxy alone, `proxy.golang.org`, and checks each against `go.sum`, or against Go's checksum database for one that `go.sum` lacks, and downloading runs none of the modules' code. So every module path that the commit's `go.mod` names is looked up on Google's proxy and checksum database, even a private one, which fails there. The build's container then runs with `--network none` and reads the modules read-only, as a module proxy's files, so the commit's code can't reach your network or the services on your machine, such as the ones that Docker Desktop and podman machine forward to the Mac's `localhost`. +- **No capabilities and no new privileges.** Every container runs with `--cap-drop ALL` and `--security-opt no-new-privileges`. So root in the container can't give a file another owner or ignore a file's mode, and a setuid file in the commit's image gives no privileges, even under a rootful runtime, where root in the container would otherwise be root on your machine. +- **Bounded processes and memory.** Every container runs with `--pids-limit 8192` and `--memory 8g`, so a build that forks without end or keeps allocating stops at those limits rather than using up your machine's, which matters most under rootful Docker on Linux, whose containers share your kernel and have no limit of their own. Rootless podman supports them only on cgroups v2, with the `pids` and `memory` controllers delegated to your user, as systemd does by default. Disk space has no limit that both runtimes support, so while a build runs, it can fill the disk that holds your temporary folder or the runtime's storage, until the time limit stops it. +- **The right user.** The container runs as root under a rootless runtime, rootless podman or Docker's rootless mode, which maps root to you, and as you under a rootful one, Docker or Docker Desktop, so the files it writes are yours either way. The runtime's info says which, never its name, so podman behind a `docker` command runs as podman does, and a runtime that doesn't answer, such as Docker Desktop when it isn't running, stops the build before it starts. +- **Only your own files back.** The build writes its files to a folder of their own, mounted at `/out`, which the container can't swap for a link, because a mount point can't be renamed. Before `release.sh` copies, signs or keeps any of them, it checks that the folder is still the one it made, not a link to another, that everything in it is a file or a folder, never a link, that each is yours and is neither setuid, setgid, sticky nor writable by anyone, and that they come to 2 GiB at most, which a release is far under. Then it copies the files to `dist/` rather than moving them, so each copy is yours, with mode 0755 or 0644. So neither minisign, `publish.sh` nor `gh` follows a link that the container made, and no file the container wrote keeps its owner or its mode. +- **A time limit, and no container left behind.** `release.sh` names each container for its run alone and removes it from your machine once it has run for two hours, or for `DEVVM_RELEASE_TIMEOUT` seconds, whatever its image does. It removes it too as soon as `release.sh` stops early. Ctrl+C, a closed terminal and `kill` stop it at once, and after `kill -9` a watchdog that outlives `release.sh` removes the container and the build's temporary folder within a few seconds. The container's first process is `bash`, so the image's own entrypoint never runs. + ## The docs sites The docs have two sites, and the Docs workflow (`.github/workflows/docs.yml`) deploys both. devvm.dev shows the docs of the latest release, so what users read matches the devvm they install. next.devvm.dev shows the docs on `main`, for the next release, which is what someone trying a prerelease reads. A pull request that touches the docs gets their lints and a build, and it deploys nothing, so a pull request from a fork never reaches either site or its keys. diff --git a/docs/content/docs/contributing/structure.md b/docs/content/docs/contributing/structure.md index bd35272c..ccc4133d 100644 --- a/docs/content/docs/contributing/structure.md +++ b/docs/content/docs/contributing/structure.md @@ -107,7 +107,7 @@ Each package owns these concerns, and a package's `doc.go`, where it has one, ma | `internal/memnet` | the network in memory for [tests in a synctest bubble](tests.md#time-and-lifecycles): connections (`Pipe`) that close their writing side alone, hold a buffer's worth and have deadlines, and listeners by address (`Network`), for tests only, and the standard library only, so the proxy's tests use it too | | `testdata` | the CLI tests (`script/*.txtar`), the [golden fixtures](testing.md#golden-fixtures) (`golden//`), a lock to test with (`mise.lock`), each package's [coverage baseline](tests.md#coverage) on each system (`coverage/.txt`), each release's [state fixture](#released-state) (`v//`), and the lines that break each forbidigo rule (`lint/`, [Go lint rules](_index.md#go-lint-rules)) | | `tests/e2e`, `tests/e2e-mise.lock` | the [end-to-end tests](tests.md#end-to-end-tests) on real VMs, in Go with the tag `e2e` and a file for each section. `TestE2E` is the run, `sandbox_test.go` has the sandbox, its slot's paths and lock and `e2eUbuntuRelease`, and `slots_test.go` runs the slots. The lock file holds the shared tools' versions that every section but `tools` uses (`scripts/bump.sh e2e-tools`) | -| `scripts`, `packaging`, `.goreleaser.yaml`, `VERSION`, `CHANGELOG.md` | `bump.sh` updates the pins. `release.sh` runs the signed tag's checks around GoReleaser, then minisign, and `publish.sh` makes the release itself, with its checks, `release.sh`, one yes, then the pushes, `gh release` and the tap. The `test` and `coverage` tasks run `test.sh`, which runs `coverage.sh` to check each package's coverage against its baseline. `packaging/` holds the Homebrew formula and `key.go`, which embeds its folder, so devvm upgrade's key is `minisign.pub`'s, and a build without that file has none. Only the scripts read `VERSION` ([releasing](maintaining.md#releasing)) | +| `scripts`, `packaging`, `.goreleaser.yaml`, `VERSION`, `CHANGELOG.md` | `bump.sh` updates the pins. `release.sh` runs the signed tag's checks, then GoReleaser in its pinned container, then minisign, `repro-check.sh` builds a release twice and compares the bytes, and `publish.sh` makes the release itself, with its checks, `release.sh`, one yes, then the pushes, `gh release` and the tap. The `test` and `coverage` tasks run `test.sh`, which runs `coverage.sh` to check each package's coverage against its baseline. `packaging/` holds the Homebrew formula and `key.go`, which embeds its folder, so devvm upgrade's key is `minisign.pub`'s, and a build without that file has none. Only the scripts read `VERSION` ([releasing](maintaining.md#releasing)) | | `install.sh` | `curl \| bash`: it installs the host's archive, with the binary, the README, the changelog and the license, checked, into `~/.local/lib/devvm/`, then runs doctor's fixes, asking first. Tests source it (`DEVVM_INSTALL_TEST`) | ### The checks on owners diff --git a/docs/content/docs/releases/0.2.0.md b/docs/content/docs/releases/0.2.0.md index 43b544ad..6899b66d 100644 --- a/docs/content/docs/releases/0.2.0.md +++ b/docs/content/docs/releases/0.2.0.md @@ -162,6 +162,10 @@ opencode makes its worktrees in `~/.local/share/opencode/worktree` in the VM, an `devvm rm`, and a command that makes the VM again with `--clean-home`, now check those worktrees first, starting a stopped VM for the check. devvm shows each worktree's uncommitted changes under its path and asks before they go, and it asks too about a detached HEAD's commits that nothing else in the VM has, a worktree that git can't read, and more than 100 worktrees. `--force` never answers that question, so without a terminal devvm refuses and keeps the VM. When only the worktrees have work, its refusal names `--no-worktree-check`, a new flag that warns and goes ahead without the check. A remake's messages name the command with `--clean-home`, because `--no-worktree-check` works only with it, and so do the clone check's messages for `devvm clone off --clean-home`. For a VM whose folder is gone, `devvm rm VM` reads the worktrees from the running VM, and it refuses a stopped one, even with `--no-export`, naming `devvm rm VM --no-export --no-worktree-check`, because starting it would make its folder again. If a script deletes such VMs, or remakes them with `--clean-home`, give it `--no-worktree-check` where losing those changes is fine ([opencode's worktrees](../using/coding-agents.md#opencodes-worktrees)). +### Reproducible release builds + +Two builds of the same release on two machines gave different archives, because each archive recorded the owner and group of the files on the machine that built it, and the binary's version came from whichever tags that machine's clone of the repo held. Now every release file but the signature is built in one container image, pinned by its digest, with no network, no capabilities, bounded processes and memory, and a time limit kept outside it, with the Go and GoReleaser that the release's `mise.lock` pins, from a repository that holds only the release's commit and its own tag, and each archive file's owner, group, mode and time are set. So the same tag, built on an arm64 Mac or on an x86_64 Linux machine, gives byte-identical archives, source tarball, `install.sh` and `SHA256SUMS`. On each change, CI builds the release twice, once under podman as root and once under Docker as another user, from a repository with a stray tag, and checks that the two builds agree and that every archive's files are root's. `scripts/release.sh --tag` builds a published release again, unsigned, so another builder can compare its `SHA256SUMS` with the release's. Nothing changes for you ([Reproducible releases](../contributing/maintaining.md#reproducible-releases)). + ## Fixes ### A project folder devvm can't read diff --git a/internal/structure/pins_test.go b/internal/structure/pins_test.go index d1e12786..18d57e10 100644 --- a/internal/structure/pins_test.go +++ b/internal/structure/pins_test.go @@ -47,6 +47,8 @@ func pinPatterns() []pinPattern { // tests/e2e's pinned consts: an image digest, a dated release or a // version. {"tests/e2e/*.go", "", "", regexp.MustCompile(`(?m)^const (\w+) = ".*(?:sha256:[0-9a-f]{64}|release-[0-9]{8}|[0-9]+\.[0-9]+\.[0-9]+).*"$`)}, + // The container scripts/release.sh builds every release in. + {"scripts/release.sh", "", "", regexp.MustCompile(`(?m)^([a-z_]+_image)=`)}, {"docs/hugo.yaml", "", "", regexp.MustCompile(`([A-Za-z0-9_.-]+)@` + version)}, {"docs/hugo.yaml", "", "", regexp.MustCompile(`(?m)^\s*([A-Za-z_]+): ["']?` + version + `\.[0-9]+["']?\s*$`)}, // The docs build's npm packages: each "name": "version" in diff --git a/scripts/bump.sh b/scripts/bump.sh index 7e9e8dba..97302893 100755 --- a/scripts/bump.sh +++ b/scripts/bump.sh @@ -32,6 +32,9 @@ # ci: ci-mise actions # ci-mise: the mise the workflows install (jdx/mise-action's version), base's mise # actions: every workflow's uses:, by its release's tag's commit, then actionlint and zizmor +# release: release-image +# release-image: the container scripts/release.sh builds every release in (release_image), +# Debian's buildpack-deps:trixie-scm, by its index's digest # docs: hextra pele # hextra: the docs site's theme, docs/go.mod # pele (only when named): docs/package.json's pele, which draws the site's diagrams, through npm @@ -95,6 +98,7 @@ holds="node 25" # NAME BOUND...: node stays on its major, 24, which is an LTS re # pin tests/e2e:fromUbuntuDigest e2e-from # pin tests/e2e:curlImage e2e-curl # pin tests/e2e:dotnetOther - an SDK other than the shared one for a global.json to ask for: any older one works +# pin scripts/release.sh:release_image release-image # pin docs/package.json:npm:pele pele # pin docs/hugo.yaml:min - Hextra's oldest Hugo, which Hugo checks; mise.toml pins the Hugo that builds the site # Needs curl and jq, and per group mise (dev-tools, go, e2e lock checks, pele when applied), go @@ -103,7 +107,7 @@ holds="node 25" # NAME BOUND...: node stays on its major, 24, which is an LTS re # keys, so the affected images rebuild on next use: test with `devvm build `, then `devvm gc`. set -euo pipefail root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" -every="docker nix direnv nix-direnv mise git-lfs rustup crane omb eza tealdeer cursor e2e-tools e2e-from e2e-curl e2e-ubuntu e2e-lima go go-minor go-mods deadcode dev-tools ci-mise actions hextra pele" +every="docker nix direnv nix-direnv mise git-lfs rustup crane omb eza tealdeer cursor e2e-tools e2e-from e2e-curl e2e-ubuntu e2e-lima go go-minor go-mods deadcode dev-tools ci-mise actions release-image hextra pele" # Applied only when named: --check reports them. named_only="cursor go-minor pele" # Naming one of these applies its major too. @@ -588,6 +592,24 @@ bump_e2e-curl() { set_var $f curlImage "$repo:$new@sha256:$(shasum -a 256 "$tmp/e2e-curl-index" | cut -c1-64)" } +# The container every release is built in (scripts/release.sh's release_image): its tag's index on +# Docker Hub, by digest. Every release trusts what's in it: its git, awk, tar and gzip write and +# check the release's files, so read what a new digest changes before committing it. The digest is +# the SHA-256 of the index fetched, which every pull checks the registry's index against, and the +# index has to list linux/amd64 and linux/arm64 images, the two that builders run. +# scripts/repro-check.sh then checks that two builds still agree. +bump_release-image() { + local f=scripts/release.sh repo=library/buildpack-deps tag=trixie-scm cur new + cur=$(get $f release_image); cur=${cur##*@sha256:} + hub_index "$repo" "$tag" "$tmp/release-image-index" + new=$(sha256 "$tmp/release-image-index") + jq -e '[.manifests[].platform | "\(.os)/\(.architecture)"] | any(. == "linux/amd64") and any(. == "linux/arm64")' \ + "$tmp/release-image-index" >/dev/null || + { echo "bump: $repo:$tag's index has no linux/amd64 or no linux/arm64 image" >&2; exit 1; } + report "$tag" "${cur:0:12}" "${new:0:12}" digest || return 0 + set_var $f release_image "docker.io/$repo:$tag@sha256:$new" releaseImage +} + # Cursor's CLI, the one shared tool pinned for users (assets/shared-tools/mise.toml): the release # Cursor's install script fetches, with each platform's SHA-256 computed from its download, as Cursor # publishes none. Only when named: devvm's login and proxy code was read against the pinned release. @@ -832,6 +854,7 @@ for cur_tool in $tools; do go | go-minor | go-mods | deadcode) g=go ;; dev-tools) g=dev-tools ;; ci-mise | actions) g=ci ;; + release-image) g=release ;; hextra | pele) g=docs ;; *) g=images ;; esac diff --git a/scripts/publish.sh b/scripts/publish.sh index 030fda88..59f524ad 100755 --- a/scripts/publish.sh +++ b/scripts/publish.sh @@ -16,7 +16,8 @@ # devvm stays on the last release. # DEVVM_TAP_DIR: the checkout of devvmhq/homebrew-tap, clean and on main (default ../homebrew-tap, next to # this repo). DEVVM_MINISIGN_KEY: the release key (scripts/release.sh's). -# Needs gh, logged in (gh auth login), and release.sh's goreleaser and minisign: mise exec -- scripts/publish.sh. +# Needs gh, logged in (gh auth login), and release.sh's podman or Docker, curl and minisign: +# mise exec -- scripts/publish.sh. set -euo pipefail root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" cd "$root" diff --git a/scripts/release.sh b/scripts/release.sh index 08f30889..5a61e4d1 100755 --- a/scripts/release.sh +++ b/scripts/release.sh @@ -11,32 +11,61 @@ # Nothing is published. The version is VERSION's: x.y.z, or a prerelease's x.y.z-rc.N (any lowercase word, # such as beta or alpha, then a number). The public key is packaging/minisign.pub (committed); the secret key # is the maintainer's, at DEVVM_MINISIGN_KEY (default ~/.minisign/devvm.key), never in the repo. +# Every file but the signature is built in one container image, with the Go and GoReleaser that the +# built commit's mise.lock pins, so every builder makes the same bytes (scripts/repro-check.sh checks +# it). The image and the build's own code, this script's build below, are the built commit's copy of +# this script's, so a tag builds the same from any checkout. The build has no network: the Go modules +# it needs are downloaded first, in a container of this checkout's, with this checkout's Go (modules +# below). What runs here, outside the containers, is this checkout's: the tag's checks, the +# downloads, the checks on what the build wrote, and the signature, made after the containers are +# gone. Nothing of the built commit's runs outside its container, which runs with no capabilities, +# no new privileges, bounded processes and memory, and a time limit kept here, but it does run: it's +# as isolated as the container runtime keeps it. # scripts/release.sh from the tag v, which must exist and be signed (git tag -s) -# scripts/release.sh --head from HEAD, for testing (DEVVM_RELEASE_URL: where the archives will be; -# DEVVM_MINISIGN_KEY: a test key, else nothing is signed; +# scripts/release.sh --tag TAG +# the tag TAG's build, as its release's, with the same checks, but not +# signed, to compare with the published SHA256SUMS +# scripts/release.sh --head from HEAD, for testing, with HEAD's VERSION (DEVVM_RELEASE_URL: where the +# archives will be; DEVVM_MINISIGN_KEY: a test key, else nothing is signed; # DEVVM_MINISIGN_PUB: its public key, else packaging/minisign.pub) +# scripts/release.sh --commit COMMIT +# the same, from COMMIT # scripts/release.sh --check only the tag's checks and what the build needs, then prints the tag's commit # (scripts/publish.sh runs it first); nothing is built # scripts/release.sh --formula-from DIR # only the formulas, for VERSION's published release, from its SHA256SUMS # and SHA256SUMS.minisig downloaded into DIR, checked against minisign.pub # and its trusted comment, devvm -# Needs goreleaser and minisign, pinned in mise.toml: mise exec -- scripts/release.sh. +# Needs podman or Docker (DEVVM_RELEASE_RUNTIME names one, else podman is tried first), git, curl, and +# minisign to sign, pinned in mise.toml: mise exec -- scripts/release.sh. The downloads are kept in +# ${XDG_CACHE_HOME:-~/.cache}/devvm-release, by their SHA-256, and checked again before each build. +# Each container is removed after DEVVM_RELEASE_TIMEOUT seconds (two hours by default), or as soon +# as this script stops early: Ctrl+C, a closed terminal, kill, or kill -9. An unsigned build never +# replaces a dist/ that holds a signature, nor a test build one signed with the release key: move +# it, or set DEVVM_RELEASE_DIST. +# scripts/repro-check.sh sets DEVVM_RELEASE_SRC, a repository to fetch the commit and the tag from in +# place of this one (they're still checked here, by their hashes), and DEVVM_RELEASE_DIST, a folder +# that doesn't exist yet, for the files in place of dist/. The tests set DEVVM_RELEASE_TEST_FILE_URLS +# to the folder of their own tarballs, the one folder mise.lock's downloads may then name by file:// +# URL; it has to exist, and not be /. set -euo pipefail -root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" -cd "$root" die() { echo "release: $*" >&2; exit 1; } -v=$(tr -d '[:space:]' < VERSION) -# A release, x.y.z, or a prerelease of one, x.y.z-.N (such as 0.2.0-rc.1 or 0.2.0-beta.2). -[[ $v =~ ^[0-9]+\.[0-9]+\.[0-9]+(-[a-z]+\.[0-9]+)?$ ]] || die "VERSION isn't x.y.z or x.y.z-rc.N: '$v'" -ref=v$v -check=false +# The container this commit's release is built in, on every builder: Debian's, with git, by its +# index's digest (scripts/bump.sh release-image), so git, which writes the source tarball, and awk, +# tar and gzip are the same everywhere. A build reads it from the built commit's copy of this script, +# and the modules' download from this checkout's. +release_image=docker.io/library/buildpack-deps:trixie-scm@sha256:23479f0336f9f8dca3bc45bb0d5ad61c47993892cc31248455e08f43117fb682 -# The Homebrew formulas VERSION gets: devvm-rc, which follows prereleases, for every release, and devvm -# for a release that isn't a prerelease. -names=(devvm-rc) -[[ $v == *-* ]] || names=(devvm devvm-rc) +# sha256 FILE: its SHA-256, with sha256sum (coreutils) or shasum (macOS's). +sha256() { { sha256sum "$1" 2>/dev/null || shasum -a 256 "$1"; } | cut -c1-64; } + +# set_names VERSION: the Homebrew formulas VERSION gets, in names: devvm-rc, which follows prereleases, for +# every release, and devvm for a release that isn't a prerelease. +set_names() { + names=(devvm-rc) + [[ $1 == *-* ]] || names=(devvm devvm-rc) +} # formula TEMPLATE SUMS URL VERSION NAME: the Homebrew formula NAME, devvm or devvm-rc, from its template: # its class, the other formula, which it conflicts with (by its full name, which no other tap's devvm @@ -75,10 +104,124 @@ formulas() { for n in "${names[@]}"; do formula "$1" "$2" "$3" "$v" "$n" > "$4/$n.rb" || return 1; done } +# build VERSION COMMIT URL PUBKEY MODS OUT: the build, in the container, with no network, in its work +# folder (the current one), which holds src (a clone of the repo, not checked out) and dl (go.tar.gz +# and goreleaser.tar.gz, checked against mise.lock). MODS holds the Go modules the commit needs, as a +# GOPROXY's files (modules below), read-only. It builds in src/dist, then copies to OUT, a folder of +# its own: GoReleaser's files, install.sh set to VERSION and PUBKEY ("" for an unsigned test build), +# the formulas for the archives at URL, and SHA256SUMS with install.sh's line. Only what the commit +# and the container hold decides the bytes: the paths, the user, the umask, the zone and the locale +# are the same on every builder. +build() { + local commit=$2 url=$3 pubkey=$4 mods=$5 dest=$6 work=$PWD snap=() arch bin got + v=$1 + set_names "$v" + umask 022 + # The tools, HOME and Go's caches go in a folder of the container's own, not the shared work folder: + # Docker Desktop's share loses files that Go's parallel module downloads rename. Their paths never + # reach the files built (-trimpath). Not local: the trap reads it once build has returned. + local_=$(mktemp -d "${TMPDIR:-/tmp}/devvm-release-build.XXXXXX") + trap 'rm -rf "$local_"' EXIT + export HOME=$local_/home TZ=UTC LC_ALL=C.UTF-8 CGO_ENABLED=0 GOTOOLCHAIN=local GOFLAGS="-mod=readonly -modcacherw" \ + GOPATH=$local_/go GOCACHE=$local_/cache GOPROXY=file://$mods GOWORK=off GIT_CONFIG_NOSYSTEM=1 GIT_CONFIG_GLOBAL=/dev/null \ + GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0=safe.directory GIT_CONFIG_VALUE_0='*' + mkdir -p "$HOME" "$local_/tools/goreleaser" + # --no-same-owner: the container has no capabilities, so root in it can't give files the tarballs' + # owners. + { tar --no-same-owner -xzf dl/go.tar.gz -C "$local_/tools" && + tar --no-same-owner -xzf dl/goreleaser.tar.gz -C "$local_/tools/goreleaser"; } || + die "couldn't unpack Go and GoReleaser" + [[ -x $local_/tools/go/bin/go && -x $local_/tools/goreleaser/goreleaser ]] || + die "mise.lock's Go or GoReleaser download holds no go/bin/go or goreleaser" + export PATH=$local_/tools/go/bin:$local_/tools/goreleaser:$PATH + git -C src checkout -q --detach "$commit" || die "couldn't check out $commit" + [[ -n ${GORELEASER_CURRENT_TAG:-} ]] || snap=(--snapshot) + (cd src && DEVVM_VERSION=$v goreleaser release --clean --skip=publish ${snap[@]+"${snap[@]}"}) || die "goreleaser failed" + local out=$work/src/dist + + # The built binary for the container's system says the release's version (GoReleaser's own default + # sets one devvm doesn't read). + case $(uname -m) in arm64 | aarch64) arch=arm64 ;; x86_64) arch=amd64 ;; *) arch=none ;; esac + for bin in "$out"/devvm*_linux_"$arch"*/devvm; do + [[ -x $bin ]] || continue + got=$("$bin" --version) || die "$bin --version failed" + [[ $got == "$v" ]] || die "$bin --version says '$got', not $v" + done + + git -C src show "$commit:install.sh" | + awk -v v="$v" -v k="$pubkey" ' + /^release_version=""$/ { $0 = "release_version=\"" v "\""; n++ } + /^minisign_key=""$/ { $0 = "minisign_key=\"" k "\""; m++ } + { print } END { exit !(n == 1 && m == 1) }' \ + > "$out/install.sh" || die "install.sh needs one release_version=\"\" and one minisign_key=\"\" line" + chmod 755 "$out/install.sh" + git -C src show "$commit:packaging/homebrew/devvm.rb" > "$work/devvm.rb" || die "no packaging/homebrew/devvm.rb in $commit" + formulas "$work/devvm.rb" "$out/SHA256SUMS" "$url" "$out" || die "couldn't write the formulas" + + # install.sh's checksum goes in SHA256SUMS before it's signed, so you can check the script against the + # release key before you run it. + (cd "$out" && echo "$(sha256 install.sh) install.sh" >> SHA256SUMS) || die "couldn't add install.sh to SHA256SUMS" + cp -RP "$out/." "$dest/" || die "couldn't copy dist/ to $dest" +} + +# modules IN OUT: in the modules' container, the one with the network, this checkout's code, image +# and Go: the modules that IN's go.mod and go.sum need, downloaded with this checkout's Go +# (IN/go.tar.gz, from Google's downloads, checked against this checkout's mise.lock) from Go's +# module proxy alone, into OUT as a GOPROXY's files, for the build. Downloading runs none of the +# modules' code, and nothing of the commit's but those two files goes in. Every module path they +# name is looked up on Go's public proxy and checksum database, Google's. +modules() { + local in=$1 dest=$2 + umask 022 + local_=$(mktemp -d "${TMPDIR:-/tmp}/devvm-release-modules.XXXXXX") + trap 'rm -rf "$local_"' EXIT + export HOME=$local_/home GOPATH=$local_/go GOMODCACHE=$local_/go/pkg/mod GOCACHE=$local_/cache CGO_ENABLED=0 \ + GOTOOLCHAIN=local GOWORK=off GOFLAGS=-modcacherw GOPROXY=https://proxy.golang.org GOSUMDB=sum.golang.org \ + GONOSUMDB='' GONOPROXY='' GOPRIVATE='' GOVCS='*:off' + mkdir -p "$HOME" "$local_/tools" "$local_/m" + tar --no-same-owner -xzf "$in/go.tar.gz" -C "$local_/tools" || die "couldn't unpack Go" + cp "$in/go.mod" "$in/go.sum" "$local_/m/" || die "couldn't copy go.mod and go.sum" + (cd "$local_/m" && "$local_/tools/go/bin/go" mod download) || die "couldn't download the Go modules" + [[ ! -d $GOMODCACHE/cache/download ]] || cp -R "$GOMODCACHE/cache/download/." "$dest/" || + die "couldn't copy the Go modules to $dest" +} + +# In a container: the built commit's release.sh _build VERSION COMMIT URL PUBKEY MODS OUT, which the +# build below runs, and this checkout's release.sh _modules IN OUT. Every release.sh keeps _build's +# arguments, since a checkout builds other commits with theirs. case ${1:-} in - --head) ref=HEAD ;; + _build) shift; build "$@"; exit 0 ;; + _modules) shift; modules "$@"; exit 0 ;; +esac + +root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" +cd "$root" +# valid_version VERSION: a release, x.y.z, or a prerelease of one, x.y.z-.N (such as 0.2.0-rc.1 +# or 0.2.0-beta.2). +valid_version() { [[ $1 =~ ^[0-9]+\.[0-9]+\.[0-9]+(-[a-z]+\.[0-9]+)?$ ]]; } +# version_file: v, this checkout's VERSION. +version_file() { + v=$(tr -d '[:space:]' < VERSION) + valid_version "$v" || die "VERSION isn't x.y.z or x.y.z-rc.N: '$v'" +} + +# What's built: the tag ref, or a snapshot of the commit ref (--head, --commit), which takes its +# version from the commit's VERSION. A release is signed, --tag's build never is, and a snapshot only +# with a test key. +check=false snapshot=false unsigned=false +case ${1:-} in + --head) snapshot=true ref=HEAD ;; + --commit) + [[ $# == 2 && -n ${2:-} ]] || die "--commit needs one commit" + snapshot=true ref=$2 ;; + --tag) + [[ $# == 2 ]] || die "--tag needs one tag, v" + ref=$2 v=${2#v} unsigned=true + { [[ $ref == v* ]] && valid_version "$v"; } || die "--tag needs a release's tag, v, not '$ref'" ;; --check) check=true ;; --formula-from) + version_file + set_names "$v" # The formulas for a published release, from its downloaded SHA256SUMS and SHA256SUMS.minisig in # DIR, checked against packaging/minisign.pub, and signed as VERSION's release: its trusted comment # is devvm , as this script signs it. Nothing is built. @@ -95,16 +238,23 @@ case ${1:-} in for n in "${names[@]}"; do echo "==> dist/$n.rb for devvm $v, from $dir/SHA256SUMS"; done exit 0 ;; "") ;; - *) die "unknown argument '$1' (--head, --check, --formula-from DIR)" ;; + *) die "unknown argument '$1' (--head, --commit COMMIT, --tag TAG, --check, --formula-from DIR)" ;; esac -if [[ $ref == HEAD ]]; then obj=HEAD; else obj=$(git rev-parse -q --verify "refs/tags/$ref") || die "no tag $ref: tag the release first (git tag -s $ref)"; fi -# A release comes from a tag the maintainer signed, not just any tag with the right name. The tag -# object checked is the one built from: its commit is resolved once, and used for everything below. -[[ $ref == HEAD ]] || git verify-tag "$obj" >/dev/null 2>&1 || - die "tag $ref isn't signed by a key git trusts (make it with git tag -s; see docs/content/docs/contributing/maintaining.md)" -# And by the release signer, not just any key git trusts: its fingerprint is pinned in this checkout's -# packaging/release-signer (one per line; # comments), never the tagged commit's, which the tag brings. -if [[ $ref != HEAD ]]; then +if [[ -z ${ref:-} ]]; then version_file; ref=v$v; fi + +if $snapshot; then + commit=$(git rev-parse -q --verify --end-of-options "$ref^{commit}") || die "no commit $ref" + v=$(git show "$commit:VERSION" 2>/dev/null | tr -d '[:space:]') || true + valid_version "$v" || die "VERSION isn't x.y.z or x.y.z-rc.N: '$v'" +else + obj=$(git rev-parse -q --verify "refs/tags/$ref") || die "no tag $ref: tag the release first (git tag -s $ref)" + # A release comes from a tag the maintainer signed, not just any tag with the right name. The tag + # object checked is the one built from: its commit is resolved once, and used for everything below. + git verify-tag "$obj" >/dev/null 2>&1 || + die "tag $ref isn't signed by a key git trusts (make it with git tag -s; see docs/content/docs/contributing/maintaining.md)" + # And by the release signer, not just any key git trusts: its fingerprint is pinned in this + # checkout's packaging/release-signer (one per line; # comments), never the tagged commit's, which + # the tag brings. signers=$root/packaging/release-signer [[ -s $signers ]] || die "no packaging/release-signer: write the tag-signing key's fingerprint there (see docs/content/docs/contributing/maintaining.md)" raw=$(git verify-tag --raw "$obj" 2>&1) || true @@ -117,75 +267,293 @@ if [[ $ref != HEAD ]]; then [[ -n $fp ]] && grep -v '^#' "$signers" | tr -d ' \t' | grep -xiF "$fp" >/dev/null && ok=true done <<<"$fps" $ok || die "tag $ref is signed by $(paste -sd' ' - <<<"$fps"), not a key in packaging/release-signer" + commit=$(git rev-parse -q --verify "$obj^{commit}") || die "no commit for $ref" + [[ "$(git show "$commit:VERSION" | tr -d '[:space:]')" == "$v" ]] || die "$ref's VERSION isn't $v" fi -commit=$(git rev-parse -q --verify "$obj^{commit}") || die "no commit for $ref" -[[ "$(git show "$commit:VERSION" | tr -d '[:space:]')" == "$v" ]] || die "$ref's VERSION isn't $v" pubkey=$(git show "$commit:packaging/minisign.pub" 2>/dev/null | sed -n 2p) || true -# A test key's public key, for HEAD only: a release verifies with the committed one. -if [[ $ref == HEAD && -n ${DEVVM_MINISIGN_PUB:-} ]]; then +# A test key's public key, for a snapshot only: a release verifies with the committed one. +if $snapshot && [[ -n ${DEVVM_MINISIGN_PUB:-} ]]; then pubkey=$(sed -n 2p "$DEVVM_MINISIGN_PUB") || die "can't read $DEVVM_MINISIGN_PUB" fi key=${DEVVM_MINISIGN_KEY:-$HOME/.minisign/devvm.key} sign=true -if [[ $ref == HEAD && -z ${DEVVM_MINISIGN_KEY:-} ]]; then sign=false -else +if $unsigned || { $snapshot && [[ -z ${DEVVM_MINISIGN_KEY:-} ]]; }; then sign=false; fi +# A release's install.sh trusts the committed key, signed or not (--tag). +if $sign || ! $snapshot; then [[ -n $pubkey ]] || die "no packaging/minisign.pub in $ref: create the release key first (see docs/content/docs/contributing/maintaining.md)" +fi +if $sign; then [[ -f $key ]] || die "no release key at $key (DEVVM_MINISIGN_KEY)" command -v minisign >/dev/null || die "needs minisign to sign the release (mise exec -- scripts/release.sh)" fi git cat-file -e "$commit:install.sh" 2>/dev/null || die "no install.sh in $ref" -command -v goreleaser >/dev/null || die "needs goreleaser (mise exec -- scripts/release.sh)" +# The container image is the built commit's, as its build is (the header says why), pinned by its +# digest. A commit from before reproducible builds names none, and builds with its own release.sh. +image=$(git show "$commit:scripts/release.sh" 2>/dev/null | sed -n 's/^release_image=//p') || true +[[ $image =~ ^docker\.io/[a-z0-9._/-]+:[A-Za-z0-9._-]+@sha256:[0-9a-f]{64}$ ]] || + die "$ref's scripts/release.sh pins no release_image by digest, so it's from before reproducible builds: build it with its own scripts/release.sh" +# The container runtime: DEVVM_RELEASE_RUNTIME's, else podman, else Docker. +runtime=${DEVVM_RELEASE_RUNTIME:-} +if [[ -z $runtime ]]; then + for r in podman docker; do command -v "$r" >/dev/null && { runtime=$r; break; }; done +fi +if [[ -z $runtime ]] || ! command -v "$runtime" >/dev/null; then + die "needs podman or Docker to build in its container (DEVVM_RELEASE_RUNTIME names one)" +fi +# The user the container runs as, so that what it writes in the work folder is yours: root under a +# rootless runtime (podman's default, and Docker's rootless mode), which maps root to you, and you +# under a rootful one (Docker, Docker Desktop). The runtime says which: podman in its info's +# Host.Security.Rootless, as does podman behind a docker command (podman-docker), and Docker by +# listing rootless in its security options. Its name doesn't. +rootless= +if ver=$("$runtime" --version 2>/dev/null) && [[ $ver == podman* ]]; then + rootless=$("$runtime" info --format '{{.Host.Security.Rootless}}' 2>/dev/null) || rootless= +elif so=$("$runtime" info --format '{{json .SecurityOptions}}' 2>/dev/null); then + rootless=false + [[ $so != *name=rootless* ]] || rootless=true +fi +case $rootless in + true) user=0:0 ;; + false) user=$(id -u):$(id -g) ;; + *) die "$runtime didn't say whether it's rootless: is it running? ($runtime info)" ;; +esac +command -v curl >/dev/null || die "needs curl to download Go and GoReleaser" if $check; then echo "$commit"; exit 0; fi url=${DEVVM_RELEASE_URL:-https://github.com/devvmhq/devvm/releases/download/v$v} - -# GoReleaser builds a clone of the commit, so only what's committed goes in, whatever this checkout -# holds. The version is VERSION's, for HEAD too (DEVVM_VERSION, in .goreleaser.yaml's snapshot). out=$root/dist +if [[ -n ${DEVVM_RELEASE_DIST:-} ]]; then + out=$DEVVM_RELEASE_DIST + [[ $out == /* && ! -e $out && ! -L $out ]] || die "DEVVM_RELEASE_DIST isn't an absolute path that doesn't exist yet: '$out'" +fi +# An unsigned build, such as --tag's, never replaces a signed one's files, and a test build, signed +# with a test key, never replaces a build signed with the release key, this checkout's +# packaging/minisign.pub. +if ! $sign && [[ -z ${DEVVM_RELEASE_DIST:-} && -e $out/SHA256SUMS.minisig ]]; then + die "dist/ holds a signed build, which this unsigned one would replace: move it first, or set DEVVM_RELEASE_DIST to a new folder" +fi +if $sign && $snapshot && [[ -z ${DEVVM_RELEASE_DIST:-} && -e $out/SHA256SUMS.minisig && -f $root/packaging/minisign.pub ]] && + minisign -Vm "$out/SHA256SUMS" -x "$out/SHA256SUMS.minisig" -p "$root/packaging/minisign.pub" >/dev/null 2>&1; then + die "dist/ holds a build signed with the release key (packaging/minisign.pub), which this test build would replace: move it first, or set DEVVM_RELEASE_DIST to a new folder" +fi +src=${DEVVM_RELEASE_SRC:-$root} +[[ $src == /* ]] || die "DEVVM_RELEASE_SRC isn't an absolute path: '$src'" +limit=${DEVVM_RELEASE_TIMEOUT:-7200} +[[ $limit =~ ^[1-9][0-9]{0,5}$ ]] || die "DEVVM_RELEASE_TIMEOUT isn't a number of seconds: '$limit'" + +# The container runs this system's processor, and gets that platform's Go and GoReleaser from the +# commit's mise.lock: its URL, and its SHA-256, which every copy is checked against before it's used. +case $(uname -m) in + arm64 | aarch64) arch=arm64 platform=linux-arm64 ;; + x86_64 | amd64) arch=amd64 platform=linux-x64 ;; + *) die "no release container for $(uname -m)" ;; +esac +lock=$(git show "$commit:mise.lock" 2>/dev/null) || die "no mise.lock in $ref" +[[ -f $root/mise.lock ]] || die "no mise.lock in this checkout" +# The commit's go.mod needs a Go no newer than this checkout's, which downloads its modules (below). +modgo=$(git show "$commit:go.mod" 2>/dev/null | sed -n 's/^go[[:space:]]\{1,\}\([0-9][0-9a-z.]*\).*/\1/p' | head -1) || true + tmp=$(mktemp -d "${TMPDIR:-/tmp}/devvm-release.XXXXXX") -trap 'rm -rf "$tmp"' EXIT -src=$tmp/src -{ git clone -q --no-checkout "$root" "$src" && git -C "$src" checkout -q --detach "$commit"; } || - die "couldn't check out $ref" -snap=() -if [[ $ref == HEAD ]]; then snap=(--snapshot); else export GORELEASER_CURRENT_TAG=$ref; fi -(cd "$src" && DEVVM_VERSION=$v goreleaser release --clean --skip=publish ${snap[@]+"${snap[@]}"}) || die "goreleaser failed" -rm -rf "$out" -mv "$src/dist" "$out" +# The container running now (contained, below): its name, its client's pid and its watchdog's. +live='' live_pid='' live_wd='' +# stop NAME PID: the container NAME removed, running or not, and its client, PID, ended: given 5 +# seconds to exit as its container goes, then killed. Then the container's removed again, in case +# the client was creating it. +stop() { + local i=0 + "$runtime" rm -f "$1" >/dev/null 2>&1 || true + if [[ -n $2 ]]; then + while kill -0 "$2" 2>/dev/null && (( i++ < 50 )); do sleep 0.1; done + kill -9 "$2" 2>/dev/null || true + fi + "$runtime" rm -f "$1" >/dev/null 2>&1 || true +} +# However this script ends, the running container is removed, and the temp folder (chmod first: a +# folder the container left without write permission would keep rm from emptying it). Ctrl+C, a +# closed terminal and kill end it through the EXIT trap, at once, as the client runs in the +# background (contained). kill -9 runs no trap: the watchdog does the same. +trap 'if [[ -n $live ]]; then + echo "release: stopping the container $live" >&2 + [[ -z $live_wd ]] || kill "$live_wd" 2>/dev/null || true + stop "$live" "$live_pid" + fi + chmod -R u+rwx "$tmp" 2>/dev/null; rm -rf "$tmp"' EXIT +trap 'exit 130' INT +trap 'exit 129' HUP +trap 'exit 143' TERM +work=$tmp/work +mkdir -p "$work/dl" +cache=${XDG_CACHE_HOME:-$HOME/.cache}/devvm-release -# The built binary for this host says the release's version (GoReleaser's own default sets one devvm -# doesn't read). -os=$(uname -s | tr '[:upper:]' '[:lower:]') -case $(uname -m) in arm64 | aarch64) arch=arm64 ;; x86_64) arch=amd64 ;; *) arch=none ;; esac -for bin in "$out"/devvm*_"${os}_$arch"*/devvm; do - [[ -x $bin ]] || continue - got=$("$bin" --version) || die "$bin --version failed" - [[ $got == "$v" ]] || die "$bin --version says '$got', not $v" -done +# fetch LOCK WHOSE TOOL DEST: TOOL's download for this platform, as LOCK, WHOSE mise.lock (HEAD's, +# this checkout's), pins it, into DEST, checked; tool_version: its version there. +fetch() { + local lock=$1 whose=$2 tool=$3 dest=$4 n m dl sum from proto files + # The tool's one [[tools.TOOL]] entry, its version, and its one [tools.TOOL."platforms.PLATFORM"] + # table: its url and checksum. A lock with two of either (two versions, or a merge gone wrong) is + # refused, rather than read for whichever comes last. + read -r n m dl sum tool_version < <(awk -v e="[[tools.$tool]]" -v t="[tools.$tool.\"platforms.$platform\"]" ' + $0 == e { n++; g = 1; s = 0; next } $0 == t { m++; s = 1; g = 0; next } /^\[/ { s = 0; g = 0 } + g && $1 == "version" { ver = $3 } s && $1 == "url" { u = $3 } s && $1 == "checksum" { c = $3 } + END { gsub(/"/, "", u); gsub(/"/, "", c); gsub(/"/, "", ver); sub(/^sha256:/, "", c); print n + 0, m + 0, u, c, ver }' <<<"$lock") || true + (( n <= 1 )) || die "$whose mise.lock has $n $tool entries, not one" + (( m <= 1 )) || die "$whose mise.lock has $m $tool downloads for $platform, not one" + [[ $n == 1 && -n $dl && $sum =~ ^[0-9a-f]{64}$ ]] || die "$whose mise.lock has no $tool download for $platform" + # The download comes only from the tool's own publisher, over https, and goes to curl as --url's + # value, so nothing in the lock can be read as one of curl's options. No %, which curl would + # decode, so .. can't hide in it. file:// is for the tests, and only from the one folder they name, + # which has to exist and not be /, so the switch set by mistake reads nothing else of yours. + case $tool in + go) from=https://dl.google.com/go/ ;; + *) from=https://github.com/goreleaser/goreleaser/releases/download/ ;; + esac + proto='=https' files=${DEVVM_RELEASE_TEST_FILE_URLS:-} + if [[ $files == /* && -d $files && $(cd -P "$files" && pwd) != / ]]; then from=file://$files/ proto='=file'; fi + if [[ $dl != "$from"* || $dl == *..* || ! $dl =~ ^[A-Za-z0-9:/._~+-]+$ ]]; then + die "$whose mise.lock downloads $tool from '$dl', not $from" + fi + if [[ ! -f $cache/$sum ]]; then + mkdir -p "$cache" + curl -fsSL --retry 3 --proto "$proto" --proto-redir =https --connect-timeout 30 --max-time 900 \ + --max-filesize $((1 << 30)) -o "$cache/$sum.part" --url "$dl" || die "couldn't download $dl" + mv "$cache/$sum.part" "$cache/$sum" + fi + cp "$cache/$sum" "$dest" + [[ $(sha256 "$dest") == "$sum" ]] || + { rm -f "$cache/$sum"; die "$dl doesn't match $whose mise.lock (sha256:$sum)"; } +} +# newer A B: whether Go version A (1.22, 1.22.3, 1.23rc1) is newer than B, number by number. +newer() { + awk -v a="$1" -v b="$2" 'BEGIN { + na = split(a, x, "."); nb = split(b, y, ".") + for (i = 1; i <= (na > nb ? na : nb); i++) if (x[i] + 0 != y[i] + 0) exit !(x[i] + 0 > y[i] + 0) + exit 1 }' +} +fetch "$lock" "$ref's" go "$work/dl/go.tar.gz" +fetch "$lock" "$ref's" goreleaser "$work/dl/goreleaser.tar.gz" +# The modules' Go is this checkout's, so the container with the network runs nothing the commit +# chose. go.sum pins the module files, so they're the same whichever Go downloads them. +fetch "$(cat "$root/mise.lock")" "this checkout's" go "$tmp/checkout-go.tar.gz" +[[ -n $tool_version ]] || die "this checkout's mise.lock has no go version" +if [[ -n $modgo ]] && newer "$modgo" "$tool_version"; then + die "$ref's go.mod needs Go $modgo, newer than the $tool_version this checkout's mise.lock pins: build it from a checkout at least as new" +fi -$sign || pubkey="" # an unsigned test build: its install.sh doesn't expect a signature +# GoReleaser builds the commit in a repository of the build's own, so only what's committed goes +# in, whatever this checkout holds. The version is the commit's VERSION (DEVVM_VERSION, in +# .goreleaser.yaml's snapshot too). The repository holds the commit and, for a tag, the tag, fetched +# into a pack: none of this one's other branches, tags or objects, which the container would see, +# and no files shared with it, as a local clone's hardlinks would be, which the container could +# write. No tag but the one built from, too, because Go stamps the binary with a version from the +# tags it finds, and every builder holds different ones. It starts with no hooks (--template=). Its +# origin is devvm's repository on GitHub, which GoReleaser reads but nothing fetches from: without +# one, GoReleaser refuses a release and builds a snapshot with no commit. +{ git -c init.defaultBranch=build init -q --template= "$work/src" && + git -C "$work/src" -c protocol.version=2 fetch -q --no-tags --update-shallow "$src" "$commit" && + git -C "$work/src" cat-file -e "$commit^{commit}" && + git -C "$work/src" remote add origin https://github.com/devvmhq/devvm.git; } || die "couldn't fetch $commit from $src" +if ! $snapshot; then + git -C "$work/src" fetch -q --no-tags "$src" "refs/tags/$ref:refs/tags/$ref" || die "couldn't fetch the tag $ref" + [[ $(git -C "$work/src" rev-parse "refs/tags/$ref") == "$obj" ]] || die "the tag $ref changed during the build" +fi +git show "$commit:scripts/release.sh" > "$work/release.sh" || die "no scripts/release.sh in $ref" -git show "$commit:install.sh" | - awk -v v="$v" -v k="$pubkey" ' - /^release_version=""$/ { $0 = "release_version=\"" v "\""; n++ } - /^minisign_key=""$/ { $0 = "minisign_key=\"" k "\""; m++ } - { print } END { exit !(n == 1 && m == 1) }' \ - > "$out/install.sh" || die "install.sh needs one release_version=\"\" and one minisign_key=\"\" line" -chmod 755 "$out/install.sh" -git show "$commit:packaging/homebrew/devvm.rb" > "$tmp/devvm.rb" || die "no packaging/homebrew/devvm.rb in $ref" -formulas "$tmp/devvm.rb" "$out/SHA256SUMS" "$url" "$out" || die "couldn't write the formulas" +# contained WHAT ARGS…: "$runtime" run ARGS, named for this run alone (its temp folder's suffix, so +# no other run's container, even one left over, has the name), and removed from here, whatever its +# image does: the image's own timeout could be anything. A watchdog removes it once it has run for +# the time limit, or as soon as this script is gone, even by kill -9, and then the temp folder too. +# The client runs in the background, so Ctrl+C, which it then ignores, and kill run this script's +# traps at once: in the foreground, bash would wait for the client, and the client for the +# container's first process, bash as its PID 1, which ignores them. WHAT, in a failure's message, is +# what it ran. +n=0 +contained() { + local what=$1 name rc=0 + shift + n=$((n + 1)) name=devvm-release-${tmp##*.}-$n + live=$name + "$runtime" run --name "$name" "$@" & + live_pid=$! + ( trap '' INT HUP + i=0 + while (( i < limit )); do + sleep 1 + if ! kill -0 "$$" 2>/dev/null; then + stop "$name" "$live_pid" + chmod -R u+rwx "$tmp" 2>/dev/null; rm -rf "$tmp" + exit 0 + fi + i=$((i + 1)) + done + : > "$tmp/$name.late" + stop "$name" "$live_pid" ) >/dev/null 2>&1 & + live_wd=$! + wait "$live_pid" || rc=$? + kill "$live_wd" 2>/dev/null || true + wait "$live_wd" 2>/dev/null || true + live='' live_pid='' live_wd='' + [[ ! -e $tmp/$name.late ]] || die "$what ran for $limit seconds, the limit (DEVVM_RELEASE_TIMEOUT), so it was stopped" + (( rc == 0 )) || die "$what failed" +} +# Every container: no capabilities, so root in it can't take a file's owner or bypass its mode, no +# new privileges, so a setuid file in the image gives none, at most 8192 processes and 8 GiB of +# memory, so a build under a rootful runtime can't use up the machine's, and bash as its first +# process, so the image's own entrypoint never runs. +base=(--rm --platform "linux/$arch" --user "$user" --security-opt no-new-privileges --cap-drop ALL + --pids-limit 8192 --memory 8g --entrypoint bash) + +# The Go modules the commit's go.mod needs, downloaded first, the only step with the network: in this +# checkout's release_image, by this checkout's release.sh (modules) and Go, from go.mod and go.sum +# alone. +in=$tmp/in mods=$tmp/mod o=$tmp/out +mkdir "$in" "$mods" "$o" +git show "$commit:go.mod" > "$in/go.mod" 2>/dev/null || die "no go.mod in $ref" +git show "$commit:go.sum" > "$in/go.sum" 2>/dev/null || : > "$in/go.sum" +mv "$tmp/checkout-go.tar.gz" "$in/go.tar.gz" +cp "$root/scripts/release.sh" "$in/release.sh" +echo "==> downloading $ref's Go modules in $release_image, under $runtime as $user" +contained "the modules' download in $release_image" "${base[@]}" -v "$in:/in:ro,z" -v "$mods:/out:z" -w /in \ + "$release_image" /in/release.sh _modules /in /out + +# The build, with no network, the modules read-only, and its files written to a folder of their own, +# /out, which the container can't swap for a link, as a mount point can't be renamed. +opts=("${base[@]}" --network none -v "$work:/work:z" -v "$mods:/mod:ro,z" -v "$o:/out:z" -w /work) +$snapshot || opts+=(-e "GORELEASER_CURRENT_TAG=$ref") +# An unsigned snapshot is a test build, whose install.sh expects no signature; --tag's is the release's. +if $snapshot && ! $sign; then pubkey=""; fi +echo "==> building $commit in $image, under $runtime as $user" +contained "the build in $image" "${opts[@]}" "$image" /work/release.sh _build "$v" "$commit" "$url" "$pubkey" /mod /out + +# What the container wrote is checked before anything here reads it, and copied, never moved: the +# folder is still the one this script made, every path in it is a file or a folder, never a link, +# which minisign, publish.sh and gh would follow to a file of yours, and each is yours, and neither +# setuid, setgid, sticky nor writable by anyone. The copies are yours, 0755 or 0644. +[[ -d $o && ! -L $o && $(cd -P "$o" && pwd) == "$(cd -P "$tmp" && pwd)/out" ]] || + die "the build's output folder isn't the one it was given: nothing is signed or kept" +[[ -f $o/SHA256SUMS && ! -L $o/SHA256SUMS ]] || die "the build left no SHA256SUMS: nothing is signed or kept" +bad=$(find "$o" -mindepth 1 ! -type f ! -type d -print -quit) || die "couldn't read the build's files" +[[ -z $bad ]] || die "the build left ${bad#"$o/"}, which isn't a file or a folder: nothing is signed or kept" +bad=$(find "$o" -mindepth 1 \( ! -user "$(id -u)" -o -perm -4000 -o -perm -2000 -o -perm -1000 -o -perm -0002 \) -print -quit) || + die "couldn't read the build's files" +[[ -z $bad ]] || + die "the build left ${bad#"$o/"}, which isn't yours, or is setuid, setgid, sticky or writable by anyone: nothing is signed or kept" +# And no more than 2 GiB, which a release is far under, so the copy can't fill dist/'s disk: counted +# as read, sparse files whole, and read no further than the limit. +cap=$((2 << 30)) +size=$({ find "$o" -type f -exec cat {} + 2>/dev/null || true; } | head -c $((cap + 1)) | wc -c | tr -d ' ') +(( size <= cap )) || die "the build left more than 2 GiB of files: nothing is signed or kept" +[[ -n ${DEVVM_RELEASE_DIST:-} ]] || rm -rf "$out" +mkdir "$out" +{ cp -R "$o/." "$out/" && chmod -R u=rwX,go=rX "$out"; } || die "couldn't copy the build's files to $out" -# install.sh's checksum goes in SHA256SUMS before it's signed, so you can check the script against the -# release key before you run it. -(cd "$out" && { sha256sum install.sh 2>/dev/null || shasum -a 256 install.sh; } >> SHA256SUMS) || - die "couldn't add install.sh to SHA256SUMS" if $sign; then minisign -Sm "$out/SHA256SUMS" -s "$key" -t "devvm $v" || die "couldn't sign SHA256SUMS" minisign -Vm "$out/SHA256SUMS" -P "$pubkey" >/dev/null || die "SHA256SUMS.minisig doesn't verify with packaging/minisign.pub" fi -echo "==> dist/ for devvm $v (from $ref):" +echo "==> ${DEVVM_RELEASE_DIST:-dist}/ for devvm $v (from $ref):" (cd "$out" && ls -l devvm-*.tar.gz SHA256SUMS* install.sh devvm*.rb 2>/dev/null) || true -$sign || echo "(not signed: a test build without DEVVM_MINISIGN_KEY)" +if $unsigned; then echo "(not signed: --tag builds the release without its signature)" +elif ! $sign; then echo "(not signed: a test build without DEVVM_MINISIGN_KEY)"; fi if [[ $v == *-* ]]; then echo "scripts/publish.sh publishes them: the archives, SHA256SUMS, SHA256SUMS.minisig and install.sh to the GitHub prerelease v$v, devvm-rc.rb to devvmhq/homebrew-tap's Formula/; the formula devvm keeps the last release." else diff --git a/scripts/repro-check.sh b/scripts/repro-check.sh new file mode 100755 index 00000000..3719b4cf --- /dev/null +++ b/scripts/repro-check.sh @@ -0,0 +1,105 @@ +#!/bin/bash +# Check that a release builds to the same bytes twice. Both builds are this checkout's +# scripts/release.sh, which runs the built commit's code only in its container, never here directly. +# That code still runs, in a container only as isolated as the runtime keeps it, so an outside +# commit, such as a pull request's, is checked only with the maintainer's go-ahead for that run. +# A commit (HEAD by default) builds as release.sh --commit builds it, unsigned; +# a tag, v, builds as its release does (release.sh --tag: the tag's checks, and no +# signature), so its SHA256SUMS can be compared with the published one. +# The second build differs from the first in what release.sh and .goreleaser.yaml keep out of the +# bytes, so that losing either shows as a difference: +# - it fetches the commit from a repository with a stray tag at it, v0.0.0-stray, which Go would +# stamp into the binary as its version if the build saw it (a v0 version, as Go ignores a tag +# whose major version the module's path doesn't name); +# - it runs under Docker where the first runs under podman, when both are installed, so as you +# where the first runs as root, which the archives would record. +# And every file in each platform's archive has to be root's, with mode 0755 or 0644, whatever +# either build ran as. It prints each file's SHA-256, says DIFFERS beside any file whose two builds +# differ, and exits 1 when one does or an archive's headers aren't those. Both builds run on this +# machine, in the same image and on its processor: to compare two machines, run it on each and +# compare the printouts. Nothing is signed or published. CI's repro job runs it. +# scripts/repro-check.sh [COMMIT | TAG] +set -euo pipefail +root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" +die() { echo "repro-check: $*" >&2; exit 1; } +case ${1:-} in -h | --help) awk 'NR > 1 && !/^#/ { exit } NR > 1 { sub(/^# ?/, ""); print }' "$0"; exit 0 ;; esac +(( $# <= 1 )) || die "too many arguments: scripts/repro-check.sh [COMMIT | TAG]" +arg=${1:-HEAD} +commit=$(git -C "$root" rev-parse -q --verify --end-of-options "$arg^{commit}") || die "no commit $arg" +how=(--commit "$commit") +if [[ $arg == v* ]] && git -C "$root" rev-parse -q --verify "refs/tags/$arg" >/dev/null; then how=(--tag "$arg"); fi + +# The runtimes: podman, then Docker, when both are installed, else the one there is, or +# DEVVM_RELEASE_RUNTIME's for both. +if [[ -n ${DEVVM_RELEASE_RUNTIME:-} ]]; then rt1=$DEVVM_RELEASE_RUNTIME rt2=$rt1 +elif command -v podman >/dev/null && command -v docker >/dev/null; then rt1=podman rt2=docker +elif command -v podman >/dev/null; then rt1=podman rt2=podman +elif command -v docker >/dev/null; then rt1=docker rt2=docker +else die "needs podman or Docker to build in the release's container (DEVVM_RELEASE_RUNTIME names one)" +fi + +sha256() { { sha256sum "$1" 2>/dev/null || shasum -a 256 "$1"; } | cut -c1-64; } +tmp=$(mktemp -d "${TMPDIR:-/tmp}/devvm-repro.XXXXXX") +trap 'rm -rf "$tmp"' EXIT + +# Build 2's repository, never checked out: the commit, the tag when it's one, and the stray tag. +src=$tmp/src +{ git -c init.defaultBranch=build init -q --template= "$src" && + git -C "$src" -c protocol.version=2 fetch -q --no-tags --update-shallow "$root" "$commit" && + git -C "$src" tag v0.0.0-stray "$commit"; } || die "couldn't make build 2's repository" +if [[ ${how[0]} == --tag ]]; then + git -C "$src" fetch -q --no-tags "$root" "refs/tags/$arg:refs/tags/$arg" || die "couldn't fetch $arg" +fi + +# build N RUNTIME REPO: build N, into $tmp/N, under RUNTIME, fetching from REPO; then what it ran +# under, as release.sh says it: RUNTIME as UID:GID. A run that says nothing of it, or leaves no +# files, failed, whatever its exit status. +build() { + local under + echo "==> build $1 of $arg ($commit), under $2" >&2 + env -u DEVVM_MINISIGN_KEY -u DEVVM_MINISIGN_PUB -u DEVVM_RELEASE_URL DEVVM_RELEASE_RUNTIME="$2" \ + DEVVM_RELEASE_SRC="$3" DEVVM_RELEASE_DIST="$tmp/$1" "$root/scripts/release.sh" "${how[@]}" > "$tmp/$1.log" 2>&1 || + { tail -40 "$tmp/$1.log" >&2; die "build $1 failed: its log is above"; } + under=$(sed -n 's/^==> building .*, under //p' "$tmp/$1.log") + [[ -n $under && -d $tmp/$1 ]] || { tail -40 "$tmp/$1.log" >&2; die "build $1 made no release: its log is above"; } + echo "$under" +} +u1=$(build 1 "$rt1" "$root") +u2=$(build 2 "$rt2" "$src") +echo "==> build 1: under $u1, from this repository" +echo "==> build 2: under $u2, from one with a stray tag, v0.0.0-stray, at the commit" +if [[ ${u1##* as } == "${u2##* as }" ]]; then + echo "(both ran as the same user: with podman and Docker both installed, they don't; the archives' headers are checked either way)" +fi + +# headers ARCHIVE: each entry's mode and its owner/group, by name, then by number, from tar -tv: +# GNU tar's listing has owner/group in one field, and bsdtar's a link count, then each. +headers() { + { tar -tvzf "$1" && tar --numeric-owner -tvzf "$1"; } | + awk '{ if ($2 ~ /\//) print $1, $2; else print $1, $3 "/" $4 }' +} + +# The release's files: what scripts/publish.sh uploads, and the formulas, in C's order on every +# builder. +a=$tmp/1 b=$tmp/2 +files=$(cd "$a" && LC_ALL=C ls devvm-*.tar.gz SHA256SUMS install.sh devvm*.rb) +[[ $(cd "$b" && LC_ALL=C ls devvm-*.tar.gz SHA256SUMS install.sh devvm*.rb) == "$files" ]] || die "the builds made different files" +same=true root_owned=true +while IFS= read -r f; do + x=$(sha256 "$a/$f") y=$(sha256 "$b/$f") + if [[ $x == "$y" ]]; then + echo "$x $f" + else + echo "$x $f DIFFERS: build 2 made $y" + same=false + fi + [[ $f =~ -(darwin|linux)-(arm64|amd64)\.tar\.gz$ ]] || continue + for n in 1 2; do + bad=$(headers "$tmp/$n/$f" | awk '!(($1 == "-rwxr-xr-x" || $1 == "-rw-r--r--" || $1 == "drwxr-xr-x") && ($2 == "root/root" || $2 == "0/0"))') || + die "couldn't list $f" + [[ -z $bad ]] || { echo " $f, build $n: not root's with mode 0755 or 0644: $(head -n 1 <<<"$bad")"; root_owned=false; } + done +done <<<"$files" +$same || die "the two builds differ" +$root_owned || die "an archive holds a file that isn't root's with mode 0755 or 0644" +echo "==> both builds of $arg ($commit) made the same bytes" diff --git a/testdata/script/bump.txtar b/testdata/script/bump.txtar index 683dd49d..11e913f9 100644 --- a/testdata/script/bump.txtar +++ b/testdata/script/bump.txtar @@ -25,6 +25,28 @@ cmp stdout mise-base.want exec grep -E 'miseVersion =|"(macos|linux)-' repo/internal/tools/mise.go cmp stdout mise-go.want +# release-image moves the container release.sh builds in to its tag's +# index on Docker Hub, by the index's digest, and leaves the rest of the +# script as it was. +exec repo/scripts/bump.sh release-image +stdout '^\[release\]$' +stdout '^ trixie-scm [0-9a-f]{12} +-> 22d8ca894214 \(digest\)$' +exec grep '^release_image=' repo/scripts/release.sh +cmp stdout release-image.want +exec bash -c 'diff "$DEVVM_REPO/scripts/release.sh" repo/scripts/release.sh | grep -c "^[<>]"' +stdout '^2$' +exec repo/scripts/bump.sh --check release-image +stdout '^ trixie-scm +22d8ca894214 +up to date$' + +# An index without both builders' images, linux/amd64 and linux/arm64: +# refused, and nothing is edited. +cp repo/scripts/release.sh release.sh.before +cp release-index-amd64 up/release-index +! exec repo/scripts/bump.sh release-image +stderr '^bump: library/buildpack-deps:trixie-scm''s index has no linux/amd64 or no linux/arm64 image$' +cmp repo/scripts/release.sh release.sh.before +cp release-index up/release-index + # e2e-ubuntu moves the cloud image release e2e pins to the newest Ubuntu # lists; with none listed, nothing is edited. exec repo/scripts/bump.sh e2e-ubuntu @@ -262,10 +284,13 @@ cp sums-good up/crane-sums cp mise-latest up/mise-latest cp mise-sums up/mise-sums cp cloud-listing up/cloud-listing +cp "$DEVVM_REPO/scripts/release.sh" repo/scripts/ +cp release-index up/release-index -- bin/curl -- #!/bin/bash -# Answers crane's, mise's and Lima's releases and Ubuntu's list of cloud -# image releases from $WORK/up/, to stdout or -o's file; anything else fails. +# Answers crane's, mise's and Lima's releases, Ubuntu's list of cloud +# image releases and Docker Hub's index of the release container, by its +# tag, from $WORK/up/, to stdout or -o's file; anything else fails. # Every call goes in $WORK/curl.calls. echo "curl $*" >> "$WORK/curl.calls" out=/dev/stdout @@ -287,6 +312,8 @@ for a in "$@"; do case $a in */jdx/mise/releases/latest) cat "$WORK/up/mise-latest"; exit ;; */jdx/mise/*/SHASUMS256.txt) cat "$WORK/up/mise-sums"; exit ;; https://cloud-images.ubuntu.com/releases/resolute/) cat "$WORK/up/cloud-listing"; exit ;; + 'https://auth.docker.io/token?service=registry.docker.io&scope=repository:library/buildpack-deps:pull') echo '{"token":"t"}'; exit ;; + https://registry-1.docker.io/v2/library/buildpack-deps/manifests/trixie-scm) cat "$WORK/up/release-index"; exit ;; 'https://go.dev/dl/?mode=json&include=all') cat "$WORK/go-releases"; exit ;; https://proxy.golang.org/github.com/spf13/cobra/@v/list) printf 'v1.10.2\nv1.11.0\nv1.12.0-rc.1\n'; exit ;; https://proxy.golang.org/github.com/spf13/cobra/v2/@v/list) printf 'v2.0.1\n'; exit ;; @@ -415,3 +442,9 @@ const miseVersion = "2099.1.1" "macos-x64": "6666666666666666666666666666666666666666666666666666666666666666", "linux-arm64": "1111111111111111111111111111111111111111111111111111111111111111", "linux-x64": "2222222222222222222222222222222222222222222222222222222222222222", +-- release-index -- +{"manifests":[{"digest":"sha256:1111111111111111111111111111111111111111111111111111111111111111","platform":{"architecture":"amd64","os":"linux"}},{"digest":"sha256:2222222222222222222222222222222222222222222222222222222222222222","platform":{"architecture":"arm64","os":"linux"}}]} +-- release-index-amd64 -- +{"manifests":[{"digest":"sha256:1111111111111111111111111111111111111111111111111111111111111111","platform":{"architecture":"amd64","os":"linux"}}]} +-- release-image.want -- +release_image=docker.io/library/buildpack-deps:trixie-scm@sha256:22d8ca894214b65e7eb25b1b56c3e7ce9665886408f1ccf98ba9bb263a78f951 diff --git a/testdata/script/publish.txtar b/testdata/script/publish.txtar index 6a141402..22beab90 100644 --- a/testdata/script/publish.txtar +++ b/testdata/script/publish.txtar @@ -10,7 +10,9 @@ exec bash -c 'ln -s "$(command -v minisign)" bin/minisign' env GIT_CONFIG_NOSYSTEM=1 env PATH=$WORK/bin:/usr/bin:/bin +env DEVVM_RELEASE_TEST_FILE_URLS=$WORK/tools chmod 755 bin/goreleaser +chmod 755 bin/podman chmod 755 bin/gh exec bash repo.sh env DEVVM_TAP_DIR=$WORK/tap @@ -84,6 +86,31 @@ exec bash refs.sh cmp stdout refs.before exists repo/dist/SHA256SUMS.minisig +# The build's repository held the tag alone, though the repo has a stray +# one at the same commit. +grep '^release --clean --skip=publish tags=v1\.2\.3$' log + +# --tag: the tag's build, as the release's, with the same checks, but not +# signed, so it matches the signed build's SHA256SUMS, and its install.sh +# trusts the release key. It never replaces the signed build's dist/. +cp repo/dist/SHA256SUMS signed.sums +! exec repo/scripts/release.sh --tag v1.2.3 +stderr '^release: dist/ holds a signed build, which this unsigned one would replace: move it first, or set DEVVM_RELEASE_DIST to a new folder$' +exists repo/dist/SHA256SUMS.minisig +rm repo/dist +exec repo/scripts/release.sh --tag v1.2.3 +stdout '^\(not signed: --tag builds the release without its signature\)$' +! exists repo/dist/SHA256SUMS.minisig +cmp repo/dist/SHA256SUMS signed.sums +exec bash -c 'grep -c "^minisign_key=\"$(sed -n 2p repo/packaging/minisign.pub)\"$" repo/dist/install.sh' +stdout '^1$' +exec bash tag.sh other v1.2.4 +! exec repo/scripts/release.sh --tag v1.2.4 +stderr '^release: tag v1\.2\.4 is signed by SHA256:\S+, not a key in packaging/release-signer$' +exec git -C repo tag -d v1.2.4 +! exec repo/scripts/release.sh --tag 1.2.3 +stderr '^release: --tag needs a release''s tag, v, not ''1\.2\.3''$' + # Answering n: nothing published. rm calls ttyin -stdin no.txt @@ -273,15 +300,18 @@ n y -- repo.sh -- # The repo (VERSION 1.2.3, a changelog, release.sh and publish.sh), its -# origin one commit behind, two SSH keys git trusts (good, which -# packaging/release-signer pins, and other), the release key, and the tap. +# origin one commit behind, a stray tag at its HEAD, two SSH keys git +# trusts (good, which packaging/release-signer pins, and other), the +# release key, and the tap. set -eu mkdir -p repo/scripts repo/packaging/homebrew keys gh cp "$DEVVM_REPO/scripts/release.sh" "$DEVVM_REPO/scripts/publish.sh" repo/scripts/ cp "$DEVVM_REPO/packaging/homebrew/devvm.rb" repo/packaging/homebrew/ echo 1.2.3 > repo/VERSION +printf 'module example.com/x\n\ngo 1.22\n' > repo/go.mod echo dist/ > repo/.gitignore printf '#!/bin/sh\nrelease_version=""\nminisign_key=""\n' > repo/install.sh +bash tools.sh > repo/mise.lock printf '# Changelog\n\n## 1.2.3\n\nReleased today.\n\n- **New:** a thing.\n\n## 1.2.2\n\nOlder.\n' > repo/CHANGELOG.md for n in good other; do ssh-keygen -q -t ed25519 -N '' -C "$n" -f "keys/$n"; done { printf 'e@e %s\n' "$(cat keys/good.pub)"; printf 'e@e %s\n' "$(cat keys/other.pub)"; } > keys/allowed @@ -305,6 +335,7 @@ git -C repo push -q origin main echo more > repo/more git -C repo add more git -C repo commit -qm 'release 1.2.3' +git -C repo tag v9.9.9 git init -q tap echo tap > tap/README git -C tap add -A @@ -312,6 +343,58 @@ git -C tap commit -qm tap git -C tap remote add origin "$PWD/tap.git" git -C tap push -q origin main rm -f calls +-- tools.sh -- +# A mise.lock's go and goreleaser, for both Linux processors: tarballs of a +# go that does nothing and of bin/goreleaser, by file URL and SHA-256. +set -eu +mkdir -p tools/go/bin +printf '#!/bin/sh\n' > tools/go/bin/go +chmod 755 tools/go/bin/go +tar -czf tools/go.tar.gz -C tools go +tar -czf tools/goreleaser.tar.gz -C bin goreleaser +for t in go goreleaser; do + sum=$({ sha256sum "tools/$t.tar.gz" 2>/dev/null || shasum -a 256 "tools/$t.tar.gz"; } | cut -c1-64) + printf '[[tools.%s]]\nversion = "1.30.0"\n\n' "$t" + for p in linux-arm64 linux-x64; do + printf '[tools.%s."platforms.%s"]\nchecksum = "sha256:%s"\nurl = "file://%s"\n\n' "$t" "$p" "$sum" "$PWD/tools/$t.tar.gz" + done +done +-- bin/podman -- +#!/bin/bash +# Rootless podman, here: --version and info say so, and run runs +# --entrypoint, then the command, with each -v's container folder replaced +# by its host folder, in -w's folder, with each -e's variable set. +set -eu +case $1 in + --version) echo 'podman version 5.6.0'; exit 0 ;; + info) echo true; exit 0 ;; + run) ;; + *) echo "podman: no fake for $*" >&2; exit 1 ;; +esac +shift +from=() to=() dir= entry=() +while [[ $1 == -* ]]; do + case $1 in + --rm) shift ;; + --platform | --user | --name | --security-opt | --cap-drop | --pids-limit | --memory | --network) shift 2 ;; + --entrypoint) entry=("$2"); shift 2 ;; + -v) IFS=: read -r h c _ <<<"$2"; from+=("$c"); to+=("$h"); shift 2 ;; + -w) dir=$2; shift 2 ;; + -e) export "${2?}"; shift 2 ;; + *) echo "podman: no fake for $1" >&2; exit 1 ;; + esac +done +shift +set -- ${entry[@]+"${entry[@]}"} "$@" +map() { + local a=$1 i + for i in "${!from[@]}"; do [[ $a != "${from[i]}"* ]] || a=${to[i]}${a#"${from[i]}"}; done + printf '%s' "$a" +} +args=() +for a in "$@"; do args+=("$(map "$a")"); done +cd "$(map "$dir")" +exec "${args[@]}" -- tag.sh -- # Tag $2, v1.2.3 without it, (again), signed with key $1. set -eu @@ -430,11 +513,12 @@ case "$1 $2" in esac -- bin/goreleaser -- #!/bin/bash -# Logs its call and writes a dist/ like GoReleaser's, the same each time: -# each system's and processor's build, a script printing $DEVVM_VERSION, an -# archive for each (a line of text), the source tarball and SHA256SUMS. +# Logs its call and its repository's tags, and writes a dist/ like +# GoReleaser's, the same each time: each system's and processor's build, a +# script printing $DEVVM_VERSION, an archive for each (a line of text), the +# source tarball and SHA256SUMS. set -eu -echo "$*" >> "$WORK/log" +echo "$* tags=$(git tag -l | paste -sd, -)" >> "$WORK/log" rm -rf dist mkdir dist for os in darwin linux; do diff --git a/testdata/script/release_head.txtar b/testdata/script/release_head.txtar index c1ab0769..03283701 100644 --- a/testdata/script/release_head.txtar +++ b/testdata/script/release_head.txtar @@ -1,15 +1,47 @@ # scripts/release.sh --head: a test build from HEAD's commit, signed with a -# test key, in a throwaway repo with a goreleaser that writes a small dist/. +# test key, in a throwaway repo with a goreleaser that writes a small dist/, +# which mise.lock pins as file:// URLs in tools/, which +# DEVVM_RELEASE_TEST_FILE_URLS allows, a podman and a docker that run the +# container's command here, and a curl that logs its arguments. [!exec:git] skip [!exec:minisign] skip env GIT_CONFIG_NOSYSTEM=1 env PATH=$WORK/bin:$PATH +env DEVVM_RELEASE_TEST_FILE_URLS=$WORK/tools +cp bin/podman bin/docker chmod 755 bin/goreleaser +chmod 755 bin/podman +chmod 755 bin/docker +chmod 755 bin/curl exec bash repo.sh -# Unsigned without a test key: install.sh trusts no key. +# Unsigned without a test key: install.sh trusts no key. The build ran in +# the pinned container, as this system's processor, as root under rootless +# podman, and its Go and GoReleaser came from mise.lock, kept in the cache +# by their SHA-256, downloaded within bounds. First the modules' download +# ran, by this checkout's release.sh, given only go.mod, go.sum and Go, +# read-only, then the build, with no network and the modules read-only, +# writing to an output folder of its own: each in a container named for +# its run (the stub checks the name is its temp folder's), with no +# capabilities, no new privileges, at most 8192 processes and 8 GiB of +# memory, and bash as its entrypoint. +env XDG_CACHE_HOME=$WORK/cache exec repo/scripts/release.sh --head stdout '^\(not signed: a test build without DEVVM_MINISIGN_KEY\)$' +stdout '^==> downloading HEAD''s Go modules in docker\.io/library/buildpack-deps:trixie-scm@sha256:[0-9a-f]{64}, under podman as 0:0$' +stdout '^==> building [0-9a-f]{40} in docker\.io/library/buildpack-deps:trixie-scm@sha256:[0-9a-f]{64}, under podman as 0:0$' +exec grep -c '^run --name devvm-release-[A-Za-z0-9]*-1 --rm --platform linux/[a-z0-9]* --user 0:0 --security-opt no-new-privileges --cap-drop ALL --pids-limit 8192 --memory 8g --entrypoint bash -v [^ ]*/in:/in:ro,z -v [^ ]*/mod:/out:z -w /in docker\.io/library/buildpack-deps:trixie-scm@sha256:[0-9a-f]\{64\} /in/release\.sh _modules /in /out$' runtime.log +stdout '^1$' +exec grep -c '^run --name devvm-release-[A-Za-z0-9]*-2 --rm --platform linux/[a-z0-9]* --user 0:0 --security-opt no-new-privileges --cap-drop ALL --pids-limit 8192 --memory 8g --entrypoint bash --network none -v [^ ]*/work:/work:z -v [^ ]*/mod:/mod:ro,z -v [^ ]*/out:/out:z -w /work docker\.io/library/buildpack-deps:trixie-scm@sha256:[0-9a-f]\{64\} /work/release\.sh _build 1\.2\.3 [0-9a-f]\{40\} .* /mod /out$' runtime.log +stdout '^1$' +cmp go-in.log go-in.want +cmp go.log go.want +exec bash -c 'cmp repo/scripts/release.sh container-modules.sh && echo same' +stdout '^same$' +exec bash -c 'ls cache/devvm-release | grep -cE "^[0-9a-f]{64}$"' +stdout '^2$' +exec bash -c 'grep -c -- "^-fsSL --retry 3 --proto =file --proto-redir =https --connect-timeout 30 --max-time 900 --max-filesize 1073741824 -o [^ ]* --url file:///" curl.log' +stdout '^2$' ! exists repo/dist/SHA256SUMS.minisig grep '^release_version="1.2.3"$' repo/dist/install.sh grep '^minisign_key=""$' repo/dist/install.sh @@ -25,6 +57,7 @@ exec repo/scripts/release.sh --head cmp log log.want exec minisign -Vm repo/dist/SHA256SUMS -p keys/test.pub stdout 'Trusted comment: devvm 1.2.3' +exec bash -c 'git -C repo show HEAD:scripts/release.sh | cmp - container-release.sh' exec bash key.sh grep '^release_version="1.2.3"$' repo/dist/install.sh cmp stdout key.want @@ -35,6 +68,36 @@ cmp stdout formula.want exec bash formula.sh devvm-rc.rb cmp stdout formula.want +# An unsigned build never replaces a signed one's dist/: refused before +# it's built, unless DEVVM_RELEASE_DIST names a new folder for it. +env DEVVM_MINISIGN_KEY= +rm log +! exec repo/scripts/release.sh --head +stderr '^release: dist/ holds a signed build, which this unsigned one would replace: move it first, or set DEVVM_RELEASE_DIST to a new folder$' +! exists log +exists repo/dist/SHA256SUMS.minisig +env DEVVM_RELEASE_DIST=$WORK/unsigned +exec repo/scripts/release.sh --head +exists unsigned/SHA256SUMS +exists repo/dist/SHA256SUMS.minisig +env DEVVM_RELEASE_DIST= +env DEVVM_MINISIGN_KEY=$WORK/keys/test.key + +# Nor does a build signed with a test key replace one signed with the +# release key, this checkout's packaging/minisign.pub; one signed with +# another test key it does. +exec minisign -G -W -p keys/release.pub -s keys/release.key +cp keys/release.pub repo/packaging/minisign.pub +exec minisign -Sm repo/dist/SHA256SUMS -s keys/release.key -x repo/dist/SHA256SUMS.minisig -t 'devvm 1.2.3' +rm log +! exec repo/scripts/release.sh --head +stderr '^release: dist/ holds a build signed with the release key \(packaging/minisign\.pub\), which this test build would replace: move it first, or set DEVVM_RELEASE_DIST to a new folder$' +! exists log +exec minisign -Vm repo/dist/SHA256SUMS -p keys/release.pub +rm repo/packaging/minisign.pub +exec repo/scripts/release.sh --head +exec minisign -Vm repo/dist/SHA256SUMS -p keys/test.pub + # A release gets both formulas, devvm and devvm-rc, each conflicting with # the other: they differ only in that. exec bash -c 'diff repo/dist/devvm.rb repo/dist/devvm-rc.rb || true' @@ -128,26 +191,499 @@ exec bash -c 'echo 1.2.3-RC1 > repo/VERSION && git -C repo commit -qam bad-prere ! exec repo/scripts/release.sh --head stderr '^release: VERSION isn''t x.y.z or x.y.z-rc.N: ''1.2.3-RC1''$' +# A download that doesn't match mise.lock: refused, and dropped from the +# cache, so the next build downloads it again. +exec bash -c 'echo 1.2.3 > repo/VERSION && printf ''#!/bin/sh\nrelease_version=""\nminisign_key=""\n'' > repo/install.sh && git -C repo commit -qam good' +exec bash -c 'f=$(ls cache/devvm-release | head -1) && echo x >> "cache/devvm-release/$f"' +! exec repo/scripts/release.sh --head +stderr '^release: file://\S+ doesn''t match HEAD''s mise\.lock \(sha256:[0-9a-f]{64}\)$' +exec repo/scripts/release.sh --head +stdout '^==> dist/ for devvm 1\.2\.3 \(from HEAD\):$' + +# A commit whose mise.lock has no GoReleaser for this platform: refused. +exec bash -c 'sed "/goreleaser/,\$d" repo/mise.lock > lock && mv lock repo/mise.lock && git -C repo commit -qam no-goreleaser' +! exec repo/scripts/release.sh --head +stderr '^release: HEAD''s mise\.lock has no goreleaser download for linux-(arm64|x64)$' +exec git -C repo revert --no-edit HEAD + +# A runtime that isn't there: refused before anything is built. +env DEVVM_RELEASE_RUNTIME=no-such-runtime +! exec repo/scripts/release.sh --head +stderr '^release: needs podman or Docker to build in its container \(DEVVM_RELEASE_RUNTIME names one\)$' +env DEVVM_RELEASE_RUNTIME= + +# A build that fails in the container: release.sh says so. +env GR_FAIL=1 +! exec repo/scripts/release.sh --head +stderr '^release: goreleaser failed$' +stderr '^release: the build in docker\.io/library/buildpack-deps:trixie-scm@sha256:[0-9a-f]{64} failed$' +env GR_FAIL= + +# The container runs as root under a rootless runtime, which maps root to +# you, and as you under a rootful one, as the runtime's info says, never +# its name: podman, rootless by default, then rootful; Docker, rootful by +# default, then in its rootless mode; and podman behind a docker command. +exec repo/scripts/release.sh --head +exec bash user.sh +stdout '^root$' +env RT_ROOTLESS=false +exec repo/scripts/release.sh --head +exec bash user.sh +stdout '^you$' +env RT_ROOTLESS= +env DEVVM_RELEASE_RUNTIME=docker +exec repo/scripts/release.sh --head +stdout ', under docker as \d+:\d+$' +exec bash user.sh +stdout '^you$' +env RT_ROOTLESS=true +exec repo/scripts/release.sh --head +exec bash user.sh +stdout '^root$' +env RT_ROOTLESS= +env RT_PODMAN=1 +exec repo/scripts/release.sh --head +exec bash user.sh +stdout '^root$' +env RT_PODMAN= + +# A runtime that doesn't answer, such as Docker Desktop when it isn't +# running: refused before anything is built. +env RT_NO_INFO=1 +rm runtime.log +! exec repo/scripts/release.sh --head +stderr '^release: docker didn''t say whether it''s rootless: is it running\? \(docker info\)$' +! grep '^run ' runtime.log +env RT_NO_INFO= +env DEVVM_RELEASE_RUNTIME= + +# A mise.lock download from anywhere but Go's and GoReleaser's own +# publishers, over https, is refused before curl runs: a URL that starts +# with - would be curl's options (here -K, a config that copies a file), +# and neither http:// nor another host is the publisher's. +rm curl.log +env DEVVM_RELEASE_TEST_FILE_URLS= +exec bash lockurl.sh -K$WORK/curlrc +! exec repo/scripts/release.sh --head +stderr '^release: HEAD''s mise\.lock downloads go from ''-K\S+/curlrc'', not https://dl\.google\.com/go/$' +! exists exfil +exec git -C repo reset -q --hard HEAD~1 +exec bash lockurl.sh http://dl.google.com/go/go1.linux-arm64.tar.gz +! exec repo/scripts/release.sh --head +stderr '^release: HEAD''s mise\.lock downloads go from ''http://dl\.google\.com/go/go1\.linux-arm64\.tar\.gz'', not https://dl\.google\.com/go/$' +exec git -C repo reset -q --hard HEAD~1 +exec bash lockurl.sh https://dl.google.com.example/go/go1.linux-arm64.tar.gz +! exec repo/scripts/release.sh --head +stderr '^release: HEAD''s mise\.lock downloads go from ''https://dl\.google\.com\.example/go/go1\.linux-arm64\.tar\.gz'', not https://dl\.google\.com/go/$' +exec git -C repo reset -q --hard HEAD~1 +exec bash lockurl.sh https://dl.google.com/go/../go1.linux-arm64.tar.gz +! exec repo/scripts/release.sh --head +stderr 'downloads go from ''https://dl\.google\.com/go/\.\./go1\.linux-arm64\.tar\.gz'', not https://dl\.google\.com/go/$' +exec git -C repo reset -q --hard HEAD~1 +# Nor .. percent-encoded, which curl decodes: here from the tests' folder +# to secret, outside it. +env DEVVM_RELEASE_TEST_FILE_URLS=$WORK/tools +exec bash lockurl.sh file://$WORK/tools/%2e%2e/secret +! exec repo/scripts/release.sh --head +stderr '^release: HEAD''s mise\.lock downloads go from ''file:///\S+/tools/%2e%2e/secret'', not file:///\S+/tools/$' +exec git -C repo reset -q --hard HEAD~1 +env DEVVM_RELEASE_TEST_FILE_URLS= +! exists curl.log + +# file:// URLs, the tests' own, only from the folder that +# DEVVM_RELEASE_TEST_FILE_URLS names: not without it, nor with it set to +# anything but a folder, one that doesn't exist or /, nor from another +# folder. +! exec repo/scripts/release.sh --head +stderr '^release: HEAD''s mise\.lock downloads go from ''file:///\S+/tools/go\.tar\.gz'', not https://dl\.google\.com/go/$' +env DEVVM_RELEASE_TEST_FILE_URLS=1 +! exec repo/scripts/release.sh --head +stderr '^release: HEAD''s mise\.lock downloads go from ''file:///\S+/tools/go\.tar\.gz'', not https://dl\.google\.com/go/$' +env DEVVM_RELEASE_TEST_FILE_URLS=$WORK/nowhere +! exec repo/scripts/release.sh --head +stderr '^release: HEAD''s mise\.lock downloads go from ''file:///\S+/tools/go\.tar\.gz'', not https://dl\.google\.com/go/$' +env DEVVM_RELEASE_TEST_FILE_URLS=/ +! exec repo/scripts/release.sh --head +stderr '^release: HEAD''s mise\.lock downloads go from ''file:///\S+/tools/go\.tar\.gz'', not https://dl\.google\.com/go/$' +mkdir elsewhere +env DEVVM_RELEASE_TEST_FILE_URLS=$WORK/elsewhere +! exec repo/scripts/release.sh --head +stderr '^release: HEAD''s mise\.lock downloads go from ''file:///\S+/tools/go\.tar\.gz'', not file:///\S+/elsewhere/$' +env DEVVM_RELEASE_TEST_FILE_URLS=$WORK/tools + +# A mise.lock with two go entries, even the same one twice: refused, not +# read for the last. +exec bash -c 'sed -n "/^\[\[tools\.go\]\]/,/^\[\[tools\.goreleaser\]\]/p" repo/mise.lock | sed "\$d" >> repo/mise.lock && git -C repo commit -qam two-gos' +! exec repo/scripts/release.sh --head +stderr '^release: HEAD''s mise\.lock has 2 go entries, not one$' +exec git -C repo reset -q --hard HEAD~1 + +# The build's repository holds the commit alone: no tags, though the repo +# has a stray one, no other branch's commits, and no files it shares with +# the repo, and its origin is devvm's on GitHub (log.want). +rm log +exec repo/scripts/release.sh --head +cmp log log.want + +# What the build wrote is refused before it's copied, signed or kept when +# it holds anything but files and folders, so nothing here follows a link +# the container made; when its output folder is a link to another; and +# when a file in it is setuid, or writable by anyone, as a build under a +# rootful runtime could leave one of root's. Otherwise each copy is yours, +# 0755 or 0644, whatever the build's file was. +env GR_OUT=private +exec repo/scripts/release.sh --head +exec bash modes.sh +cmp stdout modes.want +rm repo/dist +env GR_OUT=link +! exec repo/scripts/release.sh --head +stderr '^release: the build left leak, which isn''t a file or a folder: nothing is signed or kept$' +! exists repo/dist +env GR_OUT=swap +! exec repo/scripts/release.sh --head +stderr '^release: the build''s output folder isn''t the one it was given: nothing is signed or kept$' +! exists repo/dist +env GR_OUT=setuid +! exec repo/scripts/release.sh --head +stderr '^release: the build left su, which isn''t yours, or is setuid, setgid, sticky or writable by anyone: nothing is signed or kept$' +! exists repo/dist +env GR_OUT=writable +! exec repo/scripts/release.sh --head +stderr '^release: the build left notes, which isn''t yours, or is setuid, setgid, sticky or writable by anyone: nothing is signed or kept$' +! exists repo/dist +env GR_OUT=setgid +! exec repo/scripts/release.sh --head +stderr '^release: the build left sg, which isn''t yours, or is setuid, setgid, sticky or writable by anyone: nothing is signed or kept$' +! exists repo/dist +env GR_OUT=sticky +! exec repo/scripts/release.sh --head +stderr '^release: the build left tmp, which isn''t yours, or is setuid, setgid, sticky or writable by anyone: nothing is signed or kept$' +! exists repo/dist +env GR_OUT=writable-folder +! exec repo/scripts/release.sh --head +stderr '^release: the build left shared, which isn''t yours, or is setuid, setgid, sticky or writable by anyone: nothing is signed or kept$' +! exists repo/dist +# A file of another user's would be refused too, which a test can't make +# without root. + +# Nor more than 2 GiB of files, which would fill dist/'s disk: here one +# sparse file a byte over. +env GR_OUT=big +! exec repo/scripts/release.sh --head +stderr '^release: the build left more than 2 GiB of files: nothing is signed or kept$' +! exists repo/dist +env GR_OUT= + +# A build that runs past the time limit is stopped from here, its +# container removed by name, whatever its image does. +env DEVVM_RELEASE_TIMEOUT=2 GR_SLEEP=1 +! exec repo/scripts/release.sh --head +stderr '^release: the build in docker\.io/\S+ ran for 2 seconds, the limit \(DEVVM_RELEASE_TIMEOUT\), so it was stopped$' +grep '^rm -f devvm-release-[A-Za-z0-9]+-2$' runtime.log +env DEVVM_RELEASE_TIMEOUT= GR_SLEEP= + +# release.sh stopped mid-build stops its container: Ctrl+C (INT), a closed +# terminal (HUP) and kill (TERM) through its traps, at once, and kill -9 +# through the watchdog, which outlives it. Each time the container is +# removed by name, its processes are gone, and so is the temp folder. +exec bash interrupt.sh INT +stderr '^exit 130$' +cmp stdout interrupt.want +exec bash interrupt.sh HUP +stderr '^exit 129$' +cmp stdout interrupt.want +exec bash interrupt.sh TERM +stderr '^exit 143$' +cmp stdout interrupt.want +exec bash interrupt.sh KILL +stderr '^exit 137$' +cmp stdout interrupt-kill.want +env DEVVM_RELEASE_TIMEOUT=x +! exec repo/scripts/release.sh --head +stderr '^release: DEVVM_RELEASE_TIMEOUT isn''t a number of seconds: ''x''$' +env DEVVM_RELEASE_TIMEOUT= + +# The image and the build's own code are the commit's, never this +# checkout's: a release_image changed here changes neither. The modules' +# download, which only this checkout's code runs, is in this checkout's. +exec bash -c 'sed "s/^release_image=.*/release_image=docker.io\/library\/changed:x@sha256:$(printf %064d 0)/" repo/scripts/release.sh > rs && cat rs > repo/scripts/release.sh' +exec repo/scripts/release.sh --head +stdout '^==> downloading HEAD''s Go modules in docker\.io/library/changed:x@sha256:0{64}, under ' +stdout '^==> building [0-9a-f]{40} in docker\.io/library/buildpack-deps:trixie-scm@sha256:[0-9a-f]{64}, under ' +exec bash -c 'grep "^run " runtime.log | tail -1' +! stdout changed +exec bash -c 'git -C repo show HEAD:scripts/release.sh | cmp - container-release.sh' +exec git -C repo checkout -q scripts/release.sh + +# So is its Go, this checkout's mise.lock's, never the commit's: here this +# checkout's names another Go, which logs its call as the checkout's. A +# commit whose go.mod needs a newer Go than that is refused before anything +# runs. +exec bash checkout-go.sh +rm go.log +exec repo/scripts/release.sh --head +cmp go.log go-checkout.want +exec git -C repo checkout -q mise.lock +exec bash -c 'printf ''module example.com/x\n\ngo 1.30.1\n'' > repo/go.mod && git -C repo commit -qam newer-go' +rm runtime.log +! exec repo/scripts/release.sh --head +stderr '^release: HEAD''s go\.mod needs Go 1\.30\.1, newer than the 1\.30\.0 this checkout''s mise\.lock pins: build it from a checkout at least as new$' +! grep '^run ' runtime.log +exec git -C repo reset -q --hard HEAD~1 + +# A commit whose release.sh pins no release_image, from before +# reproducible builds: refused. +exec bash -c 'sed "/^release_image=/d" repo/scripts/release.sh > rs && cat rs > repo/scripts/release.sh && git -C repo commit -qam no-image' +! exec repo/scripts/release.sh --head +stderr '^release: HEAD''s scripts/release\.sh pins no release_image by digest, so it''s from before reproducible builds: build it with its own scripts/release\.sh$' +exec git -C repo reset -q --hard HEAD~1 + +# --commit builds another commit, with its VERSION, by this checkout's +# release.sh: the commit's own runs only in the container. Here HEAD~1's +# would touch outside here, and its VERSION is 1.2.4. +exec bash outside.sh +exec repo/scripts/release.sh --commit HEAD~1 +stdout '^==> dist/ for devvm 1\.2\.4 \(from HEAD~1\):$' +! exists outside +exec bash -c 'grep "^run " runtime.log | tail -1' +stdout ' _build 1\.2\.4 [0-9a-f]{40} ' +exec bash -c 'git -C repo show HEAD~1:scripts/release.sh | cmp - container-release.sh' +! exec repo/scripts/release.sh --commit +stderr '^release: --commit needs one commit$' +! exec repo/scripts/release.sh --commit no-such-commit +stderr '^release: no commit no-such-commit$' + # A HEAD without install.sh: refused too. -exec bash -c 'echo 1.2.3 > repo/VERSION && git -C repo rm -q install.sh && git -C repo commit -qam no-install' +exec bash -c 'git -C repo rm -q install.sh && git -C repo commit -qam no-install' ! exec repo/scripts/release.sh --head stderr '^release: no install.sh in HEAD$' -- repo.sh -- -# A repo with release.sh, the formula, an install.sh to fill in and -# VERSION 1.2.3, and a file that isn't committed. +# A repo with release.sh, the formula, an install.sh to fill in, VERSION +# 1.2.3, go.mod and go.sum, and a mise.lock pinning a Go and this test's +# goreleaser (tools.sh), a stray tag, a branch whose commit is in +# other.sha, and a file that isn't committed. set -eu mkdir -p repo/scripts repo/packaging/homebrew keys cp "$DEVVM_REPO/scripts/release.sh" repo/scripts/ cp "$DEVVM_REPO/packaging/homebrew/devvm.rb" repo/packaging/homebrew/ echo 1.2.3 > repo/VERSION +printf 'module example.com/x\n\ngo 1.22\n' > repo/go.mod +: > repo/go.sum printf '#!/bin/sh\nrelease_version=""\nminisign_key=""\n' > repo/install.sh +bash tools.sh > repo/mise.lock git -C repo init -q git -C repo config user.email e@e git -C repo config user.name e git -C repo add -A git -C repo commit -qm r +git -C repo tag v9.9.9 +git -C repo checkout -q -b other +echo other > repo/other +git -C repo add other +git -C repo commit -qm other +git -C repo rev-parse HEAD > other.sha +git -C repo checkout -q - touch repo/uncommitted +-- modes.sh -- +# Each file's mode in dist/: the container's install.sh 0755, its 0600 +# private 0644, the rest 0644 too, and folders 0755, with no other mode. +cd repo/dist +find . -type f -name install.sh -perm 0755 +find . -type f -name private -perm 0644 +find . -type f -name SHA256SUMS -perm 0644 +find . ! -perm 0755 ! -perm 0644 +find . -type d ! -perm 0755 +-- modes.want -- +./install.sh +./private +./SHA256SUMS +-- user.sh -- +# The user the last build's container ran as: root, you, or its --user. +u=$(grep '^run ' runtime.log | tail -1 | sed -n 's/.* --user \([^ ]*\) .*/\1/p') +case $u in + 0:0) echo root ;; + "$(id -u):$(id -g)") echo you ;; + *) echo "${u:-none}" ;; +esac +-- lockurl.sh -- +# mise.lock's go downloads from $1, committed, with nothing in the cache, +# and curlrc, a curl config that would copy secret to exfil. +set -eu +echo secret > secret +printf 'upload-file = "%s/secret"\nurl = "file://%s/exfil"\n' "$PWD" "$PWD" > curlrc +awk -v u="$1" '/^\[tools\.go\./ { g = 1 } /^\[tools\.goreleaser\./ { g = 0 } + g && $1 == "url" { $0 = "url = \"" u "\"" } { print }' repo/mise.lock > lock +cat lock > repo/mise.lock +git -C repo commit -qam "go from $1" +rm -rf cache +-- outside.sh -- +# HEAD~1: VERSION 1.2.4, and a release.sh that touches outside when it +# runs outside its container; HEAD: back to HEAD~2. +set -eu +awk '{ print } /^root=/ { print "touch \"$WORK/outside\"" }' repo/scripts/release.sh > rs +cat rs > repo/scripts/release.sh +echo 1.2.4 > repo/VERSION +git -C repo commit -qam outside +git -C repo revert --no-edit HEAD >/dev/null +-- interrupt.sh -- +# A build that never ends, with release.sh sent signal $1 once its build's +# goreleaser runs; its exit status on stderr, then whether it ended within +# 10 seconds, whether its own trap stopped the container, and what's left: whether the container +# was removed by name, whether goreleaser is gone, and whether release.sh's +# temp folder is. Job control (-m), so release.sh doesn't start with INT +# ignored, as a background job would. +set -mu +rm -f runtime.log gr.pid +GR_SLEEP=1 repo/scripts/release.sh --head > interrupt.log 2>&1 & +pid=$! +i=0 +until [[ -s gr.pid ]] || ((i++ > 300)); do sleep 0.1; done +SECONDS=0 +kill -s "$1" "$pid" +wait "$pid" +echo "exit $?" >&2 +((SECONDS < 10)) && echo prompt +gr=$(cat gr.pid) +i=0 +while { kill -0 "$gr" 2>/dev/null || compgen -G "${TMPDIR:-/tmp}/devvm-release.*" >/dev/null; } && ((i++ < 100)); do sleep 0.1; done +grep -q '^release: stopping the container devvm-release-[A-Za-z0-9]*-2$' interrupt.log && echo trapped +grep -q '^rm -f devvm-release-[A-Za-z0-9]*-2$' runtime.log && echo removed +kill -0 "$gr" 2>/dev/null || echo gone +compgen -G "${TMPDIR:-/tmp}/devvm-release.*" >/dev/null || echo clean +-- interrupt.want -- +prompt +trapped +removed +gone +clean +-- interrupt-kill.want -- +prompt +removed +gone +clean +-- checkout-go.sh -- +# This checkout's mise.lock, uncommitted, names another Go, which logs its +# call as the checkout's. +set -eu +mkdir -p tools/checkout/go/bin +sed 's/^echo "go /echo "checkout go /' go > tools/checkout/go/bin/go +chmod 755 tools/checkout/go/bin/go +tar -czf tools/checkout-go.tar.gz -C tools/checkout go +sum=$({ sha256sum tools/checkout-go.tar.gz 2>/dev/null || shasum -a 256 tools/checkout-go.tar.gz; } | cut -c1-64) +awk -v u="file://$PWD/tools/checkout-go.tar.gz" -v c="sha256:$sum" '/^\[tools\.go\./ { g = 1 } /^\[tools\.goreleaser\./ { g = 0 } + g && $1 == "url" { $0 = "url = \"" u "\"" } g && $1 == "checksum" { $0 = "checksum = \"" c "\"" } { print }' repo/mise.lock > lock +cat lock > repo/mise.lock +-- go-checkout.want -- +checkout go mod download GOPROXY=https://proxy.golang.org GOVCS=*:off GOWORK=off in go.mod,go.sum +-- bin/curl -- +#!/bin/bash +# Logs its arguments, then runs the system's curl. +echo "$*" >> "$WORK/curl.log" +PATH=${PATH#"$WORK/bin:"} exec curl "$@" +-- go-in.want -- +go.mod +go.sum +go.tar.gz +release.sh +-- go.want -- +go mod download GOPROXY=https://proxy.golang.org GOVCS=*:off GOWORK=off in go.mod,go.sum +-- go -- +#!/bin/sh +# Go, downloading modules: it logs its call, its proxy, and the files in +# its folder, then downloads one module's go.mod into the module cache. +echo "go $* GOPROXY=$GOPROXY GOVCS=$GOVCS GOWORK=$GOWORK in $(ls | paste -sd, -)" >> "$WORK/go.log" +mkdir -p "$GOMODCACHE/cache/download/example.com/m/@v" +echo 'module example.com/m' > "$GOMODCACHE/cache/download/example.com/m/@v/v1.0.0.mod" +-- tools.sh -- +# A mise.lock's go and goreleaser, for both Linux processors: tarballs of +# go (above) and of bin/goreleaser, by file URL and SHA-256. +set -eu +mkdir -p tools/go/bin +cp go tools/go/bin/go +chmod 755 tools/go/bin/go +tar -czf tools/go.tar.gz -C tools go +tar -czf tools/goreleaser.tar.gz -C bin goreleaser +for t in go goreleaser; do + sum=$({ sha256sum "tools/$t.tar.gz" 2>/dev/null || shasum -a 256 "tools/$t.tar.gz"; } | cut -c1-64) + printf '[[tools.%s]]\nversion = "1.30.0"\n\n' "$t" + for p in linux-arm64 linux-x64; do + printf '[tools.%s."platforms.%s"]\nchecksum = "sha256:%s"\nurl = "file://%s"\n\n' "$t" "$p" "$sum" "$PWD/tools/$t.tar.gz" + done +done +-- bin/podman -- +#!/bin/bash +# A container runtime, here: podman, or Docker when it's called docker, or +# podman behind a docker command with RT_PODMAN=1. It logs its arguments. +# --version says which, and info whether it's rootless: RT_ROOTLESS, else +# true for podman and false for Docker; with RT_NO_INFO=1 it can't. run +# runs --entrypoint, then the command, with each -v's container folder +# replaced by its host folder, in -w's folder, with each -e's variable set +# and RT_OUT set to /out's host folder, and keeps its pid by --name, for +# rm -f NAME, which ends it and everything it started. A --name has to be +# devvm-release--, where release.sh's temp folder, which is +# new for each run, is devvm-release.. What /in holds goes in +# go-in.log, and its release.sh in container-modules.sh. +set -eu +echo "$*" >> "$WORK/runtime.log" +podman=true +[[ ${0##*/} != docker || -n ${RT_PODMAN:-} ]] || podman=false +tree() { local c; for c in $(pgrep -P "$1"); do tree "$c"; done; kill -9 "$1" 2>/dev/null || true; } +case $1 in + --version) + if $podman; then echo 'podman version 5.6.0'; else echo 'Docker version 28.5.1, build e180ab8'; fi + exit 0 ;; + info) + [[ -z ${RT_NO_INFO:-} ]] || exit 1 + case $podman,$3 in + 'true,{{.Host.Security.Rootless}}') echo "${RT_ROOTLESS:-true}" ;; + 'false,{{json .SecurityOptions}}') + o='"name=seccomp,profile=builtin"' + [[ ${RT_ROOTLESS:-false} != true ]] || o+=',"name=rootless"' + echo "[$o]" ;; + *) echo "info: no fake for $*" >&2; exit 1 ;; + esac + exit 0 ;; + rm) + [[ $2 == -f ]] || { echo "runtime: no fake for $*" >&2; exit 1; } + [[ ! -f $WORK/run-$3.pid ]] || tree "$(cat "$WORK/run-$3.pid")" + exit 0 ;; + run) ;; + *) echo "runtime: no fake for $*" >&2; exit 1 ;; +esac +shift +from=() to=() dir= entry=() +while [[ $1 == -* ]]; do + case $1 in + --rm) shift ;; + --platform | --user | --security-opt | --cap-drop | --pids-limit | --memory | --network) shift 2 ;; + --name) + s=${2#devvm-release-} + [[ -d ${TMPDIR:-/tmp}/devvm-release.${s%-*} ]] || { echo "runtime: --name $2 isn't its run's" >&2; exit 1; } + echo $$ > "$WORK/run-$2.pid"; shift 2 ;; + --entrypoint) entry=("$2"); shift 2 ;; + -v) + IFS=: read -r h c _ <<<"$2"; from+=("$c"); to+=("$h") + [[ $c != /out ]] || export RT_OUT=$h + [[ $c != /in ]] || { ls "$h" > "$WORK/go-in.log"; cp "$h/release.sh" "$WORK/container-modules.sh"; } + shift 2 ;; + -w) dir=$2; shift 2 ;; + -e) export "${2?}"; shift 2 ;; + *) echo "runtime: no fake for $1" >&2; exit 1 ;; + esac +done +shift +set -- ${entry[@]+"${entry[@]}"} "$@" +map() { + local a=$1 i + for i in "${!from[@]}"; do [[ $a != "${from[i]}"* ]] || a=${to[i]}${a#"${from[i]}"}; done + printf '%s' "$a" +} +args=() +for a in "$@"; do args+=("$(map "$a")"); done +cd "$(map "$dir")" +exec "${args[@]}" -- key.sh -- # install.sh's key is the test key's. grep "^minisign_key=\"$(sed -n 2p keys/test.pub)\"$" repo/dist/install.sh >/dev/null && echo trusted @@ -233,14 +769,31 @@ class DevvmRc < Formula end end -- log.want -- -release --clean --skip=publish --snapshot DEVVM_VERSION=1.2.3 GORELEASER_CURRENT_TAG= +release --clean --skip=publish --snapshot DEVVM_VERSION=1.2.3 GORELEASER_CURRENT_TAG= tags= refs= other=absent shared=0 origin=https://github.com/devvmhq/devvm.git proxy=./example.com/m/@v/v1.0.0.mod -- bin/goreleaser -- #!/bin/bash -# Logs its call and writes a dist/ like GoReleaser's: each system's and -# processor's build, a script printing $GR_VERSION, else $DEVVM_VERSION, the -# Linux archives, the source tarball and SHA256SUMS. +# Logs its call, with what its repository holds: its tags and refs, whether +# it has the other branch's commit, how many of its files are linked to +# others, and its origin, which GoReleaser needs. It copies the build's own release.sh to container-release.sh, and +# writes a dist/ like GoReleaser's: each system's and processor's build, a +# script printing $GR_VERSION, else $DEVVM_VERSION, the Linux archives, the +# source tarball and SHA256SUMS. With $GR_FAIL, it fails, and with +# $GR_SLEEP, it never ends, its pid in gr.pid. GR_OUT writes to the +# container's /out ($RT_OUT) as a build could: link, a link; swap, /out +# itself a link to another folder; setuid, a file of mode 4755; setgid, +# one of mode 2755; writable, one of mode 0666; private, one of mode 0600; +# sticky, a folder of mode 1755; writable-folder, one of mode 0777; big, a +# sparse file a byte over 2 GiB. set -eu -echo "$* DEVVM_VERSION=$DEVVM_VERSION GORELEASER_CURRENT_TAG=${GORELEASER_CURRENT_TAG:-}" >> "$WORK/log" +echo "$* DEVVM_VERSION=$DEVVM_VERSION GORELEASER_CURRENT_TAG=${GORELEASER_CURRENT_TAG:-}" \ + "tags=$(git tag -l | paste -sd, -) refs=$(git for-each-ref --format='%(refname)' | paste -sd, -)" \ + "other=$(git cat-file -t "$(cat "$WORK/other.sha")" 2>/dev/null || echo absent)" \ + "shared=$(find .git/objects -type f -links +1 | wc -l | tr -d ' ')" \ + "origin=$(git remote get-url origin 2>/dev/null || echo none)" \ + "proxy=$(cd "${GOPROXY#file://}" && find . -type f | paste -sd, -)" >> "$WORK/log" +cp ../release.sh "$WORK/container-release.sh" +[[ -z ${GR_FAIL:-} ]] || exit 1 +[[ -z ${GR_SLEEP:-} ]] || { echo $$ > "$WORK/gr.pid"; sleep 60; } rm -rf dist for os in darwin linux; do for a in arm64 amd64; do @@ -259,3 +812,14 @@ done rm -rf dist/x git archive --prefix="devvm-$DEVVM_VERSION/" HEAD | gzip -n > "dist/devvm-$DEVVM_VERSION.tar.gz" (cd dist && { sha256sum devvm-*.tar.gz 2>/dev/null || shasum -a 256 devvm-*.tar.gz; } > SHA256SUMS) +case ${GR_OUT:-} in + link) ln -s "$WORK/secret" dist/leak ;; + swap) mkdir -p "$WORK/victim" && rm -rf "$RT_OUT" && ln -s "$WORK/victim" "$RT_OUT" ;; + setuid) printf '#!/bin/sh\n' > "$RT_OUT/su" && chmod 4755 "$RT_OUT/su" ;; + writable) printf 'x\n' > "$RT_OUT/notes" && chmod 666 "$RT_OUT/notes" ;; + private) printf 'x\n' > "$RT_OUT/private" && chmod 600 "$RT_OUT/private" ;; + setgid) printf '#!/bin/sh\n' > "$RT_OUT/sg" && chmod 2755 "$RT_OUT/sg" ;; + sticky) mkdir "$RT_OUT/tmp" && chmod 1755 "$RT_OUT/tmp" ;; + writable-folder) mkdir "$RT_OUT/shared" && chmod 777 "$RT_OUT/shared" ;; + big) dd if=/dev/null of="$RT_OUT/big" bs=1 seek=$(((2 << 30) + 1)) count=0 2>/dev/null ;; +esac diff --git a/testdata/script/repro_check.txtar b/testdata/script/repro_check.txtar new file mode 100644 index 00000000..3cca7d3c --- /dev/null +++ b/testdata/script/repro_check.txtar @@ -0,0 +1,200 @@ +# scripts/repro-check.sh: two builds of a commit or a tag by this +# checkout's release.sh, compared, in a throwaway repo with a goreleaser +# that writes the same small dist/ each time (unless told to record what +# a real one would leak), a mise.lock of file:// tarballs, and a podman +# and a docker that run the container's command here. The system's +# commands, not the stubs (ssh-keygen's): git signs with ssh-keygen. +[!exec:git] skip +env GIT_CONFIG_NOSYSTEM=1 +env PATH=$WORK/bin:/usr/bin:/bin +env DEVVM_RELEASE_TEST_FILE_URLS=$WORK/tools +env XDG_CACHE_HOME=$WORK/cache +cp bin/podman bin/docker +chmod 755 bin/goreleaser +chmod 755 bin/podman +chmod 755 bin/docker +exec bash repo.sh + +# HEAD, twice: the second build under Docker, as you, where the first ran +# under podman, as root, and from a repository with a stray tag, and the +# two agree, every archive's files root's. +exec repo/scripts/repro-check.sh +stdout '^==> build 1: under podman as 0:0, from this repository$' +stdout '^==> build 2: under docker as \d+:\d+, from one with a stray tag, v0\.0\.0-stray, at the commit$' +! stdout 'same user' +stdout '^[0-9a-f]{64} devvm-1\.2\.3-linux-arm64\.tar\.gz$' +stdout '^[0-9a-f]{64} SHA256SUMS$' +stdout '^==> both builds of HEAD \([0-9a-f]{40}\) made the same bytes$' +! stdout DIFFERS + +# A build that records the user it ran as, as GoReleaser does without the +# archives' owner set: the two differ. +env GR_RECORD=user +! exec repo/scripts/repro-check.sh +stdout ' devvm-1\.2\.3-linux-arm64\.tar\.gz DIFFERS: build 2 made [0-9a-f]{64}$' +stderr '^repro-check: the two builds differ$' + +# Archives whose files are the user's on disk, not root's: refused, though +# both builds ran as the same user here and agree. +env GR_RECORD=disk +env DEVVM_RELEASE_RUNTIME=docker +! exec repo/scripts/repro-check.sh +stdout '^\(both ran as the same user' +! stdout DIFFERS +stdout '^ devvm-1\.2\.3-linux-arm64\.tar\.gz, build 1: not root''s with mode 0755 or 0644: ' +stderr '^repro-check: an archive holds a file that isn''t root''s with mode 0755 or 0644$' +env GR_RECORD= +env DEVVM_RELEASE_RUNTIME= + +# A release.sh that ends without building but exits 0, as macOS's bash +# 3.2 can after a syntax error: refused. +exec bash -c 'printf ''#!/bin/bash\nexit 0\n'' > repo/scripts/release.sh' +! exec repo/scripts/repro-check.sh +stderr '^repro-check: build 1 made no release: its log is above$' +exec git -C repo checkout -q scripts/release.sh + +# Another commit is built by this checkout's release.sh, never its own: +# HEAD~1's would touch outside here, outside its container. +exec bash outside.sh +exec repo/scripts/repro-check.sh HEAD~1 +stdout '^==> both builds of HEAD~1 \([0-9a-f]{40}\) made the same bytes$' +! exists outside + +# A tag builds as its release does, with its checks, unsigned. +exec bash tag.sh +exec repo/scripts/repro-check.sh v1.2.3 +stdout '^==> both builds of v1\.2\.3 \([0-9a-f]{40}\) made the same bytes$' +grep 'GORELEASER_CURRENT_TAG=v1\.2\.3$' log + +! exec repo/scripts/repro-check.sh HEAD v1.2.3 +stderr '^repro-check: too many arguments' +! exec repo/scripts/repro-check.sh no-such-commit +stderr '^repro-check: no commit no-such-commit$' + +-- repo.sh -- +# A repo with release.sh and repro-check.sh, the formula, an install.sh to +# fill in, VERSION 1.2.3, the release key's public key, a release signer, +# a key git trusts, and a mise.lock pinning a Go and this test's +# goreleaser (tools.sh). +set -eu +mkdir -p repo/scripts repo/packaging/homebrew keys +cp "$DEVVM_REPO/scripts/release.sh" "$DEVVM_REPO/scripts/repro-check.sh" repo/scripts/ +cp "$DEVVM_REPO/packaging/homebrew/devvm.rb" repo/packaging/homebrew/ +echo 1.2.3 > repo/VERSION +printf 'module example.com/x\n\ngo 1.22\n' > repo/go.mod +printf '#!/bin/sh\nrelease_version=""\nminisign_key=""\n' > repo/install.sh +printf 'untrusted comment: a test key\nRWQtestkeytestkeytestkeytestkeytestkeytestkeytestkey\n' > repo/packaging/minisign.pub +ssh-keygen -q -t ed25519 -N '' -C good -f keys/good +printf 'e@e %s\n' "$(cat keys/good.pub)" > keys/allowed +ssh-keygen -lf keys/good.pub | awk '{ print $2 }' > repo/packaging/release-signer +bash tools.sh > repo/mise.lock +git -C repo init -q +git -C repo config user.email e@e +git -C repo config user.name e +git -C repo config gpg.format ssh +git -C repo config gpg.ssh.allowedSignersFile "$PWD/keys/allowed" +git -C repo add -A +git -C repo commit -qm r +-- tag.sh -- +# The tag v1.2.3 at HEAD, signed with the release signer's key. +git -C repo -c user.signingkey="$PWD/keys/good" tag -s v1.2.3 -m v1.2.3 +-- outside.sh -- +# HEAD~1: a release.sh that touches outside when it runs outside its +# container; HEAD: back to HEAD~2. +set -eu +awk '{ print } /^root=/ { print "touch \"$WORK/outside\"" }' repo/scripts/release.sh > rs +cat rs > repo/scripts/release.sh +git -C repo commit -qam outside +git -C repo revert --no-edit HEAD >/dev/null +-- tools.sh -- +# A mise.lock's go and goreleaser, for both Linux processors: tarballs of a +# go that does nothing and of bin/goreleaser, by file URL and SHA-256. +set -eu +mkdir -p tools/go/bin +printf '#!/bin/sh\n' > tools/go/bin/go +chmod 755 tools/go/bin/go +tar -czf tools/go.tar.gz -C tools go +tar -czf tools/goreleaser.tar.gz -C bin goreleaser +for t in go goreleaser; do + sum=$({ sha256sum "tools/$t.tar.gz" 2>/dev/null || shasum -a 256 "tools/$t.tar.gz"; } | cut -c1-64) + printf '[[tools.%s]]\nversion = "1.30.0"\n\n' "$t" + for p in linux-arm64 linux-x64; do + printf '[tools.%s."platforms.%s"]\nchecksum = "sha256:%s"\nurl = "file://%s"\n\n' "$t" "$p" "$sum" "$PWD/tools/$t.tar.gz" + done +done +-- bin/podman -- +#!/bin/bash +# A container runtime, here: rootless podman, or rootful Docker when it's +# called docker. --version says which, and info whether it's rootless. run +# runs --entrypoint, then the command, with each -v's container folder +# replaced by its host folder, in -w's folder, with each -e's variable set +# and RT_USER set to --user's. +set -eu +podman=true +[[ ${0##*/} != docker ]] || podman=false +case $1 in + --version) + if $podman; then echo 'podman version 5.6.0'; else echo 'Docker version 28.5.1, build e180ab8'; fi + exit 0 ;; + info) + if $podman; then echo true; else echo '["name=seccomp,profile=builtin"]'; fi + exit 0 ;; + run) ;; + *) echo "runtime: no fake for $*" >&2; exit 1 ;; +esac +shift +from=() to=() dir= entry=() +while [[ $1 == -* ]]; do + case $1 in + --rm) shift ;; + --platform | --name | --security-opt | --cap-drop | --pids-limit | --memory | --network) shift 2 ;; + --entrypoint) entry=("$2"); shift 2 ;; + --user) export RT_USER=$2; shift 2 ;; + -v) IFS=: read -r h c _ <<<"$2"; from+=("$c"); to+=("$h"); shift 2 ;; + -w) dir=$2; shift 2 ;; + -e) export "${2?}"; shift 2 ;; + *) echo "runtime: no fake for $1" >&2; exit 1 ;; + esac +done +shift +set -- ${entry[@]+"${entry[@]}"} "$@" +map() { + local a=$1 i + for i in "${!from[@]}"; do [[ $a != "${from[i]}"* ]] || a=${to[i]}${a#"${from[i]}"}; done + printf '%s' "$a" +} +args=() +for a in "$@"; do args+=("$(map "$a")"); done +cd "$(map "$dir")" +exec "${args[@]}" +-- bin/goreleaser -- +#!/bin/bash +# Logs its call, and writes a dist/ like GoReleaser's, the same each time: +# each system's and processor's build, a script printing $DEVVM_VERSION, an +# archive for each holding it and its repository's tags, with root's files +# and fixed times, the source tarball and SHA256SUMS. With GR_RECORD=user, +# each archive holds the user the container ran as too; with +# GR_RECORD=disk, its files are the user's on disk, not root's. +set -eu +echo "$* GORELEASER_CURRENT_TAG=${GORELEASER_CURRENT_TAG:-}" >> "$WORK/log" +# GNU tar's options, or bsdtar's, which also leaves out macOS's metadata. +if tar --version 2>/dev/null | grep -q GNU; then own=() root=(--owner=root:0 --group=root:0) +else own=(--no-xattrs --no-acls --no-fflags --no-mac-metadata) root=(--uid 0 --gid 0 --uname root --gname root); fi +[[ ${GR_RECORD:-} == disk ]] || own+=("${root[@]}") +rm -rf dist +for os in darwin linux; do + for a in arm64 amd64; do + d=dist/x/devvm-$DEVVM_VERSION-$os-$a + mkdir -p "dist/devvm_${os}_$a" "$d" + printf '#!/bin/sh\necho %s\n' "$DEVVM_VERSION" > "dist/devvm_${os}_$a/devvm" + chmod 755 "dist/devvm_${os}_$a/devvm" + cp "dist/devvm_${os}_$a/devvm" "$d/devvm" + git tag -l > "$d/tags" + [[ ${GR_RECORD:-} != user ]] || echo "$RT_USER" > "$d/user" + touch -t 202601010000 "$d"/* "$d" + tar -cf - ${own[@]+"${own[@]}"} -C dist/x "devvm-$DEVVM_VERSION-$os-$a" | gzip -n > "dist/devvm-$DEVVM_VERSION-$os-$a.tar.gz" + done +done +rm -rf dist/x +git archive --prefix="devvm-$DEVVM_VERSION/" HEAD | gzip -n > "dist/devvm-$DEVVM_VERSION.tar.gz" +(cd dist && { sha256sum devvm-*.tar.gz 2>/dev/null || shasum -a 256 devvm-*.tar.gz; } > SHA256SUMS)