-
Notifications
You must be signed in to change notification settings - Fork 8
853 lines (779 loc) · 35.3 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
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
name: CI
on:
push:
branches:
- 'main'
- '!dependabot/**'
tags:
# semver tags
- 'v[0-9]+\.[0-9]+\.[0-9]+-?**'
pull_request: {}
jobs:
unit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: "go.mod"
- name: Test
run: make test
- uses: codecov/codecov-action@v4
- name: Build
run: |
set -o errexit
set -o nounset
set -o pipefail
make dist
git diff --exit-code dist
stage:
runs-on: ubuntu-latest
env:
REGISTRY_NAME: registry.local
KO_DOCKER_REPO: registry.local/conventions
BUNDLE: registry.local/conventions/bundle
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: "go.mod"
- uses: carvel-dev/setup-action@v2
with:
token: ${{ secrets.GITHUB_TOKEN }}
- uses: ko-build/[email protected]
- name: Generate certs
run: |
set -o errexit
set -o nounset
set -o pipefail
CERT_DIR=$(mktemp -d -t certs.XXXX)
echo "CERT_DIR=$CERT_DIR" >> $GITHUB_ENV
echo "##[group]Install cfssl"
curl -L https://github.com/cloudflare/cfssl/releases/download/v1.6.1/cfssl_1.6.1_linux_amd64 -o cfssl
curl -L https://github.com/cloudflare/cfssl/releases/download/v1.6.1/cfssljson_1.6.1_linux_amd64 -o cfssljson
chmod +x cfssl*
sudo mv cfssl* /usr/local/bin
echo "##[endgroup]"
echo "##[group]Generate CA"
cfssl gencert -initca .github/tls/root-csr.json \
| cfssljson -bare ${CERT_DIR}/root-ca
cfssl gencert -ca ${CERT_DIR}/root-ca.pem -ca-key ${CERT_DIR}/root-ca-key.pem \
-config=".github/tls/config.json" \
-profile="intermediate" .github/tls/intermediate-csr.json \
| cfssljson -bare ${CERT_DIR}/signing-ca
cat ${CERT_DIR}/signing-ca.pem ${CERT_DIR}/root-ca.pem > ${CERT_DIR}/ca.pem
echo "##[endgroup]"
echo "##[group]Install CA"
# https://ubuntu.com/server/docs/security-trust-store
sudo apt-get install -y ca-certificates
sudo cp ${CERT_DIR}/ca.pem /usr/local/share/ca-certificates/ca.crt
sudo update-ca-certificates
echo "##[endgroup]"
echo "##[group]Generate cert"
cfssl gencert -ca ${CERT_DIR}/signing-ca.pem -ca-key ${CERT_DIR}/signing-ca-key.pem \
-config=".github/tls/config.json" \
-profile="server" \
-hostname="${REGISTRY_NAME},local-registry" \
.github/tls/server-csr.json \
| cfssljson -bare ${CERT_DIR}/server
echo "##[endgroup]"
- name: Setup local registry
run: |
set -o errexit
set -o nounset
set -o pipefail
# Run a registry.
docker run -d \
--restart=always \
--name local-registry \
-v ${CERT_DIR}:/certs \
-e REGISTRY_HTTP_ADDR=0.0.0.0:443 \
-e REGISTRY_HTTP_TLS_CERTIFICATE=/certs/server.pem \
-e REGISTRY_HTTP_TLS_KEY=/certs/server-key.pem \
-p "443:443" \
registry:2
# Make the $REGISTRY_NAME -> local-registry
echo "$(hostname -I | cut -d' ' -f1) $REGISTRY_NAME" | sudo tee -a /etc/hosts
- name: Build Cartographer Conventions
run: |
set -o errexit
set -o nounset
set -o pipefail
scratch=$(mktemp -d -t bundle.XXXX)
mkdir -p "${scratch}/.imgpkg"
mkdir -p "${scratch}/config"
cp LICENSE "${scratch}/LICENSE"
cp CHANGELOG.md "${scratch}/CHANGELOG.md"
cp dist/bundle.yaml "${scratch}/bundle.yaml"
cp dist/bundle.values.yaml "${scratch}/bundle.values.yaml"
cp dist/ca-overlay.yaml "${scratch}/ca-overlay.yaml"
echo "##[group]Build"
cat hack/boilerplate.ytt.txt > "${scratch}/config/cartographer-conventions.yaml"
ko resolve -f dist/cartographer-conventions.yaml >> "${scratch}/config/cartographer-conventions.yaml"
kbld -f "${scratch}/config/cartographer-conventions.yaml" --imgpkg-lock-output "${scratch}/.imgpkg/images.yml" > /dev/null
echo "##[endgroup]"
echo "##[group]Create bundle"
imgpkg push -f "${scratch}" -b "${BUNDLE}/controller"
imgpkg copy -b "${BUNDLE}/controller" --to-tar cartographer-conventions-bundle.tar
echo "##[endgroup]"
- name: Build samples
run: |
set -o errexit
set -o nounset
set -o pipefail
scratch=$(mktemp -d -t bundle.XXXX)
mkdir "${scratch}/.imgpkg"
cp LICENSE "${scratch}/LICENSE"
echo "##[group]Build"
mkdir -p ${scratch}/convention-server
cp samples/convention-server/*.{md,yaml} ${scratch}/convention-server/
pushd samples/convention-server
ko resolve -f server.yaml > "${scratch}/convention-server/server.yaml"
popd
mkdir -p ${scratch}/dumper-server
cp samples/dumper-server/*.{md,yaml} ${scratch}/dumper-server/
pushd samples/dumper-server
ko resolve -f server.yaml > "${scratch}/dumper-server/server.yaml"
popd
mkdir -p ${scratch}/spring-convention-server
cp samples/spring-convention-server/*.{md,yaml} ${scratch}/spring-convention-server/
pushd samples/spring-convention-server
ko resolve -f server.yaml > "${scratch}/spring-convention-server/server.yaml"
popd
kbld --imgpkg-lock-output "${scratch}/.imgpkg/images.yml" \
-f "${scratch}/convention-server/server.yaml" \
-f "${scratch}/dumper-server/server.yaml" \
-f "${scratch}/spring-convention-server/server.yaml" \
> /dev/null
echo "##[endgroup]"
echo "##[group]Create sample bundle"
imgpkg push -f "${scratch}" -b "${BUNDLE}/samples"
imgpkg copy -b "${BUNDLE}/samples" --to-tar cartographer-conventions-samples-bundle.tar
echo "##[endgroup]"
- uses: actions/upload-artifact@v4
with:
name: cartographer-conventions-bundle.tar
path: cartographer-conventions-bundle.tar
retention-days: 1
- uses: actions/upload-artifact@v4
with:
name: cartographer-conventions-samples-bundle.tar
path: cartographer-conventions-samples-bundle.tar
retention-days: 1
acceptance:
needs: stage
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
k8s:
- 1.25.11
- 1.26.6
- 1.27.3
- 1.28.0
- 1.29.0
- 1.30.0
env:
REGISTRY_NAME: registry.local
BUNDLE: registry.local/conventions/bundle
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: "go.mod"
- uses: carvel-dev/setup-action@v2
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Install kind
run: |
cd $(mktemp -d -t kind.XXXX)
curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.19.0/kind-$(go env GOHOSTOS)-$(go env GOHOSTARCH)
chmod +x ./kind
sudo mv ./kind /usr/local/bin
cd -
- name: Generate certs
run: |
set -o errexit
set -o nounset
set -o pipefail
CERT_DIR=$(mktemp -d -t certs.XXXX)
echo "CERT_DIR=$CERT_DIR" >> $GITHUB_ENV
echo "##[group]Install cfssl"
curl -L https://github.com/cloudflare/cfssl/releases/download/v1.6.1/cfssl_1.6.1_linux_amd64 -o cfssl
curl -L https://github.com/cloudflare/cfssl/releases/download/v1.6.1/cfssljson_1.6.1_linux_amd64 -o cfssljson
chmod +x cfssl*
sudo mv cfssl* /usr/local/bin
echo "##[endgroup]"
echo "##[group]Generate CA"
cfssl gencert -initca .github/tls/root-csr.json \
| cfssljson -bare ${CERT_DIR}/root-ca
cfssl gencert -ca ${CERT_DIR}/root-ca.pem -ca-key ${CERT_DIR}/root-ca-key.pem \
-config=".github/tls/config.json" \
-profile="intermediate" .github/tls/intermediate-csr.json \
| cfssljson -bare ${CERT_DIR}/signing-ca
cat ${CERT_DIR}/signing-ca.pem ${CERT_DIR}/root-ca.pem > ${CERT_DIR}/ca.pem
echo "##[endgroup]"
echo "##[group]Install CA"
# https://ubuntu.com/server/docs/security-trust-store
sudo apt-get install -y ca-certificates
sudo cp ${CERT_DIR}/ca.pem /usr/local/share/ca-certificates/ca.crt
sudo update-ca-certificates
echo "##[endgroup]"
echo "##[group]Generate cert"
cfssl gencert -ca ${CERT_DIR}/signing-ca.pem -ca-key ${CERT_DIR}/signing-ca-key.pem \
-config=".github/tls/config.json" \
-profile="server" \
-hostname="${REGISTRY_NAME},local-registry" \
.github/tls/server-csr.json \
| cfssljson -bare ${CERT_DIR}/server
echo "##[endgroup]"
- name: Setup local registry
run: |
set -o errexit
set -o nounset
set -o pipefail
# Run a registry.
docker run -d \
--restart=always \
--name local-registry \
-v ${CERT_DIR}:/certs \
-e REGISTRY_HTTP_ADDR=0.0.0.0:443 \
-e REGISTRY_HTTP_TLS_CERTIFICATE=/certs/server.pem \
-e REGISTRY_HTTP_TLS_KEY=/certs/server-key.pem \
-p "443:443" \
registry:2
# Make the $REGISTRY_NAME -> local-registry
echo "$(hostname -I | cut -d' ' -f1) $REGISTRY_NAME" | sudo tee -a /etc/hosts
- name: Create Cluster
run: |
set -o errexit
set -o nounset
set -o pipefail
# create a cluster with the local registry enabled in containerd
cat <<EOF | kind create cluster --config=-
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
containerdConfigPatches:
- |-
[plugins."io.containerd.grpc.v1.cri".registry.mirrors."${REGISTRY_NAME}"]
endpoint = ["https://local-registry"]
- |-
[plugins."io.containerd.grpc.v1.cri".registry.configs."local-registry".tls]
ca_file = "/etc/docker/certs.d/local-registry/ca.pem"
nodes:
- role: control-plane
image: kindest/node:v${{ matrix.k8s }}
extraMounts:
- containerPath: /etc/docker/certs.d/local-registry
hostPath: ${CERT_DIR}
EOF
# connect the registry to the cluster network
docker network connect kind local-registry
# Document the local registry
# https://github.com/kubernetes/enhancements/tree/master/keps/sig-cluster-lifecycle/generic/1755-communicating-a-local-registry
cat <<EOF | kubectl apply -f -
apiVersion: v1
kind: ConfigMap
metadata:
name: local-registry-hosting
namespace: kube-public
data:
localRegistryHosting.v1: |
host: "localhost"
help: "https://kind.sigs.k8s.io/docs/user/local-registry/"
EOF
- name: Download staged Cartographer Conventions build
uses: actions/download-artifact@v4
with:
name: cartographer-conventions-bundle.tar
- name: Download staged Cartographer Conventions build
uses: actions/download-artifact@v4
with:
name: cartographer-conventions-samples-bundle.tar
- name: Relocate bundles
run: |
set -o errexit
set -o nounset
set -o pipefail
imgpkg copy --tar cartographer-conventions-bundle.tar --to-repo "${BUNDLE}/controller"
mkdir -p convention-bundle/controller
imgpkg pull -b "${BUNDLE}/controller" -o convention-bundle/controller
imgpkg copy --tar cartographer-conventions-samples-bundle.tar --to-repo "${BUNDLE}/samples"
mkdir -p convention-bundle/samples
imgpkg pull -b "${BUNDLE}/samples" -o convention-bundle/samples
- name: Install kapp-controller
run: |
set -o errexit
set -o nounset
set -o pipefail
kapp deploy -a kapp-controller -n kube-system \
--wait-timeout 5m -y \
-f https://github.com/vmware-tanzu/carvel-kapp-controller/releases/latest/download/release.yml \
-f <( \
ytt -f .github/kapp/kapp-controller-config.yaml \
--data-value-file ca_cert_data=${CERT_DIR}/ca.pem \
)
- name: Install cert-manager
run: |
set -o errexit
set -o nounset
set -o pipefail
kapp deploy -a cert-manager -n kube-system -y -f dist/third-party/cert-manager.yaml
- name: Deploy Cartographer Conventions Package
run: |
set -o errexit
set -o nounset
set -o pipefail
kapp deploy -a cartographer-conventions-controller-package -y \
--wait-timeout 5m \
-f <( \
ytt -f dist/package.yaml -f dist/package.values.yaml \
--data-value version=0.0.0-snapshot \
--data-value image=${BUNDLE}/controller \
)
- name: Deploy Cartographer Conventions with no package values
run: |
set -o errexit
set -o nounset
set -o pipefail
kapp deploy -a cartographer-conventions-controller -y \
-f <( \
ytt -f dist/package-install.yaml -f dist/package-install.values.yaml \
--data-value package_constraints=0.0.0-snapshot \
--data-value-yaml 'package_prerelease={}' \
)
kapp delete -a cartographer-conventions-controller --wait-timeout 5m -y
- name: Deploy Cartographer Conventions
run: |
set -o errexit
set -o nounset
set -o pipefail
kapp deploy -a cartographer-conventions-controller -y \
-f <( \
ytt -f dist/package-install.yaml -f dist/package-install.values.yaml \
--data-value package_constraints=0.0.0-snapshot \
--data-value-yaml 'package_prerelease={}' \
--data-value sync_period=10s \
--data-value-yaml 'has_values=true' \
--data-value-file ca_cert_data=${CERT_DIR}/ca.pem
)
- name: Deploy Convention Dumper
run: |
set -o errexit
set -o nounset
set -o pipefail
echo "##[group]Deploy convention server"
kapp deploy -a convention-dumper -n kube-system \
-f <(kbld -f convention-bundle/samples/dumper-server/server.yaml -f convention-bundle/samples/.imgpkg/images.yml) -y
echo "##[endgroup]"
- name: Deploy Sample Convention Server
run: |
set -o errexit
set -o nounset
set -o pipefail
echo "##[group]Deploy convention server"
kapp deploy -a convention-server -n kube-system \
-f <(kbld -f convention-bundle/samples/convention-server/server.yaml -f convention-bundle/samples/.imgpkg/images.yml) -y
echo "##[endgroup]"
echo "##[group]Deploy workload"
kapp deploy -a convention-server-workload -f convention-bundle/samples/convention-server/workload.yaml -y
echo "##[endgroup]"
echo "##[group]Wait for workload status to be ready"
kubectl wait podintents.conventions.carto.run sample --for condition=ready
echo "##[endgroup]"
echo "##[group]Verify convention is applied to workload"
actual=$(kubectl get podintent.conventions.carto.run sample -ojson | jq -r ".status.template.spec.containers[].env[] | select(.name==\"CONVENTION_SERVER\") | .value ")
expects="HELLO FROM CONVENTION"
if [ "$actual" != "$expects" ]; then echo "Environmental variable do not match. Got \"$actual\"; expected \"$expects\". Exiting..."; exit 1; fi;
echo "Environmental variables matched. Got \"$actual\"; expected \"$expects\""
echo "##[endgroup]"
- name: Deploy Spring Sample Convention Server
run: |
set -o errexit
set -o nounset
set -o pipefail
echo "##[group]Deploy spring convention server"
kapp deploy -a spring-convention-server -n kube-system \
-f <(kbld -f convention-bundle/samples/spring-convention-server/server.yaml -f convention-bundle/samples/.imgpkg/images.yml) -y
echo "##[endgroup]"
echo "##[group]Deploy workload"
kapp deploy -a spring-convention-server-workload -f convention-bundle/samples/spring-convention-server/workload.yaml -y
echo "##[endgroup]"
echo "##[group]Wait for workload status to be ready"
kubectl wait podintents.conventions.carto.run spring-sample --for condition=ready
echo "##[endgroup]"
echo "##[group]Verify spring convention is applied to workload"
actual_annotation=$(kubectl get podintent.conventions.carto.run spring-sample -ojson | jq -r ".status.template.metadata.annotations"[\"boot.spring.io/version\"])
if [[ "${actual_annotation}" == "null" || -z "${actual_annotation}" ]]; then echo "Annotations \"boot.spring.io/version\" is not present. Exiting..."; exit 1; fi;
echo "Found Annotation \"boot.spring.io/version\" with value \"$actual_annotation\";"
actual_label=$(kubectl get podintent.conventions.carto.run spring-sample -ojson | jq -r ".status.template.metadata.labels"[\"conventions.carto.run/framework\"])
if [[ "${actual_label}" == "null" || -z "${actual_label}" ]]; then echo "Label \"conventions.carto.run/framework\" is not present. Exiting..."; exit 1; fi;
echo "Found Label \"conventions.carto.run/framework\" with value \"$actual_label\";"
echo "##[endgroup]"
- name: Collect diagnostics
run: |
set +o errexit
set -o nounset
set +o pipefail
echo "##[group]Packages"
kubectl get package -A -oyaml
echo "##[endgroup]"
echo "##[group]Package Installs"
kubectl get packageinstall -A -oyaml
echo "##[endgroup]"
echo "##[group]Kapp list apps"
kapp list -A
echo "##[endgroup]"
echo "##[group]Package changesets"
kapp app-change list -a cartographer-conventions-controller.app
echo "##[endgroup]"
echo "##[group]kapp-controller logs"
kubectl logs -n kapp-controller -l app=kapp-controller -c kapp-controller --tail 1000
echo "##[endgroup]"
echo "##[group]Cartographer Conventions logs"
kubectl logs -n conventions-system -l component=conventions.carto.run,control-plane=controller-manager -c manager --tail 1000
echo "##[endgroup]"
echo "##[group]Convention Server deployment"
kubectl describe deployment webhook -n sample-conventions
echo "##[endgroup]"
echo "##[group]ClusterPodConvention resource"
kubectl describe clusterpodconventions.conventions.carto.run sample
kubectl describe clusterpodconventions.conventions.carto.run spring-sample
echo "##[endgroup]"
echo "##[group]WorkloadPodIntent resource"
kubectl describe podintents.conventions.carto.run sample
kubectl describe podintents.conventions.carto.run spring-sample
echo "##[endgroup]"
echo "##[group]Convention Dumper logs"
# NOTE: uncomment if you need dumper logs, deactivated because it can be very slow
# kubectl logs -n dumper-conventions -l app=webhook --tail 500
echo "##[endgroup]"
echo "##[group]Convention Server logs"
kubectl logs -l app=webhook -n sample-conventions --tail 100
echo "##[endgroup]"
echo "##[group]Resources in sample-conventions namespace"
kubectl get deployments,pods,svc,secrets,cm -n sample-conventions
echo "##[endgroup]"
echo "##[group]Spring Convention Server deployment"
kubectl describe deployment spring-webhook -n sample-spring-conventions
echo "##[endgroup]"
echo "##[group]Spring Convention Server logs"
kubectl logs -l app=spring-webhook -n sample-spring-conventions --tail 100
echo "##[endgroup]"
echo "##[group]Resources in sample-spring-conventions namespace"
kubectl get deployments,pods,svc,secrets,cm -n sample-spring-conventions
echo "##[endgroup]"
echo "##[group]Docker processes"
docker ps
echo "##[endgroup]"
echo "##[group]Registry logs"
docker logs local-registry
echo "##[endgroup]"
echo "##[group]Registry certs"
openssl s_client -connect ${REGISTRY_NAME}:443 -showcerts
echo "##[endgroup]"
echo "##[group]Registry request"
curl -v https://${REGISTRY_NAME}/v2/
echo "##[endgroup]"
if: always()
continue-on-error: true
- name: Fail for multiple kapp changes
run: |
set -o errexit
set -o nounset
set -o pipefail
deploys=$(kapp app-change list -a cartographer-conventions-controller.app --json | jq '.Tables[0].Rows | length')
if [ "$deploys" != "1" ]; then
echo "Too many app changes for the cartographer-conventions-controller package, expected 1 found ${deploys}"
exit 1
fi
- name: Delete Gracefully
run: |
set -o errexit
set -o nounset
set -o pipefail
echo "##[group]Delete sample convention servers"
kapp delete -a convention-dumper -n kube-system -y
kapp delete -a convention-server -n kube-system -y
kapp delete -a spring-convention-server -n kube-system -y
echo "##[endgroup]"
echo "##[group]Delete PodIntent resources"
kapp delete -a convention-server-workload -y
kapp delete -a spring-convention-server-workload -y
echo "##[endgroup]"
echo "##[group]Delete cartographer-conventions-controller"
kapp delete -a cartographer-conventions-controller -y
echo "##[endgroup]"
echo "##[group]Delete cartographer-conventions-controller-package"
kapp delete -a cartographer-conventions-controller-package --wait-timeout 5m -y
echo "##[endgroup]"
echo "##[group]Delete kapp-controller"
kapp delete -a kapp-controller -n kube-system --wait-timeout 5m -y
echo "##[endgroup]"
echo "##[group]Delete cert-manager"
kapp delete -a cert-manager -n kube-system --wait-timeout 5m -y
echo "##[endgroup]"
if: always()
- name: Cleanup cluster
run: kind delete cluster
if: always()
security:
needs: stage
runs-on: ubuntu-latest
env:
REGISTRY_NAME: registry.local
BUNDLE: registry.local/conventions/bundle
steps:
- uses: actions/checkout@v4
- uses: carvel-dev/setup-action@v2
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Generate certs
run: |
set -o errexit
set -o nounset
set -o pipefail
CERT_DIR=$(mktemp -d -t certs.XXXX)
echo "CERT_DIR=$CERT_DIR" >> $GITHUB_ENV
echo "##[group]Install cfssl"
curl -L https://github.com/cloudflare/cfssl/releases/download/v1.6.1/cfssl_1.6.1_linux_amd64 -o cfssl
curl -L https://github.com/cloudflare/cfssl/releases/download/v1.6.1/cfssljson_1.6.1_linux_amd64 -o cfssljson
chmod +x cfssl*
sudo mv cfssl* /usr/local/bin
echo "##[endgroup]"
echo "##[group]Generate CA"
cfssl gencert -initca .github/tls/root-csr.json \
| cfssljson -bare ${CERT_DIR}/root-ca
cfssl gencert -ca ${CERT_DIR}/root-ca.pem -ca-key ${CERT_DIR}/root-ca-key.pem \
-config=".github/tls/config.json" \
-profile="intermediate" .github/tls/intermediate-csr.json \
| cfssljson -bare ${CERT_DIR}/signing-ca
cat ${CERT_DIR}/signing-ca.pem ${CERT_DIR}/root-ca.pem > ${CERT_DIR}/ca.pem
echo "##[endgroup]"
echo "##[group]Install CA"
# https://ubuntu.com/server/docs/security-trust-store
sudo apt-get install -y ca-certificates
sudo cp ${CERT_DIR}/ca.pem /usr/local/share/ca-certificates/ca.crt
sudo update-ca-certificates
echo "##[endgroup]"
echo "##[group]Generate cert"
cfssl gencert -ca ${CERT_DIR}/signing-ca.pem -ca-key ${CERT_DIR}/signing-ca-key.pem \
-config=".github/tls/config.json" \
-profile="server" \
-hostname="${REGISTRY_NAME},local-registry" \
.github/tls/server-csr.json \
| cfssljson -bare ${CERT_DIR}/server
echo "##[endgroup]"
- name: Setup local registry
run: |
set -o errexit
set -o nounset
set -o pipefail
# Run a registry.
docker run -d \
--restart=always \
--name local-registry \
-v ${CERT_DIR}:/certs \
-e REGISTRY_HTTP_ADDR=0.0.0.0:443 \
-e REGISTRY_HTTP_TLS_CERTIFICATE=/certs/server.pem \
-e REGISTRY_HTTP_TLS_KEY=/certs/server-key.pem \
-p "443:443" \
registry:2
# Make the $REGISTRY_NAME -> local-registry
echo "$(hostname -I | cut -d' ' -f1) $REGISTRY_NAME" | sudo tee -a /etc/hosts
- name: Install grype
run: |
set -o errexit
set -o nounset
set -o pipefail
curl -sSfL https://raw.githubusercontent.com/anchore/grype/main/install.sh | sh -s -- -b /usr/local/bin
- name: Download staged Cartographer Conventions bundle
uses: actions/download-artifact@v4
with:
name: cartographer-conventions-bundle.tar
- name: Scan source
run: |
set -o errexit
set -o nounset
set -o pipefail
echo "##[group]Scan source ."
grype dir:.
echo "##[endgroup]"
echo "##[group]Scan source ./webhook"
grype dir:webhook
echo "##[endgroup]"
- name: Scan bundle images
run: |
set -o errexit
set -o nounset
set -o pipefail
imgpkg copy --tar cartographer-conventions-bundle.tar --to-repo "${BUNDLE}/controller"
mkdir -p convention-bundle/controller
imgpkg pull -b "${BUNDLE}/controller" -o convention-bundle/controller
# scan each image from .imgpkg/images.yml
buffer=""
for line in $(yq -o=json '.images[]' convention-bundle/controller/.imgpkg/images.yml) ; do
buffer="${buffer}${line}"
if [ "$line" = "}" ] ; then
echo "##[group]Scan image $(jq -r '.annotations["kbld.carvel.dev/id"]' <(echo "$buffer"))"
grype registry:$(jq -r '.image' <(echo "$buffer"))
echo "##[endgroup]"
buffer=""
fi
done
# aggregate the unit, acceptance, and security results into a single job
test:
needs:
- unit
- acceptance
- security
runs-on: ubuntu-latest
steps:
- run: echo "it passed"
release:
needs:
- test
if: startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Get the version
id: get_version
run: echo ::set-output name=VERSION::${GITHUB_REF/refs\/tags\//}
- name: Draft release
id: create_release
uses: actions/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: Release ${{ steps.get_version.outputs.VERSION }}
draft: true
- name: Download staged Cartographer Conventions build
uses: actions/download-artifact@v4
with:
name: cartographer-conventions-bundle.tar
- name: Download staged samples build
uses: actions/download-artifact@v4
with:
name: cartographer-conventions-samples-bundle.tar
- name: Upload Cartographer Conventions release
uses: actions/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }} # This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`. See this blog post for more info: https://jasonet.co/posts/new-features-of-github-actions/#passing-data-to-future-steps
asset_path: cartographer-conventions-bundle.tar
asset_name: cartographer-conventions-bundle-${{ steps.get_version.outputs.VERSION }}.tar
asset_content_type: application/x-tar
- name: Upload Convention samples
uses: actions/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }} # This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`. See this blog post for more info: https://jasonet.co/posts/new-features-of-github-actions/#passing-data-to-future-steps
asset_path: cartographer-conventions-samples-bundle.tar
asset_name: cartographer-conventions-samples-bundle-${{ steps.get_version.outputs.VERSION }}.tar
asset_content_type: application/x-tar
- uses: carvel-dev/setup-action@v2
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Install crane
run: |
cd $(mktemp -d -t kind.XXXX)
curl -L https://github.com/google/go-containerregistry/releases/download/v0.8.0/go-containerregistry_Linux_x86_64.tar.gz | tar -xz
chmod +x ./crane
sudo mv ./crane /usr/local/bin
cd -
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Relocate bundle to public registry
run: |
set -o errexit
set -o nounset
set -o pipefail
version=${{ steps.get_version.outputs.VERSION }}
imgpkg copy --tar cartographer-conventions-bundle.tar --to-repo "ghcr.io/${{ github.repository }}/bundle"
crane tag "ghcr.io/${{ github.repository }}/bundle" "${version}"
digest=$(crane digest "ghcr.io/${{ github.repository }}/bundle:${version}")
scratch=$(mktemp -d -t bundle.XXXX)
mkdir -p ${scratch}
imgpkg pull -b "ghcr.io/${{ github.repository }}/bundle:${version}@${digest}" -o ${scratch}
cp hack/boilerplate.ytt.txt cartographer-conventions.yaml
kbld -f ${scratch}/config/cartographer-conventions.yaml -f ${scratch}/.imgpkg/images.yml \
>> cartographer-conventions.yaml
cp hack/boilerplate.ytt.txt cartographer-conventions-package.yaml
ytt -f dist/package.yaml -f dist/package.values.yaml \
--data-value version=${version} \
--data-value image="ghcr.io/${{ github.repository }}/bundle:${version}@${digest}" \
>> cartographer-conventions-package.yaml
- name: Relocate samples to public registry
run: |
set -o errexit
set -o nounset
set -o pipefail
version=${{ steps.get_version.outputs.VERSION }}
imgpkg copy --tar cartographer-conventions-samples-bundle.tar --to-repo "ghcr.io/${{ github.repository }}/samples"
crane tag "ghcr.io/${{ github.repository }}/samples" "${version}"
digest=$(crane digest "ghcr.io/${{ github.repository }}/samples:${version}")
scratch=$(mktemp -d -t bundle.XXXX)
mkdir -p ${scratch}
imgpkg pull -b "ghcr.io/${{ github.repository }}/samples:${version}@${digest}" -o ${scratch}
cp hack/boilerplate.ytt.txt cartographer-conventions-samples-convention-server.yaml
kbld -f ${scratch}/convention-server/server.yaml -f ${scratch}/.imgpkg/images.yml \
>> cartographer-conventions-samples-convention-server.yaml
cp hack/boilerplate.ytt.txt cartographer-conventions-samples-dumper-server.yaml
kbld -f ${scratch}/dumper-server/server.yaml -f ${scratch}/.imgpkg/images.yml \
>> cartographer-conventions-samples-dumper-server.yaml
cp hack/boilerplate.ytt.txt cartographer-conventions-samples-spring-convention-server.yaml
kbld -f ${scratch}/spring-convention-server/server.yaml -f ${scratch}/.imgpkg/images.yml \
>> cartographer-conventions-samples-spring-convention-server.yaml
- name: Upload cartographer-conventions.yaml
uses: actions/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }} # This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`. See this blog post for more info: https://jasonet.co/posts/new-features-of-github-actions/#passing-data-to-future-steps
asset_path: cartographer-conventions.yaml
asset_name: cartographer-conventions-${{ steps.get_version.outputs.VERSION }}.yaml
asset_content_type: application/x-yaml
- name: Upload cartographer-conventions-package.yaml
uses: actions/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }} # This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`. See this blog post for more info: https://jasonet.co/posts/new-features-of-github-actions/#passing-data-to-future-steps
asset_path: cartographer-conventions-package.yaml
asset_name: cartographer-conventions-package-${{ steps.get_version.outputs.VERSION }}.yaml
asset_content_type: application/x-yaml
- name: Upload cartographer-conventions-samples-convention-server.yaml
uses: actions/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }} # This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`. See this blog post for more info: https://jasonet.co/posts/new-features-of-github-actions/#passing-data-to-future-steps
asset_path: cartographer-conventions-samples-convention-server.yaml
asset_name: cartographer-conventions-samples-convention-server-${{ steps.get_version.outputs.VERSION }}.yaml
asset_content_type: application/x-yaml
- name: Upload cartographer-conventions-samples-dumper-server.yaml
uses: actions/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }} # This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`. See this blog post for more info: https://jasonet.co/posts/new-features-of-github-actions/#passing-data-to-future-steps
asset_path: cartographer-conventions-samples-dumper-server.yaml
asset_name: cartographer-conventions-samples-dumper-server-${{ steps.get_version.outputs.VERSION }}.yaml
asset_content_type: application/x-yaml
- name: Upload cartographer-conventions-samples-spring-convention-server.yaml
uses: actions/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }} # This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`. See this blog post for more info: https://jasonet.co/posts/new-features-of-github-actions/#passing-data-to-future-steps
asset_path: cartographer-conventions-samples-spring-convention-server.yaml
asset_name: cartographer-conventions-samples-spring-convention-server-${{ steps.get_version.outputs.VERSION }}.yaml
asset_content_type: application/x-yaml