Skip to content

Commit 415b62c

Browse files
authored
Merge pull request #1107 from cipherstash/fix/alpine-musl-build-image
ci(musl): build the Alpine image from a pinned Dockerfile Dependabot can move
2 parents c7b8a3a + ee87669 commit 415b62c

13 files changed

Lines changed: 480 additions & 59 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'stash': patch
3+
---
4+
5+
The supply-chain skill names every Dependabot ecosystem the repository monitors, including the Go module and the Docker image the musl binaries are built in.

‎.github/dependabot.yml‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,3 +296,28 @@ updates:
296296
- dependency-name: "*"
297297
update-types:
298298
- version-update:semver-major
299+
300+
# ── Docker ─────────────────────────────────────────────────────
301+
# The Alpine image the musl binaries are built in. Only the `FROM` digest is
302+
# read here: the `apk` pins in that Dockerfile are moved by hand, and
303+
# musl-build-image.yml says when they stop resolving.
304+
- package-ecosystem: docker
305+
directory: /.github/docker/musl-build
306+
schedule:
307+
interval: weekly
308+
day: monday
309+
cooldown:
310+
default-days: 7
311+
open-pull-requests-limit: 2
312+
labels:
313+
- dependencies
314+
- supply-chain
315+
commit-message:
316+
prefix: "chore"
317+
include: scope
318+
ignore:
319+
# A new Node.js major (node:24-alpine) is reviewed and applied manually,
320+
# with the host legs' Node version, not by Dependabot.
321+
- dependency-name: "*"
322+
update-types:
323+
- version-update:semver-major
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Builds the linux-x64-musl binaries of @cipherstash/auth and
2+
# @cipherstash/protect-ffi. Alpine is a musl system, so its compiler links
3+
# musl; the Ubuntu runner's compiler links glibc, and the result does not load
4+
# on musl.
5+
#
6+
# Pinned because the output is published with provenance. Dependabot moves the
7+
# digest; nothing moves the package versions, and Alpine drops a version from
8+
# its index when it publishes the next one, so a pin can stop resolving at any
9+
# time. musl-build-image.yml builds this file weekly so that is a failed check,
10+
# not a failed release. Re-pin from the FROM image with
11+
# `apk update >/dev/null && apk search --exact <packages>`.
12+
FROM node:22-alpine@sha256:0a7108bf6c7bf5de370ffb1a3ed6be93d405b43ff159f681a8d18c0e2bc2e402
13+
14+
# build-base is a metapackage whose compiler and linker dependencies carry no
15+
# version, so gcc, g++, binutils, musl-dev and make are pinned beside it.
16+
RUN apk add --no-cache \
17+
binutils=2.45.1-r1 \
18+
build-base=0.5-r4 \
19+
cmake=4.2.3-r0 \
20+
curl=8.22.0-r0 \
21+
g++=15.2.0-r5 \
22+
gcc=15.2.0-r5 \
23+
git=2.54.0-r0 \
24+
linux-headers=7.0.0-r1 \
25+
make=4.4.1-r4 \
26+
musl-dev=1.2.6-r2 \
27+
perl=5.42.2-r1 \
28+
rustup=1.29.0-r0

