Skip to content

Commit

Permalink
test: harden e2e image build logic
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
sdowell committed Jul 16, 2024
1 parent 6af1e69 commit f6f7401
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions test_e2e.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down Expand Up @@ -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 \
Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit f6f7401

Please sign in to comment.