-
Notifications
You must be signed in to change notification settings - Fork 182
Expand file tree
/
Copy pathTaskfile.yaml
More file actions
146 lines (137 loc) · 5.34 KB
/
Copy pathTaskfile.yaml
File metadata and controls
146 lines (137 loc) · 5.34 KB
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
# SPDX-FileCopyrightText: the secureCodeBox authors
#
# SPDX-License-Identifier: Apache-2.0
version: "3.44.0"
includes:
demo-targets:
taskfile: ../demo-targets/Taskfile.yaml
internal: true
core:
taskfile: ../Taskfile.yaml
internal: true
vars:
# addtional cli args to pass to the helm install command which installs the hook into the testing environment
additionalHelmInstallArgsForHook: '{{ .additionalHelmInstallArgsForHook | default "" }}'
hasIntegrationTests:
sh: 'if [ -d "{{ .TASKFILE_DIR }}/{{ .hookName }}/integration-tests" ]; then echo "true"; else echo "false"; fi'
hookUsesNpmDependencies:
sh: 'if [ -f "{{ .TASKFILE_DIR }}/{{ .hookName }}/hook/package.json" ]; then echo "true"; else echo "false"; fi'
env:
IMG_TAG:
sh: 'echo "sha-$(git rev-parse --short HEAD)"'
tasks:
build:
desc: Build the Docker image for the {{ .hookName }} hook
status:
- docker images | grep -q "docker.io/securecodebox/hook-{{ .hookName }}:${IMG_TAG}" || false
preconditions:
- msg: "Docker is not running, please start Docker first"
sh: "docker info >/dev/null 2>&1 || false"
deps:
- core:build-hook-sdk-image
cmds:
- |
echo "Building custom hook image for {{ .hookName }} with tag ${IMG_TAG}"
docker build -t docker.io/securecodebox/hook-{{ .hookName }}:${IMG_TAG} \
--build-arg=baseImageTag=${IMG_TAG} \
{{ .TASKFILE_DIR }}/{{ .hookName }}/hook/
kind load docker-image --name testing-env docker.io/securecodebox/hook-{{ .hookName }}:${IMG_TAG}
predeploy:
desc: Can be overwritten by the hook to perform any pre-deployment steps
cmds: []
silent: true
deploy:
desc: Deploy the {{ .hookName }} hook to the testing environment
status:
- helm ls {{ .hookName }} -n integration-tests | grep -q '{{ .hookName }}' || false
cmds:
- task: core:prepare-testing-env
- task: build
- 'echo "Deploying {{ .hookName }} to the testing environment"'
- task: predeploy
- |
helm upgrade --install {{ .hookName }} {{ .TASKFILE_DIR }}/{{ .hookName }} --namespace integration-tests \
--set="hook.image.tag=${IMG_TAG}" \
--set="hook.image.pullPolicy=Never" \
{{ if ne "" .additionalHelmInstallArgsForHook -}}
{{ .additionalHelmInstallArgsForHook -}}
{{ end -}}
--wait
# test:setup tasks
test:setup:hook-sdk:
internal: true
status:
- "[ -d {{ .TASKFILE_DIR }}/../hook-sdk/nodejs/node_modules ] || false"
cmds:
- cd {{ .TASKFILE_DIR }}/../hook-sdk/nodejs/ && bun install
test:setup:test-helpers:
internal: true
status:
- "[ -d {{ .TASKFILE_DIR }}/../tests/integration/node_modules ] || false"
cmds:
- cd {{ .TASKFILE_DIR }}/../tests/integration && bun install
test:setup:hook-deps:
internal: true
status:
- "[ -d {{ .TASKFILE_DIR }}/{{ .hookName }}/hook/node_modules ] || false"
cmds:
- |
{{ if eq "true" .hookUsesNpmDependencies }}
cd {{ .TASKFILE_DIR }}/{{ .hookName }}/hook/ && bun install
{{ else }}
echo "Hook has no custom dependencies. Skipping."
{{ end }}
test:setup:
cmds:
- task: test:setup:hook-sdk
- task: test:setup:test-helpers
- task: test:setup:hook-deps
test:unit:
desc: Run unit tests for the {{ .hookName }} hook
deps:
- test:setup
cmds:
- |
echo "Running unit tests for {{ .hookName }}"
bun test {{ .TASKFILE_DIR }}/{{ .hookName }}/hook/
test:integration:
desc: Run integration tests for the {{ .hookName }} hook
deps:
- test:setup
- deploy
preconditions:
- msg: "kind cluster is not running, run 'task prepare-testing-env' from project root dir first"
sh: "kubectl config get-contexts | grep -q 'kind-testing-env' || false"
- msg: "secureCodeBox operator is not deployed, run 'task prepare-testing-env' from project root dir first"
sh: "kubectl get pods -n securecodebox-system | grep -q 'securecodebox-operator' || false"
- msg: "{{ .hookName }} hook is not deployed, run 'task build deploy' from hook dir first"
sh: "helm -n integration-tests ls | grep -q '{{ .hookName }}' || false"
cmds:
# Workaround for https://github.com/oven-sh/bun/issues/7332
- 'echo "Forwarding the Kubernetes API to localhost"'
- kubectl proxy >/dev/null 2>&1 &
- sleep 1 # Wait a bit to ensure the proxy is up
- defer: |
# kill pid with command "kubectl proxy"
echo "Killing kubectl proxy"
pkill -f "kubectl proxy"
- echo "Running integration tests for {{ .hookName }}"
- |-
{{ if eq "true" .hasIntegrationTests -}}
bun test {{ .TASKFILE_DIR }}/{{ .hookName }}/integration-tests/
{{ else -}}
echo "Hook has no integration-tests. Skipping."
{{ end -}}
test:helm:
desc: Run helm tests for the {{ .hookName }} hook
preconditions:
- msg: "Helm unittest plugin is not installed, you need to install it first. See: https://github.com/helm-unittest/helm-unittest/"
sh: "helm plugin list | grep -q 'unittest' || false"
cmds:
- helm unittest {{ .TASKFILE_DIR }}/{{ .hookName }}
test:
desc: Run all tests for the {{ .hookName }} hook
cmds:
- task test:unit
- task test:helm
- task test:integration