‎.github/workflows/_build-auth-artifacts.yml‎

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -118,28 +118,29 @@ jobs:
118118
# suite's 0.44.0 has that fault. Ubuntu's musl-gcc cannot link a Rust
119119
# shared library (it has no musl libgcc_s), and the musl.cc toolchain
120120
# that _build-ffi-artifacts.yml downloads timed out from GitHub's runners
121-
# on 2 October 2026. The image is pinned by digest because its output is
122-
# published with provenance. `-crt-static` keeps the binary linked
123-
# against musl at load time, which a Node.js native module needs, and
124-
# which the C library check below reads. The same napi flags as the host
125-
# build, for the same reasons.
121+
# on 2 October 2026. The image is .github/docker/musl-build/Dockerfile,
122+
# base image and packages pinned, because its output is published with
123+
# provenance. `-crt-static` keeps the binary linked against musl at load
124+
# time, which a Node.js native module needs, and which the C library
125+
# check below reads. The same napi flags as the host build, for the same
126+
# reasons.
126127
- name: Build the native binding in Alpine (linux-x64-musl)
127128
if: ${{ matrix.platform == 'linux-x64-musl' }}
128129
env:
129130
TARGET: ${{ matrix.target }}
130-
ALPINE_NODE_IMAGE: node:22-alpine@sha256:0a7108bf6c7bf5de370ffb1a3ed6be93d405b43ff159f681a8d18c0e2bc2e402
131+
MUSL_BUILD_IMAGE: cipherstash/musl-build:local
131132
run: |
132133
set -euo pipefail
133134
rust_version=$(mise current rust)
134135
pnpm_spec=$(node -p "require('./package.json').packageManager")
136+
docker build --pull -t "$MUSL_BUILD_IMAGE" .github/docker/musl-build
135137
docker run --rm \
136138
-v "$GITHUB_WORKSPACE:/build" -w /build \
137139
-e TARGET -e RUST_VERSION="$rust_version" -e PNPM_SPEC="$pnpm_spec" \
138140
-e HOST_UID="$(id -u)" -e HOST_GID="$(id -g)" \
139141
-e RUSTFLAGS="-C target-feature=-crt-static" \
140-
"$ALPINE_NODE_IMAGE" sh -euc '
142+
"$MUSL_BUILD_IMAGE" sh -euc '
141143
trap "chown -R \"\$HOST_UID:\$HOST_GID\" /build" EXIT
142-
apk add --no-cache build-base cmake perl linux-headers git curl rustup
143144
rustup-init -y --profile minimal --default-toolchain "$RUST_VERSION" --target "$TARGET"
144145
. "$HOME/.cargo/env"
145146
corepack enable

‎.github/workflows/_build-ffi-artifacts.yml‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -235,20 +235,20 @@ jobs:
235235
PLATFORM: ${{ matrix.cfg.platform }}
236236
BUILD_SCRIPT: ${{ matrix.cfg.script }}
237237
BUILD_LOG: ${{ matrix.cfg.log }}
238-
ALPINE_NODE_IMAGE: node:22-alpine@sha256:0a7108bf6c7bf5de370ffb1a3ed6be93d405b43ff159f681a8d18c0e2bc2e402
238+
MUSL_BUILD_IMAGE: cipherstash/musl-build:local
239239
run: |
240240
set -euo pipefail
241241
rust_version=$(rustc --version | cut -d' ' -f2)
242242
pnpm_spec=$(node -p "require('./package.json').packageManager")
243+
docker build --pull -t "$MUSL_BUILD_IMAGE" .github/docker/musl-build
243244
docker run --rm \
244245
-v "$GITHUB_WORKSPACE:/build" -w /build \
245246
-e CARGO_BUILD_TARGET -e PLATFORM -e BUILD_SCRIPT -e BUILD_LOG \
246247
-e RUST_VERSION="$rust_version" -e PNPM_SPEC="$pnpm_spec" \
247248
-e HOST_UID="$(id -u)" -e HOST_GID="$(id -g)" \
248249
-e RUSTFLAGS="-C target-feature=-crt-static" \
249-
"$ALPINE_NODE_IMAGE" sh -euc '
250+
"$MUSL_BUILD_IMAGE" sh -euc '
250251
trap "chown -R \"\$HOST_UID:\$HOST_GID\" /build" EXIT
251-
apk add --no-cache build-base cmake perl linux-headers git curl rustup
252252
rustup-init -y --profile minimal --default-toolchain "$RUST_VERSION" --target "$CARGO_BUILD_TARGET"
253253
. "$HOME/.cargo/env"
254254
corepack enable

