rete funzionante

Signed-off-by: Francesco Canovai <francesco.canovai@enterprisedb.com>
This commit is contained in:
Francesco Canovai 2024-12-17 17:04:08 +01:00
parent 3f0a6b0232
commit a5196074cc
No known key found for this signature in database
GPG Key ID: C3867DCF133BFEB6
5 changed files with 55 additions and 62 deletions

View File

@ -1,9 +1,9 @@
version: 3 version: 3
# Environment variables that are shared across tasks. vars:
env:
REGISTRY_NETWORK: barman-cloud-plugin
REGISTRY_NAME: registry.barman-cloud-plugin REGISTRY_NAME: registry.barman-cloud-plugin
REGISTRY_NETWORK: barman-cloud-plugin
REGISTRY_EXTERNAL_PORT: '{{ default 5000 .REGISTRY_EXTERNAL_PORT }}'
REGISTRY_PORT: 5000 REGISTRY_PORT: 5000
DAGGER_ENGINE_CONTAINER_NAME: e2e-dagger-engine DAGGER_ENGINE_CONTAINER_NAME: e2e-dagger-engine
@ -78,78 +78,47 @@ tasks:
sources: sources:
- ./**/*.go - ./**/*.go
generate-certs:
desc: Generate certificates for the local registry
run: once
cmds:
- >
mkdir -p certs &&
pushd certs &&
openssl genrsa -out ca-key.pem 4096 &&
openssl req -new -x509 -days 365 -key ca-key.pem -sha256 -out ca.pem \
-subj "/O=CloudNativePG/OU=Barman Cloud Plugin Testing" &&
openssl genrsa -out server-key.pem 4096 &&
openssl req -subj "/CN=${REGISTRY_NAME}" -sha256 -new -key server-key.pem -out server.csr &&
echo subjectAltName = DNS:${REGISTRY_NAME},IP:127.0.0.1 >> extfile.cnf &&
echo extendedKeyUsage = serverAuth >> extfile.cnf &&
openssl x509 -req -days 365 -sha256 -in server.csr -CA ca.pem -CAkey ca-key.pem \
-CAcreateserial -out server-cert.pem -extfile extfile.cnf &&
popd
status:
- test -f certs/ca-key.pem
- test -f certs/ca.pem
- test -f certs/server-key.pem
- test -f certs/server.csr
- test -f certs/server-cert.pem
start-build-network: start-build-network:
desc: Create a docker network for image building used by the dagger engine and the registry desc: Create a docker network for image building used by the dagger engine and the registry
run: once run: once
cmds: cmds:
- docker network create ${REGISTRY_NETWORK} - docker network create {{ .REGISTRY_NETWORK }}
status: status:
- docker network inspect ${REGISTRY_NETWORK} - docker network inspect {{ .REGISTRY_NETWORK }}
start-registry: start-registry:
desc: Start a container registry desc: Start a container registry
run: once run: once
deps: deps:
- generate-certs
- start-build-network - start-build-network
env: vars:
# TODO: renovate # TODO: renovate
REGISTRY_VERSION: 2 REGISTRY_VERSION: 2
cmds: cmds:
- > - >
docker run -d --name ${REGISTRY_NAME} docker run -d --name {{ .REGISTRY_NAME }}
-p ${REGISTRY_PORT}:5000 --network {{ .REGISTRY_NETWORK }}
--network ${REGISTRY_NETWORK} -p {{ .REGISTRY_EXTERNAL_PORT }}:{{ .REGISTRY_PORT }}
-v $(pwd)/certs:/certs registry:{{ .REGISTRY_VERSION }}
-e REGISTRY_HTTP_TLS_CERTIFICATE=/certs/server-cert.pem -e REGISTRY_HTTP_TLS_KEY=/certs/server-key.pem
registry:${REGISTRY_VERSION}
status: status:
- \[ "$(docker inspect -f {{`'{{.State.Running}}'`}} "${REGISTRY_NAME}" 2> /dev/null )" == 'true' \] - \[ "$(docker inspect -f {{`'{{.State.Running}}'`}} "{{ .REGISTRY_NAME }}" 2> /dev/null )" == 'true' \]
# Start a dagger engine that can use the local registry.
# Start a dagger engine that mounts the CA certificate for the local registry.
start-dagger-engine-for-local-builds: start-dagger-engine-for-local-builds:
desc: Start a dagger engine mounting the CA desc: Start a dagger engine
run: once run: once
deps:
- generate-certs
- start-build-network
vars: vars:
# renovate: datasource=github-tags depName=dagger/dagger versioning=semver # renovate: datasource=github-tags depName=dagger/dagger versioning=semver
DAGGER_VERSION: 0.15.1 DAGGER_VERSION: 0.15.1
DAGGER_ENGINE_IMAGE: registry.dagger.io/engine:v{{ .DAGGER_VERSION }} DAGGER_ENGINE_IMAGE: registry.dagger.io/engine:v{{ .DAGGER_VERSION }}
cmds: cmds:
- > - >
docker run -d -v /var/lib/dagger --name "${DAGGER_ENGINE_CONTAINER_NAME}" docker run -d -v /var/lib/dagger --name "{{ .DAGGER_ENGINE_CONTAINER_NAME }}"
--network=${REGISTRY_NETWORK} -v $(pwd)/hack/dagger-engine.toml:/etc/dagger/engine.toml
-v $(pwd)/certs/ca.pem:/usr/local/share/ca-certificates/ca.crt --network {{ .REGISTRY_NETWORK }}
--privileged {{ .DAGGER_ENGINE_IMAGE }} --privileged {{ .DAGGER_ENGINE_IMAGE }}
status: status:
- \[ "$(docker inspect -f {{`'{{.State.Running}}'`}} "${DAGGER_ENGINE_CONTAINER_NAME}" 2> /dev/null )" == 'true' \] - \[ "$(docker inspect -f {{`'{{.State.Running}}'`}} "{{ .DAGGER_ENGINE_CONTAINER_NAME }}" 2> /dev/null )" == 'true' \]
# We build an image and push it to a local registry. # We build an image and push it to a local registry.
# The name is always `plugin-barman-cloud:testing`. # The name is always `plugin-barman-cloud:testing`.
@ -166,7 +135,14 @@ tasks:
- > - >
GITHUB_REF= dagger call -m github.com/purpleclay/daggerverse/docker@${DAGGER_DOCKER_SHA} GITHUB_REF= dagger call -m github.com/purpleclay/daggerverse/docker@${DAGGER_DOCKER_SHA}
build --dir . --file containers/Dockerfile.plugin --platform linux/amd64 build --dir . --file containers/Dockerfile.plugin --platform linux/amd64
publish --ref ${REGISTRY_NAME}:${REGISTRY_PORT}/plugin-barman-cloud --tags testing publish --ref {{ .REGISTRY_NAME }}:{{ .REGISTRY_PORT }}/plugin-barman-cloud --tags testing
sources:
- ./go.mod
- ./go.sum
- ./containers/Dockerfile.plugin
- ./**/*.go
- ./Taskfile.yml
- exclude: ./test/e2e/**
# We build an image and push it to a local registry. # We build an image and push it to a local registry.
# The name is always `sidecar-barman-cloud:testing`. # The name is always `sidecar-barman-cloud:testing`.
@ -183,7 +159,14 @@ tasks:
- > - >
GITHUB_REF= dagger call -m github.com/purpleclay/daggerverse/docker@${DAGGER_DOCKER_SHA} GITHUB_REF= dagger call -m github.com/purpleclay/daggerverse/docker@${DAGGER_DOCKER_SHA}
build --dir . --file containers/Dockerfile.sidecar --platform linux/amd64 build --dir . --file containers/Dockerfile.sidecar --platform linux/amd64
publish --ref ${REGISTRY_NAME}:${REGISTRY_PORT}/sidecar-barman-cloud --tags testing publish --ref {{ .REGISTRY_NAME }}:{{ .REGISTRY_PORT }}/sidecar-barman-cloud --tags testing
sources:
- ./go.mod
- ./go.sum
- ./containers/Dockerfile.sidecar
- ./**/*.go
- ./Taskfile.yml
- exclude: ./test/e2e/**
build-images: build-images:
desc: Build the container images for the plugin desc: Build the container images for the plugin
@ -194,11 +177,6 @@ tasks:
# TODO: see if it is possible to daggerize this. It will have to manage docker to make kind work. # TODO: see if it is possible to daggerize this. It will have to manage docker to make kind work.
# TODO: add a task to clean up the kind cluster for new test runs. # TODO: add a task to clean up the kind cluster for new test runs.
# Run the e2e tests. This task will start a kind cluster, deploy the plugin, and run the tests. # Run the e2e tests. This task will start a kind cluster, deploy the plugin, and run the tests.
# Running the e2e tests requires:
# * The registry to have a valid TLS certificate.
# * The registry to be in the same network of the dagger-engine.
# * The dagger-engine to mount the CA.
# * The kind cluster to mount the CA.
e2e: e2e:
desc: Run e2e tests desc: Run e2e tests
deps: deps:

5
hack/dagger-engine.toml Normal file
View File

@ -0,0 +1,5 @@
trace = false
insecure-entitlements = ["security.insecure"]
[registry."registry.barman-cloud-plugin:5000"]
http = true

View File

@ -0,0 +1 @@
[host."http://registry.barman-cloud-plugin:5000"]

View File

@ -6,6 +6,10 @@ apiVersion: kind.x-k8s.io/v1alpha4
nodes: nodes:
- role: control-plane - role: control-plane
extraMounts: extraMounts:
- hostPath: ../../certs/ca.pem - hostPath: config/certs.d/
containerPath: /usr/local/share/ca-certificates/ca.crt containerPath: "/etc/containerd/certs.d/"
readOnly: true readOnly: true
containerdConfigPatches:
- |-
[plugins."io.containerd.grpc.v1.cri".registry]
config_path = "/etc/containerd/certs.d"

View File

@ -39,12 +39,15 @@ import (
. "github.com/onsi/gomega" . "github.com/onsi/gomega"
) )
const testRegistry = "registry.barman-cloud-plugin:5000"
const testNetwork = "barman-cloud-plugin"
// We don't want multiple ginkgo nodes to run the setup concurrently, we use a single cluster for all tests. // We don't want multiple ginkgo nodes to run the setup concurrently, we use a single cluster for all tests.
var _ = SynchronizedBeforeSuite(func(ctx SpecContext) []byte { var _ = SynchronizedBeforeSuite(func(ctx SpecContext) []byte {
var cl client.Client var cl client.Client
var err error var err error
if cl, err = e2etestenv.Setup(ctx, if cl, err = e2etestenv.Setup(ctx,
e2etestenv.WithKindAdditionalNetworks([]string{"barman-cloud-plugin"})); err != nil { e2etestenv.WithKindAdditionalNetworks([]string{testNetwork})); err != nil {
Fail(fmt.Sprintf("failed to setup environment: %v", err)) Fail(fmt.Sprintf("failed to setup environment: %v", err))
} }
@ -54,7 +57,7 @@ var _ = SynchronizedBeforeSuite(func(ctx SpecContext) []byte {
Images: []kustomizeTypes.Image{ Images: []kustomizeTypes.Image{
{ {
Name: "docker.io/library/plugin-barman-cloud", Name: "docker.io/library/plugin-barman-cloud",
NewName: "registry.barman-cloud-plugin:5000/plugin-barman-cloud", NewName: fmt.Sprintf("%v/plugin-barman-cloud", testRegistry),
NewTag: "testing", NewTag: "testing",
}, },
}, },
@ -64,7 +67,9 @@ var _ = SynchronizedBeforeSuite(func(ctx SpecContext) []byte {
Name: "plugin-barman-cloud", Name: "plugin-barman-cloud",
Behavior: "replace", Behavior: "replace",
KvPairSources: kustomizeTypes.KvPairSources{ KvPairSources: kustomizeTypes.KvPairSources{
LiteralSources: []string{"SIDECAR_IMAGE=registry.barman-cloud-plugin:5000/sidecar-barman-cloud:testing"}, LiteralSources: []string{
fmt.Sprintf("SIDECAR_IMAGE=%v/sidecar-barman-cloud:testing", testRegistry),
},
}, },
}, },
}, },