diff --git a/Makefile b/Makefile index 49a707b3c..5e8033f51 100644 --- a/Makefile +++ b/Makefile @@ -165,12 +165,16 @@ test-unit: $(SETUP_ENVTEST) #HELP Run the unit tests $(UNIT_TEST_DIRS) \ -test.gocoverdir=$(ROOT_DIR)/coverage/unit -image-registry: ## Setup in-cluster image registry - ./hack/test/image-registry.sh $(E2E_REGISTRY_NAMESPACE) $(E2E_REGISTRY_NAME) - -build-push-e2e-catalog: ## Build the testdata catalog used for e2e tests and push it to the image registry - ./hack/test/build-push-e2e-catalog.sh $(E2E_REGISTRY_NAMESPACE) $(LOCAL_REGISTRY_HOST)/$(E2E_TEST_CATALOG_V1) - ./hack/test/build-push-e2e-catalog.sh $(E2E_REGISTRY_NAMESPACE) $(LOCAL_REGISTRY_HOST)/$(E2E_TEST_CATALOG_V2) +.PHONY: image-registry +E2E_REGISTRY_IMAGE=localhost/e2e-test-registry:devel +image-registry: export GOOS=linux +image-registry: export GOARCH=amd64 +image-registry: ## Build the testdata catalog used for e2e tests and push it to the image registry + go build $(GO_BUILD_FLAGS) -tags '$(GO_BUILD_TAGS)' -ldflags '$(GO_BUILD_LDFLAGS)' -gcflags '$(GO_BUILD_GCFLAGS)' -asmflags '$(GO_BUILD_ASMFLAGS)' -o ./testdata/registry/bin/registry ./testdata/registry/registry.go + go build $(GO_BUILD_FLAGS) -tags '$(GO_BUILD_TAGS)' -ldflags '$(GO_BUILD_LDFLAGS)' -gcflags '$(GO_BUILD_GCFLAGS)' -asmflags '$(GO_BUILD_ASMFLAGS)' -o ./testdata/push/bin/push ./testdata/push/push.go + $(CONTAINER_RUNTIME) build -f ./testdata/Dockerfile -t $(E2E_REGISTRY_IMAGE) ./testdata + $(CONTAINER_RUNTIME) save $(E2E_REGISTRY_IMAGE) | $(KIND) load image-archive /dev/stdin --name $(KIND_CLUSTER_NAME) + ./testdata/build-test-registry.sh $(E2E_REGISTRY_NAMESPACE) $(E2E_REGISTRY_NAME) $(E2E_REGISTRY_IMAGE) # When running the e2e suite, you can set the ARTIFACT_PATH variable to the absolute path # of the directory for the operator-controller e2e tests to store the artifacts, which @@ -181,7 +185,7 @@ build-push-e2e-catalog: ## Build the testdata catalog used for e2e tests and pus test-e2e: KIND_CLUSTER_NAME := operator-controller-e2e test-e2e: KUSTOMIZE_BUILD_DIR := config/overlays/e2e test-e2e: GO_BUILD_FLAGS := -cover -test-e2e: run image-registry build-push-e2e-catalog registry-load-bundles e2e e2e-coverage kind-clean #HELP Run e2e test suite on local kind cluster +test-e2e: run image-registry e2e e2e-coverage kind-clean #HELP Run e2e test suite on local kind cluster .PHONY: extension-developer-e2e extension-developer-e2e: KUSTOMIZE_BUILD_DIR := config/overlays/cert-manager @@ -205,7 +209,7 @@ post-upgrade-checks: test-upgrade-e2e: KIND_CLUSTER_NAME := operator-controller-upgrade-e2e test-upgrade-e2e: export TEST_CLUSTER_CATALOG_NAME := test-catalog test-upgrade-e2e: export TEST_CLUSTER_EXTENSION_NAME := test-package -test-upgrade-e2e: kind-cluster run-latest-release image-registry build-push-e2e-catalog registry-load-bundles pre-upgrade-setup docker-build kind-load kind-deploy post-upgrade-checks kind-clean #HELP Run upgrade e2e tests on a local kind cluster +test-upgrade-e2e: kind-cluster run-latest-release image-registry pre-upgrade-setup docker-build kind-load kind-deploy post-upgrade-checks kind-clean #HELP Run upgrade e2e tests on a local kind cluster .PHONY: e2e-coverage e2e-coverage: @@ -231,12 +235,6 @@ kind-cluster: $(KIND) #EXHELP Standup a kind cluster. kind-clean: $(KIND) #EXHELP Delete the kind cluster. $(KIND) delete cluster --name $(KIND_CLUSTER_NAME) -registry-load-bundles: ## Load selected e2e testdata container images created in kind-load-bundles into registry - testdata/bundles/registry-v1/build-push-e2e-bundle.sh ${E2E_REGISTRY_NAMESPACE} $(LOCAL_REGISTRY_HOST)/bundles/registry-v1/prometheus-operator:v1.0.0 prometheus-operator.v1.0.0 prometheus-operator.v1.0.0 - testdata/bundles/registry-v1/build-push-e2e-bundle.sh ${E2E_REGISTRY_NAMESPACE} $(LOCAL_REGISTRY_HOST)/bundles/registry-v1/prometheus-operator:v1.0.1 prometheus-operator.v1.0.1 prometheus-operator.v1.0.0 - testdata/bundles/registry-v1/build-push-e2e-bundle.sh ${E2E_REGISTRY_NAMESPACE} $(LOCAL_REGISTRY_HOST)/bundles/registry-v1/prometheus-operator:v1.2.0 prometheus-operator.v1.2.0 prometheus-operator.v1.0.0 - testdata/bundles/registry-v1/build-push-e2e-bundle.sh ${E2E_REGISTRY_NAMESPACE} $(LOCAL_REGISTRY_HOST)/bundles/registry-v1/prometheus-operator:v2.0.0 prometheus-operator.v2.0.0 prometheus-operator.v1.0.0 - #SECTION Build ifeq ($(origin VERSION), undefined) diff --git a/hack/test/build-push-e2e-catalog.sh b/hack/test/build-push-e2e-catalog.sh deleted file mode 100755 index 9fd1a9d6b..000000000 --- a/hack/test/build-push-e2e-catalog.sh +++ /dev/null @@ -1,66 +0,0 @@ -#! /bin/bash - -set -o errexit -set -o nounset -set -o pipefail - -help=" -build-push-e2e-catalog.sh is a script to build and push the e2e catalog image using kaniko. -Usage: - build-push-e2e-catalog.sh [NAMESPACE] [TAG] - -Argument Descriptions: - - NAMESPACE is the namespace the kaniko Job should be created in - - TAG is the full tag used to build and push the catalog image -" - -if [[ "$#" -ne 2 ]]; then - echo "Illegal number of arguments passed" - echo "${help}" - exit 1 -fi - -namespace=$1 -image=$2 -tag=${image##*:} - -echo "${namespace}" "${image}" "${tag}" - -kubectl create configmap -n "${namespace}" --from-file=testdata/catalogs/test-catalog-${tag}.Dockerfile operator-controller-e2e-${tag}.dockerfile -kubectl create configmap -n "${namespace}" --from-file=testdata/catalogs/test-catalog-${tag} operator-controller-e2e-${tag}.build-contents - -kubectl apply -f - << EOF -apiVersion: batch/v1 -kind: Job -metadata: - name: "kaniko-${tag}" - namespace: "${namespace}" -spec: - template: - spec: - containers: - - name: kaniko-${tag} - image: gcr.io/kaniko-project/executor:latest - args: ["--dockerfile=/workspace/test-catalog-${tag}.Dockerfile", - "--context=/workspace/", - "--destination=${image}", - "--skip-tls-verify"] - volumeMounts: - - name: dockerfile - mountPath: /workspace/ - - name: build-contents - mountPath: /workspace/test-catalog-${tag}/ - restartPolicy: Never - volumes: - - name: dockerfile - configMap: - name: operator-controller-e2e-${tag}.dockerfile - items: - - key: test-catalog-${tag}.Dockerfile - path: test-catalog-${tag}.Dockerfile - - name: build-contents - configMap: - name: operator-controller-e2e-${tag}.build-contents -EOF - -kubectl wait --for=condition=Complete -n "${namespace}" jobs/kaniko-${tag} --timeout=60s diff --git a/test/e2e/cluster_extension_install_test.go b/test/e2e/cluster_extension_install_test.go index d03aacf5e..6efe98ca8 100644 --- a/test/e2e/cluster_extension_install_test.go +++ b/test/e2e/cluster_extension_install_test.go @@ -550,7 +550,7 @@ func TestClusterExtensionInstallReResolvesWhenCatalogIsPatched(t *testing.T) { // patch imageRef tag on test-catalog image with v2 image t.Log("By patching the catalog ImageRef to point to the v2 catalog") - updatedCatalogImage := fmt.Sprintf("%s/e2e/test-catalog:v2", os.Getenv("LOCAL_REGISTRY_HOST")) + updatedCatalogImage := fmt.Sprintf("%s/test-catalog:v2", os.Getenv("LOCAL_REGISTRY_HOST")) err := patchTestCatalog(context.Background(), testCatalogName, updatedCatalogImage) require.NoError(t, err) require.EventuallyWithT(t, func(ct *assert.CollectT) { diff --git a/testdata/.gitignore b/testdata/.gitignore new file mode 100644 index 000000000..1eca1dc7e --- /dev/null +++ b/testdata/.gitignore @@ -0,0 +1,2 @@ +push/bin +registry/bin diff --git a/testdata/Dockerfile b/testdata/Dockerfile new file mode 100644 index 000000000..0f1355f56 --- /dev/null +++ b/testdata/Dockerfile @@ -0,0 +1,12 @@ +from gcr.io/distroless/static:nonroot + +WORKDIR / + +COPY registry/bin/registry registry +COPY push/bin/push push + +COPY images images + +EXPOSE 5000 + +USER 65532:65532 diff --git a/hack/test/image-registry.sh b/testdata/build-test-registry.sh similarity index 61% rename from hack/test/image-registry.sh rename to testdata/build-test-registry.sh index ac3e68eb7..3ea0e65b0 100755 --- a/hack/test/image-registry.sh +++ b/testdata/build-test-registry.sh @@ -1,22 +1,21 @@ -#! /bin/bash +#!/bin/bash set -o errexit set -o nounset set -o pipefail help=" -image-registry.sh is a script to stand up an image registry within a cluster. +build-test-registry.sh is a script to stand up an image registry within a cluster. Usage: - image-registry.sh [NAMESPACE] [NAME] [CERT_REF] + build-test-registry.sh [NAMESPACE] [NAME] [IMAGE] Argument Descriptions: - NAMESPACE is the namespace that should be created and is the namespace in which the image registry will be created - NAME is the name that should be used for the image registry Deployment and Service - - CERT_REF is the reference to the CA certificate that should be used to serve the image registry over HTTPS, in the - format of 'Issuer/' or 'ClusterIssuer/' + - IMAGE is the name of the image that should be used to run the image registry " -if [[ "$#" -ne 2 ]]; then +if [[ "$#" -ne 3 ]]; then echo "Illegal number of arguments passed" echo "${help}" exit 1 @@ -24,6 +23,7 @@ fi namespace=$1 name=$2 +image=$3 kubectl apply -f - << EOF apiVersion: v1 @@ -69,7 +69,12 @@ spec: spec: containers: - name: registry - image: registry:2 + image: ${image} + imagePullPolicy: IfNotPresent + command: + - /registry + args: + - "--registry-address=:5000" volumeMounts: - name: certs-vol mountPath: "/certs" @@ -100,3 +105,35 @@ spec: EOF kubectl wait --for=condition=Available -n "${namespace}" "deploy/${name}" --timeout=60s + +kubectl apply -f - << EOF +apiVersion: batch/v1 +kind: Job +metadata: + name: ${name}-push + namespace: "${namespace}" +spec: + template: + spec: + restartPolicy: Never + containers: + - name: push + image: ${image} + command: + - /push + args: + - "--registry-address=${name}.${namespace}.svc:5000" + - "--images-path=/images" + volumeMounts: + - name: certs-vol + mountPath: "/certs" + env: + - name: SSL_CERT_DIR + value: "/certs/" + volumes: + - name: certs-vol + secret: + secretName: ${namespace}-registry +EOF + +kubectl wait --for=condition=Complete -n "${namespace}" "job/${name}-push" --timeout=60s diff --git a/testdata/bundles/registry-v1/build-push-e2e-bundle.sh b/testdata/bundles/registry-v1/build-push-e2e-bundle.sh deleted file mode 100755 index 0aec13cc9..000000000 --- a/testdata/bundles/registry-v1/build-push-e2e-bundle.sh +++ /dev/null @@ -1,84 +0,0 @@ -#! /bin/bash - -set -o errexit -set -o nounset -set -o pipefail - -help=" -build-push-e2e-bundle.sh is a script to build and push the e2e bundle image using kaniko. -Usage: - build-push-e2e-bundle.sh [NAMESPACE] [TAG] [BUNDLE_NAME] [BUNDLE_DIR] - -Argument Descriptions: - - NAMESPACE is the namespace the kaniko Job should be created in - - TAG is the full tag used to build and push the catalog image -" - -if [[ "$#" -ne 4 ]]; then - echo "Illegal number of arguments passed" - echo "${help}" - exit 1 -fi - - -namespace=$1 -tag=$2 -bundle_name=$3 -package_name=$4 -bundle_dir="testdata/bundles/registry-v1/${package_name}" - -echo "${namespace}" "${tag}" - -kubectl create configmap -n "${namespace}" --from-file="${bundle_dir}/Dockerfile" operator-controller-e2e-${bundle_name}.root - -tgz="${bundle_dir}/manifests.tgz" -tar czf "${tgz}" -C "${bundle_dir}/" manifests metadata -kubectl create configmap -n "${namespace}" --from-file="${tgz}" operator-controller-${bundle_name}.manifests -rm "${tgz}" - -# Remove periods from bundle name due to pod name issues -job_name=${bundle_name//.} - -kubectl apply -f - << EOF -apiVersion: batch/v1 -kind: Job -metadata: - name: "kaniko-${job_name}" - namespace: "${namespace}" -spec: - template: - spec: - initContainers: - - name: copy-manifests - image: busybox - command: ['sh', '-c', 'cp /manifests-data/* /manifests'] - volumeMounts: - - name: manifests - mountPath: /manifests - - name: manifests-data - mountPath: /manifests-data - containers: - - name: kaniko - image: gcr.io/kaniko-project/executor:latest - args: ["--dockerfile=/workspace/Dockerfile", - "--context=tar:///workspace/manifests/manifests.tgz", - "--destination=${tag}", - "--skip-tls-verify"] - volumeMounts: - - name: dockerfile - mountPath: /workspace/ - - name: manifests - mountPath: /workspace/manifests/ - restartPolicy: Never - volumes: - - name: dockerfile - configMap: - name: operator-controller-e2e-${bundle_name}.root - - name: manifests - emptyDir: {} - - name: manifests-data - configMap: - name: operator-controller-${bundle_name}.manifests -EOF - -kubectl wait --for=condition=Complete -n "${namespace}" jobs/kaniko-${job_name} --timeout=60s diff --git a/testdata/bundles/registry-v1/prometheus-operator.v1.0.0/Dockerfile b/testdata/bundles/registry-v1/prometheus-operator.v1.0.0/Dockerfile deleted file mode 100644 index 5a1458148..000000000 --- a/testdata/bundles/registry-v1/prometheus-operator.v1.0.0/Dockerfile +++ /dev/null @@ -1,15 +0,0 @@ -FROM scratch - -# Core bundle labels. -LABEL operators.operatorframework.io.bundle.mediatype.v1=registry+v1 -LABEL operators.operatorframework.io.bundle.manifests.v1=manifests/ -LABEL operators.operatorframework.io.bundle.metadata.v1=metadata/ -LABEL operators.operatorframework.io.bundle.package.v1=prometheusoperator -LABEL operators.operatorframework.io.bundle.channels.v1=beta -LABEL operators.operatorframework.io.metrics.builder=operator-sdk-v1.28.0 -LABEL operators.operatorframework.io.metrics.mediatype.v1=metrics+v1 -LABEL operators.operatorframework.io.metrics.project_layout=unknown - -# Copy files to locations specified by labels. -COPY manifests /manifests/ -COPY metadata /metadata/ diff --git a/testdata/catalogs/test-catalog-v1.Dockerfile b/testdata/catalogs/test-catalog-v1.Dockerfile deleted file mode 100644 index d255e0774..000000000 --- a/testdata/catalogs/test-catalog-v1.Dockerfile +++ /dev/null @@ -1,6 +0,0 @@ -FROM scratch -ADD test-catalog-v1 /configs - -# Set DC-specific label for the location of the DC root directory -# in the image -LABEL operators.operatorframework.io.index.configs.v1=/configs diff --git a/testdata/catalogs/test-catalog-v2.Dockerfile b/testdata/catalogs/test-catalog-v2.Dockerfile deleted file mode 100644 index 72b3a7a2e..000000000 --- a/testdata/catalogs/test-catalog-v2.Dockerfile +++ /dev/null @@ -1,6 +0,0 @@ -FROM scratch -ADD test-catalog-v2 /configs - -# Set DC-specific label for the location of the DC root directory -# in the image -LABEL operators.operatorframework.io.index.configs.v1=/configs diff --git a/testdata/bundles/registry-v1/prometheus-operator.v1.0.0/manifests/monitoring.coreos.com_alertmanagerconfigs.yaml b/testdata/images/bundles/prometheus-operator/v1.0.0/manifests/monitoring.coreos.com_alertmanagerconfigs.yaml similarity index 100% rename from testdata/bundles/registry-v1/prometheus-operator.v1.0.0/manifests/monitoring.coreos.com_alertmanagerconfigs.yaml rename to testdata/images/bundles/prometheus-operator/v1.0.0/manifests/monitoring.coreos.com_alertmanagerconfigs.yaml diff --git a/testdata/bundles/registry-v1/prometheus-operator.v1.0.0/manifests/monitoring.coreos.com_alertmanagers.yaml b/testdata/images/bundles/prometheus-operator/v1.0.0/manifests/monitoring.coreos.com_alertmanagers.yaml similarity index 100% rename from testdata/bundles/registry-v1/prometheus-operator.v1.0.0/manifests/monitoring.coreos.com_alertmanagers.yaml rename to testdata/images/bundles/prometheus-operator/v1.0.0/manifests/monitoring.coreos.com_alertmanagers.yaml diff --git a/testdata/bundles/registry-v1/prometheus-operator.v1.0.0/manifests/monitoring.coreos.com_podmonitors.yaml b/testdata/images/bundles/prometheus-operator/v1.0.0/manifests/monitoring.coreos.com_podmonitors.yaml similarity index 100% rename from testdata/bundles/registry-v1/prometheus-operator.v1.0.0/manifests/monitoring.coreos.com_podmonitors.yaml rename to testdata/images/bundles/prometheus-operator/v1.0.0/manifests/monitoring.coreos.com_podmonitors.yaml diff --git a/testdata/bundles/registry-v1/prometheus-operator.v1.0.0/manifests/monitoring.coreos.com_probes.yaml b/testdata/images/bundles/prometheus-operator/v1.0.0/manifests/monitoring.coreos.com_probes.yaml similarity index 100% rename from testdata/bundles/registry-v1/prometheus-operator.v1.0.0/manifests/monitoring.coreos.com_probes.yaml rename to testdata/images/bundles/prometheus-operator/v1.0.0/manifests/monitoring.coreos.com_probes.yaml diff --git a/testdata/bundles/registry-v1/prometheus-operator.v1.0.0/manifests/monitoring.coreos.com_prometheusagents.yaml b/testdata/images/bundles/prometheus-operator/v1.0.0/manifests/monitoring.coreos.com_prometheusagents.yaml similarity index 100% rename from testdata/bundles/registry-v1/prometheus-operator.v1.0.0/manifests/monitoring.coreos.com_prometheusagents.yaml rename to testdata/images/bundles/prometheus-operator/v1.0.0/manifests/monitoring.coreos.com_prometheusagents.yaml diff --git a/testdata/bundles/registry-v1/prometheus-operator.v1.0.0/manifests/monitoring.coreos.com_prometheuses.yaml b/testdata/images/bundles/prometheus-operator/v1.0.0/manifests/monitoring.coreos.com_prometheuses.yaml similarity index 100% rename from testdata/bundles/registry-v1/prometheus-operator.v1.0.0/manifests/monitoring.coreos.com_prometheuses.yaml rename to testdata/images/bundles/prometheus-operator/v1.0.0/manifests/monitoring.coreos.com_prometheuses.yaml diff --git a/testdata/bundles/registry-v1/prometheus-operator.v1.0.0/manifests/monitoring.coreos.com_prometheusrules.yaml b/testdata/images/bundles/prometheus-operator/v1.0.0/manifests/monitoring.coreos.com_prometheusrules.yaml similarity index 100% rename from testdata/bundles/registry-v1/prometheus-operator.v1.0.0/manifests/monitoring.coreos.com_prometheusrules.yaml rename to testdata/images/bundles/prometheus-operator/v1.0.0/manifests/monitoring.coreos.com_prometheusrules.yaml diff --git a/testdata/bundles/registry-v1/prometheus-operator.v1.0.0/manifests/monitoring.coreos.com_scrapeconfigs.yaml b/testdata/images/bundles/prometheus-operator/v1.0.0/manifests/monitoring.coreos.com_scrapeconfigs.yaml similarity index 100% rename from testdata/bundles/registry-v1/prometheus-operator.v1.0.0/manifests/monitoring.coreos.com_scrapeconfigs.yaml rename to testdata/images/bundles/prometheus-operator/v1.0.0/manifests/monitoring.coreos.com_scrapeconfigs.yaml diff --git a/testdata/bundles/registry-v1/prometheus-operator.v1.0.0/manifests/monitoring.coreos.com_servicemonitors.yaml b/testdata/images/bundles/prometheus-operator/v1.0.0/manifests/monitoring.coreos.com_servicemonitors.yaml similarity index 100% rename from testdata/bundles/registry-v1/prometheus-operator.v1.0.0/manifests/monitoring.coreos.com_servicemonitors.yaml rename to testdata/images/bundles/prometheus-operator/v1.0.0/manifests/monitoring.coreos.com_servicemonitors.yaml diff --git a/testdata/bundles/registry-v1/prometheus-operator.v1.0.0/manifests/monitoring.coreos.com_thanosrulers.yaml b/testdata/images/bundles/prometheus-operator/v1.0.0/manifests/monitoring.coreos.com_thanosrulers.yaml similarity index 100% rename from testdata/bundles/registry-v1/prometheus-operator.v1.0.0/manifests/monitoring.coreos.com_thanosrulers.yaml rename to testdata/images/bundles/prometheus-operator/v1.0.0/manifests/monitoring.coreos.com_thanosrulers.yaml diff --git a/testdata/bundles/registry-v1/prometheus-operator.v1.0.0/manifests/prometheus-operator_v1_service.yaml b/testdata/images/bundles/prometheus-operator/v1.0.0/manifests/prometheus-operator_v1_service.yaml similarity index 100% rename from testdata/bundles/registry-v1/prometheus-operator.v1.0.0/manifests/prometheus-operator_v1_service.yaml rename to testdata/images/bundles/prometheus-operator/v1.0.0/manifests/prometheus-operator_v1_service.yaml diff --git a/testdata/bundles/registry-v1/prometheus-operator.v1.0.0/manifests/prometheusoperator.clusterserviceversion.yaml b/testdata/images/bundles/prometheus-operator/v1.0.0/manifests/prometheusoperator.clusterserviceversion.yaml similarity index 100% rename from testdata/bundles/registry-v1/prometheus-operator.v1.0.0/manifests/prometheusoperator.clusterserviceversion.yaml rename to testdata/images/bundles/prometheus-operator/v1.0.0/manifests/prometheusoperator.clusterserviceversion.yaml diff --git a/testdata/bundles/registry-v1/prometheus-operator.v1.0.0/metadata/annotations.yaml b/testdata/images/bundles/prometheus-operator/v1.0.0/metadata/annotations.yaml similarity index 100% rename from testdata/bundles/registry-v1/prometheus-operator.v1.0.0/metadata/annotations.yaml rename to testdata/images/bundles/prometheus-operator/v1.0.0/metadata/annotations.yaml diff --git a/testdata/catalogs/test-catalog-v1/.indexignore b/testdata/images/catalogs/test-catalog/v1/configs/.indexignore similarity index 100% rename from testdata/catalogs/test-catalog-v1/.indexignore rename to testdata/images/catalogs/test-catalog/v1/configs/.indexignore diff --git a/testdata/catalogs/test-catalog-v1/catalog.yaml b/testdata/images/catalogs/test-catalog/v1/configs/catalog.yaml similarity index 90% rename from testdata/catalogs/test-catalog-v1/catalog.yaml rename to testdata/images/catalogs/test-catalog/v1/configs/catalog.yaml index 41c843d72..ac1613ad1 100644 --- a/testdata/catalogs/test-catalog-v1/catalog.yaml +++ b/testdata/images/catalogs/test-catalog/v1/configs/catalog.yaml @@ -32,7 +32,7 @@ properties: schema: olm.bundle name: prometheus-operator.1.0.1 package: prometheus -image: docker-registry.operator-controller-e2e.svc.cluster.local:5000/bundles/registry-v1/prometheus-operator:v1.0.1 +image: docker-registry.operator-controller-e2e.svc.cluster.local:5000/bundles/registry-v1/prometheus-operator:v1.0.0 properties: - type: olm.package value: @@ -42,7 +42,7 @@ properties: schema: olm.bundle name: prometheus-operator.1.2.0 package: prometheus -image: docker-registry.operator-controller-e2e.svc.cluster.local:5000/bundles/registry-v1/prometheus-operator:v1.2.0 +image: docker-registry.operator-controller-e2e.svc.cluster.local:5000/bundles/registry-v1/prometheus-operator:v1.0.0 properties: - type: olm.package value: @@ -63,7 +63,7 @@ entries: schema: olm.bundle name: prometheus-mirrored-operator.1.2.0 package: prometheus-mirrored -image: mirrored-registry.operator-controller-e2e.svc.cluster.local:5000/bundles/registry-v1/prometheus-operator:v1.2.0 +image: mirrored-registry.operator-controller-e2e.svc.cluster.local:5000/bundles/registry-v1/prometheus-operator:v1.0.0 properties: - type: olm.package value: diff --git a/testdata/catalogs/test-catalog-v2/.indexignore b/testdata/images/catalogs/test-catalog/v2/configs/.indexignore similarity index 100% rename from testdata/catalogs/test-catalog-v2/.indexignore rename to testdata/images/catalogs/test-catalog/v2/configs/.indexignore diff --git a/testdata/catalogs/test-catalog-v2/catalog.yaml b/testdata/images/catalogs/test-catalog/v2/configs/catalog.yaml similarity index 89% rename from testdata/catalogs/test-catalog-v2/catalog.yaml rename to testdata/images/catalogs/test-catalog/v2/configs/catalog.yaml index 7208809cc..779d5cc4f 100644 --- a/testdata/catalogs/test-catalog-v2/catalog.yaml +++ b/testdata/images/catalogs/test-catalog/v2/configs/catalog.yaml @@ -13,7 +13,7 @@ entries: schema: olm.bundle name: prometheus-operator.2.0.0 package: prometheus -image: docker-registry.operator-controller-e2e.svc.cluster.local:5000/bundles/registry-v1/prometheus-operator:v2.0.0 +image: docker-registry.operator-controller-e2e.svc.cluster.local:5000/bundles/registry-v1/prometheus-operator:v1.0.0 properties: - type: olm.package value: diff --git a/testdata/push/README.md b/testdata/push/README.md new file mode 100644 index 000000000..f45f0cc46 --- /dev/null +++ b/testdata/push/README.md @@ -0,0 +1,46 @@ +# Test Registry Image Push + +This tool builds our test bundle and catalog images via crane. It accepts two command line arguments: +``` +Usage of push: + --images-path string Image directory path (default "/images") + --registry-address string The address of the registry. (default ":12345") +``` + +`--registry-address` is the address of the registry to be pushed to. + +`--images-path` should point to the root directory of the images tree structure. The tool expects a particular directory format in order to work properly. Bundles should be placed in `/bundles`, and catalogs in `/catalogs`. From these directories the same convention should be followed: folders within `[catalogs|bundles]` are image names i.e. `test-catalog`. Within these folders is where each tag for that image should be placed. What that ends up looking like is: +```bash +$ tree ./testdata/images/ +./testdata/images/ +├── bundles +│   └── prometheus-operator +│   └── v1.0.0 +│ ├── metadata +│       │ └── annotations.yaml +│      └── manifests +│       └── example.yaml +└── catalogs + └── test-catalog +    ├── v1 +    │   └── configs +    │   └── catalog.yaml +    └── v2 +    └── configs +    └── catalog.yaml +``` +The inside of each tag folder will be placed directly into `/` of the built container i.e. `test-catalog:v1` will have `/configs/catalog.yaml`. + +To add a new image or tag for the tool, create the folders required and populate them with the files to be mounted. Bundle images requiring metadata should contain a `metadata` folder with `annotations.yaml`. Example content: +```yaml +annotations: + # Core bundle annotations. + operators.operatorframework.io.bundle.mediatype.v1: registry+v1 + operators.operatorframework.io.bundle.manifests.v1: manifests/ + operators.operatorframework.io.bundle.metadata.v1: metadata/ + operators.operatorframework.io.bundle.package.v1: prometheus + operators.operatorframework.io.bundle.channels.v1: beta + operators.operatorframework.io.metrics.builder: operator-sdk-v1.28.0 + operators.operatorframework.io.metrics.mediatype.v1: metrics+v1 + operators.operatorframework.io.metrics.project_layout: unknown +``` diff --git a/testdata/push/go.mod b/testdata/push/go.mod new file mode 100644 index 000000000..72bb1b9e8 --- /dev/null +++ b/testdata/push/go.mod @@ -0,0 +1,26 @@ +module registry + +go 1.22.5 + +require ( + github.com/google/go-containerregistry v0.20.2 + github.com/spf13/pflag v1.0.5 + gopkg.in/yaml.v2 v2.4.0 +) + +require ( + github.com/containerd/stargz-snapshotter/estargz v0.15.1 // indirect + github.com/docker/cli v27.3.1+incompatible // indirect + github.com/docker/distribution v2.8.3+incompatible // indirect + github.com/docker/docker-credential-helpers v0.8.2 // indirect + github.com/klauspost/compress v1.17.11 // indirect + github.com/kr/pretty v0.3.1 // indirect + github.com/mitchellh/go-homedir v1.1.0 // indirect + github.com/opencontainers/go-digest v1.0.0 // indirect + github.com/opencontainers/image-spec v1.1.0 // indirect + github.com/pkg/errors v0.9.1 // indirect + github.com/sirupsen/logrus v1.9.3 // indirect + github.com/vbatts/tar-split v0.11.6 // indirect + golang.org/x/sync v0.8.0 // indirect + golang.org/x/sys v0.26.0 // indirect +) diff --git a/testdata/push/go.sum b/testdata/push/go.sum new file mode 100644 index 000000000..6f7cce0f8 --- /dev/null +++ b/testdata/push/go.sum @@ -0,0 +1,60 @@ +github.com/containerd/stargz-snapshotter/estargz v0.15.1 h1:eXJjw9RbkLFgioVaTG+G/ZW/0kEe2oEKCdS/ZxIyoCU= +github.com/containerd/stargz-snapshotter/estargz v0.15.1/go.mod h1:gr2RNwukQ/S9Nv33Lt6UC7xEx58C+LHRdoqbEKjz1Kk= +github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/docker/cli v27.3.1+incompatible h1:qEGdFBF3Xu6SCvCYhc7CzaQTlBmqDuzxPDpigSyeKQQ= +github.com/docker/cli v27.3.1+incompatible/go.mod h1:JLrzqnKDaYBop7H2jaqPtU4hHvMKP+vjCwu2uszcLI8= +github.com/docker/distribution v2.8.3+incompatible h1:AtKxIZ36LoNK51+Z6RpzLpddBirtxJnzDrHLEKxTAYk= +github.com/docker/distribution v2.8.3+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w= +github.com/docker/docker-credential-helpers v0.8.2 h1:bX3YxiGzFP5sOXWc3bTPEXdEaZSeVMrFgOr3T+zrFAo= +github.com/docker/docker-credential-helpers v0.8.2/go.mod h1:P3ci7E3lwkZg6XiHdRKft1KckHiO9a2rNtyFbZ/ry9M= +github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= +github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/google/go-containerregistry v0.20.2 h1:B1wPJ1SN/S7pB+ZAimcciVD+r+yV/l/DSArMxlbwseo= +github.com/google/go-containerregistry v0.20.2/go.mod h1:z38EKdKh4h7IP2gSfUUqEvalZBqs6AoLeWfUy34nQC8= +github.com/klauspost/compress v1.17.11 h1:In6xLpyWOi1+C7tXUUWv2ot1QvBjxevKAaI6IXrJmUc= +github.com/klauspost/compress v1.17.11/go.mod h1:pMDklpSncoRMuLFrf1W9Ss9KT+0rH90U12bZKk7uwG0= +github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= +github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= +github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= +github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= +github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y= +github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= +github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U= +github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM= +github.com/opencontainers/image-spec v1.1.0 h1:8SG7/vwALn54lVB/0yZ/MMwhFrPYtpEHQb2IpWsCzug= +github.com/opencontainers/image-spec v1.1.0/go.mod h1:W4s4sFTMaBeK1BQLXbG4AdM2szdn85PY75RI83NrTrM= +github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= +github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= +github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8= +github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs= +github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ= +github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= +github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= +github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= +github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/vbatts/tar-split v0.11.6 h1:4SjTW5+PU11n6fZenf2IPoV8/tz3AaYHMWjf23envGs= +github.com/vbatts/tar-split v0.11.6/go.mod h1:dqKNtesIOr2j2Qv3W/cHjnvk9I8+G7oAkFDFN6TCBEI= +golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ= +golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo= +golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= +gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= +gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gotest.tools/v3 v3.0.3 h1:4AuOwCGf4lLR9u3YOe2awrHygurzhO/HeQ6laiA6Sx0= +gotest.tools/v3 v3.0.3/go.mod h1:Z7Lb0S5l+klDB31fvDQX8ss/FlKDxtlFlw3Oa8Ymbl8= diff --git a/testdata/push/push.go b/testdata/push/push.go new file mode 100644 index 000000000..72989b1dc --- /dev/null +++ b/testdata/push/push.go @@ -0,0 +1,178 @@ +package main + +import ( + "flag" + "fmt" + "io/fs" + "log" + "os" + "strings" + + "github.com/google/go-containerregistry/pkg/crane" + v1 "github.com/google/go-containerregistry/pkg/v1" + "github.com/google/go-containerregistry/pkg/v1/mutate" + "github.com/spf13/pflag" + "gopkg.in/yaml.v2" +) + +const ( + bundlesSubPath string = "bundles" + catalogsSubPath string = "catalogs" +) + +func main() { + var ( + registryAddr string + imagesPath string + ) + flag.StringVar(®istryAddr, "registry-address", ":12345", "The address the registry binds to.") + flag.StringVar(&imagesPath, "images-path", "/images", "Image directory path") + pflag.CommandLine.AddGoFlagSet(flag.CommandLine) + pflag.Parse() + + log.Printf("push operation configured with images path %s and destination %s", imagesPath, registryAddr) + + bundlesFullPath := fmt.Sprintf("%s/%s", imagesPath, bundlesSubPath) + catalogsFullPath := fmt.Sprintf("%s/%s", imagesPath, catalogsSubPath) + + bundles, err := buildBundles(bundlesFullPath) + if err != nil { + log.Fatalf("failed to build bundles: %s", err.Error()) + } + catalogs, err := buildCatalogs(catalogsFullPath) + if err != nil { + log.Fatalf("failed to build catalogs: %s", err.Error()) + } + // Push the images + for name, image := range bundles { + if err := crane.Push(image, fmt.Sprintf("%s/%s", registryAddr, name)); err != nil { + log.Fatalf("failed to push bundle images: %s", err.Error()) + } + } + for name, image := range catalogs { + if err := crane.Push(image, fmt.Sprintf("%s/%s", registryAddr, name)); err != nil { + log.Fatalf("failed to push catalog images: %s", err.Error()) + } + } + log.Printf("finished") + os.Exit(0) +} + +func buildBundles(path string) (map[string]v1.Image, error) { + bundles, err := processImageDirTree(path) + if err != nil { + return nil, err + } + mutatedMap := make(map[string]v1.Image, 0) + // Apply required bundle labels + for key, img := range bundles { + // Replace ':' between image name and image tag for file path + metadataPath := strings.Replace(key, ":", "/", 1) + labels, err := getBundleLabels(fmt.Sprintf("%s/%s/%s", path, metadataPath, "metadata/annotations.yaml")) + if err != nil { + return nil, err + } + mutatedMap[fmt.Sprintf("bundles/registry-v1/%s", key)], err = mutate.Config(img, v1.Config{Labels: labels}) + if err != nil { + return nil, fmt.Errorf("failed to apply image labels: %w", err) + } + } + return mutatedMap, nil +} + +type bundleAnnotations struct { + annotations map[string]string +} + +func getBundleLabels(path string) (map[string]string, error) { + var metadata bundleAnnotations + yamlFile, err := os.ReadFile(path) + if err != nil { + return nil, err + } + err = yaml.Unmarshal(yamlFile, metadata) + if err != nil { + return nil, err + } + return metadata.annotations, nil +} + +func buildCatalogs(path string) (map[string]v1.Image, error) { + catalogs, err := processImageDirTree(path) + if err != nil { + return nil, err + } + mutatedMap := make(map[string]v1.Image, 0) + // Apply required catalog label + for key, img := range catalogs { + cfg := v1.Config{ + Labels: map[string]string{ + "operators.operatorframework.io.index.configs.v1": "/configs", + }, + } + mutatedMap[fmt.Sprintf("e2e/%s", key)], err = mutate.Config(img, cfg) + if err != nil { + return nil, fmt.Errorf("failed to apply image labels: %w", err) + } + } + return mutatedMap, nil +} + +func processImageDirTree(path string) (map[string]v1.Image, error) { + imageMap := make(map[string]v1.Image, 0) + images, err := os.ReadDir(path) + if err != nil { + return nil, err + } + + // Each directory in 'path' represents an image + for _, entry := range images { + entryFullPath := fmt.Sprintf("%s/%s", path, entry.Name()) + if !entry.IsDir() { + continue + } + tags, err := os.ReadDir(entryFullPath) + if err != nil { + return nil, err + } + // Each directory in the image directory represents a separate tag + for _, tag := range tags { + if !tag.IsDir() { + continue + } + tagFullPath := fmt.Sprintf("%s/%s", entryFullPath, tag.Name()) + + var fileMap map[string][]byte + fileMap, err = createFileMap(tagFullPath) + if err != nil { + return nil, fmt.Errorf("failed to read files for image: %w", err) + } + + image, err := crane.Image(fileMap) + if err != nil { + return nil, fmt.Errorf("failed to generate image: %w", err) + } + imageMap[fmt.Sprintf("%s:%s", entry.Name(), tag.Name())] = image + } + } + return imageMap, nil +} + +func createFileMap(originPath string) (map[string][]byte, error) { + fileMap := make(map[string][]byte) + if err := fs.WalkDir(os.DirFS(originPath), ".", func(path string, d fs.DirEntry, err error) error { + if err != nil { + return err + } + if d != nil && !d.IsDir() { + fileMap[path], err = os.ReadFile(fmt.Sprintf("%s/%s", originPath, path)) + if err != nil { + return err + } + } + return nil + }); err != nil { + return nil, err + } + return fileMap, nil +} diff --git a/testdata/registry/README.md b/testdata/registry/README.md new file mode 100644 index 000000000..18c41722a --- /dev/null +++ b/testdata/registry/README.md @@ -0,0 +1,15 @@ +# Test Registry + +This tool is a bare-bones image registry using the `go-containerregistry` library; it is intended to be used in a test environment only. + +Usage: +``` +Usage of registry: + --registry-address string The address the registry binds to. (default ":12345") +``` + +The server key and cert locations should be set under the following environment variables: +``` + REGISTRY_HTTP_TLS_CERTIFICATE + REGISTRY_HTTP_TLS_KEY +``` diff --git a/testdata/registry/go.mod b/testdata/registry/go.mod new file mode 100644 index 000000000..ce79002d4 --- /dev/null +++ b/testdata/registry/go.mod @@ -0,0 +1,8 @@ +module registry + +go 1.22.5 + +require ( + github.com/google/go-containerregistry v0.20.2 + github.com/spf13/pflag v1.0.5 +) diff --git a/testdata/registry/go.sum b/testdata/registry/go.sum new file mode 100644 index 000000000..ebadf4aec --- /dev/null +++ b/testdata/registry/go.sum @@ -0,0 +1,36 @@ +github.com/containerd/stargz-snapshotter/estargz v0.14.3 h1:OqlDCK3ZVUO6C3B/5FSkDwbkEETK84kQgEeFwDC+62k= +github.com/containerd/stargz-snapshotter/estargz v0.14.3/go.mod h1:KY//uOCIkSuNAHhJogcZtrNHdKrA99/FCCRjE3HD36o= +github.com/docker/cli v27.1.1+incompatible h1:goaZxOqs4QKxznZjjBWKONQci/MywhtRv2oNn0GkeZE= +github.com/docker/cli v27.1.1+incompatible/go.mod h1:JLrzqnKDaYBop7H2jaqPtU4hHvMKP+vjCwu2uszcLI8= +github.com/docker/distribution v2.8.2+incompatible h1:T3de5rq0dB1j30rp0sA2rER+m322EBzniBPB6ZIzuh8= +github.com/docker/distribution v2.8.2+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w= +github.com/docker/docker-credential-helpers v0.7.0 h1:xtCHsjxogADNZcdv1pKUHXryefjlVRqWqIhk/uXJp0A= +github.com/docker/docker-credential-helpers v0.7.0/go.mod h1:rETQfLdHNT3foU5kuNkFR1R1V12OJRRO5lzt2D1b5X0= +github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= +github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/google/go-containerregistry v0.20.2 h1:B1wPJ1SN/S7pB+ZAimcciVD+r+yV/l/DSArMxlbwseo= +github.com/google/go-containerregistry v0.20.2/go.mod h1:z38EKdKh4h7IP2gSfUUqEvalZBqs6AoLeWfUy34nQC8= +github.com/klauspost/compress v1.16.5 h1:IFV2oUNUzZaz+XyusxpLzpzS8Pt5rh0Z16For/djlyI= +github.com/klauspost/compress v1.16.5/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE= +github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y= +github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= +github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U= +github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM= +github.com/opencontainers/image-spec v1.1.0-rc3 h1:fzg1mXZFj8YdPeNkRXMg+zb88BFV0Ys52cJydRwBkb8= +github.com/opencontainers/image-spec v1.1.0-rc3/go.mod h1:X4pATf0uXsnn3g5aiGIsVnJBR4mxhKzfwmvK/B2NTm8= +github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= +github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/sirupsen/logrus v1.9.1 h1:Ou41VVR3nMWWmTiEUnj0OlsgOSCUFgsPAOl6jRIcVtQ= +github.com/sirupsen/logrus v1.9.1/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= +github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= +github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= +github.com/vbatts/tar-split v0.11.3 h1:hLFqsOLQ1SsppQNTMpkpPXClLDfC2A3Zgy9OUU+RVck= +github.com/vbatts/tar-split v0.11.3/go.mod h1:9QlHN18E+fEH7RdG+QAJJcuya3rqT7eXSTY7wGrAokY= +golang.org/x/mod v0.10.0 h1:lFO9qtOdlre5W1jxS3r/4szv2/6iXxScdzjoBMXNhYk= +golang.org/x/mod v0.10.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= +golang.org/x/sync v0.2.0 h1:PUR+T4wwASmuSTYdKjYHI5TD22Wy5ogLU5qZCOLxBrI= +golang.org/x/sync v0.2.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc= +golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/tools v0.9.1 h1:8WMNJAz3zrtPmnYC7ISf5dEn3MT0gY7jBJfw27yrrLo= +golang.org/x/tools v0.9.1/go.mod h1:owI94Op576fPu3cIGQeHs3joujW/2Oc6MtlxbF5dfNc= diff --git a/testdata/registry/registry.go b/testdata/registry/registry.go new file mode 100644 index 000000000..553d9bcd4 --- /dev/null +++ b/testdata/registry/registry.go @@ -0,0 +1,40 @@ +package main + +import ( + "flag" + "log" + "net/http" + "os" + "time" + + "github.com/google/go-containerregistry/pkg/registry" + "github.com/spf13/pflag" +) + +const ( + certEnv = "REGISTRY_HTTP_TLS_CERTIFICATE" + keyEnv = "REGISTRY_HTTP_TLS_KEY" +) + +func main() { + var ( + registryAddr string + ) + flag.StringVar(®istryAddr, "registry-address", ":12345", "The address the registry binds to.") + pflag.CommandLine.AddGoFlagSet(flag.CommandLine) + pflag.Parse() + + s := &http.Server{ + Addr: registryAddr, + Handler: registry.New(), + ReadTimeout: 60 * time.Second, + WriteTimeout: 60 * time.Second, + } + + err := s.ListenAndServeTLS(os.Getenv(certEnv), os.Getenv(keyEnv)) + if err != nil { + log.Fatalf("failed to start image registry: %s", err.Error()) + } + + defer s.Close() +}