Skip to content

Commit 6ad1054

Browse files
committed
ci: avoid using TLS for e2e test registry
We can mount a toml configuration in a custom dagger engine that allows buildkit to use a http registry. This simplifies the CI workflows. Signed-off-by: Francesco Canovai <[email protected]>
1 parent 3f0a6b0 commit 6ad1054

File tree

4 files changed

+42
-73
lines changed

4 files changed

+42
-73
lines changed

Taskfile.yml

Lines changed: 30 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
version: 3
22

3-
# Environment variables that are shared across tasks.
4-
env:
5-
REGISTRY_NETWORK: barman-cloud-plugin
3+
vars:
64
REGISTRY_NAME: registry.barman-cloud-plugin
7-
REGISTRY_PORT: 5000
5+
REGISTRY_PORT: 5001
86
DAGGER_ENGINE_CONTAINER_NAME: e2e-dagger-engine
97

108
tasks:
@@ -78,78 +76,36 @@ tasks:
7876
sources:
7977
- ./**/*.go
8078

81-
generate-certs:
82-
desc: Generate certificates for the local registry
83-
run: once
84-
cmds:
85-
- >
86-
mkdir -p certs &&
87-
pushd certs &&
88-
openssl genrsa -out ca-key.pem 4096 &&
89-
openssl req -new -x509 -days 365 -key ca-key.pem -sha256 -out ca.pem \
90-
-subj "/O=CloudNativePG/OU=Barman Cloud Plugin Testing" &&
91-
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 &&
94-
echo extendedKeyUsage = serverAuth >> extfile.cnf &&
95-
openssl x509 -req -days 365 -sha256 -in server.csr -CA ca.pem -CAkey ca-key.pem \
96-
-CAcreateserial -out server-cert.pem -extfile extfile.cnf &&
97-
popd
98-
status:
99-
- test -f certs/ca-key.pem
100-
- test -f certs/ca.pem
101-
- test -f certs/server-key.pem
102-
- test -f certs/server.csr
103-
- test -f certs/server-cert.pem
104-
105-
start-build-network:
106-
desc: Create a docker network for image building used by the dagger engine and the registry
107-
run: once
108-
cmds:
109-
- docker network create ${REGISTRY_NETWORK}
110-
status:
111-
- docker network inspect ${REGISTRY_NETWORK}
112-
11379
start-registry:
11480
desc: Start a container registry
11581
run: once
116-
deps:
117-
- generate-certs
118-
- start-build-network
119-
env:
82+
vars:
12083
# TODO: renovate
12184
REGISTRY_VERSION: 2
12285
cmds:
12386
- >
124-
docker run -d --name ${REGISTRY_NAME}
125-
-p ${REGISTRY_PORT}:5000
126-
--network ${REGISTRY_NETWORK}
127-
-v $(pwd)/certs:/certs
128-
-e REGISTRY_HTTP_TLS_CERTIFICATE=/certs/server-cert.pem -e REGISTRY_HTTP_TLS_KEY=/certs/server-key.pem
129-
registry:${REGISTRY_VERSION}
87+
docker run -d --name {{ .REGISTRY_NAME }}
88+
-p {{ .REGISTRY_PORT }}:5000
89+
registry:{{ .REGISTRY_VERSION }}
13090
status:
131-
- \[ "$(docker inspect -f {{`'{{.State.Running}}'`}} "${REGISTRY_NAME}" 2> /dev/null )" == 'true' \]
132-
91+
- \[ "$(docker inspect -f {{`'{{.State.Running}}'`}} "{{ .REGISTRY_NAME }}" 2> /dev/null )" == 'true' \]
13392

134-
# Start a dagger engine that mounts the CA certificate for the local registry.
93+
# Start a dagger engine that can use the local registry.
13594
start-dagger-engine-for-local-builds:
136-
desc: Start a dagger engine mounting the CA
95+
desc: Start a dagger engine
13796
run: once
138-
deps:
139-
- generate-certs
140-
- start-build-network
14197
vars:
14298
# renovate: datasource=github-tags depName=dagger/dagger versioning=semver
14399
DAGGER_VERSION: 0.15.1
144100
DAGGER_ENGINE_IMAGE: registry.dagger.io/engine:v{{ .DAGGER_VERSION }}
145101
cmds:
146102
- >
147-
docker run -d -v /var/lib/dagger --name "${DAGGER_ENGINE_CONTAINER_NAME}"
148-
--network=${REGISTRY_NETWORK}
149-
-v $(pwd)/certs/ca.pem:/usr/local/share/ca-certificates/ca.crt
103+
docker run -d -v /var/lib/dagger --name "{{ .DAGGER_ENGINE_CONTAINER_NAME }}"
104+
-v $(pwd)/hack/dagger-engine.toml:/etc/dagger/engine.toml
105+
--add-host "{{ .REGISTRY_NAME }}:host-gateway"
150106
--privileged {{ .DAGGER_ENGINE_IMAGE }}
151107
status:
152-
- \[ "$(docker inspect -f {{`'{{.State.Running}}'`}} "${DAGGER_ENGINE_CONTAINER_NAME}" 2> /dev/null )" == 'true' \]
108+
- \[ "$(docker inspect -f {{`'{{.State.Running}}'`}} "{{ .DAGGER_ENGINE_CONTAINER_NAME }}" 2> /dev/null )" == 'true' \]
153109

