11version : 3
22
3- # Environment variables that are shared across tasks.
4- env :
3+ # We have multiple parallel tasks that run for a long time. Prefix their output with the task name so we can understand
4+ # what task is writing.
5+ output : prefixed
6+
7+ # Variables that are shared across tasks.
8+ vars :
9+ # renovate: datasource=docker depName=kindest/node versioning=semver
10+ E2E_KUBERNETES_VERSION : v1.32.0
11+ E2E_CLUSTER_NAME : barman-cloud-plugin-e2e-{{.E2E_KUBERNETES_VERSION}}
512 REGISTRY_NETWORK : barman-cloud-plugin
613 REGISTRY_NAME : registry.barman-cloud-plugin
714 REGISTRY_PORT : 5000
8996 openssl req -new -x509 -days 365 -key ca-key.pem -sha256 -out ca.pem \
9097 -subj "/O=CloudNativePG/OU=Barman Cloud Plugin Testing" &&
9198 openssl genrsa -out server-key.pem 4096 &&
92- openssl req -subj "/CN=${ REGISTRY_NAME}" -sha256 -new -key server-key.pem -out server.csr &&
93- echo subjectAltName = DNS:${ REGISTRY_NAME},IP:127.0.0.1 >> extfile.cnf &&
99+ openssl req -subj "/CN={{ . REGISTRY_NAME } }" -sha256 -new -key server-key.pem -out server.csr &&
100+ echo subjectAltName = DNS:{{ . REGISTRY_NAME } },IP:127.0.0.1 >> extfile.cnf &&
94101 echo extendedKeyUsage = serverAuth >> extfile.cnf &&
95102 openssl x509 -req -days 365 -sha256 -in server.csr -CA ca.pem -CAkey ca-key.pem \
96103 -CAcreateserial -out server-cert.pem -extfile extfile.cnf &&
@@ -106,9 +113,9 @@ tasks:
106113 desc : Create a docker network for image building used by the dagger engine and the registry
107114 run : once
108115 cmds :
109- - docker network create ${ REGISTRY_NETWORK}
116+ - docker network create {{ . REGISTRY_NETWORK} }
110117 status :
111- - docker network inspect ${ REGISTRY_NETWORK}
118+ - docker network inspect {{ . REGISTRY_NETWORK } }
112119
113120 start-registry :
114121 desc : Start a container registry
@@ -121,14 +128,14 @@ tasks:
121128 REGISTRY_VERSION : 2
122129 cmds :
123130 - >
124- docker run -d --name ${ REGISTRY_NAME}
125- -p ${ REGISTRY_PORT}:5000
126- --network ${ REGISTRY_NETWORK}
131+ docker run -d --name {{ . REGISTRY_NAME } }
132+ -p {{ . REGISTRY_PORT } }:5000
133+ --network {{ . REGISTRY_NETWORK } }
127134 -v $(pwd)/certs:/certs
128135 -e REGISTRY_HTTP_TLS_CERTIFICATE=/certs/server-cert.pem -e REGISTRY_HTTP_TLS_KEY=/certs/server-key.pem
129136 registry:${REGISTRY_VERSION}
130137 status :
131- - \[ "$(docker inspect -f {{`'{{.State.Running}}'`}} "${ REGISTRY_NAME}" 2> /dev/null )" == 'true' \]
138+ - \[ "$(docker inspect -f {{`'{{.State.Running}}'`}} "{{ . REGISTRY_NAME } }" 2> /dev/null )" == 'true' \]
132139
133140
134141 # Start a dagger engine that mounts the CA certificate for the local registry.
@@ -144,12 +151,12 @@ tasks:
144151 DAGGER_ENGINE_IMAGE : registry.dagger.io/engine:v{{ .DAGGER_VERSION }}
145152 cmds :
146153 - >
147- docker run -d -v /var/lib/dagger --name "${ DAGGER_ENGINE_CONTAINER_NAME}"
148- --network=${ REGISTRY_NETWORK}
154+ docker run -d -v /var/lib/dagger --name "{{ . DAGGER_ENGINE_CONTAINER_NAME } }"
155+ --network={{ . REGISTRY_NETWORK } }
149156 -v $(pwd)/certs/ca.pem:/usr/local/share/ca-certificates/ca.crt
150157 --privileged {{ .DAGGER_ENGINE_IMAGE }}
151158 status :
152- - \[ "$(docker inspect -f {{`'{{.State.Running}}'`}} "${ DAGGER_ENGINE_CONTAINER_NAME}" 2> /dev/null )" == 'true' \]
159+ - \[ "$(docker inspect -f {{`'{{.State.Running}}'`}} "{{ . DAGGER_ENGINE_CONTAINER_NAME } }" 2> /dev/null )" == 'true' \]
153160
154161 # We build an image and push it to a local registry.
155162 # The name is always `plugin-barman-cloud:testing`.
@@ -161,12 +168,12 @@ tasks:
161168 env :
162169 # renovate: datasource=git-refs depName=docker lookupName=https://github.com/purpleclay/daggerverse currentValue=main
163170 DAGGER_DOCKER_SHA : 1379b455587e74072cee73db1b78e11af4215d53
164- _EXPERIMENTAL_DAGGER_RUNNER_HOST : docker-container://{{.DAGGER_ENGINE_CONTAINER_NAME}}
171+ _EXPERIMENTAL_DAGGER_RUNNER_HOST : docker-container://{{ .DAGGER_ENGINE_CONTAINER_NAME }}
165172 cmds :
166173 - >
167- GITHUB_REF= dagger call -m github.com/purpleclay/daggerverse/docker@${DAGGER_DOCKER_SHA}
174+ GITHUB_REF= dagger -s call -m github.com/purpleclay/daggerverse/docker@${DAGGER_DOCKER_SHA}
168175 build --dir . --file containers/Dockerfile.plugin --platform linux/amd64
169- publish --ref ${ REGISTRY_NAME}:${ REGISTRY_PORT}/plugin-barman-cloud --tags testing
176+ publish --ref {{ . REGISTRY_NAME }}:{{ . REGISTRY_PORT } }/plugin-barman-cloud --tags testing
170177
171178 # We build an image and push it to a local registry.
172179 # The name is always `sidecar-barman-cloud:testing`.
@@ -178,19 +185,52 @@ tasks:
178185 env :
179186 # renovate: datasource=git-refs depName=docker lookupName=https://github.com/purpleclay/daggerverse currentValue=main
180187 DAGGER_DOCKER_SHA : 1379b455587e74072cee73db1b78e11af4215d53
181- _EXPERIMENTAL_DAGGER_RUNNER_HOST : docker-container://{{.DAGGER_ENGINE_CONTAINER_NAME}}
188+ _EXPERIMENTAL_DAGGER_RUNNER_HOST : docker-container://{{ .DAGGER_ENGINE_CONTAINER_NAME }}
182189 cmds :
183190 - >
184- GITHUB_REF= dagger call -m github.com/purpleclay/daggerverse/docker@${DAGGER_DOCKER_SHA}
191+ GITHUB_REF= dagger -s call -m github.com/purpleclay/daggerverse/docker@${DAGGER_DOCKER_SHA}
185192 build --dir . --file containers/Dockerfile.sidecar --platform linux/amd64
186- publish --ref ${ REGISTRY_NAME}:${ REGISTRY_PORT}/sidecar-barman-cloud --tags testing
193+ publish --ref {{ . REGISTRY_NAME }}:{{ . REGISTRY_PORT } }/sidecar-barman-cloud --tags testing
187194
188195 build-images :
189196 desc : Build the container images for the plugin
190197 deps :
191198 - build-plugin-image
192199 - build-sidecar-image
193200
201+ # Install kind if not at the expected version.
202+ install-kind :
203+ desc : Install kind
204+ run : once
205+ vars :
206+ # renovate: datasource=git-refs depName=kind lookupName=https://github.com/kubernetes-sigs/kind versioning=semver
207+ KIND_VERSION : v0.26.0
208+ cmds :
209+ - go install sigs.k8s.io/kind@{{.KIND_VERSION}}
210+ - kind version | grep -q {{.KIND_VERSION}}
211+ status :
212+ - kind version | grep -q {{.KIND_VERSION}}
213+
214+ start-kind-cluster :
215+ desc : Start a kind cluster
216+ deps :
217+ - install-kind
218+ - start-build-network
219+ run : once
220+ cmds :
221+ - >
222+ kind create cluster --name {{ .E2E_CLUSTER_NAME }}
223+ --image kindest/node:{{ .E2E_KUBERNETES_VERSION }}
224+ --config hack/kind-config.yaml
225+ --wait 5m
226+ - >
227+ for node in $(kind get nodes --name {{ .E2E_CLUSTER_NAME }} ); do
228+ docker network connect {{ .REGISTRY_NETWORK }} $node;
229+ docker exec $node sh -c "update-ca-certificates";
230+ done
231+ status :
232+ - kind get clusters | grep -q {{ .E2E_CLUSTER_NAME }}
233+
194234 # TODO: see if it is possible to daggerize this. It will have to manage docker to make kind work.
195235 # TODO: add a task to clean up the kind cluster for new test runs.
196236 # Run the e2e tests. This task will start a kind cluster, deploy the plugin, and run the tests.
@@ -199,22 +239,42 @@ tasks:
199239 # * The registry to be in the same network of the dagger-engine.
200240 # * The dagger-engine to mount the CA.
201241 # * The kind cluster to mount the CA.
202- e2e :
203- desc : Run e2e tests
242+ e2e-external-kind :
243+ desc : Run e2e tests in a local kind cluster
204244 deps :
205245 - build-images
246+ - start-kind-cluster
247+ vars :
248+ # renovate: datasource=docker depName=golang versioning=semver
249+ GOLANG_IMAGE_VERSION : 1.23.4
250+ KUBECONFIG_PATH :
251+ sh : mktemp -t kubeconfig-XXXXX
252+ env :
253+ _EXPERIMENTAL_DAGGER_RUNNER_HOST : docker-container://{{ .DAGGER_ENGINE_CONTAINER_NAME }}
254+ cmds :
255+ - kind get kubeconfig --internal --name {{ .E2E_CLUSTER_NAME }} > {{ .KUBECONFIG_PATH }}
256+ - >
257+ GITHUB_REF= dagger call -m dagger/e2e/ run
258+ --source .
259+ --kubeconfig {{.KUBECONFIG_PATH}}
260+ --go-version {{ .GOLANG_IMAGE_VERSION }}
261+
262+ e2e-ephemeral :
263+ desc : Run e2e tests in an ephemeral k3s cluster
264+ deps :
265+ - build-images
266+ vars :
267+ # renovate: datasource=docker depName=golang versioning=semver
268+ GOLANG_IMAGE_VERSION : 1.23.4
269+ env :
270+ _EXPERIMENTAL_DAGGER_RUNNER_HOST : docker-container://{{ .DAGGER_ENGINE_CONTAINER_NAME }}
206271 cmds :
207272 - >
208- go run github.com/onsi/ginkgo/v2/ginkgo
209- --procs=8
210- --randomize-all
211- --randomize-suites
212- --fail-on-pending
213- --fail-on-empty
214- --keep-going
215- --timeout=30m
216- --github-output
217- ./test/e2e
273+ GITHUB_REF= dagger call -m dagger/e2e/ run-ephemeral
274+ --source .
275+ --ca certs/ca.pem
276+ --registry {{.REGISTRY_NAME}}:{{.REGISTRY_PORT}}
277+ --go-version {{ .GOLANG_IMAGE_VERSION }}
218278
219279 ci :
220280 desc : Run the CI pipeline
@@ -224,7 +284,7 @@ tasks:
224284 - uncommitted
225285 - lint
226286 - go-test
227- - e2e
287+ - e2e-ephemeral
228288
229289 publish :
230290 desc : Build and publish a container image for the plugin
@@ -284,7 +344,7 @@ tasks:
284344 - controller-gen
285345 desc : Generate the manifest for the main branch
286346 vars :
287- GITHUB_REPOSITORY : ' {{ default " cloudnative-pg/plugin-barman-cloud" .GITHUB_REPOSITORY }} '
347+ GITHUB_REPOSITORY : cloudnative-pg/plugin-barman-cloud
288348 GITHUB_REF : main
289349 GITHUB_REF_NAME : main
290350 cmds :
0 commit comments