‎.github/workflows/auth-preflight.yml‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,10 @@ jobs:
4747
with:
4848
ref: ${{ inputs.ref }}
4949
persist-credentials: false
50-
sparse-checkout: scripts
50+
# The musl smoke test reads the Dockerfile's FROM line.
51+
sparse-checkout: |
52+
scripts
53+
.github/docker/musl-build
5154
5255
- uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4
5356
with:
@@ -131,12 +134,14 @@ jobs:
131134
132135
# The host step above installs only linux-x64-gnu, the runner's own
133136
# platform. The musl binary loads only where musl is the C library, so it
134-
# is installed and loaded inside Alpine, from the image the build uses.
137+
# is installed and loaded inside Alpine, on the base image the build
138+
# image is made from: plain Node.js on musl, as a user's container is.
139+
# Read from the Dockerfile so there is one digest for Dependabot to move.
135140
- name: Smoke-test the musl artifact inside Alpine
136-
env:
137-
ALPINE_NODE_IMAGE: node:22-alpine@sha256:0a7108bf6c7bf5de370ffb1a3ed6be93d405b43ff159f681a8d18c0e2bc2e402
138141
run: |
139142
set -euo pipefail
143+
ALPINE_NODE_IMAGE=$(sed -n 's/^FROM //p' .github/docker/musl-build/Dockerfile)
144+
test -n "$ALPINE_NODE_IMAGE"
140145
wrapper=$(basename "$(ls "$GITHUB_WORKSPACE"/auth-dist/cipherstash-auth-[0-9]*.tgz)")
141146
musl=$(basename "$(ls "$GITHUB_WORKSPACE"/auth-dist/cipherstash-auth-linux-x64-musl-*.tgz)")
142147
docker run --rm -v "$GITHUB_WORKSPACE/auth-dist:/dist:ro" \

