From e68454e64176ffcbfd488f81fbca81c1f8049aed Mon Sep 17 00:00:00 2001 From: Akshay Gaikwad Date: Thu, 28 Dec 2023 11:39:59 +0530 Subject: [PATCH] Add docker image test script Ensures build images contains the correct binary and are for the correct architecture. Signed-off-by: Akshay Gaikwad --- Makefile | 6 ++++- hack/tools/release/testimage.sh | 44 +++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 1 deletion(-) create mode 100755 hack/tools/release/testimage.sh diff --git a/Makefile b/Makefile index 4ee4973ee287..2cf95a0c16af 100644 --- a/Makefile +++ b/Makefile @@ -1068,7 +1068,7 @@ release-binary: $(RELEASE_DIR) .PHONY: release-staging release-staging: ## Build and push container images to the staging bucket - REGISTRY=$(STAGING_REGISTRY) $(MAKE) docker-build-all docker-push-all release-alias-tag + REGISTRY=$(STAGING_REGISTRY) $(MAKE) docker-build-all docker-image-test docker-push-all release-alias-tag .PHONY: release-staging-nightly release-staging-nightly: ## Tag and push container images to the staging bucket. Example image tag: cluster-api-controller:nightly_main_20210121 @@ -1116,6 +1116,10 @@ promote-images: $(KPROMO) ## Docker ## -------------------------------------- +.PHONY: docker-image-test +docker-image-test: ## image testing + ALL_ARCH="$(ALL_ARCH)" ./hack/tools/release/testimage.sh + .PHONY: docker-push-all docker-push-all: $(addprefix docker-push-,$(ALL_ARCH)) ## Push the docker images to be included in the release for all architectures + related multiarch manifests $(MAKE) ALL_ARCH="$(ALL_ARCH)" $(addprefix docker-push-manifest-,$(ALL_DOCKER_BUILD)) diff --git a/hack/tools/release/testimage.sh b/hack/tools/release/testimage.sh new file mode 100755 index 000000000000..c6c8a5c588c9 --- /dev/null +++ b/hack/tools/release/testimage.sh @@ -0,0 +1,44 @@ +#!/usr/bin/env bash +# Copyright 2023 The Kubernetes Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +function TESTIMAGE() { + IMAGE="${1}" + ARCH="${2}" + GREPGOPATH="${3}" + BINARYPATH="${4:-manager}" + + echo "> Testing $IMAGE" + + docker save "${IMAGE}" -o img.tar + mkdir -p extracted-img extracted + tar -xf img.tar -C extracted-img/ + for layer in $(find extracted-img/ -name "*.tar"); do + tar -xf ${layer} -C extracted + done + + go version -m extracted/${BINARYPATH} | grep -P "\tpath" | grep -E -q -e ${GREPGOPATH} || (echo "FAILED ${IMAGE} expected value for path: \"${GREPGOPATH}\""; go version -m extracted/${BINARYPATH} | grep -P "\tpath") + go version -m extracted/${BINARYPATH} | grep -q -E "GOARCH=${ARCH}$" || (echo "Failed ${IMAGE} expected GOARCH to be \"$ARCH\""; go version -m extracted/${BINARYPATH} | grep "GOARCH=") + + rm -rf img.tar extracted-img extracted +} + +for arch in ${ALL_ARCH}; do + TESTIMAGE "gcr.io/k8s-staging-cluster-api/cluster-api-controller-${arch}:dev" "${arch}" "sigs.k8s.io/cluster-api$" + TESTIMAGE "gcr.io/k8s-staging-cluster-api/kubeadm-bootstrap-controller-${arch}:dev" "${arch}" "sigs.k8s.io/cluster-api/bootstrap/kubeadm$" + TESTIMAGE "gcr.io/k8s-staging-cluster-api/kubeadm-control-plane-controller-${arch}:dev" "${arch}" "sigs.k8s.io/cluster-api/controlplane/kubeadm$" + TESTIMAGE "gcr.io/k8s-staging-cluster-api/capd-manager-${arch}:dev" "${arch}" "command-line-arguments$" + TESTIMAGE "gcr.io/k8s-staging-cluster-api/capim-manager-${arch}:dev" "${arch}" "sigs.k8s.io/cluster-api/test/infrastructure/inmemory$" + TESTIMAGE "gcr.io/k8s-staging-cluster-api/test-extension-${arch}:dev" "${arch}" "sigs.k8s.io/cluster-api/test/extension$" +done