Skip to content

Commit a519607

Browse files
committed
rete funzionante
Signed-off-by: Francesco Canovai <[email protected]>
1 parent 3f0a6b0 commit a519607

File tree

5 files changed

+55
-62
lines changed

5 files changed

+55
-62
lines changed

Taskfile.yml

Lines changed: 34 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
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
5+
REGISTRY_NETWORK: barman-cloud-plugin
6+
REGISTRY_EXTERNAL_PORT: '{{ default 5000 .REGISTRY_EXTERNAL_PORT }}'
77
REGISTRY_PORT: 5000
88
DAGGER_ENGINE_CONTAINER_NAME: e2e-dagger-engine
99

@@ -78,78 +78,47 @@ tasks:
7878
sources:
7979
- ./**/*.go
8080

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-
10581
start-build-network:
10682
desc: Create a docker network for image building used by the dagger engine and the registry
10783
run: once
10884
cmds:
109-
- docker network create ${REGISTRY_NETWORK}
85+
- docker network create {{ .REGISTRY_NETWORK }}
11086
status:
111-
- docker network inspect ${REGISTRY_NETWORK}
87+
- docker network inspect {{ .REGISTRY_NETWORK }}
11288

11389
start-registry:
11490
desc: Start a container registry
11591
run: once
11692
deps:
117-
- generate-certs
11893
- start-build-network
119-
env:
94+
vars:
12095
# TODO: renovate
12196
REGISTRY_VERSION: 2
12297
cmds:
12398
- >
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}
99+
docker run -d --name {{ .REGISTRY_NAME }}
100+
--network {{ .REGISTRY_NETWORK }}
101+
-p {{ .REGISTRY_EXTERNAL_PORT }}:{{ .REGISTRY_PORT }}
102+
registry:{{ .REGISTRY_VERSION }}
130103
status:
131-
- \[ "$(docker inspect -f {{`'{{.State.Running}}'`}} "${REGISTRY_NAME}" 2> /dev/null )" == 'true' \]
104+
- \[ "$(docker inspect -f {{`'{{.State.Running}}'`}} "{{ .REGISTRY_NAME }}" 2> /dev/null )" == 'true' \]
132105

133-
134-
# Start a dagger engine that mounts the CA certificate for the local registry.
106+
# Start a dagger engine that can use the local registry.
135107
start-dagger-engine-for-local-builds:
136-
desc: Start a dagger engine mounting the CA
108+
desc: Start a dagger engine
137109
run: once
138-
deps:
139-
- generate-certs
140-
- start-build-network
141110
vars:
142111
# renovate: datasource=github-tags depName=dagger/dagger versioning=semver
143112
DAGGER_VERSION: 0.15.1
144113
DAGGER_ENGINE_IMAGE: registry.dagger.io/engine:v{{ .DAGGER_VERSION }}
145114
cmds:
146115
- >
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
116+
docker run -d -v /var/lib/dagger --name "{{ .DAGGER_ENGINE_CONTAINER_NAME }}"
117+
-v $(pwd)/hack/dagger-engine.toml:/etc/dagger/engine.toml
118+
--network {{ .REGISTRY_NETWORK }}
150119
--privileged {{ .DAGGER_ENGINE_IMAGE }}
151120
status:
152-
- \[ "$(docker inspect -f {{`'{{.State.Running}}'`}} "${DAGGER_ENGINE_CONTAINER_NAME}" 2> /dev/null )" == 'true' \]
121+
- \[ "$(docker inspect -f {{`'{{.State.Running}}'`}} "{{ .DAGGER_ENGINE_CONTAINER_NAME }}" 2> /dev/null )" == 'true' \]
153122