‎.github/workflows/ffi-preflight.yml‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,10 @@ jobs:
4949
with:
5050
ref: ${{ inputs.ref }}
5151
persist-credentials: false
52-
sparse-checkout: scripts
52+
# The musl smoke test reads the Dockerfile's FROM line.
53+
sparse-checkout: |
54+
scripts
55+
.github/docker/musl-build
5356
5457
- uses: actions/download-artifact@v4
5558
with:
@@ -152,12 +155,14 @@ jobs:
152155
153156
# The host steps above install only linux-x64-gnu, the runner's own
154157
# platform. The musl binary loads only where musl is the C library, so it
155-
# is installed and loaded inside Alpine, from the image the build uses.
158+
# is installed and loaded inside Alpine, on the base image the build
159+
# image is made from: plain Node.js on musl, as a user's container is.
160+
# Read from the Dockerfile so there is one digest for Dependabot to move.
156161
- name: Smoke-test the musl artifact inside Alpine
157-
env:
158-
ALPINE_NODE_IMAGE: node:22-alpine@sha256:0a7108bf6c7bf5de370ffb1a3ed6be93d405b43ff159f681a8d18c0e2bc2e402
159162
run: |
160163
set -euo pipefail
164+
ALPINE_NODE_IMAGE=$(sed -n 's/^FROM //p' .github/docker/musl-build/Dockerfile)
165+
test -n "$ALPINE_NODE_IMAGE"
161166
wrapper=$(basename "$(ls "$GITHUB_WORKSPACE"/ffi-dist/cipherstash-protect-ffi-[0-9]*.tgz)")
162167
musl=$(basename "$(ls "$GITHUB_WORKSPACE"/ffi-dist/cipherstash-protect-ffi-linux-x64-musl-*.tgz)")
163168
docker run --rm -v "$GITHUB_WORKSPACE/ffi-dist:/dist:ro" \
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
name: musl build image
2+
3+
# The Dockerfile pins every apk package to an exact version, and Alpine drops a
4+
# version from its index when it publishes the next one. Nothing else builds
5+
# the image between releases, so without this a pin that stopped resolving
6+
# would first be seen by a release.
7+
on:
8+
push:
9+
branches:
10+
- main
11+
paths:
12+
- ".github/docker/musl-build/**"
13+
- ".github/workflows/musl-build-image.yml"
14+
pull_request:
15+
paths:
16+
- ".github/docker/musl-build/**"
17+
- ".github/workflows/musl-build-image.yml"
18+
schedule:
19+
- cron: "0 7 * * 1"
20+
workflow_dispatch:
21+
22+
permissions:
23+
contents: read
24+
25+
jobs:
26+
build:
27+
name: Build the Alpine musl image
28+
runs-on: ubuntu-latest
29+
timeout-minutes: 15
30+
# `issues: write` for the last step alone; see there.
31+
permissions:
32+
contents: read
33+
issues: write
34+
steps:
35+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
36+
with:
37+
persist-credentials: false
38+
# `--pull` fetches the digest the Dockerfile names rather than a cached
39+
# tag, so the check builds what a release would.
40+
- name: Build the image
41+
run: docker build --pull -t cipherstash/musl-build:check .github/docker/musl-build
42+
# The build steps rely on these being present; a Dockerfile that builds
43+
# but lost one would fail minutes into a release build instead.
44+
- name: Check the tools the build steps use
45+
run: |
46+
set -euo pipefail
47+
docker run --rm cipherstash/musl-build:check sh -euc '
48+
echo "Alpine $(cat /etc/alpine-release)"
49+
for tool in cc c++ cmake perl make curl git rustup-init node; do
50+
command -v "$tool" >/dev/null || { echo "missing: $tool" >&2; exit 1; }
51+
done
52+
'
53+
# GitHub mails a scheduled run's failure to one person: whoever last
54+
# edited the cron line. An issue is what the rest of the team sees.
55+
- name: Open an issue when the weekly build fails
56+
if: ${{ failure() && github.event_name == 'schedule' }}
57+
env:
58+
GH_TOKEN: ${{ github.token }}
59+
run: |
60+
gh issue create --repo "$GITHUB_REPOSITORY" \
61+
--title "The musl build image no longer builds" \
62+
--label "github-actions" \
63+
--body "The weekly build of .github/docker/musl-build/Dockerfile failed: $GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID. An apk pin has most likely stopped resolving; re-pin with the command in the Dockerfile's comment."

