From f6f7401e6b690fb859bc5fc9c84d9242fc04f08b Mon Sep 17 00:00:00 2001 From: Sam Dowell Date: Tue, 16 Jul 2024 16:00:06 -0700 Subject: [PATCH] test: harden e2e image build logic This introduces several changes to make the e2e test image logic more robust: - Rename IMAGE to GIT_SYNC_E2E_IMAGE to minimize accidental misuse - Ensure that the image built by make container is the same as the image used by docker run - Do not build the container if a custom image is specified As an example, with the prior logic the following command always fails: IMAGE="" make test ... Unable to find image 'gcr.io/k8s-staging-git-sync/git-sync:latest' locally Because the docker run command pulls a different image from the one built by make container. --- test_e2e.sh | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/test_e2e.sh b/test_e2e.sh index 3ecd0f8..259ab34 100755 --- a/test_e2e.sh +++ b/test_e2e.sh @@ -182,9 +182,13 @@ function docker_signal() { # tags are system-global, but one might have multiple repos checked out. E2E_TAG=$(git rev-parse --show-toplevel | sed 's|/|_|g') -# Setting IMAGE forces the test to use a specific image instead of the current -# tree. -IMAGE="${IMAGE:-"e2e/git-sync:${E2E_TAG}__$(go env GOOS)_$(go env GOARCH)"}" +# Setting GIT_SYNC_E2E_IMAGE forces the test to use a specific image instead of the +# current tree. +build_container=false +if [[ "${GIT_SYNC_E2E_IMAGE:-unset}" == "unset" ]]; then + GIT_SYNC_E2E_IMAGE="e2e/git-sync:${E2E_TAG}__$(go env GOOS)_$(go env GOARCH)" + build_container=true +fi # DIR is the directory in which all this test's state lives. RUNID="${RANDOM}${RANDOM}" @@ -291,7 +295,7 @@ function GIT_SYNC() { -v "$DOT_SSH/1/id_test":"/ssh/secret.1":ro \ -v "$DOT_SSH/2/id_test":"/ssh/secret.2":ro \ -v "$DOT_SSH/3/id_test":"/ssh/secret.3":ro \ - "${IMAGE}" \ + "${GIT_SYNC_E2E_IMAGE}" \ -v=6 \ --add-user \ --group-write \ @@ -3468,7 +3472,7 @@ if [[ "$#" == 0 ]]; then fi # Build it -make container REGISTRY=e2e VERSION="${E2E_TAG}" ALLOW_STALE_APT=1 +$build_container && make container REGISTRY=e2e VERSION="${E2E_TAG}" ALLOW_STALE_APT=1 make test-tools REGISTRY=e2e function finish() {