|
| 1 | +version: "3" |
| 2 | + |
| 3 | +includes: |
| 4 | + demo-targets: |
| 5 | + taskfile: ../demo-targets/Taskfile.yaml |
| 6 | + internal: true |
| 7 | + core: |
| 8 | + taskfile: ../Taskfile.yaml |
| 9 | + internal: true |
| 10 | + |
| 11 | +vars: |
| 12 | + # addtional cli args to pass to the helm install command which installs the hook into the testing environment |
| 13 | + additionalHelmInstallArgsForHook: '{{ .additionalHelmInstallArgsForHook | default "" }}' |
| 14 | +env: |
| 15 | + IMG_TAG: |
| 16 | + sh: 'echo "sha-$(git rev-parse --short HEAD)"' |
| 17 | + |
| 18 | +tasks: |
| 19 | + build: |
| 20 | + desc: Build the Docker image for the {{ .hookName }} hook |
| 21 | + status: |
| 22 | + - docker images | grep -q "docker.io/securecodebox/hook-{{ .hookName }}:${IMG_TAG}" || false |
| 23 | + preconditions: |
| 24 | + - msg: "Docker is not running, please start Docker first" |
| 25 | + sh: "docker info >/dev/null 2>&1 || false" |
| 26 | + deps: |
| 27 | + - core:build-hook-sdk-image |
| 28 | + cmds: |
| 29 | + - | |
| 30 | + echo "Building custom hook image for {{ .hookName }} with tag ${IMG_TAG}" |
| 31 | + docker build -t docker.io/securecodebox/hook-{{ .hookName }}:${IMG_TAG} \ |
| 32 | + --build-arg=baseImageTag=${IMG_TAG} \ |
| 33 | + {{ .ROOT_DIR }}/hook/ |
| 34 | + kind load docker-image --name testing-env docker.io/securecodebox/hook-{{ .hookName }}:${IMG_TAG} |
| 35 | + predeploy: |
| 36 | + desc: Can be overwritten by the hook to perform any pre-deployment steps |
| 37 | + cmds: [] |
| 38 | + silent: true |
| 39 | + deploy: |
| 40 | + desc: Deploy the {{ .hookName }} hook to the testing environment |
| 41 | + deps: |
| 42 | + - core:prepare-testing-env |
| 43 | + - build |
| 44 | + status: |
| 45 | + - helm ls {{ .hookName }} -n integration-tests | grep -q '{{ .hookName }}' || false |
| 46 | + cmds: |
| 47 | + - 'echo "Deploying {{ .hookName }} to the testing environment"' |
| 48 | + - task: predeploy |
| 49 | + - | |
| 50 | + helm upgrade --install {{ .hookName }} {{ .ROOT_DIR }} --namespace integration-tests \ |
| 51 | + --set="hook.image.tag=${IMG_TAG}" \ |
| 52 | + --set="hook.image.pullPolicy=Never" \ |
| 53 | + {{ if ne "" .additionalHelmInstallArgsForHook -}} |
| 54 | + {{ .additionalHelmInstallArgsForHook -}} |
| 55 | + {{ end -}} |
| 56 | + --wait |
| 57 | +
|
| 58 | + # test:setup tasks |
| 59 | + test:setup:hook-sdk: |
| 60 | + internal: true |
| 61 | + status: |
| 62 | + - "[ -d {{ .ROOT_DIR }}/../../hook-sdk/nodejs/node_modules ] || false" |
| 63 | + cmds: |
| 64 | + - cd {{ .ROOT_DIR }}/../../hook-sdk/nodejs/ && bun install |
| 65 | + test:setup:test-helpers: |
| 66 | + internal: true |
| 67 | + status: |
| 68 | + - "[ -d {{ .ROOT_DIR }}/../../tests/integration/node_modules ] || false" |
| 69 | + cmds: |
| 70 | + - cd {{ .ROOT_DIR }}/../../tests/integration && bun install |
| 71 | + test:setup:hook-deps: |
| 72 | + internal: true |
| 73 | + status: |
| 74 | + - "[ -d {{ .ROOT_DIR }}/hook/node_modules ] || false" |
| 75 | + cmds: |
| 76 | + - cd {{ .ROOT_DIR }}/hook/ && bun install |
| 77 | + test:setup: |
| 78 | + cmds: |
| 79 | + - task: test:setup:hook-sdk |
| 80 | + - task: test:setup:test-helpers |
| 81 | + - task: test:setup:hook-deps |
| 82 | + |
| 83 | + test:unit: |
| 84 | + desc: Run unit tests for the {{ .hookName }} hook |
| 85 | + deps: |
| 86 | + - test:setup |
| 87 | + cmds: |
| 88 | + - | |
| 89 | + echo "Running unit tests for {{ .hookName }}" |
| 90 | + bun test {{ .ROOT_DIR }}/hook/ |
| 91 | + test:integration: |
| 92 | + desc: Run integration tests for the {{ .hookName }} hook |
| 93 | + deps: |
| 94 | + - test:setup |
| 95 | + - deploy |
| 96 | + preconditions: |
| 97 | + - msg: "kind cluster is not running, run 'task prepare-testing-env' from project root dir first" |
| 98 | + sh: "kubectl config get-contexts | grep -q 'kind-testing-env' || false" |
| 99 | + - msg: "secureCodeBox operator is not deployed, run 'task prepare-testing-env' from project root dir first" |
| 100 | + sh: "kubectl get pods -n securecodebox-system | grep -q 'securecodebox-operator' || false" |
| 101 | + - msg: "{{ .hookName }} hook is not deployed, run 'task build deploy' from hook dir first" |
| 102 | + sh: "helm -n integration-tests ls | grep -q '{{ .hookName }}' || false" |
| 103 | + cmds: |
| 104 | + # Workaround for https://github.com/oven-sh/bun/issues/7332 |
| 105 | + - 'echo "Forwarding the Kubernetes API to localhost"' |
| 106 | + - kubectl proxy >/dev/null 2>&1 & |
| 107 | + - sleep 1 # Wait a bit to ensure the proxy is up |
| 108 | + |
| 109 | + - defer: | |
| 110 | + # kill pid with command "kubectl proxy" |
| 111 | + echo "Killing kubectl proxy" |
| 112 | + pkill -f "kubectl proxy" |
| 113 | +
|
| 114 | + - echo "Running integration tests for {{ .hookName }}" |
| 115 | + - bun test {{ .ROOT_DIR }}/integration-tests/ |
| 116 | + test:helm: |
| 117 | + desc: Run helm tests for the {{ .hookName }} hook |
| 118 | + preconditions: |
| 119 | + - msg: "Helm unittest plugin is not installed, you need to install it first. See: https://github.com/helm-unittest/helm-unittest/" |
| 120 | + sh: "helm plugin list | grep -q 'unittest' || false" |
| 121 | + cmds: |
| 122 | + - helm unittest {{ .ROOT_DIR }} |
| 123 | + test: |
| 124 | + desc: Run all tests for the {{ .hookName }} hook |
| 125 | + cmds: |
| 126 | + - task test:unit |
| 127 | + - task test:helm |
| 128 | + - task test:integration |
0 commit comments