‎e2e/tests/supply-chain.e2e.test.ts‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -625,6 +625,7 @@ const MANIFEST_BY_ECOSYSTEM: Record<string, string> = {
625625
uv: 'pyproject.toml',
626626
mix: 'mix.exs',
627627
pub: 'pubspec.yaml',
628+
docker: 'Dockerfile',
628629
// github-actions is special-cased: Dependabot requires `directory: /` and
629630
// discovers .github/workflows itself.
630631
'github-actions': '.github/workflows',
@@ -722,6 +723,35 @@ describe('supply chain — automated dependency updates (Dependabot)', () => {
722723
expect(gha?.cooldown?.['default-days']).toBeGreaterThanOrEqual(3)
723724
})
724725

726+
it('every entry has a ≥ 3 day cooldown', () => {
727+
// The two above are the named controls; this is the one that catches an
728+
// entry added later without one, which would propose a dependency the
729+
// day it is published.
730+
expect(db.updates.length).toBeGreaterThan(0)
731+
for (const entry of db.updates) {
732+
expect(
733+
entry.cooldown?.['default-days'] ?? 0,
734+
`${entry['package-ecosystem']} at ${entry.directory} has no cooldown of at least 3 days`,
735+
).toBeGreaterThanOrEqual(3)
736+
}
737+
})
738+
739+
it('the skill names every ecosystem Dependabot monitors', () => {
740+
// The sentence is what a customer's agent reads; it omitted gomod for
741+
// months with nothing to say so.
742+
const skill = read('skills/stash-supply-chain-security/SKILL.md')
743+
const sentence = skill
744+
.split('\n')
745+
.find((line) => line.startsWith('Dependabot opens grouped'))
746+
expect(sentence).toBeDefined()
747+
const ecosystems = new Set(db.updates.map((u) => u['package-ecosystem']))
748+
for (const ecosystem of ecosystems) {
749+
expect(sentence, `the skill does not name \`${ecosystem}\``).toContain(
750+
`\`${ecosystem}\``,
751+
)
752+
}
753+
})
754+
725755
it('every entry ignores majors, so none configures a major cooldown window', () => {
726756
// One relationship, asserted from both ends, because either end alone
727757
// passes on the drift that matters.

‎scripts/__tests__/auth-build-artifacts.test.mjs‎

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -80,19 +80,18 @@ describe('_build-auth-artifacts.yml', () => {
8080
for (const build of builds) expect(check).toBeGreaterThan(build)
8181
})
8282

83-
it('builds the musl binding inside Alpine, from an image pinned by digest', () => {
83+
it('builds the musl binding inside Alpine, from the pinned Dockerfile', () => {
8484
// Built on the Ubuntu runner, the musl binary linked glibc and failed to
85-
// load on musl. Alpine is a musl system, so its compiler links musl.
85+
// load on musl. Alpine is a musl system, so its compiler links musl. The
86+
// image's pins, and that this is its one home, are musl-build-image.test.mjs's.
8687
const steps = binaries?.steps ?? []
8788
const musl = steps.filter((step) =>
8889
String(step?.if ?? '').includes("== 'linux-x64-musl'"),
8990
)
9091
const run = musl.map((step) => String(step?.run ?? '')).join('\n')
91-
const env = Object.assign({}, ...musl.map((step) => step?.env ?? {}))
92-
expect(env.ALPINE_NODE_IMAGE).toMatch(/-alpine@sha256:[0-9a-f]{64}$/)
93-
// The pinned image is the one that runs, not a mutable tag.
94-
expect(run).toMatch(/docker run[\s\S]*"\$ALPINE_NODE_IMAGE"/)
95-
expect(run).not.toMatch(/\bnode:\d+-alpine(?!@)/)
92+
expect(run).toMatch(
93+
/docker build --pull -t "\$MUSL_BUILD_IMAGE" \.github\/docker\/musl-build\n[\s\S]*docker run[\s\S]*"\$MUSL_BUILD_IMAGE"/,
94+
)
9695
expect(run).toContain('RUSTFLAGS="-C target-feature=-crt-static"')
9796
// The container loads the binary it built, on musl.
9897
expect(run).toMatch(
@@ -162,12 +161,11 @@ describe('_build-auth-artifacts.yml', () => {
162161
)
163162
expect(alpine).toBeDefined()
164163
expect(String(alpine.run)).toContain('linux-x64-musl')
165-
expect(String(alpine.run)).toMatch(/docker run[\s\S]*"\$ALPINE_NODE_IMAGE"/)
166-
// The same image as the build, so the load test matches the build.
167-
const build = (binaries?.steps ?? []).find(
168-
(step) => step?.env?.ALPINE_NODE_IMAGE,
164+
// On the image the build image starts from, read from the Dockerfile.
165+
expect(String(alpine.run)).toContain(
166+
"ALPINE_NODE_IMAGE=$(sed -n 's/^FROM //p'",
169167
)
170-
expect(alpine.env?.ALPINE_NODE_IMAGE).toBe(build?.env?.ALPINE_NODE_IMAGE)
168+
expect(String(alpine.run)).toMatch(/docker run[\s\S]*"\$ALPINE_NODE_IMAGE"/)
171169
})
172170

173171
it('packs the wrapper with pnpm, which rewrites its workspace peers', () => {

0 commit comments

Comments
 (0)