Skip to content

Commit

Permalink
Add docker image test script
Browse files Browse the repository at this point in the history
Fixes #9758

Ensures build images contains the correct binary and are for the
correct architecture.

Signed-off-by: Akshay Gaikwad <akgaikwad001@gmail.com>
  • Loading branch information
akshay196 committed Dec 28, 2023
1 parent 7a1830a commit b97f3f7
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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))
Expand Down
44 changes: 44 additions & 0 deletions hack/tools/release/testimage.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit b97f3f7

Please sign in to comment.