-
Notifications
You must be signed in to change notification settings - Fork 162
481 lines (421 loc) · 14.5 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
name: ci
on:
push:
branches:
- main
- release/**
- 0.7.x-ci-cherrypicks
tags:
- v[0-9]+.[0-9]+.[0-9]+-?**
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@v3
with:
fetch-depth: 0
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version-file: 'go.mod'
- name: Run tests
uses: ./.github/actions/run-tests
- name: Report coverage
uses: codecov/[email protected]
controller-image:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- 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"
builder: gcr.io/cf-build-service-public/ci/kpack-builder
additional_pack_args: '--env BP_GIT2GO_ENABLED="true" --env BP_GIT2GO_USE_LIBSSL="true"'
webhook-image:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- 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"
completion-image:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- 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"
build-init-image:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- 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"
builder: gcr.io/cf-build-service-public/ci/kpack-builder
additional_pack_args: '--env BP_GIT2GO_ENABLED="true" --env BP_GIT2GO_USE_LIBSSL="true"'
rebase-image:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- 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"
build-init-windows-image:
runs-on: windows-2019
steps:
- name: Checkout
uses: actions/checkout@v3
- 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 --env BP_MSYS2_COPY_FILES="c:\layers\samples_msys2\msys2\msys64\mingw64\bin\libgit2.dll;c:\layers\samples_msys2\msys2\msys64\mingw64\bin\zlib1.dll;c:\layers\samples_msys2\msys2\msys64\mingw64\bin\libssl-1_1-x64.dll;c:\layers\samples_msys2\msys2\msys64\mingw64\bin\libssh2-1.dll;c:\layers\samples_msys2\msys2\msys64\mingw64\bin\libcrypto-1_1-x64.dll;c:\layers\samples_msys2\msys2\msys64\mingw64\bin\libhttp_parser-2.dll"'
completion-windows-image:
runs-on: windows-2019
steps:
- name: Checkout
uses: actions/checkout@v3
- 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"
lifecycle-image:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- 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@v4
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@v3
with:
name: images
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-init-windows-image
- completion-windows-image
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version-file: 'go.mod'
- name: Setup carvel
uses: carvel-dev/setup-action@v1
with:
token: ${{ secrets.RELEASE_TOKEN }}
only: ytt, kapp
- name: Download artifacts
uses: actions/download-artifact@v3
with:
name: images
- name: Build release yaml
run: |
ytt -f config/ \
-v controller_image=$(cat controller) \
-v webhook_image=$(cat webhook) \
-v build_init_image=$(cat build-init) \
-v build_init_windows_image=$(cat build-init-windows) \
-v rebase_image=$(cat rebase) \
-v completion_image=$(cat completion) \
-v completion_windows_image=$(cat completion-windows) \
-v lifecycle_image=$(cat lifecycle) > prerelease.yaml
cat prerelease.yaml
- name: Upload Pre-Release
uses: actions/upload-artifact@v3
with:
name: prerelease
path: prerelease.yaml
e2e:
needs:
- generate-pre-release-yaml
- controller-image
- webhook-image
- completion-image
- rebase-image
- build-init-image
- build-init-windows-image
- completion-windows-image
- lifecycle-image
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version-file: 'go.mod'
- name: Setup crane
uses: imjasonh/[email protected]
- name: Setup carvel
uses: carvel-dev/setup-action@v1
with:
token: ${{ secrets.RELEASE_TOKEN }}
only: ytt, kapp
- name: Download release
uses: actions/download-artifact@v3
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
kapp deploy -a kpack -y -f prerelease.yaml
export IMAGE_REGISTRY=${{ env.REGISTRY_URL }}
export IMAGE_REGISTRY_USERNAME=${{ env.REGISTRY_USER }}
export IMAGE_REGISTRY_PASSWORD=${{ env.REGISTRY_PASS }}
make e2e
kapp delete -a kpack -y
release:
needs:
- unit
- e2e
- generate-pre-release-yaml
- controller-image
- webhook-image
- completion-image
- rebase-image
- build-init-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@v3
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version-file: 'go.mod'
- name: Setup crane
uses: imjasonh/[email protected]
- name: Setup carvel
uses: carvel-dev/setup-action@v1
with:
token: ${{ secrets.RELEASE_TOKEN }}
only: ytt
- name: Download artifacts
uses: actions/download-artifact@v3
- 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"
echo "${final_repo}@${digest}" > final-image-refs/$name
done
- name: Upload image refs
uses: actions/upload-artifact@v3
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 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 version=${{ env.KPACK_VERSION }} > $file
echo "sha=$(shasum -a 256 $file)" >> $GITHUB_OUTPUT
- name: Upload Release
uses: actions/upload-artifact@v3
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**: