forked from eumel8/cosignwebhook
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
77 lines (68 loc) · 2.63 KB
/
Makefile
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
#############
### TESTS ###
#############
.PHONY: test-e2e
test-e2e:
@echo "Running e2e tests..."
@go test -v -race -count 1 ./test/
test-cleanup:
@echo "Cleaning up..."
@helm uninstall cosignwebhook -n cosignwebhook
@k3d registry delete k3d-registry.localhost
@k3d cluster delete cosign-tests
.PHONY: test-unit
test-unit:
@echo "Running unit tests..."
@go test -v -race -count 1 ./webhook/
###########
### E2E ###
###########
e2e-cluster:
@echo "Creating registry..."
@k3d registry create registry.localhost --port 5000
@echo "Adding registry to cluster..."
@k3d cluster create cosign-tests --registry-use k3d-registry.localhost:5000
@echo "Create test namespace..."
@kubectl create namespace test-cases
e2e-keys:
@echo "Generating cosign keys..."
@export COSIGN_PASSWORD="" && \
cosign generate-key-pair && \
cosign generate-key-pair --output-key-prefix second
e2e-images:
@echo "Checking for cosign.key..."
@test -f cosign.key || (echo "cosign.key not found. Run 'make e2e-keys' to generate the pairs needed for the tests." && exit 1)
@echo "Building test image..."
@docker build -t k3d-registry.localhost:5000/cosignwebhook:dev .
@echo "Pushing test image..."
@docker push k3d-registry.localhost:5000/cosignwebhook:dev
@echo "Signing test image..."
@export COSIGN_PASSWORD="" && \
cosign sign --tlog-upload=false --key cosign.key k3d-registry.localhost:5000/cosignwebhook:dev
@echo "Importing test image to cluster..."
@k3d image import k3d-registry.localhost:5000/cosignwebhook:dev --cluster cosign-tests
@echo "Building busybox image..."
@docker pull busybox:latest
@echo "Tagging & pushing busybox images..."
@docker tag busybox:latest k3d-registry.localhost:5000/busybox:first
@docker tag busybox:latest k3d-registry.localhost:5000/busybox:second
@docker push k3d-registry.localhost:5000/busybox --all-tags
@echo "Signing busybox images..."
@export COSIGN_PASSWORD="" && \
cosign sign --tlog-upload=false --key cosign.key k3d-registry.localhost:5000/busybox:first && \
cosign sign --tlog-upload=false --key second.key k3d-registry.localhost:5000/busybox:second
e2e-deploy:
@echo "Deploying test image..."
@helm upgrade -i cosignwebhook chart -n cosignwebhook --create-namespace \
--set image.repository=k3d-registry.localhost:5000/cosignwebhook \
--set image.tag=dev \
--set-file cosign.scwebhook.key=cosign.pub \
--set logLevel=debug \
--wait --debug
e2e-prep: e2e-cluster e2e-keys e2e-images e2e-deploy
e2e-cleanup:
@echo "Cleaning up..."
@helm uninstall cosignwebhook -n cosignwebhook
@k3d registry delete k3d-registry.localhost
@k3d cluster delete cosign-tests
@rm -f cosign.pub cosign.key second.pub second.key