261 lines (248 loc) · 8.15 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
# reusable workflow
name: .release
on:
workflow_call:
inputs:
name:
required: true
type: string
envs:
required: false
type: string
release:
required: false
type: boolean
env:
REPO_SLUG: dockereng/packaging
BUILD_CACHE_REGISTRY_SLUG: dockereng/packaging-cache
jobs:
prepare:
runs-on: ubuntu-20.04
outputs:
pkgs: ${{ steps.set.outputs.pkgs }}
steps:
-
name: Checkout
uses: actions/checkout@v4
-
name: Set outputs
id: set
run: |
pkgs=$(make gha-matrix GHA_MATRIX=all)
echo "pkgs=$pkgs" >> $GITHUB_OUTPUT
-
name: Show outputs
run: |
echo pkgs=${{ steps.set.outputs.pkgs }}
build:
runs-on: ubuntu-20.04
needs:
- prepare
strategy:
fail-fast: true
matrix:
pkg: ${{ fromJson(needs.prepare.outputs.pkgs) }}
steps:
-
name: Checkout
uses: actions/checkout@v4
-
name: Environment variables
run: |
for l in "${{ inputs.envs }}"; do
echo "${l?}" >> $GITHUB_ENV
done
-
name: Set up QEMU
uses: docker/setup-qemu-action@v3
-
name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v3
with:
version: latest
-
name: Set up remote builders
if: matrix.pkg != 'static' # do not use remote builders for static builds (cross)
uses: docker/setup-buildx-action@v3
with:
version: latest
driver: remote
endpoint: docker-container://buildx_buildkit_${{ steps.buildx.outputs.name }}0
append: |
- name: aws_graviton2
endpoint: tcp://${{ secrets.AWS_ARM64_HOST }}:1234
platforms: darwin/arm64,linux/arm64,linux/arm/v5,linux/arm/v6,linux/arm/v7,windows/arm64
# - name: linuxone_s390x
# endpoint: tcp://${{ secrets.LINUXONE_S390X_HOST }}:1234
# platforms: linux/s390x
env:
BUILDER_NODE_1_AUTH_TLS_CACERT: ${{ secrets.AWS_ARM64_CACERT }}
BUILDER_NODE_1_AUTH_TLS_CERT: ${{ secrets.AWS_ARM64_CERT }}
BUILDER_NODE_1_AUTH_TLS_KEY: ${{ secrets.AWS_ARM64_KEY }}
# BUILDER_NODE_2_AUTH_TLS_CACERT: ${{ secrets.LINUXONE_S390X_CACERT }}
# BUILDER_NODE_2_AUTH_TLS_CERT: ${{ secrets.LINUXONE_S390X_CERT }}
# BUILDER_NODE_2_AUTH_TLS_KEY: ${{ secrets.LINUXONE_S390X_KEY }}
-
name: Build
run: |
make -C pkg/${{ inputs.name }} run-pkg-${{ matrix.pkg }}
-
name: List artifacts
run: |
tree -nh ./pkg/${{ inputs.name }}/bin
-
name: Verify
run: |
make -C pkg/${{ inputs.name }} run-verify-${{ matrix.pkg }}
-
name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: release-pkg-${{ inputs.name }}-${{ matrix.pkg }}
path: ./pkg/${{ inputs.name }}/bin/*
if-no-files-found: ignore
retention-days: 1
release:
runs-on: ubuntu-20.04
needs:
- build
steps:
-
name: Checkout
uses: actions/checkout@v4
-
name: Environment variables
run: |
for l in "${{ inputs.envs }}"; do
echo "${l?}" >> $GITHUB_ENV
done
-
name: Download artifacts
uses: actions/download-artifact@v4
with:
path: ./pkg/${{ inputs.name }}/bin
pattern: release-pkg-*
merge-multiple: true
-
name: Resolve metadata
run: |
make -C pkg/${{ inputs.name }} metadata
for l in $(cat ./pkg/${{ inputs.name }}/bin/metadata.env); do
export "${l?}"
echo "${l?}" >> $GITHUB_ENV
done
if [ "${{ github.event_name }}" = "schedule" ]; then
echo "GIT_TAG=nightly/${{ inputs.name }}/$VERSION" >> $GITHUB_ENV
else
echo "GIT_TAG=${{ inputs.name }}/$VERSION" >> $GITHUB_ENV
fi
-
name: List artifacts
run: |
tree -nh ./pkg/${{ inputs.name }}/bin | tee /tmp/packages.txt
-
name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: |
${{ env.REPO_SLUG }}
tags: |
type=ref,event=pr
type=raw,value=${{ env.GIT_TAG }}
type=raw,value=${{ env.GIT_TAG }}-${{ github.run_number }}
labels: |
com.github.docker.packaging.event_name=${{ github.event_name }}
com.github.docker.packaging.run_id=${{ github.run_id }}
com.github.docker.packaging.run_number=${{ github.run_number }}
bake-target: meta-helper
-
name: Login to Docker Hub
uses: docker/login-action@v3
if: ${{ inputs.release || github.event_name == 'schedule' }}
with:
username: ${{ secrets.DOCKERPUBLICBOT_USERNAME }}
password: ${{ secrets.DOCKERPUBLICBOT_WRITE_PAT }}
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
version: latest
-
name: Build image
id: build
uses: docker/bake-action@v4
with:
workdir: ./pkg/${{ inputs.name }}
files: |
./docker-bake.hcl
${{ steps.meta.outputs.bake-file }}
targets: release
provenance: false
set: |
*.output=type=image,push=${{ inputs.release || github.event_name == 'schedule' }}
-
name: Prepare release
run: |
cat > "/tmp/release-metadata.json" <<-EOF
${{ steps.build.outputs.metadata }}
EOF
for tag in $(jq -r '.tags[]' <<< "$DOCKER_METADATA_OUTPUT_JSON"); do
echo "* \`${tag}\`" >> /tmp/tags.txt
done
cat > "/tmp/summary.txt" <<-EOF
* repo: ${REPO}
* ref: \`${REF}\`
* version: \`${VERSION}\`
* commit: [\`${COMMIT}\`](${REPO}/commit/${COMMIT})
EOF
if [ "${{ inputs.name }}" = "containerd" ]; then
cat >> "/tmp/summary.txt" <<-EOF
* runc
* repo: ${RUNC_REPO}
* ref: \`${RUNC_REF}\`
* version: \`${RUNC_VERSION}\`
* commit: [\`${RUNC_COMMIT}\`](${RUNC_REPO}/commit/${RUNC_COMMIT})
EOF
fi
cat >> "/tmp/summary.txt" <<-EOF
* packages: \`$(find ./pkg/${{ inputs.name }}/bin -type f | wc -l)\` files
* size: \`$(du -sh ./pkg/${{ inputs.name }}/bin | awk '{print $1}')\`
EOF
cat /tmp/summary.txt >> $GITHUB_STEP_SUMMARY
-
name: Set outputs
uses: actions/github-script@v7
id: release-metadata
with:
script: |
const fs = require('fs');
core.setOutput('tags', fs.readFileSync('/tmp/tags.txt', {encoding: 'utf8'}));
core.setOutput('summary', fs.readFileSync('/tmp/summary.txt', {encoding: 'utf8'}));
-
name: Create release
uses: crazy-max/ghaction-github-release@v2
if: ${{ inputs.release }}
with:
name: ${{ env.GIT_TAG }}-${{ github.run_number }}
draft: true
tag_name: ${{ env.GIT_TAG }}-${{ github.run_number }}
target_commitish: ${{ github.sha }}
files: |
/tmp/packages.txt
./pkg/${{ inputs.name }}/bin/metadata.env
/tmp/release-metadata.json
body: |
Image available at [https://hub.docker.com/r/${{ env.REPO_SLUG }}](https://hub.docker.com/r/${{ env.REPO_SLUG }}).
## Tags
${{ steps.release-metadata.outputs.tags }}
## Summary
${{ steps.release-metadata.outputs.summary }}
## Usage
Extract with [Undock](https://github.com/crazy-max/undock):
```console
$ undock --wrap --rm-dist --all ${{ env.REPO_SLUG }}:${{ steps.meta.outputs.version }} ./${{ inputs.name }}/${{ env.VERSION }}
```
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}