154123
# We build an image and push it to a local registry.
155124
# The name is always `plugin-barman-cloud:testing`.
@@ -161,12 +130,19 @@ tasks:
161130
env:
162131
# renovate: datasource=git-refs depName=docker lookupName=https://github.com/purpleclay/daggerverse currentValue=main
163132
DAGGER_DOCKER_SHA: 14c1374e5878f082939aab575c36cdad19920e0d
164-
_EXPERIMENTAL_DAGGER_RUNNER_HOST: docker-container://{{.DAGGER_ENGINE_CONTAINER_NAME}}
133+
_EXPERIMENTAL_DAGGER_RUNNER_HOST: docker-container://{{ .DAGGER_ENGINE_CONTAINER_NAME }}
165134
cmds:
166135
- >
167136
GITHUB_REF= dagger call -m github.com/purpleclay/daggerverse/docker@${DAGGER_DOCKER_SHA}
168137
build --dir . --file containers/Dockerfile.plugin --platform linux/amd64
169-
publish --ref ${REGISTRY_NAME}:${REGISTRY_PORT}/plugin-barman-cloud --tags testing
138+
publish --ref {{ .REGISTRY_NAME }}:{{ .REGISTRY_PORT }}/plugin-barman-cloud --tags testing
139+
sources:
140+
- ./go.mod
141+
- ./go.sum
142+
- ./containers/Dockerfile.plugin
143+
- ./**/*.go
144+
- ./Taskfile.yml
145+
- exclude: ./test/e2e/**
170146

171147
# We build an image and push it to a local registry.
172148
# The name is always `sidecar-barman-cloud:testing`.
@@ -183,7 +159,14 @@ tasks:
183159
- >
184160
GITHUB_REF= dagger call -m github.com/purpleclay/daggerverse/docker@${DAGGER_DOCKER_SHA}
185161
build --dir . --file containers/Dockerfile.sidecar --platform linux/amd64
186-
publish --ref ${REGISTRY_NAME}:${REGISTRY_PORT}/sidecar-barman-cloud --tags testing
162+
publish --ref {{ .REGISTRY_NAME }}:{{ .REGISTRY_PORT }}/sidecar-barman-cloud --tags testing
163+
sources:
164+
- ./go.mod
165+
- ./go.sum
166+
- ./containers/Dockerfile.sidecar
167+
- ./**/*.go
168+
- ./Taskfile.yml
169+
- exclude: ./test/e2e/**
187170

188171
build-images:
189172
desc: Build the container images for the plugin
@@ -194,11 +177,6 @@ tasks:
194177
# TODO: see if it is possible to daggerize this. It will have to manage docker to make kind work.
195178
# TODO: add a task to clean up the kind cluster for new test runs.
196179
# 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.
202180
e2e:
203181
desc: Run e2e tests
204182
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:5000"]
5+
http = true
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[host."http://registry.barman-cloud-plugin:5000"]

test/e2e/config/kind-config.yaml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ apiVersion: kind.x-k8s.io/v1alpha4
66
nodes:
77
- role: control-plane
88
extraMounts:
9-
- hostPath: ../../certs/ca.pem
10-
containerPath: /usr/local/share/ca-certificates/ca.crt
11-
readOnly: true
9+
- hostPath: config/certs.d/
10+
containerPath: "/etc/containerd/certs.d/"
11+
readOnly: true
12+
containerdConfigPatches:
13+
- |-
14+
[plugins."io.containerd.grpc.v1.cri".registry]
15+
config_path = "/etc/containerd/certs.d"

test/e2e/e2e_suite_test.go

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

42+
const testRegistry = "registry.barman-cloud-plugin:5000"
43+
const testNetwork = "barman-cloud-plugin"
44+
4245
// We don't want multiple ginkgo nodes to run the setup concurrently, we use a single cluster for all tests.
4346
var _ = SynchronizedBeforeSuite(func(ctx SpecContext) []byte {
4447
var cl client.Client
4548
var err error
4649
if cl, err = e2etestenv.Setup(ctx,
47-
e2etestenv.WithKindAdditionalNetworks([]string{"barman-cloud-plugin"})); err != nil {
50+
e2etestenv.WithKindAdditionalNetworks([]string{testNetwork})); err != nil {
4851
Fail(fmt.Sprintf("failed to setup environment: %v", err))
4952
}
5053

@@ -54,7 +57,7 @@ var _ = SynchronizedBeforeSuite(func(ctx SpecContext) []byte {
5457
Images: []kustomizeTypes.Image{
5558
{
5659
Name: "docker.io/library/plugin-barman-cloud",
57-
NewName: "registry.barman-cloud-plugin:5000/plugin-barman-cloud",
60+
NewName: fmt.Sprintf("%v/plugin-barman-cloud", testRegistry),
5861
NewTag: "testing",
5962
},
6063
},
@@ -64,7 +67,9 @@ var _ = SynchronizedBeforeSuite(func(ctx SpecContext) []byte {
6467
Name: "plugin-barman-cloud",
6568
Behavior: "replace",
6669
KvPairSources: kustomizeTypes.KvPairSources{
67-
LiteralSources: []string{"SIDECAR_IMAGE=registry.barman-cloud-plugin:5000/sidecar-barman-cloud:testing"},
70+
LiteralSources: []string{
71+
fmt.Sprintf("SIDECAR_IMAGE=%v/sidecar-barman-cloud:testing", testRegistry),
72+
},
6873
},
6974
},
7075
},

0 commit comments

Comments
 (0)