From 61f66e81b61df3b5fb6c0d698ad2213d6090501a Mon Sep 17 00:00:00 2001 From: Eric Anderson Date: Thu, 23 Apr 2020 12:53:46 -0700 Subject: [PATCH] tools: Put sha1 in container tag instead of name Ideally instead of having names like ruby_jessie_x64_ruby_2_5 and ruby_jessie_x64_ruby_2_6 they would have the name "ruby" with tags containing jessie_x64_ruby_2_5/6. But fixing that would be much more invasive. The sha1 in the tag is producing the worst effects, so this is a case of the perfect being the enemy of the good. Fixes #20546 --- tools/dockerfile/push_testing_images.sh | 11 ++++++----- tools/run_tests/dockerize/build_and_run_docker.sh | 2 +- .../run_tests/dockerize/build_docker_and_run_tests.sh | 2 +- tools/run_tests/dockerize/build_interop_image.sh | 4 ++-- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/tools/dockerfile/push_testing_images.sh b/tools/dockerfile/push_testing_images.sh index 2e0841a4db5..7d2068edbe1 100755 --- a/tools/dockerfile/push_testing_images.sh +++ b/tools/dockerfile/push_testing_images.sh @@ -36,14 +36,15 @@ do # contents of the docker image always changes the SHA (e.g. using "ADD file" # cmd in the dockerfile in not ok as contents of the added file will not be # reflected in the SHA). - DOCKER_IMAGE_NAME=$(basename $DOCKERFILE_DIR)_$(sha1sum $DOCKERFILE_DIR/Dockerfile | cut -f1 -d\ ) + DOCKER_IMAGE_NAME=$(basename $DOCKERFILE_DIR) + DOCKER_IMAGE_TAG=$(sha1sum $DOCKERFILE_DIR/Dockerfile | cut -f1 -d\ ) # skip the image if it already exists in the repo - curl --silent -f -lSL https://registry.hub.docker.com/v2/repositories/${DOCKERHUB_ORGANIZATION}/${DOCKER_IMAGE_NAME}/tags/latest > /dev/null \ + curl --silent -f -lSL https://registry.hub.docker.com/v2/repositories/${DOCKERHUB_ORGANIZATION}/${DOCKER_IMAGE_NAME}/tags/${DOCKER_IMAGE_TAG} > /dev/null \ && continue - docker build -t ${DOCKERHUB_ORGANIZATION}/${DOCKER_IMAGE_NAME} ${DOCKERFILE_DIR} - + docker build -t ${DOCKERHUB_ORGANIZATION}/${DOCKER_IMAGE_NAME}:${DOCKER_IMAGE_TAG} ${DOCKERFILE_DIR} + # "docker login" needs to be run in advance - docker push ${DOCKERHUB_ORGANIZATION}/${DOCKER_IMAGE_NAME} + docker push ${DOCKERHUB_ORGANIZATION}/${DOCKER_IMAGE_NAME}:${DOCKER_IMAGE_TAG} done diff --git a/tools/run_tests/dockerize/build_and_run_docker.sh b/tools/run_tests/dockerize/build_and_run_docker.sh index a5ef4284be7..7e9bc7744eb 100755 --- a/tools/run_tests/dockerize/build_and_run_docker.sh +++ b/tools/run_tests/dockerize/build_and_run_docker.sh @@ -33,7 +33,7 @@ cd - # $@ - Extra args to pass to docker run # Use image name based on Dockerfile location checksum -DOCKER_IMAGE_NAME=$(basename "$DOCKERFILE_DIR")_$(sha1sum "$DOCKERFILE_DIR/Dockerfile" | cut -f1 -d\ ) +DOCKER_IMAGE_NAME=$(basename "$DOCKERFILE_DIR"):$(sha1sum "$DOCKERFILE_DIR/Dockerfile" | cut -f1 -d\ ) # Pull the base image to force an update if [ "$DOCKER_BASE_IMAGE" != "" ] diff --git a/tools/run_tests/dockerize/build_docker_and_run_tests.sh b/tools/run_tests/dockerize/build_docker_and_run_tests.sh index aeaae3f9a2b..4a7908b0462 100755 --- a/tools/run_tests/dockerize/build_docker_and_run_tests.sh +++ b/tools/run_tests/dockerize/build_docker_and_run_tests.sh @@ -30,7 +30,7 @@ cd - # DOCKERHUB_ORGANIZATION - If set, pull a prebuilt image from given dockerhub org. # Use image name based on Dockerfile location checksum -DOCKER_IMAGE_NAME=$(basename "$DOCKERFILE_DIR")_$(sha1sum "$DOCKERFILE_DIR/Dockerfile" | cut -f1 -d\ ) +DOCKER_IMAGE_NAME=$(basename "$DOCKERFILE_DIR"):$(sha1sum "$DOCKERFILE_DIR/Dockerfile" | cut -f1 -d\ ) if [ "$DOCKERHUB_ORGANIZATION" != "" ] then diff --git a/tools/run_tests/dockerize/build_interop_image.sh b/tools/run_tests/dockerize/build_interop_image.sh index 9516c5ade26..5b5bfb65982 100755 --- a/tools/run_tests/dockerize/build_interop_image.sh +++ b/tools/run_tests/dockerize/build_interop_image.sh @@ -84,9 +84,9 @@ fi # on OSX use md5 instead of sha1sum if command -v sha1sum > /dev/null; then - BASE_IMAGE=${BASE_NAME}_$(sha1sum "tools/dockerfile/interoptest/$BASE_NAME/Dockerfile" | cut -f1 -d\ ) + BASE_IMAGE=${BASE_NAME}:$(sha1sum "tools/dockerfile/interoptest/$BASE_NAME/Dockerfile" | cut -f1 -d\ ) else - BASE_IMAGE=${BASE_NAME}_$(md5 -r "tools/dockerfile/interoptest/$BASE_NAME/Dockerfile" | cut -f1 -d\ ) + BASE_IMAGE=${BASE_NAME}:$(md5 -r "tools/dockerfile/interoptest/$BASE_NAME/Dockerfile" | cut -f1 -d\ ) fi if [ "$DOCKERHUB_ORGANIZATION" != "" ]