-
Notifications
You must be signed in to change notification settings - Fork 341
444 lines (396 loc) · 16.8 KB
/
build.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
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
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
name: build
on:
push:
branches:
- master
- release-*
- v*
tags:
- v*
pull_request:
schedule:
- cron: "10 0,12 * * *"
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: ${{ github.ref != 'refs/heads/master' && !startsWith(github.ref, 'refs/heads/v') && !startsWith(github.ref, 'refs/tags/v') }}
jobs:
build-binaries:
name: Build binaries
runs-on: runs-on,runner=4cpu-linux-${{ matrix.arch }},hdd=50,run-id=${{ github.run_id }}
strategy:
matrix:
arch: [x64, arm64]
steps:
- name: Checkout code
uses: actions/checkout@v4
# Build binaries
- name: Run make ci
if: ${{ matrix.arch == 'x64' }}
run: make ci
- name: Run make arm
if: ${{ matrix.arch == 'arm64' }}
run: make arm
- name: Upload binaries
uses: actions/upload-artifact@v4
with:
name: binaries_${{ matrix.arch }}_artifact
path: ./bin/*
build-push-images:
name: Build and push images
runs-on: runs-on,runner=4cpu-linux-${{ matrix.arch }},run-id=${{ github.run_id }}
needs: build-binaries
if: ${{ startsWith(github.ref, 'refs/heads/') || startsWith(github.ref, 'refs/tags/') }}
strategy:
matrix:
arch: [x64, arm64]
permissions:
contents: read
id-token: write # for reading credential https://github.com/rancher-eio/read-vault-secrets
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Declare branch and sha_short
run: |
echo "sha_short=$(git rev-parse --short=8 "$GITHUB_SHA")" >> "$GITHUB_ENV"
echo "branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" >> "$GITHUB_ENV"
if [ "${{ matrix.arch }}" == "x64" ]; then
echo "arch=amd64" >> "$GITHUB_ENV"
else
echo "arch=arm64" >> "$GITHUB_ENV"
fi
- name: Download binaries
uses: actions/download-artifact@v4
with:
name: binaries_${{ matrix.arch }}_artifact
path: ./bin/
- name: Add executable permission
run: |
chmod +x ./bin/*
- name: Copy bin folder to package
run: |
cp -r ./bin/harvester ./package/
cp -r ./bin/harvester-webhook ./package/
cp -r ./bin/upgrade-helper ./package/upgrade/
- name: Read Secrets
uses: rancher-eio/read-vault-secrets@main
with:
secrets: |
secret/data/github/repo/${{ github.repository }}/dockerhub/rancher/credentials username | DOCKER_USERNAME ;
secret/data/github/repo/${{ github.repository }}/dockerhub/rancher/credentials password | DOCKER_PASSWORD ;
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ env.DOCKER_USERNAME }}
password: ${{ env.DOCKER_PASSWORD }}
# rancher/harvester image
- name: docker-publish-harvester
if: ${{ startsWith(github.ref, 'refs/heads/') }}
uses: docker/build-push-action@v5
with:
context: package/
push: true
platforms: linux/${{ env.arch }}
tags: rancher/harvester:${{ env.branch }}-head-${{ env.arch }}
file: package/Dockerfile
build-args: |
ARCH=${{ env.arch }}
VERSION=${{ env.branch }}-${{ env.sha_short }}-head
- name: docker-publish-harvester-with-tag
if: ${{ startsWith(github.ref, 'refs/tags/') }}
uses: docker/build-push-action@v5
with:
context: package/
push: true
platforms: linux/${{ env.arch }}
tags: rancher/harvester:${{ github.ref_name }}-${{ env.arch }}
file: package/Dockerfile
build-args: |
ARCH=${{ env.arch }}
VERSION=${{ github.ref_name }}
# rancher/harvester-webhook image
- name: docker-publish-harvester-webhook
if: ${{ startsWith(github.ref, 'refs/heads/') }}
uses: docker/build-push-action@v5
with:
context: package/
push: true
platforms: linux/${{ env.arch }}
tags: rancher/harvester-webhook:${{ env.branch }}-head-${{ env.arch }}
file: package/Dockerfile.webhook
build-args: |
ARCH=${{ env.arch }}
VERSION=${{ env.branch }}-${{ env.sha_short }}-head
- name: docker-publish-harvester-webhook-with-tag
if: ${{ startsWith(github.ref, 'refs/tags/') }}
uses: docker/build-push-action@v5
with:
context: package/
push: true
platforms: linux/${{ env.arch }}
tags: rancher/harvester-webhook:${{ github.ref_name }}-${{ env.arch }}
file: package/Dockerfile.webhook
build-args: |
ARCH=${{ env.arch }}
VERSION=${{ github.ref_name }}
- name: generate addon manifests
run: make generate-addons
# rancher/harvester-upgrade image
- name: docker-publish-harvester-upgrade
if: ${{ startsWith(github.ref, 'refs/heads/') }}
uses: docker/build-push-action@v5
with:
context: package/upgrade
push: true
platforms: linux/${{ env.arch }}
tags: rancher/harvester-upgrade:${{ env.branch }}-head-${{ env.arch }}
file: package/upgrade/Dockerfile
build-args: |
ARCH=${{ env.arch }}
VERSION=${{ env.branch }}-${{ env.sha_short }}-head
- name: docker-publish-harvester-upgrade-with-tag
if: ${{ startsWith(github.ref, 'refs/tags/') }}
uses: docker/build-push-action@v5
with:
context: package/upgrade
push: true
platforms: linux/${{ env.arch }}
tags: rancher/harvester-upgrade:${{ github.ref_name }}-${{ env.arch }}
file: package/upgrade/Dockerfile
build-args: |
ARCH=${{ env.arch }}
VERSION=${{ github.ref_name }}
manifest-images:
name: Manifest images
runs-on: runs-on,runner=4cpu-linux-x64,run-id=${{ github.run_id }}
needs: build-push-images
if: ${{ startsWith(github.ref, 'refs/heads/') || startsWith(github.ref, 'refs/tags/') }}
permissions:
contents: read
id-token: write # for reading credential https://github.com/rancher-eio/read-vault-secrets
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Declare branch
run: |
echo "branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" >> "$GITHUB_ENV"
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Read Secrets
uses: rancher-eio/read-vault-secrets@main
with:
secrets: |
secret/data/github/repo/${{ github.repository }}/dockerhub/rancher/credentials username | DOCKER_USERNAME ;
secret/data/github/repo/${{ github.repository }}/dockerhub/rancher/credentials password | DOCKER_PASSWORD ;
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ env.DOCKER_USERNAME }}
password: ${{ env.DOCKER_PASSWORD }}
# rancher/harvester image
- name: docker-pull-harvester
if: ${{ startsWith(github.ref, 'refs/heads/') }}
run: |
docker pull --platform linux/amd64 rancher/harvester:${{ env.branch }}-head-amd64
docker pull --platform linux/arm64 rancher/harvester:${{ env.branch }}-head-arm64
docker buildx imagetools create -t rancher/harvester:${{ env.branch }}-head \
rancher/harvester:${{ env.branch }}-head-amd64 \
rancher/harvester:${{ env.branch }}-head-arm64
- name: docker-pull-harvester-with-tag
if: ${{ startsWith(github.ref, 'refs/tags/') }}
run: |
docker pull --platform linux/amd64 rancher/harvester:${{ github.ref_name }}-amd64
docker pull --platform linux/arm64 rancher/harvester:${{ github.ref_name }}-arm64
docker buildx imagetools create -t rancher/harvester:${{ github.ref_name }} \
rancher/harvester:${{ github.ref_name }}-amd64 \
rancher/harvester:${{ github.ref_name }}-arm64
# rancher/harvester-webhook image
- name: docker-pull-harvester-webhook
if: ${{ startsWith(github.ref, 'refs/heads/') }}
run: |
docker pull --platform linux/amd64 rancher/harvester-webhook:${{ env.branch }}-head-amd64
docker pull --platform linux/arm64 rancher/harvester-webhook:${{ env.branch }}-head-arm64
docker buildx imagetools create -t rancher/harvester-webhook:${{ env.branch }}-head \
rancher/harvester-webhook:${{ env.branch }}-head-amd64 \
rancher/harvester-webhook:${{ env.branch }}-head-arm64
- name: docker-pull-harvester-webhook-with-tag
if: ${{ startsWith(github.ref, 'refs/tags/') }}
run: |
docker pull --platform linux/amd64 rancher/harvester-webhook:${{ github.ref_name }}-amd64
docker pull --platform linux/arm64 rancher/harvester-webhook:${{ github.ref_name }}-arm64
docker buildx imagetools create -t rancher/harvester-webhook:${{ github.ref_name }} \
rancher/harvester-webhook:${{ github.ref_name }}-amd64 \
rancher/harvester-webhook:${{ github.ref_name }}-arm64
# rancher/harvester-upgrade image
- name: docker-pull-harvester-upgrade
if: ${{ startsWith(github.ref, 'refs/heads/') }}
run: |
docker pull --platform linux/amd64 rancher/harvester-upgrade:${{ env.branch }}-head-amd64
docker pull --platform linux/arm64 rancher/harvester-upgrade:${{ env.branch }}-head-arm64
docker buildx imagetools create -t rancher/harvester-upgrade:${{ env.branch }}-head \
rancher/harvester-upgrade:${{ env.branch }}-head-amd64 \
rancher/harvester-upgrade:${{ env.branch }}-head-arm64
- name: docker-pull-harvester-upgrade-with-tag
if: ${{ startsWith(github.ref, 'refs/tags/') }}
run: |
docker pull --platform linux/amd64 rancher/harvester-upgrade:${{ github.ref_name }}-amd64
docker pull --platform linux/arm64 rancher/harvester-upgrade:${{ github.ref_name }}-arm64
docker buildx imagetools create -t rancher/harvester-upgrade:${{ github.ref_name }} \
rancher/harvester-upgrade:${{ github.ref_name }}-amd64 \
rancher/harvester-upgrade:${{ github.ref_name }}-arm64
build-iso:
name: Build ISO
runs-on: runs-on,runner=4cpu-linux-${{ matrix.arch }},hdd=50,run-id=${{ github.run_id }}
needs: manifest-images
if: ${{ startsWith(github.ref, 'refs/heads/') || startsWith(github.ref, 'refs/tags/') }}
strategy:
matrix:
arch: [x64, arm64]
permissions:
contents: write # for github prerelease action
id-token: write # for reading credential https://github.com/rancher-eio/read-vault-secrets
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Declare branch
run: |
echo "branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" >> "$GITHUB_ENV"
if [ "${{ matrix.arch }}" == "x64" ]; then
echo "arch=amd64" >> "$GITHUB_ENV"
else
echo "arch=arm64" >> "$GITHUB_ENV"
fi
- name: build-iso
if: ${{ startsWith(github.ref, 'refs/heads/') }}
run: |
make build-iso
env:
REPO: rancher
DRONE_BRANCH: ${{ env.branch }}
- name: build-tag-iso
if: ${{ startsWith(github.ref, 'refs/tags/') }}
run: |
make build-iso
env:
REPO: rancher
DRONE_BRANCH: ${{ github.ref_name }}
DRONE_TAG: ${{ github.ref_name }}
- name: Read Secrets
uses: rancher-eio/read-vault-secrets@main
with:
secrets: |
secret/data/github/repo/${{ github.repository }}/dockerhub/rancher/credentials username | DOCKER_USERNAME ;
secret/data/github/repo/${{ github.repository }}/dockerhub/rancher/credentials password | DOCKER_PASSWORD ;
secret/data/github/repo/${{ github.repository }}/google-auth/harvester/credentials token | GOOGLE_AUTH ;
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ env.DOCKER_USERNAME }}
password: ${{ env.DOCKER_PASSWORD }}
# rancher/harvester-cluster-repo image
- name: docker-publish-harvester-cluster-repo
if: ${{ startsWith(github.ref, 'refs/heads/') }}
uses: docker/build-push-action@v5
with:
context: dist/harvester-cluster-repo
push: true
platforms: linux/${{ env.arch }}
tags: rancher/harvester-cluster-repo:${{ env.branch }}-head-${{ env.arch }}
file: dist/harvester-cluster-repo/Dockerfile
- name: docker-publish-harvester-cluster-repo-with-tag
if: ${{ startsWith(github.ref, 'refs/tags/') }}
uses: docker/build-push-action@v5
with:
context: dist/harvester-cluster-repo
push: true
platforms: linux/${{ env.arch }}
tags: rancher/harvester-cluster-repo:${{ github.ref_name }}-${{ env.arch }}
file: dist/harvester-cluster-repo/Dockerfile
- name: Login to Google Cloud
uses: 'google-github-actions/auth@v2'
with:
credentials_json: '${{ env.GOOGLE_AUTH }}'
- name: upload-iso
uses: 'google-github-actions/upload-cloud-storage@v2'
if: ${{ startsWith(github.ref, 'refs/heads/') }}
with:
path: dist/artifacts
parent: false
destination: releases.rancher.com/harvester/${{ env.branch }}
predefinedAcl: publicRead
headers: |-
cache-control: public,no-cache,proxy-revalidate
- name: upload-iso-with-tag
uses: 'google-github-actions/upload-cloud-storage@v2'
if: ${{ startsWith(github.ref, 'refs/tags/') }}
with:
path: dist/artifacts
parent: false
destination: releases.rancher.com/harvester/${{ github.ref_name }}
predefinedAcl: publicRead
headers: |-
cache-control: public,no-cache,proxy-revalidate
- name: upload-kernel-initrd-releases
if: ${{ startsWith(github.ref, 'refs/tags/') }}
env:
GH_TOKEN: ${{ github.token }}
run: |
gh release create ${{ github.ref_name }} --draft --notes "Draft release for ${{ github.ref_name }}"
gh release upload ${{ github.ref_name }} dist/artifacts/harvester*initrd-${{ env.arch }}
gh release upload ${{ github.ref_name }} dist/artifacts/harvester*vmlinuz-${{ env.arch }}
gh release upload ${{ github.ref_name }} dist/artifacts/harvester*images-list-${{ env.arch }}.txt
manifest-cluster-repo-image:
name: Manifest harvester-cluster-repo image
runs-on: runs-on,runner=4cpu-linux-x64,run-id=${{ github.run_id }}
needs: build-iso
if: ${{ startsWith(github.ref, 'refs/heads/') || startsWith(github.ref, 'refs/tags/') }}
permissions:
contents: read
id-token: write # for reading credential https://github.com/rancher-eio/read-vault-secrets
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Declare branch
run: |
echo "branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" >> "$GITHUB_ENV"
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Read Secrets
uses: rancher-eio/read-vault-secrets@main
with:
secrets: |
secret/data/github/repo/${{ github.repository }}/dockerhub/rancher/credentials username | DOCKER_USERNAME ;
secret/data/github/repo/${{ github.repository }}/dockerhub/rancher/credentials password | DOCKER_PASSWORD ;
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ env.DOCKER_USERNAME }}
password: ${{ env.DOCKER_PASSWORD }}
# rancher/harvester-cluster-repo image
- name: docker-pull-harvester-cluster-repo
if: ${{ startsWith(github.ref, 'refs/heads/') }}
run: |
docker pull --platform linux/amd64 rancher/harvester-cluster-repo:${{ env.branch }}-head-amd64
docker pull --platform linux/arm64 rancher/harvester-cluster-repo:${{ env.branch }}-head-arm64
docker buildx imagetools create -t rancher/harvester-cluster-repo:${{ env.branch }}-head \
rancher/harvester-cluster-repo:${{ env.branch }}-head-amd64 \
rancher/harvester-cluster-repo:${{ env.branch }}-head-arm64
- name: docker-pull-harvester-cluster-repo-with-tag
if: ${{ startsWith(github.ref, 'refs/tags/') }}
run: |
docker pull --platform linux/amd64 rancher/harvester-cluster-repo:${{ github.ref_name }}-amd64
docker pull --platform linux/arm64 rancher/harvester-cluster-repo:${{ github.ref_name }}-arm64
docker buildx imagetools create -t rancher/harvester-cluster-repo:${{ github.ref_name }} \
rancher/harvester-cluster-repo:${{ github.ref_name }}-amd64 \
rancher/harvester-cluster-repo:${{ github.ref_name }}-arm64