Repository navigation
320 lines (301 loc) · 15.2 KB
/
Copy pathcontainer.yml
File metadata and controls
320 lines (301 loc) · 15.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
# Build, test and publish quay.io/crunchtools/python-sdlc, and the same digest
# as quay.io/crunchtools/sdlc, the fleet-wide name it is becoming.
#
# The shape is the Container Image profile's, and it is the same shape trentina
# arrived at the hard way in #689: the build pushes ONLY the commit SHA tag, the
# gates address the image by the DIGEST the build reported, and `latest` plus the
# semver tags move in a separate promote job that copies that tested digest
# without rebuilding. `latest` is the newest RELEASE and `main` is the branch
# (constitution 1.33.0); a push to main moves `main` alone.
#
# Why that matters more here than anywhere else: 35 repos will pin this image.
# A published tag that was never the thing the contract test ran against is a
# tool version nobody can actually verify.
#
# A TAG event therefore builds NOTHING. `release.yml` tags the commit that just
# merged, so the main-branch run of that same sha has already built, tested and
# pushed `:<sha>`; the tag run resolves that digest, verifies it again and
# promotes it. Building it twice is what cost v0.3.5 its image (#14).
name: Container
on:
push:
branches: [main]
tags: ["v*"]
pull_request:
# Weekly, to pick up base-image errata. MANDATORY for this profile, and so is
# bypassing the layer cache on it -- a cached `dnf install` layer is reused
# while the Containerfile and base digest are unchanged, so a cached rebuild
# ships the same packages and no errata at all.
schedule:
- cron: "0 6 * * 1"
workflow_dispatch:
# Keyed on the COMMIT, not the run, so the push-to-main run and the tag run of
# the same commit SERIALIZE. `github.run_id` is unique per run, so the old group
# put every run in a group of its own and controlled nothing: both builds pushed
# the same `:<sha>` tag and the second replaced the first's manifest. That cost
# v0.3.5 its image -- a GitHub release with no image behind it, which is the one
# state a pinned fleet cannot survive.
#
# The tag run no longer builds, so there is no race left to lose. The group is
# still load-bearing, for a different reason: it is what guarantees the
# main-branch run has FINISHED before the tag run looks for the `:<sha>` it
# pushed. Without it the tag run could reach `skopeo inspect` first and fail on
# an image that was still being built.
#
# cancel-in-progress stays false off pull requests: cancelling the main run
# when its tag arrives would abandon a push half-done.
concurrency:
group: ${{ github.workflow }}-${{ github.event_name == 'pull_request' && github.ref || github.sha }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
permissions: {}
env:
QUAY: quay.io/crunchtools/python-sdlc
# The fleet-wide name for the same image: one digest, two repositories, the
# same tags on both, until every consumer has moved and python-sdlc retires.
# It is never built or pushed separately -- it is a COPY of the digest pushed
# above, so the two names cannot disagree about what they hold.
SDLC: quay.io/crunchtools/sdlc
jobs:
build:
# A tag event builds nothing; it only resolves what main already pushed.
name: ${{ startsWith(github.ref, 'refs/tags/v') && 'Resolve the tested digest' || 'Build and test' }}
runs-on: ubuntu-latest
permissions:
contents: read
# Read by the step conditions below. The skip is per STEP, never per job:
# a job-level `if:` would skip every job that `needs:` this one unless each
# of them grew `always()` logic, which is how this fix fails silently on its
# first tag.
env:
IS_TAG: ${{ startsWith(github.ref, 'refs/tags/v') }}
outputs:
digest: ${{ steps.push.outputs.digest || steps.resolve.outputs.digest }}
ref: ${{ steps.push.outputs.ref || steps.resolve.outputs.ref }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- name: Shell and host-contract checks
if: env.IS_TAG != 'true'
run: |
set -eu
podman run --rm -v "$PWD:/mnt:ro,z" -w /mnt \
docker.io/koalaman/shellcheck:v0.11.0@sha256:61862eba1fcf09a484ebcc6feea46f1782532571a34ed51fedf90dd25f925a8d bin/sdlc tests/contract.sh \
tests/test_host_contract.sh tests/test_container_stack.sh scripts/release-version.sh \
scripts/revision-of.sh tests/test_revision_of.sh bin/sdlc-bootstrap
tests/test_host_contract.sh
tests/test_revision_of.sh
tests/test_release_version.py
- name: Build
if: env.IS_TAG != 'true'
env:
# A commit-driven build uses the cache; a rebuild that no commit
# triggered must not, or it ships nothing new.
NO_CACHE: ${{ github.event_name != 'push' && github.event_name != 'pull_request' }}
run: |
set -eu
args=""
if [ "$NO_CACHE" = "true" ]; then args="--no-cache"; fi
# The revision label is what promote reads to refuse a backwards
# move; without it the label is "unknown" and the guard is blind.
# shellcheck disable=SC2086
podman build $args -f Containerfile \
--build-arg "REVISION=$GITHUB_SHA" \
--build-arg "CREATED=$(date -u +%Y-%m-%dT%H:%M:%SZ)" \
-t "localhost/python-sdlc:$GITHUB_SHA" .
# The central test for THIS image: its whole purpose is "these
# executables exist at these versions". Run before anything is published.
- name: Contract test
if: env.IS_TAG != 'true'
run: tests/contract.sh "localhost/python-sdlc:$GITHUB_SHA"
# The planner and the CodeQL path matching, run in the image because
# they need its interpreter and PyYAML.
- name: Unit tests
if: env.IS_TAG != 'true'
run: |
set -eu
for t in tests/test_plan.py tests/test_codeql_globs.py \
tests/test_pycache_prefix.py tests/test_gourmand_sidecar.py \
tests/test_codeql_resilience.py tests/test_convert_repo.py \
tests/test_fleet_wave.py; do
podman run --rm -v "$PWD:/src:ro,z" -w /src \
--entrypoint /opt/constitution-venv/bin/python3 \
"localhost/python-sdlc:$GITHUB_SHA" "$t"
done
# The container stack through the real launcher and a real podman: the
# image mount grype scans is something only podman can prove.
- name: Container stack end to end
if: env.IS_TAG != 'true'
run: tests/test_container_stack.sh "localhost/python-sdlc:$GITHUB_SHA"
- name: Log in to Quay
if: github.event_name != 'pull_request'
env:
QUAY_USERNAME: ${{ secrets.QUAY_USERNAME }}
QUAY_PASSWORD: ${{ secrets.QUAY_PASSWORD }}
run: podman login -u "$QUAY_USERNAME" -p "$QUAY_PASSWORD" quay.io
- name: Push the SHA tag only
id: push
if: github.event_name != 'pull_request' && env.IS_TAG != 'true'
run: |
set -eu
podman push "localhost/python-sdlc:$GITHUB_SHA" "$QUAY:$GITHUB_SHA"
digest=$(skopeo inspect --format '{{.Digest}}' "docker://$QUAY:$GITHUB_SHA")
[ -n "$digest" ] || { echo "the registry reported no digest" >&2; exit 1; }
# The fleet name gets the SAME manifest, copied rather than pushed a
# second time: a second podman push recompresses the layers and can
# produce a different digest, and then the two names hold two images.
skopeo copy --all --preserve-digests "docker://$QUAY@$digest" "docker://$SDLC:$GITHUB_SHA"
got=$(skopeo inspect --format '{{.Digest}}' "docker://$SDLC:$GITHUB_SHA")
[ "$got" = "$digest" ] || { echo "$SDLC:$GITHUB_SHA is $got, not $digest" >&2; exit 1; }
echo "digest=$digest" >> "$GITHUB_OUTPUT"
echo "ref=$QUAY@$digest" >> "$GITHUB_OUTPUT"
echo "pushed $QUAY@$digest and $SDLC@$digest"
# The tag path, in place of everything above. Nothing is built and nothing
# is pushed: this reads the digest the main-branch run of this same commit
# already published, and `verify-digest` below tests it again before
# `promote` moves any tag onto it.
#
# Re-verifying is not ceremony. `:<sha>` is pushed BEFORE it is verified,
# so a main run whose contract test failed leaves a pushed-but-untested
# digest sitting on the registry. Promoting that on the strength of the
# push alone would publish an image no job ever tested.
- name: Resolve the digest the main-branch run pushed
id: resolve
if: env.IS_TAG == 'true'
run: |
set -eu
# stderr is NOT suppressed: "not found" and "authentication
# required" are different problems and the log has to say which.
digest=$(skopeo inspect --format '{{.Digest}}' \
"docker://$QUAY:$GITHUB_SHA") || digest=
if [ -z "$digest" ]; then
echo "$QUAY:$GITHUB_SHA does not exist." >&2
echo "The main-branch run for this commit never pushed it, so there" >&2
echo "is no tested image to promote. Promoting anything else would" >&2
echo "publish an image this release was never built from. Fix that" >&2
echo "run and re-push the tag." >&2
exit 1
fi
echo "digest=$digest" >> "$GITHUB_OUTPUT"
echo "ref=$QUAY@$digest" >> "$GITHUB_OUTPUT"
echo "promoting the already-built $QUAY@$digest"
# Re-runs the contract test against what is ACTUALLY on the registry, not
# against the local build. The profile requires this on every trigger: a
# rebuild changes packages without a commit, and a digest nobody tested is a
# digest nobody should pin.
verify-digest:
name: Verify the pushed digest
needs: build
if: github.event_name != 'pull_request'
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- name: Contract test against the pushed digest
run: tests/contract.sh "${{ needs.build.outputs.ref }}"
promote:
name: Promote
needs: [build, verify-digest]
if: github.event_name != 'pull_request'
runs-on: ubuntu-latest
permissions:
contents: read
# A FIXED group, unlike the workflow-level one, and never cancelled.
# The backwards-move guard below reads the currently published revision and
# then copies, which is check-then-act: two promotions in flight can both
# read the same `latest`, both pass, and the older one can land second and
# demote the registry. Serializing the job is what makes the guard sound.
# Not cancel-in-progress, because cancelling a half-finished promotion is
# the other way to leave the tags inconsistent.
concurrency:
group: promote-python-sdlc
cancel-in-progress: false
steps:
# Full history: the backwards-move guard below asks git whether the
# currently published commit already contains this one.
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
fetch-depth: 0
- name: Log in to Quay
env:
QUAY_USERNAME: ${{ secrets.QUAY_USERNAME }}
QUAY_PASSWORD: ${{ secrets.QUAY_PASSWORD }}
run: skopeo login -u "$QUAY_USERNAME" -p "$QUAY_PASSWORD" quay.io
# Copies the tested digest. No rebuild, so the bytes that were verified
# are the bytes that get the tag.
- name: Move main, and latest plus the version tags on a release tag
env:
REF: ${{ needs.build.outputs.ref }}
run: |
set -eu
# ONE floating tag moves per run, and which one is the whole point of
# constitution 1.33.0. `latest` is the newest RELEASE: it moves on a
# version tag and never on a push to main, because 44 units across the
# fleet pull `:latest` and every one of their authors meant "the newest
# release". `main` is the tag for the branch, for a consumer that wants
# continuous delivery and is willing to name it.
#
# Before this, `latest` was main. On 2026-11-07 that put unreleased
# trentina 6.11.0 into production at 02:01 through podman-auto-update,
# where it climbed to the unit's 4g cap and was SIGKILLed. Nothing had
# asked for it and nothing was watching (RT#1559).
#
# A prerelease moves no floating tag: `latest` is the newest STABLE
# release, and a release candidate is not the branch either. SemVer
# puts every prerelease identifier after a hyphen, so the pattern
# `v*-*` is the whole test.
floating=
case "$GITHUB_REF" in
refs/tags/v*-*) ;;
refs/tags/v*) floating=latest ;;
*) floating=main ;;
esac
# The profile: promotion MUST NOT move a floating tag back to an older
# commit when a newer one has landed. A scheduled rebuild or a
# re-dispatch of an old commit would otherwise quietly demote the
# registry, and 35 repos pin this image. Asked of whichever tag THIS
# run moves: a re-run of an old release tag must not demote `latest`
# any more than a re-dispatched old commit may demote `main`.
# Copy the tested digest, never a rewrap of it (constitution VII,
# RT#1550): --preserve-digests refuses a copy that would change the
# manifest, and the read-back fails the job if the tag resolves to
# anything but the digest that was tested.
#
# Every tag moves on BOTH names, python-sdlc and sdlc, to the same
# digest, and the guard reads both: either one ahead of this commit
# refuses the whole promotion rather than leaving them split.
want=${REF#*@}
promote() {
for repo in "$QUAY" "$SDLC"; do
skopeo copy --all --preserve-digests "docker://$REF" "docker://$repo:$1"
got=$(skopeo inspect --format '{{.Digest}}' "docker://$repo:$1")
[ "$got" = "$want" ] || { echo "$repo:$1 resolves to $got, not the tested $want" >&2; exit 1; }
done
}
if [ -n "$floating" ]; then
for repo in "$QUAY" "$SDLC"; do
# Fails closed: only an absent tag reads as empty
# (scripts/revision-of.sh, tests/test_revision_of.sh).
current=$(scripts/revision-of.sh "$repo:$floating")
if [ -n "${current:-}" ] && [ "$current" != "$GITHUB_SHA" ]; then
if git merge-base --is-ancestor "$GITHUB_SHA" "$current" 2>/dev/null; then
echo "refusing: $repo:$floating is $current, which already contains $GITHUB_SHA" >&2
exit 1
fi
fi
done
promote "$floating"
fi
case "$GITHUB_REF" in
refs/tags/v*)
version=${GITHUB_REF#refs/tags/v}
promote "$version"
# The minor tag so a consumer MAY track patches if it chooses to.
promote "${version%.*}"
echo "promoted $version"
;;
esac