Skip to content

Commit 74bc9e2

Browse files
authored
test(e2e): environment setup (#43)
Create the CI and testing infrastructure for e2e testing. Running the ci task now will push the plugin and sidecar images to a local registry, start kind, install the CloudNativePG and cert-manager operators, and then install the plugin-barman-cloud one. No actual test is implemented. Signed-off-by: Francesco Canovai <[email protected]>
1 parent b7c4a4b commit 74bc9e2

File tree

25 files changed

+1455
-312
lines changed

25 files changed

+1455
-312
lines changed

.github/workflows/ci.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,35 @@ jobs:
88
ci:
99
runs-on: ubuntu-latest
1010
steps:
11+
- name: Cleanup Disk
12+
uses: jlumbroso/[email protected]
13+
with:
14+
android: true
15+
dotnet: true
16+
haskell: true
17+
tool-cache: true
18+
large-packages: false
19+
swap-storage: false
20+
- name: Cleanup docker cache
21+
run: |
22+
echo "-------------Disk info before cleanup----------------"
23+
df -h
24+
echo "-----------------------------------------------------"
25+
docker system prune -a -f
26+
echo "-------------Disk info after cleanup----------------"
27+
df -h
28+
echo "-----------------------------------------------------"
1129
- name: Checkout
1230
uses: actions/checkout@v4
1331
# We need the full history for the commitlint task
1432
with:
1533
fetch-depth: 0
1634
ref: ${{ github.event.pull_request.head.sha }}
35+
# TODO: remove this when we daggerize the e2e
36+
- name: Setup Go
37+
uses: actions/setup-go@v5
38+
with:
39+
go-version: '1.23.x'
1740
- name: Install Task
1841
uses: arduino/setup-task@v2
1942
- name: Install Dagger

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,8 @@ go.work
3434

3535
# Taskfile cache
3636
.task
37+
38+
# E2e test artifacts
39+
test/e2e/bin
40+
# Test registry certificates
41+
certs/

Taskfile.yml

Lines changed: 115 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
version: 3
22

3+
# Environment variables that are shared across tasks.
4+
env:
5+
REGISTRY_NETWORK: barman-cloud-plugin
6+
REGISTRY_NAME: registry.barman-cloud-plugin
7+
REGISTRY_PORT: 5000
8+
DAGGER_ENGINE_CONTAINER_NAME: e2e-dagger-engine
9+
310
tasks:
411
lint:
512
desc: Run golangci-lint
@@ -66,32 +73,133 @@ tasks:
6673
sources:
6774
- ./**/*.go
6875

76+
generate-certs:
77+
desc: Generate certificates for the local registry
78+
run: once
79+
cmds:
80+
- >
81+
mkdir -p certs &&
82+
pushd certs &&
83+
openssl genrsa -out ca-key.pem 4096 &&
84+
openssl req -new -x509 -days 365 -key ca-key.pem -sha256 -out ca.pem \
85+
-subj "/O=CloudNativePG/OU=Barman Cloud Plugin Testing" &&
86+
openssl genrsa -out server-key.pem 4096 &&
87+
openssl req -subj "/CN=${REGISTRY_NAME}" -sha256 -new -key server-key.pem -out server.csr &&
88+
echo subjectAltName = DNS:${REGISTRY_NAME},IP:127.0.0.1 >> extfile.cnf &&
89+
echo extendedKeyUsage = serverAuth >> extfile.cnf &&
90+
openssl x509 -req -days 365 -sha256 -in server.csr -CA ca.pem -CAkey ca-key.pem \
91+
-CAcreateserial -out server-cert.pem -extfile extfile.cnf &&
92+
popd
93+
status:
94+
- test -f certs/ca-key.pem
95+
- test -f certs/ca.pem
96+
- test -f certs/server-key.pem
97+
- test -f certs/server.csr
98+
- test -f certs/server-cert.pem
99+
100+
start-build-network:
101+
desc: Create a docker network for image building used by the dagger engine and the registry
102+
run: once
103+
cmds:
104+
- docker network create ${REGISTRY_NETWORK}
105+
status:
106+
- docker network inspect ${REGISTRY_NETWORK}
107+
108+
start-registry:
109+
desc: Start a container registry
110+
run: once
111+
deps:
112+
- generate-certs
113+
- start-build-network
114+
env:
115+
# TODO: renovate
116+
REGISTRY_VERSION: 2
117+
cmds:
118+
- >
119+
docker run -d --name ${REGISTRY_NAME}
120+
-p ${REGISTRY_PORT}:5000
121+
--network ${REGISTRY_NETWORK}
122+
-v $(pwd)/certs:/certs
123+
-e REGISTRY_HTTP_TLS_CERTIFICATE=/certs/server-cert.pem -e REGISTRY_HTTP_TLS_KEY=/certs/server-key.pem
124+
registry:${REGISTRY_VERSION}
125+
status:
126+
- \[ "$(docker inspect -f {{`'{{.State.Running}}'`}} "${REGISTRY_NAME}" 2> /dev/null )" == 'true' \]
127+
128+
129+
# Start a dagger engine that mounts the CA certificate for the local registry.
130+
start-dagger-engine-for-local-builds:
131+
desc: Start a dagger engine mounting the CA
132+
run: once
133+
deps:
134+
- generate-certs
135+
- start-build-network
136+
env:
137+
# TODO: renovate
138+
DAGGER_ENGINE_IMAGE: registry.dagger.io/engine:v0.13.6
139+
cmds:
140+
- >
141+
docker run -d -v /var/lib/dagger --name "${DAGGER_ENGINE_CONTAINER_NAME}"
142+
--network=${REGISTRY_NETWORK}
143+
-v $(pwd)/certs/ca.pem:/usr/local/share/ca-certificates/ca.crt
144+
--privileged ${DAGGER_ENGINE_IMAGE}
145+
status:
146+
- \[ "$(docker inspect -f {{`'{{.State.Running}}'`}} "${DAGGER_ENGINE_CONTAINER_NAME}" 2> /dev/null )" == 'true' \]
147+
148+
# We build an image and push it to a local registry.
149+
# The name is always `plugin-barman-cloud:testing`.
69150
build-plugin-image:
70151
desc: Build the operator container image for the plugin
152+
deps:
153+
- start-registry
154+
- start-dagger-engine-for-local-builds
71155
env:
72156
# renovate: datasource=git-refs depName=docker lookupName=https://github.com/purpleclay/daggerverse currentValue=main
73157
DAGGER_DOCKER_SHA: 4778f39b9cf56e0242c124000a563f9486dafa4b
158+
_EXPERIMENTAL_DAGGER_RUNNER_HOST: docker-container://{{.DAGGER_ENGINE_CONTAINER_NAME}}
74159
cmds:
75160
- >
76-
GITHUB_REF= dagger -s call -m github.com/purpleclay/daggerverse/docker@${DAGGER_DOCKER_SHA}
77-
build --dir . --file containers/Dockerfile.plugin --platform linux/amd64 image > /dev/null
161+
GITHUB_REF= dagger call -m github.com/purpleclay/daggerverse/docker@${DAGGER_DOCKER_SHA}
162+
build --dir . --file containers/Dockerfile.plugin --platform linux/amd64
163+
publish --ref ${REGISTRY_NAME}:${REGISTRY_PORT}/plugin-barman-cloud --tags testing
78164
165+
# We build an image and push it to a local registry.
166+
# The name is always `sidecar-barman-cloud:testing`.
79167
build-sidecar-image:
80168
desc: Build the sidecar container image for the plugin
169+
deps:
170+
- start-registry
171+
- start-dagger-engine-for-local-builds
81172
env:
82173
# renovate: datasource=git-refs depName=docker lookupName=https://github.com/purpleclay/daggerverse currentValue=main
83174
DAGGER_DOCKER_SHA: 4778f39b9cf56e0242c124000a563f9486dafa4b
175+
_EXPERIMENTAL_DAGGER_RUNNER_HOST: docker-container://{{.DAGGER_ENGINE_CONTAINER_NAME}}
84176
cmds:
85177
- >
86-
GITHUB_REF= dagger -s call -m github.com/purpleclay/daggerverse/docker@${DAGGER_DOCKER_SHA}
87-
build --dir . --file containers/Dockerfile.sidecar --platform linux/amd64 image > /dev/null
178+
GITHUB_REF= dagger call -m github.com/purpleclay/daggerverse/docker@${DAGGER_DOCKER_SHA}
179+
build --dir . --file containers/Dockerfile.sidecar --platform linux/amd64
180+
publish --ref ${REGISTRY_NAME}:${REGISTRY_PORT}/sidecar-barman-cloud --tags testing
88181
89182
build-images:
90183
desc: Build the container images for the plugin
91184
deps:
92185
- build-plugin-image
93186
- build-sidecar-image
94187

188+
# TODO: see if it is possible to daggerize this. It will have to manage docker to make kind work.
189+
# TODO: add a task to clean up the kind cluster for new test runs.
190+
# Run the e2e tests. This task will start a kind cluster, deploy the plugin, and run the tests.
191+
# Running the e2e tests requires:
192+
# * The registry to have a valid TLS certificate.
193+
# * The registry to be in the same network of the dagger-engine.
194+
# * The dagger-engine to mount the CA.
195+
# * The kind cluster to mount the CA.
196+
e2e:
197+
desc: Run e2e tests
198+
deps:
199+
- build-images
200+
cmds:
201+
- go test -v ./test/e2e
202+
95203
ci:
96204
desc: Run the CI pipeline
97205
deps:
@@ -100,7 +208,7 @@ tasks:
100208
- uncommitted
101209
- lint
102210
- go-test
103-
- build-images
211+
- e2e
104212

105213
publish:
106214
desc: Build and publish a container image for the plugin
@@ -125,12 +233,12 @@ tasks:
125233
DAGGER_DOCKER_SHA: 4778f39b9cf56e0242c124000a563f9486dafa4b
126234
cmds:
127235
- >
128-
dagger -s call -m github.com/purpleclay/daggerverse/docker@${DAGGER_DOCKER_SHA}
236+
dagger call -m github.com/purpleclay/daggerverse/docker@${DAGGER_DOCKER_SHA}
129237
--registry ghcr.io --username $REGISTRY_USER --password env:REGISTRY_PASSWORD
130238
build --dir . --file containers/Dockerfile.plugin --platform linux/amd64 --platform linux/arm64
131239
publish --ref {{.PLUGIN_IMAGE_NAME}} --tags {{.IMAGE_VERSION}}
132240
- >
133-
dagger -s call -m github.com/purpleclay/daggerverse/docker@${DAGGER_DOCKER_SHA}
241+
dagger call -m github.com/purpleclay/daggerverse/docker@${DAGGER_DOCKER_SHA}
134242
--registry ghcr.io --username $REGISTRY_USER --password env:REGISTRY_PASSWORD
135243
build --dir . --file containers/Dockerfile.sidecar --platform linux/amd64 --platform linux/arm64
136244
publish --ref {{.SIDECAR_IMAGE_NAME}} --tags {{.IMAGE_VERSION}}

go.mod

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,31 @@ go 1.23
55
toolchain go1.23.1
66

77
require (
8-
github.com/cloudnative-pg/barman-cloud v0.0.0-20240924124724-92831d48562a
9-
github.com/cloudnative-pg/cloudnative-pg v1.24.1-0.20241031170209-ad2b0d78a230
10-
github.com/cloudnative-pg/cnpg-i v0.0.0-20241030162745-80b6d07403c1
8+
github.com/cert-manager/cert-manager v1.16.1
9+
github.com/cloudnative-pg/barman-cloud v0.0.0-20241105055149-ae6c2408bd14
10+
github.com/cloudnative-pg/cloudnative-pg v1.24.1-0.20241113134512-8608232c2813
11+
github.com/cloudnative-pg/cnpg-i v0.0.0-20241109002750-8abd359df734
1112
github.com/cloudnative-pg/cnpg-i-machinery v0.0.0-20241014090747-e9c2b3738d19
12-
github.com/cloudnative-pg/machinery v0.0.0-20241014090714-c27747f9974b
13-
github.com/onsi/ginkgo/v2 v2.20.2
14-
github.com/onsi/gomega v1.34.2
13+
github.com/cloudnative-pg/machinery v0.0.0-20241030141148-670a0f16f836
14+
github.com/onsi/ginkgo/v2 v2.21.0
15+
github.com/onsi/gomega v1.35.1
1516
github.com/spf13/cobra v1.8.1
1617
github.com/spf13/viper v1.19.0
17-
google.golang.org/grpc v1.67.1
18+
google.golang.org/grpc v1.68.0
19+
gopkg.in/yaml.v3 v3.0.1
1820
k8s.io/api v0.31.2
21+
k8s.io/apiextensions-apiserver v0.31.2
1922
k8s.io/apimachinery v0.31.2
2023
k8s.io/client-go v0.31.2
21-
k8s.io/utils v0.0.0-20240921022957-49e7df575cb6
24+
k8s.io/utils v0.0.0-20241104163129-6fe5fd82f078
2225
sigs.k8s.io/controller-runtime v0.19.1
26+
sigs.k8s.io/kustomize/api v0.17.3
27+
sigs.k8s.io/kustomize/kyaml v0.17.2
2328
)
2429

2530
require (
2631
github.com/antlr4-go/antlr/v4 v4.13.0 // indirect
27-
github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a // indirect
32+
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 // indirect
2833
github.com/beorn7/perks v1.0.1 // indirect
2934
github.com/blang/semver v3.5.1+incompatible // indirect
3035
github.com/blang/semver/v4 v4.0.0 // indirect
@@ -37,6 +42,7 @@ require (
3742
github.com/felixge/httpsnoop v1.0.4 // indirect
3843
github.com/fsnotify/fsnotify v1.7.0 // indirect
3944
github.com/fxamacker/cbor/v2 v2.7.0 // indirect
45+
github.com/go-errors/errors v1.5.1 // indirect
4046
github.com/go-logr/logr v1.4.2 // indirect
4147
github.com/go-logr/stdr v1.2.2 // indirect
4248
github.com/go-logr/zapr v1.3.0 // indirect
@@ -51,12 +57,13 @@ require (
5157
github.com/google/gnostic-models v0.6.8 // indirect
5258
github.com/google/go-cmp v0.6.0 // indirect
5359
github.com/google/gofuzz v1.2.0 // indirect
54-
github.com/google/pprof v0.0.0-20240910150728-a0b0bb1d4134 // indirect
60+
github.com/google/pprof v0.0.0-20241029153458-d1b30febd7db // indirect
61+
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
5562
github.com/google/uuid v1.6.0 // indirect
56-
github.com/gorilla/websocket v1.5.0 // indirect
63+
github.com/gorilla/websocket v1.5.1 // indirect
5764
github.com/grpc-ecosystem/go-grpc-middleware/v2 v2.1.0 // indirect
5865
github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0 // indirect
59-
github.com/hashicorp/hcl v1.0.0 // indirect
66+
github.com/hashicorp/hcl v1.0.1-vault-5 // indirect
6067
github.com/imdario/mergo v0.3.16 // indirect
6168
github.com/inconshreveable/mousetrap v1.1.0 // indirect
6269
github.com/josharian/intern v1.0.0 // indirect
@@ -70,11 +77,12 @@ require (
7077
github.com/moby/spdystream v0.4.0 // indirect
7178
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
7279
github.com/modern-go/reflect2 v1.0.2 // indirect
80+
github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00 // indirect
7381
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
7482
github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f // indirect
7583
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
7684
github.com/pkg/errors v0.9.1 // indirect
77-
github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring v0.77.2 // indirect
85+
github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring v0.78.1 // indirect
7886
github.com/prometheus/client_golang v1.20.5 // indirect
7987
github.com/prometheus/client_model v0.6.1 // indirect
8088
github.com/prometheus/common v0.59.1 // indirect
@@ -91,14 +99,16 @@ require (
9199
github.com/subosito/gotenv v1.6.0 // indirect
92100
github.com/thoas/go-funk v0.9.3 // indirect
93101
github.com/x448/float16 v0.8.4 // indirect
94-
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.53.0 // indirect
95-
go.opentelemetry.io/otel v1.28.0 // indirect
102+
github.com/xlab/treeprint v1.2.0 // indirect
103+
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.54.0 // indirect
104+
go.opentelemetry.io/otel v1.29.0 // indirect
96105
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.28.0 // indirect
97106
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.27.0 // indirect
98-
go.opentelemetry.io/otel/metric v1.28.0 // indirect
107+
go.opentelemetry.io/otel/metric v1.29.0 // indirect
99108
go.opentelemetry.io/otel/sdk v1.28.0 // indirect
100-
go.opentelemetry.io/otel/trace v1.28.0 // indirect
109+
go.opentelemetry.io/otel/trace v1.29.0 // indirect
101110
go.opentelemetry.io/proto/otlp v1.3.1 // indirect
111+
go.starlark.net v0.0.0-20240925182052-1207426daebd // indirect
102112
go.uber.org/multierr v1.11.0 // indirect
103113
go.uber.org/zap v1.27.0 // indirect
104114
golang.org/x/exp v0.0.0-20240909161429-701f63a606c0 // indirect
@@ -109,21 +119,21 @@ require (
109119
golang.org/x/term v0.25.0 // indirect
110120
golang.org/x/text v0.19.0 // indirect
111121
golang.org/x/time v0.7.0 // indirect
112-
golang.org/x/tools v0.25.0 // indirect
122+
golang.org/x/tools v0.26.0 // indirect
113123
gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect
114-
google.golang.org/genproto/googleapis/api v0.0.0-20240814211410-ddb44dafa142 // indirect
115-
google.golang.org/genproto/googleapis/rpc v0.0.0-20240814211410-ddb44dafa142 // indirect
124+
google.golang.org/genproto/googleapis/api v0.0.0-20240903143218-8af14fe29dc1 // indirect
125+
google.golang.org/genproto/googleapis/rpc v0.0.0-20240903143218-8af14fe29dc1 // indirect
116126
google.golang.org/protobuf v1.35.1 // indirect
127+
gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect
117128
gopkg.in/inf.v0 v0.9.1 // indirect
118129
gopkg.in/ini.v1 v1.67.0 // indirect
119130
gopkg.in/yaml.v2 v2.4.0 // indirect
120-
gopkg.in/yaml.v3 v3.0.1 // indirect
121-
k8s.io/apiextensions-apiserver v0.31.2 // indirect
122131
k8s.io/apiserver v0.31.2 // indirect
123132
k8s.io/component-base v0.31.2 // indirect
124133
k8s.io/klog/v2 v2.130.1 // indirect
125134
k8s.io/kube-openapi v0.0.0-20240903163716-9e1beecbcb38 // indirect
126135
sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.30.3 // indirect
136+
sigs.k8s.io/gateway-api v1.1.0 // indirect
127137
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
128138
sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect
129139
sigs.k8s.io/yaml v1.4.0 // indirect

0 commit comments

Comments
 (0)