154110
# We build an image and push it to a local registry.
155111
# The name is always `plugin-barman-cloud:testing`.
@@ -161,12 +117,19 @@ tasks:
161117
env:
162118
# renovate: datasource=git-refs depName=docker lookupName=https://github.com/purpleclay/daggerverse currentValue=main
163119
DAGGER_DOCKER_SHA: 14c1374e5878f082939aab575c36cdad19920e0d
164-
_EXPERIMENTAL_DAGGER_RUNNER_HOST: docker-container://{{.DAGGER_ENGINE_CONTAINER_NAME}}
120+
_EXPERIMENTAL_DAGGER_RUNNER_HOST: docker-container://{{ .DAGGER_ENGINE_CONTAINER_NAME }}
165121
cmds:
166122
- >
167123
GITHUB_REF= dagger call -m github.com/purpleclay/daggerverse/docker@${DAGGER_DOCKER_SHA}
168124
build --dir . --file containers/Dockerfile.plugin --platform linux/amd64
169-
publish --ref ${REGISTRY_NAME}:${REGISTRY_PORT}/plugin-barman-cloud --tags testing
125+
publish --ref {{ .REGISTRY_NAME }}:{{ .REGISTRY_PORT }}/plugin-barman-cloud --tags testing
126+
sources:
127+
- ./go.mod
128+
- ./go.sum
129+
- ./containers/Dockerfile.plugin
130+
- ./**/*.go
131+
- ./Taskfile.yml
132+
- exclude: ./test/e2e/**
170133

171134
# We build an image and push it to a local registry.
172135
# The name is always `sidecar-barman-cloud:testing`.
@@ -183,7 +146,14 @@ tasks:
183146
- >
184147
GITHUB_REF= dagger call -m github.com/purpleclay/daggerverse/docker@${DAGGER_DOCKER_SHA}
185148
build --dir . --file containers/Dockerfile.sidecar --platform linux/amd64
186-
publish --ref ${REGISTRY_NAME}:${REGISTRY_PORT}/sidecar-barman-cloud --tags testing
149+
publish --ref {{ .REGISTRY_NAME }}:{{ .REGISTRY_PORT }}/sidecar-barman-cloud --tags testing
150+
sources:
151+
- ./go.mod
152+
- ./go.sum
153+
- ./containers/Dockerfile.sidecar
154+
- ./**/*.go
155+
- ./Taskfile.yml
156+
- exclude: ./test/e2e/**
187157

188158
build-images:
189159
desc: Build the container images for the plugin
@@ -194,11 +164,6 @@ tasks:
194164
# TODO: see if it is possible to daggerize this. It will have to manage docker to make kind work.
195165
# TODO: add a task to clean up the kind cluster for new test runs.
196166
# Run the e2e tests. This task will start a kind cluster, deploy the plugin, and run the tests.
197-
# Running the e2e tests requires:
198-
# * The registry to have a valid TLS certificate.
199-
# * The registry to be in the same network of the dagger-engine.
200-
# * The dagger-engine to mount the CA.
201-
# * The kind cluster to mount the CA.
202167
e2e:
203168
desc: Run e2e tests
204169
deps:

hack/dagger-engine.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
trace = false
2+
insecure-entitlements = ["security.insecure"]
3+
4+
[registry."registry.barman-cloud-plugin:5001"]
5+
http = true

test/e2e/config/kind-config.yaml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,3 @@ kind: Cluster
55
apiVersion: kind.x-k8s.io/v1alpha4
66
nodes:
77
- role: control-plane
8-
extraMounts:
9-
- hostPath: ../../certs/ca.pem
10-
containerPath: /usr/local/share/ca-certificates/ca.crt
11-
readOnly: true

test/e2e/e2e_suite_test.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,13 @@ import (
3939
. "github.com/onsi/gomega"
4040
)
4141

42+
const testRegistry = "registry.barman-cloud-plugin:5001"
43+
4244
// We don't want multiple ginkgo nodes to run the setup concurrently, we use a single cluster for all tests.
4345
var _ = SynchronizedBeforeSuite(func(ctx SpecContext) []byte {
4446
var cl client.Client
4547
var err error
46-
if cl, err = e2etestenv.Setup(ctx,
47-
e2etestenv.WithKindAdditionalNetworks([]string{"barman-cloud-plugin"})); err != nil {
48+
if cl, err = e2etestenv.Setup(ctx); err != nil {
4849
Fail(fmt.Sprintf("failed to setup environment: %v", err))
4950
}
5051

@@ -54,7 +55,7 @@ var _ = SynchronizedBeforeSuite(func(ctx SpecContext) []byte {
5455
Images: []kustomizeTypes.Image{
5556
{
5657
Name: "docker.io/library/plugin-barman-cloud",
57-
NewName: "registry.barman-cloud-plugin:5000/plugin-barman-cloud",
58+
NewName: fmt.Sprintf("%v:5001/plugin-barman-cloud", testRegistry),
5859
NewTag: "testing",
5960
},
6061
},
@@ -64,7 +65,9 @@ var _ = SynchronizedBeforeSuite(func(ctx SpecContext) []byte {
6465
Name: "plugin-barman-cloud",
6566
Behavior: "replace",
6667
KvPairSources: kustomizeTypes.KvPairSources{
67-
LiteralSources: []string{"SIDECAR_IMAGE=registry.barman-cloud-plugin:5000/sidecar-barman-cloud:testing"},
68+
LiteralSources: []string{
69+
fmt.Sprintf("SIDECAR_IMAGE=%v/sidecar-barman-cloud:testing", testRegistry),
70+
},
6871
},
6972
},
7073
},

0 commit comments

Comments
 (0)