-
Notifications
You must be signed in to change notification settings - Fork 18
288 lines (247 loc) · 11.2 KB
/
release.yml
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
name: policy-server release
on:
push:
tags:
- "v*"
# Declare default permissions as read only.
permissions: read-all
jobs:
ci:
uses: ./.github/workflows/ci.yml
permissions: read-all
build:
name: Build container image
permissions:
packages: write
id-token: write
runs-on: ubuntu-latest
outputs:
repository: ${{ steps.setoutput.outputs.repository }}
tag: ${{ steps.setoutput.outputs.tag }}
artifact: ${{ steps.setoutput.outputs.artifact }}
digest: ${{ steps.setoutput.outputs.digest }}
steps:
- name: Checkout code
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Install cosign
uses: sigstore/cosign-installer@dc72c7d5c4d10cd6bcb8cf6e3fd625a9e5e537da # v3.7.0
- name: Set up QEMU
uses: docker/setup-qemu-action@49b3bc8e6bdd4a60e6116a5414239cba5943d3cf # v3.2.0
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@6524bf65af31da8d45b59e8c27de4bd072b392f5 # v3.8.0
- name: Login to GitHub Container Registry
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3.3.0
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Retrieve tag name (tag)
run: |
echo TAG_NAME=$(echo $GITHUB_REF | sed -e "s|refs/tags/||") >> $GITHUB_ENV
- name: Push and push container image
id: build-image
uses: docker/build-push-action@48aba3b46d1b1fec4febb7c5d0c644b249a11355 # v6.10.0
with:
context: .
file: ./Dockerfile
platforms: linux/amd64, linux/arm64
push: true
sbom: true
provenance: mode=max
tags: |
ghcr.io/${{github.repository_owner}}/policy-server:${{ env.TAG_NAME }}
- name: Sign container image
run: |
cosign sign --yes ghcr.io/${{github.repository_owner}}/policy-server@${{ steps.build-image.outputs.digest }}
cosign verify \
--certificate-oidc-issuer=https://token.actions.githubusercontent.com \
--certificate-identity="https://github.com/${{github.repository_owner}}/policy-server/.github/workflows/release.yml@${{ github.ref }}" \
ghcr.io/${{github.repository_owner}}/policy-server@${{ steps.build-image.outputs.digest }}
- id: setoutput
name: Set output parameters
run: |
echo "digest=${{ steps.build-image.outputs.digest }}" >> $GITHUB_OUTPUT
sbom:
name: Fetch, sign and verify SBOM and provenance files
strategy:
matrix:
arch: [amd64, arm64]
permissions:
packages: write
id-token: write
needs:
- build
runs-on: ubuntu-latest
steps:
- name: Install cosign
uses: sigstore/cosign-installer@dc72c7d5c4d10cd6bcb8cf6e3fd625a9e5e537da # v3.7.0
- name: Install the crane command
uses: kubewarden/github-actions/crane-installer@23f81f83e6392c869faacd8bfe86a8053d213d99 # v3.4.2
- name: Login to GitHub Container Registry
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3.3.0
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Verify container image signature
run: |
cosign verify \
--certificate-oidc-issuer=https://token.actions.githubusercontent.com \
--certificate-identity="https://github.com/${{github.repository_owner}}/policy-server/.github/workflows/release.yml@${{ github.ref }}" \
ghcr.io/${{ github.repository_owner }}/policy-server@${{ needs.build.outputs.digest }}
- name: Find platform digest
shell: bash
run: |
set -e
DIGEST=$(crane digest \
--platform "linux/${{ matrix.arch }}" \
ghcr.io/${{ github.repository_owner }}/policy-server@${{ needs.build.outputs.digest }})
echo "PLATFORM_DIGEST=${DIGEST}" >> "$GITHUB_ENV"
- name: Find attestation digest
run: |
set -e
DIGEST=$(crane manifest ghcr.io/${{github.repository_owner}}/policy-server@${{ needs.build.outputs.digest }} \
| jq '.manifests[] | select(.annotations["vnd.docker.reference.type"]=="attestation-manifest") | select(.annotations["vnd.docker.reference.digest"]=="${{ env.PLATFORM_DIGEST }}") | .digest'
)
echo "ATTESTATION_MANIFEST_DIGEST=${DIGEST}" >> "$GITHUB_ENV"
- name: Find provenance manifest digest
run: |
set -e
DIGEST=$(crane manifest ghcr.io/${{github.repository_owner}}/policy-server@${{ env.ATTESTATION_MANIFEST_DIGEST}} | \
jq '.layers[] | select(.annotations["in-toto.io/predicate-type"] == "https://slsa.dev/provenance/v0.2") | .digest')
echo "PROVENANCE_DIGEST=${DIGEST}" >> "$GITHUB_ENV"
- name: Find SBOM manifest layers digest
run: |
set -e
DIGEST=$(crane manifest ghcr.io/${{github.repository_owner}}/policy-server@${{ env.ATTESTATION_MANIFEST_DIGEST}} | \
jq '.layers | map(select(.annotations["in-toto.io/predicate-type"] == "https://spdx.dev/Document")) | map(.digest) | join(" ")')
echo "SBOM_DIGEST=${DIGEST}" >> "$GITHUB_ENV"
- name: Download provenance and SBOM files
run: |
set -e
crane blob ghcr.io/${{github.repository_owner}}/policy-server@${{ env.PROVENANCE_DIGEST}} > policy-server-attestation-${{ matrix.arch }}-provenance.json
sha256sum policy-server-attestation-${{ matrix.arch }}-provenance.json >> policy-server-attestation-${{ matrix.arch }}-checksum.txt
for sbom_digest in "${{ env.SBOM_DIGEST }}"; do
crane blob ghcr.io/${{github.repository_owner}}/policy-server@$sbom_digest > policy-server-attestation-${{ matrix.arch }}-sbom-${sbom_digest#"sha256:"}.json
sha256sum policy-server-attestation-${{ matrix.arch }}-sbom-${sbom_digest#"sha256:"}.json >> policy-server-attestation-${{ matrix.arch }}-checksum.txt
done
- name: Sign checksum file
run: |
cosign sign-blob --yes \
--bundle policy-server-attestation-${{ matrix.arch }}-checksum-cosign.bundle \
policy-server-attestation-${{ matrix.arch }}-checksum.txt
cosign verify-blob \
--bundle policy-server-attestation-${{ matrix.arch }}-checksum-cosign.bundle \
--certificate-oidc-issuer=https://token.actions.githubusercontent.com \
--certificate-identity="https://github.com/${{github.repository_owner}}/policy-server/.github/workflows/release.yml@${{ github.ref }}" \
policy-server-attestation-${{ matrix.arch }}-checksum.txt
- name: Upload SBOMs as artifacts
uses: actions/upload-artifact@6f51ac03b9356f520e9adb1b1b7802705f340c2b # v4.5.0
with:
name: attestation-${{ matrix.arch }}
path: policy-server-attestation-${{ matrix.arch }}*
release:
name: Create release
needs:
- ci
- build
- sbom
permissions:
contents: write
runs-on: ubuntu-latest
steps:
- name: Retrieve tag name
if: ${{ startsWith(github.ref, 'refs/tags/') }}
run: |
echo TAG_NAME=$(echo ${{ github.ref_name }}) >> $GITHUB_ENV
- name: Get latest release tag
id: get_last_release_tag
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
with:
script: |
let release = await github.rest.repos.getLatestRelease({
owner: context.repo.owner,
repo: context.repo.repo,
});
if (release.status === 200 ) {
core.setOutput('old_release_tag', release.data.tag_name)
return
}
core.setFailed("Cannot find latest release")
- name: Get release ID from the release created by release drafter
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
with:
script: |
let releases = await github.rest.repos.listReleases({
owner: context.repo.owner,
repo: context.repo.repo,
});
for (const release of releases.data) {
if (release.draft) {
core.info(release)
core.exportVariable('RELEASE_ID', release.id)
return
}
}
core.setFailed(`Draft release not found`)
- name: Checkout code for kubewarden-dashboard.json
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Download attestation artifact
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8
with:
pattern: attestation-*
path: ./
merge-multiple: true
- name: Display structure of downloaded files
run: ls -R
- name: Create tarball for the attestation files
run: |
for arch in "amd64" "arm64"; do
tar -czf attestation-$arch.tar.gz $(ls policy-server-attestation-$arch-*)
done
- name: Upload release assets
id: upload_release_assets
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
with:
script: |
let fs = require('fs');
let path = require('path');
let files = [
'attestation-amd64.tar.gz',
'attestation-arm64.tar.gz',
'kubewarden-dashboard.json']
const {RELEASE_ID} = process.env
for (const file of files) {
let file_data = fs.readFileSync(file);
let response = await github.rest.repos.uploadReleaseAsset({
owner: context.repo.owner,
repo: context.repo.repo,
release_id: `${RELEASE_ID}`,
name: path.basename(file),
data: file_data,
});
}
- name: Publish release
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
with:
script: |
const {RELEASE_ID} = process.env
const {TAG_NAME} = process.env
isPreRelease = ${{ contains(github.ref_name, '-alpha') || contains(github.ref_name, '-beta') || contains(github.ref_name, '-rc') }}
github.rest.repos.updateRelease({
owner: context.repo.owner,
repo: context.repo.repo,
release_id: `${RELEASE_ID}`,
draft: false,
tag_name: `${TAG_NAME}`,
name: `${TAG_NAME}`,
prerelease: isPreRelease,
make_latest: !isPreRelease
});
- name: Trigger chart update
uses: peter-evans/repository-dispatch@ff45666b9427631e3450c54a1bcbee4d9ff4d7c0 # v3.0.0
with:
token: ${{ secrets.WORKFLOW_PAT }}
repository: "${{github.repository_owner}}/helm-charts"
event-type: update-chart
client-payload: '{"version": "${{ github.ref_name }}", "oldVersion": "${{ steps.get_last_release_tag.outputs.old_release_tag }}", "repository": "${{ github.repository }}"}'