-
Notifications
You must be signed in to change notification settings - Fork 0
580 lines (511 loc) · 17.6 KB
/
ci.yaml
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
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
name: ci
on:
push:
branches:
- main
- release/**
tags:
- v[0-9]+.[0-9]+.[0-9]+-?**
pull_request:
branches:
- release/**
defaults:
run:
shell: bash
env:
PUBLIC_IMAGE_DEV_REPO: ${{ vars.PUBLIC_IMAGE_DEV_REPO }}
PUBLIC_IMAGE_REPO: ${{ vars.PUBLIC_IMAGE_REPO }}
PACK_VERSION: ${{ vars.PACK_VERSION }}
jobs:
unit:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'
- name: Run tests
run: make unit-ci
- name: Report coverage
uses: codecov/[email protected]
controller-image:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Docker Login
uses: docker/[email protected]
with:
registry: ${{ secrets.REGISTRY_HOST }}
username: ${{ secrets.REGISTRY_USER }}
password: ${{ secrets.REGISTRY_PASSWORD }}
- name: Build
uses: ./.github/actions/pack-build
with:
pack_version: ${{ env.PACK_VERSION }}
tag: ${{ env.PUBLIC_IMAGE_DEV_REPO }}/controller
bp_go_targets: "./cmd/controller"
artifact_name: controller-image
webhook-image:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Docker Login
uses: docker/[email protected]
with:
registry: ${{ secrets.REGISTRY_HOST }}
username: ${{ secrets.REGISTRY_USER }}
password: ${{ secrets.REGISTRY_PASSWORD }}
- name: Build
uses: ./.github/actions/pack-build
with:
pack_version: ${{ env.PACK_VERSION }}
tag: ${{ env.PUBLIC_IMAGE_DEV_REPO }}/webhook
bp_go_targets: "./cmd/webhook"
artifact_name: webhook-image
completion-image:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Docker Login
uses: docker/[email protected]
with:
registry: ${{ secrets.REGISTRY_HOST }}
username: ${{ secrets.REGISTRY_USER }}
password: ${{ secrets.REGISTRY_PASSWORD }}
- name: Build
uses: ./.github/actions/pack-build
with:
pack_version: ${{ env.PACK_VERSION }}
tag: ${{ env.PUBLIC_IMAGE_DEV_REPO }}/completion
bp_go_targets: "./cmd/completion"
artifact_name: completion-image
build-init-image:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Docker Login
uses: docker/[email protected]
with:
registry: ${{ secrets.REGISTRY_HOST }}
username: ${{ secrets.REGISTRY_USER }}
password: ${{ secrets.REGISTRY_PASSWORD }}
- name: Build
uses: ./.github/actions/pack-build
with:
pack_version: ${{ env.PACK_VERSION }}
tag: ${{ env.PUBLIC_IMAGE_DEV_REPO }}/build-init
bp_go_targets: "./cmd/build-init"
artifact_name: build-init-image
build-waiter-image:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Docker Login
uses: docker/[email protected]
with:
registry: ${{ secrets.REGISTRY_HOST }}
username: ${{ secrets.REGISTRY_USER }}
password: ${{ secrets.REGISTRY_PASSWORD }}
- name: Build
uses: ./.github/actions/pack-build
with:
pack_version: ${{ env.PACK_VERSION }}
tag: ${{ env.PUBLIC_IMAGE_DEV_REPO }}/build-waiter
bp_go_targets: "./cmd/build-waiter"
artifact_name: build-waiter-image
rebase-image:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Docker Login
uses: docker/[email protected]
with:
registry: ${{ secrets.REGISTRY_HOST }}
username: ${{ secrets.REGISTRY_USER }}
password: ${{ secrets.REGISTRY_PASSWORD }}
- name: Build
uses: ./.github/actions/pack-build
with:
pack_version: ${{ env.PACK_VERSION }}
tag: ${{ env.PUBLIC_IMAGE_DEV_REPO }}/rebase
bp_go_targets: "./cmd/rebase"
artifact_name: rebase-image
build-init-windows-image:
runs-on: windows-2019
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Docker Login
uses: docker/[email protected]
with:
registry: ${{ secrets.REGISTRY_HOST }}
username: ${{ secrets.REGISTRY_USER }}
password: ${{ secrets.REGISTRY_PASSWORD }}
- name: Build
uses: ./.github/actions/pack-build
with:
pack_version: ${{ env.PACK_VERSION }}
tag: ${{ env.PUBLIC_IMAGE_DEV_REPO }}/build-init-windows
bp_go_targets: '.\cmd\build-init;.\cmd\network-wait-launcher'
builder: gcr.io/cf-build-service-public/kpack-windows-builder
additional_pack_args: "--trust-builder"
artifact_name: build-init-windows-image
completion-windows-image:
runs-on: windows-2019
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Docker Login
uses: docker/[email protected]
with:
registry: ${{ secrets.REGISTRY_HOST }}
username: ${{ secrets.REGISTRY_USER }}
password: ${{ secrets.REGISTRY_PASSWORD }}
- name: Build
uses: ./.github/actions/pack-build
with:
pack_version: ${{ env.PACK_VERSION }}
tag: ${{ env.PUBLIC_IMAGE_DEV_REPO }}/completion-windows
bp_go_targets: '.\cmd\completion'
builder: gcr.io/cf-build-service-public/kpack-windows-builder
additional_pack_args: "--trust-builder"
artifact_name: completion-windows-image
lifecycle-image:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Docker Login
uses: docker/[email protected]
with:
registry: ${{ secrets.REGISTRY_HOST }}
username: ${{ secrets.REGISTRY_USER }}
password: ${{ secrets.REGISTRY_PASSWORD }}
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'
- name: Build
run: |
trap 'echo -e "$output"' EXIT
output=$(go run ./hack/lifecycle/main.go --tag=${{ env.PUBLIC_IMAGE_DEV_REPO }}/lifecycle 2>&1)
image=$(echo "$output" | grep "saved lifecycle" | awk -F "saved lifecycle image: " '{print $2}')
mkdir images
echo $image > images/lifecycle
- name: Upload Image Artifacts
uses: actions/upload-artifact@v4
with:
name: lifecycle-image
path: images/
generate-pre-release-yaml:
runs-on: ubuntu-latest
needs:
- lifecycle-image
- controller-image
- webhook-image
- completion-image
- rebase-image
- build-init-image
- build-waiter-image
- build-init-windows-image
- completion-windows-image
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'
- name: Setup carvel
uses: carvel-dev/setup-action@v2
with:
token: ${{ secrets.RELEASE_TOKEN }}
only: ytt, kapp
- name: Download artifacts
uses: actions/download-artifact@v4
with:
pattern: '*-image'
path: images
merge-multiple: true
- name: Build release yaml
run: |
ytt -f config/ \
-v controller.image=$(cat images/controller) \
-v webhook.image=$(cat images/webhook) \
-v build_init.image=$(cat images/build-init) \
-v build_init_windows.image=$(cat images/build-init-windows) \
-v build_waiter.image=$(cat images/build-waiter) \
-v rebase.image=$(cat images/rebase) \
-v completion.image=$(cat images/completion) \
-v completion_windows.image=$(cat images/completion-windows) \
-v lifecycle.image=$(cat images/lifecycle) > prerelease.yaml
cat prerelease.yaml
- name: Upload Pre-Release
uses: actions/upload-artifact@v4
with:
name: prerelease
path: prerelease.yaml
e2e:
needs:
- generate-pre-release-yaml
- controller-image
- webhook-image
- completion-image
- rebase-image
- build-init-image
- build-waiter-image
- build-init-windows-image
- completion-windows-image
- lifecycle-image
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'
- name: Setup crane
uses: imjasonh/[email protected]
- name: Setup carvel
uses: carvel-dev/setup-action@v2
with:
token: ${{ secrets.RELEASE_TOKEN }}
only: ytt, kapp
- name: Download release
uses: actions/download-artifact@v4
with:
name: prerelease
- name: Setup local registry
run: |
user="test"
pass="test"
echo "Generating users"
htpasswd -Bbn "$user" "$pass" >> htpasswd # authenticated user for tests
# the registry can be accessed from inside the kind cluster via it's name.
# however, due to a quirk with ggcr, it will force https connections UNLESS
# it fits certain patterns (https://github.com/google/go-containerregistry/blob/b8d1c0a1df12a3b3dd3e7f98330780fdc015ce40/pkg/name/registry.go#L75)
# so in order to avoid setting tls for the registry, we can name it something.local
# to trick ggcr into using the http scheme
name="registry.local"
echo "Starting registry"
if [ "$(docker inspect -f '{{.State.Running}}' "${reg_name}" 2>/dev/null || true)" != 'true' ]; then
docker run --detach \
--name "$name" \
-v "$(pwd)/htpasswd:/auth/htpasswd" \
-e "REGISTRY_AUTH=htpasswd" \
-e "REGISTRY_AUTH_HTPASSWD_REALM=Registry Realm" \
-e "REGISTRY_AUTH_HTPASSWD_PATH=/auth/htpasswd" \
-e "REGISTRY_STORAGE_DELETE_ENABLED=true" \
--publish "5000:5000" \
registry:2
fi
echo "REGISTRY_URL=$name:5000" >> $GITHUB_ENV
echo "REGISTRY_USER=$user" >> $GITHUB_ENV
echo "REGISTRY_PASS=$pass" >> $GITHUB_ENV
# alias registry.local to localhost
# ip=$(docker container inspect $name --format '{{ .NetworkSettings.Networks.kind.IPAddress }}')
ip=127.0.0.1
echo "$ip registry.local" | sudo tee -a /etc/hosts
cat <<EOF > kind.yaml
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
containerdConfigPatches:
- |-
[plugins."io.containerd.grpc.v1.cri".registry.mirrors."registry.local:5000"]
endpoint = ["http://registry.local:5000"]
EOF
- name: Create Kind Cluster
uses: helm/[email protected]
with:
cluster_name: e2e
config: kind.yaml
- name: Docker Login
uses: docker/[email protected]
with:
registry: ${{ env.REGISTRY_URL }}
username: ${{ env.REGISTRY_USER }}
password: ${{ env.REGISTRY_PASS }}
- name: Run tests
run: |
# make the registry container accessible by name from inside the cluster
docker network connect kind registry.local
cat <<EOF > overlay.yaml
#@ load("@ytt:overlay", "overlay")
#@overlay/match by=overlay.subset({"metadata":{"name":"kpack-controller"}, "kind": "Deployment"})
---
spec:
template:
spec:
containers:
#@overlay/match by="name"
- name: controller
#@overlay/match-child-defaults missing_ok=True
env:
#@overlay/match by="name"
#@overlay/replace or_add=True
- name: EXPERIMENTAL_GENERATE_SLSA_ATTESTATION
value: "true"
EOF
ytt -f prerelease.yaml -f overlay.yaml | kapp deploy -a kpack -y -f-
export IMAGE_REGISTRY=${{ env.REGISTRY_URL }}
export IMAGE_REGISTRY_USERNAME=${{ env.REGISTRY_USER }}
export IMAGE_REGISTRY_PASSWORD=${{ env.REGISTRY_PASS }}
export GIT_PRIVATE_REPO=${{ vars.E2E_PRIVATE_REPO }}
export GIT_BASIC_USERNAME="${{ secrets.E2E_PRIVATE_REPO_USERNAME }}"
export GIT_BASIC_PASSWORD="${{ secrets.E2E_PRIVATE_REPO_PASSWORD }}"
export GIT_SSH_PRIVATE_KEY="${{ secrets.E2E_PRIVATE_REPO_PRIVATE_KEY }}"
E2E_SLSA="true" make e2e
kapp delete -a kpack -y
- name: Run tests with Istio
run: |
helm repo add istio https://istio-release.storage.googleapis.com/charts
helm repo update
kubectl create namespace istio-system
helm install istio-base istio/base -n istio-system --wait
helm install istiod istio/istiod -n istio-system --wait
cat <<EOF > overlay.yaml
#@ load("@ytt:overlay", "overlay")
#@overlay/match by=overlay.subset({"metadata":{"name":"kpack-controller"}, "kind": "Deployment"})
---
spec:
template:
spec:
containers:
#@overlay/match by="name"
- name: controller
#@overlay/match-child-defaults missing_ok=True
env:
#@overlay/match by="name"
#@overlay/replace or_add=True
- name: INJECTED_SIDECAR_SUPPORT
value: "true"
EOF
ytt -f prerelease.yaml -f overlay.yaml | kapp deploy -a kpack -y -f-
export IMAGE_REGISTRY=${{ env.REGISTRY_URL }}
export IMAGE_REGISTRY_USERNAME=${{ env.REGISTRY_USER }}
export IMAGE_REGISTRY_PASSWORD=${{ env.REGISTRY_PASS }}
export KPACK_TEST_NAMESPACE_LABELS="istio-injection=enabled"
export GIT_PRIVATE_REPO=${{ vars.E2E_PRIVATE_REPO }}
export GIT_BASIC_USERNAME="${{ secrets.E2E_PRIVATE_REPO_USERNAME }}"
export GIT_BASIC_PASSWORD="${{ secrets.E2E_PRIVATE_REPO_PASSWORD }}"
export GIT_SSH_PRIVATE_KEY="${{ secrets.E2E_PRIVATE_REPO_PRIVATE_KEY }}"
make e2e
release:
needs:
- unit
- e2e
- generate-pre-release-yaml
- controller-image
- webhook-image
- completion-image
- rebase-image
- build-init-image
- build-waiter-image
- build-init-windows-image
- completion-windows-image
- lifecycle-image
if: ${{ startsWith(github.ref, 'refs/tags/v') }}
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'
- name: Setup crane
uses: imjasonh/[email protected]
- name: Setup carvel
uses: carvel-dev/setup-action@v2
with:
token: ${{ secrets.RELEASE_TOKEN }}
only: ytt
- name: Download artifacts
uses: actions/download-artifact@v4
with:
pattern: '*-image'
path: images
merge-multiple: true
- name: Docker Login
uses: docker/[email protected]
with:
registry: ${{ secrets.REGISTRY_HOST }}
username: ${{ secrets.REGISTRY_USER }}
password: ${{ secrets.REGISTRY_PASSWORD }}
- name: Parse tag name
run: |
echo "GITHUB_REF=${GITHUB_REF}"
[[ $GITHUB_REF =~ ^refs\/tags\/v(.*)$ ]] && version=${BASH_REMATCH[1]}
if [[ -z "${version}" ]]; then
echo "ERROR: kpack version not detected."
exit 1
fi
echo "KPACK_VERSION=${version}" >> $GITHUB_ENV
- name: Promote images
run: |
mkdir final-image-refs
for image in images/*; do
dev_image=$(cat $image)
digest=$(echo $dev_image| cut -d "@" -f 2)
name=$(basename $image)
final_repo="${{ env.PUBLIC_IMAGE_REPO }}/${name}"
crane copy "$dev_image" "$final_repo"
crane tag "${final_repo}@${digest}" ${{ env.KPACK_VERSION }}
echo "${final_repo}@${digest}" > final-image-refs/$name
done
- name: Upload image refs
uses: actions/upload-artifact@v4
with:
name: final-image-refs
path: final-image-refs/*
- name: Generate release yaml
id: release_yaml
run: |
file="release-${{ env.KPACK_VERSION }}.yaml"
ytt -f config/ \
-v controller.image=$(cat final-image-refs/controller) \
-v webhook.image=$(cat final-image-refs/webhook) \
-v build_init.image=$(cat final-image-refs/build-init) \
-v build_init_windows.image=$(cat final-image-refs/build-init-windows) \
-v build_waiter.image=$(cat final-image-refs/build-waiter) \
-v rebase.image=$(cat final-image-refs/rebase) \
-v completion.image=$(cat final-image-refs/completion) \
-v completion_windows.image=$(cat final-image-refs/completion-windows) \
-v lifecycle.image=$(cat final-image-refs/lifecycle) \
-v kpack_version=${{ env.KPACK_VERSION }} > $file
echo "sha=$(shasum -a 256 $file)" >> $GITHUB_OUTPUT
- name: Upload Release
uses: actions/upload-artifact@v4
with:
name: release
path: release-${{ env.KPACK_VERSION }}.yaml
- name: Create Draft Release
uses: softprops/action-gh-release@v1
with:
name: kpack v${{ env.KPACK_VERSION }}
tag_name: v${{ env.KPACK_VERSION }}
target_commitish: ${{ github.sha }}
token: ${{ secrets.RELEASE_TOKEN }}
draft: true
prerelease: true
files: release-*.yaml
body: |
## What's Changed
## Bug Fixes
## Bumped Dependencies
sha256 checksum:
```
${{ steps.release_yaml.outputs.sha }}
```
**Full Changelog**: