Repository navigation
186 lines (175 loc) · 9.17 KB
/
Copy pathrelease-docker.yml
File metadata and controls
186 lines (175 loc) · 9.17 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
# Build and Push Docker Images using Docker Bake
name: release / docker
# Images are built from version tags only. A branch push used to build a
# floating chain-<name> image whose version string satisfies no
# halt_min_version and which operators nevertheless pulled; and a chain/<name>
# launch tag would recreate that name for an image reporting a different
# version. A runnable node image is always a vX.Y.Z tag (RELEASING.md).
#
# Tag pushes only, with no manual trigger, and a published release is never
# replaced (RELEASING.md, "Cutting a release").
on:
push:
tags:
- v*
permissions:
contents: read
jobs:
bake:
strategy:
# Every image runs to its end: a failing leg must not cancel a sibling
# between its push and its signature.
fail-fast: false
matrix:
# `latest` only for the CLI tools: a node image that moves by itself
# breaks coordinated upgrades (RELEASING.md, "Container images").
include:
- { image: gnoland, latest: false }
- { image: gnokey, latest: true }
- { image: gnoweb, latest: true }
- { image: gno, latest: true }
- { image: gnofaucet, latest: false }
- { image: gnodev, latest: true }
- { image: gnocontribs, latest: false }
- { image: gpao, latest: false }
runs-on: ubuntu-latest
permissions:
contents: read
actions: write # kept in case type=gha is re-enabled; not required by type=registry
packages: write # to push images to ghcr.io
id-token: write # to sign the images (keyless, sigstore)
steps:
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
persist-credentials: false
# Every tag, for the ordering below; blob:none keeps that cheap.
fetch-depth: 0
filter: blob:none
- name: Decide whether this is the highest release
id: release_order
run: |
# `latest` may only move forward. Gate it on being the highest final
# v* tag, not merely a final one: a backport cut after a newer line
# must not re-point latest at the older line.
HIGHEST=$(git -c versionsort.suffix=- tag --list 'v*' --sort=-v:refname | grep -v -- '-' | head -1 || true)
echo "is_highest=$([ -n "$HIGHEST" ] && [ "$HIGHEST" = "$GITHUB_REF_NAME" ] && echo true || echo false)" >> "$GITHUB_OUTPUT"
- name: Login to GitHub Container Registry
uses: docker/login-action@af1e73f918a031802d376d3c8bbc3fe56130a9b0 # v4.4.0
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@bb05f3f5519dd87d3ba754cc423b652a5edd6d2c # v4.2.0
# Tags: the git tag itself, the built commit's sha,
# and `latest` for the images the matrix marks, only when this tag is the
# highest final release. The action's own default adds `latest` to every
# tag build, gnoland included, so it is turned off and the raw rule below
# is the only `latest` published. See RELEASING.md, "Container images".
- name: Extract metadata
uses: docker/metadata-action@dc802804100637a589fabce1cb79ff13a1411302 # v6.2.0
id: meta
with:
images: ghcr.io/${{ github.repository }}/${{ matrix.image }}
tags: |
type=ref,event=tag
type=sha
type=raw,value=latest,enable=${{ matrix.latest && steps.release_order.outputs.is_highest == 'true' }}
flavor: |
latest=false
labels: |
org.opencontainers.image.authors=Gno Core Team
# A published image tag is never re-pushed: its digest is what the upgrade
# ledgers record (RELEASING.md, "Cutting a release"). Asked of the
# registry by HTTP status rather than by parsing a tool's message: 404 is
# the only answer that lets the build go on.
- name: Refuse a published image tag
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
REPO: ${{ github.repository }}/${{ matrix.image }}
# The tag bake pushes: the git tag, with what a registry tag cannot
# hold replaced by metadata-action.
VERSION: ${{ steps.meta.outputs.version }}
run: |
[ -n "${VERSION}" ] || { echo "::error::metadata-action gave no version to check"; exit 1; }
# Authenticated, so a package never pushed before answers 404 instead
# of refusing an anonymous token. Credentials go through curl's
# config on stdin, not its argument list.
token="$(printf 'user = "%s:%s"\n' "${GITHUB_REPOSITORY_OWNER}" "${GH_TOKEN}" \
| curl -fsS -K - "https://ghcr.io/token?scope=repository:${REPO}:pull" | jq -er .token)" \
|| { echo "::error::cannot get a token to read ghcr.io/${REPO}"; exit 1; }
code="$(printf 'header = "Authorization: Bearer %s"\n' "${token}" \
| curl -sS -K - -o /dev/null -w '%{http_code}' -I \
-H "Accept: application/vnd.oci.image.index.v1+json, application/vnd.docker.distribution.manifest.list.v2+json, application/vnd.oci.image.manifest.v1+json, application/vnd.docker.distribution.manifest.v2+json" \
"https://ghcr.io/v2/${REPO}/manifests/${VERSION}")"
case "${code}" in
404) echo "ghcr.io/${REPO}:${VERSION} is not published yet" ;;
200)
echo "::error::ghcr.io/${REPO}:${VERSION} is already published, and a published image tag is never re-pushed (RELEASING.md, \"Cutting a release\")"
exit 1
;;
*)
echo "::error::cannot tell whether ghcr.io/${REPO}:${VERSION} is published: HTTP ${code}"
exit 1
;;
esac
# Installed before anything is pushed: an installer failure after the push
# would leave published images with no signature.
- name: Install cosign
uses: sigstore/cosign-installer@6f9f17788090df1f26f669e9d70d6ae9567deba6 # v4.1.2
- name: Bake build and push
id: bake
uses: docker/bake-action@d3418bd7d0e9324001bca92fa8ba175ea7e6dc9b # v7.3.0
env:
# The tag that triggered the run, verbatim, never a version derived
# from the checkout: a final release shares its last candidate's
# commit. Pinned by gno.land/pkg/gnoland.TestReleaseToolingMatchesTheParser.
BUILD_VERSION: ${{ github.ref_name }}
with:
source: . # use checked-out code, not git URL at GITHUB_SHA
files: |
misc/deployments/bake/docker-bake.hcl
cwd://${{ steps.meta.outputs.bake-file-tags }}
cwd://${{ steps.meta.outputs.bake-file-labels }}
push: true
targets: ${{ matrix.image }}
# type=registry is used instead of type=gha because GHA cache blob
# entries are global (not scoped). When matrix jobs export concurrently,
# they race on the shared blob namespace, corrupting each other's cache.
# type=registry gives each image a fully independent OCI cache manifest.
# ignore-error: the cache only saves build time, and a failed export
# would otherwise fail a run whose image is pushed but not yet signed.
set: |
*.cache-from=type=registry,ref=ghcr.io/${{ github.repository }}/cache:${{ matrix.image }}
*.cache-to=type=registry,ref=ghcr.io/${{ github.repository }}/cache:${{ matrix.image }},mode=max,ignore-error=true
*.context=.
# Keyless signature on the pushed image, by digest, so `cosign verify`
# can tie ghcr.io/gnolang/gno/<tool>:vX.Y.Z to this workflow and tag
# (RELEASING.md, "Signing and provenance"). --recursive signs every
# manifest in the multi-arch index as well as the index itself: each
# platform image, and the attestation manifest buildx adds for each
# platform, which carries both its provenance and its SBOM. A host
# pulls the manifest for its platform, and a check made against that
# digest finds no signature on the index alone.
- name: Sign the image
timeout-minutes: 30
env:
IMAGE: ghcr.io/${{ github.repository }}/${{ matrix.image }}
DIGEST: ${{ fromJSON(steps.bake.outputs.metadata)[matrix.image]['containerimage.digest'] }}
run: |
[ -n "${DIGEST}" ] || { echo "::error::bake reported no digest for ${IMAGE}"; exit 1; }
# The image is pushed by now and its tag is never pushed again, so a
# Sigstore or registry outage must not end the job: five attempts of
# at most three minutes each, ten minutes of pauses between them, 25
# minutes in all, inside the step's 30. Signing again is additive.
for attempt in 1 2 3 4 5; do
if cosign sign --yes --recursive --timeout 3m "${IMAGE}@${DIGEST}"; then
exit 0
fi
if [ "${attempt}" -lt 5 ]; then
echo "::warning::cosign sign failed (attempt ${attempt} of 5); retrying in $((attempt * 60))s"
sleep $((attempt * 60))
fi
done
echo "::error::${IMAGE}@${DIGEST} is pushed but could not be signed"
exit 1