From 8e9cd7f52b8adba01d55018fe6cd7e453cbe3ce0 Mon Sep 17 00:00:00 2001 From: Luca Comellini Date: Thu, 10 Nov 2022 18:45:56 -0800 Subject: [PATCH] Fix git command to retrieve commit matching the tag To find the correct binary to use for the build when a user checks out a tag, we need to match the exact commit for the tag. `git tag --contains` would list all the tags containing the commit, but we need to verify that the commit we're on matches the current tag. --- hack/docker.sh | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/hack/docker.sh b/hack/docker.sh index 09c3747529..57aac1c785 100755 --- a/hack/docker.sh +++ b/hack/docker.sh @@ -4,16 +4,17 @@ git_commit=$1 git_tag=$2 docker_tag=edge -commit_tag=$(git tag --contains ${git_commit}) +commit_tag=$(git describe --exact-match ${git_commit} 2>/dev/null) -if [[ ${commit_tag} == *${git_tag}* ]]; then - # we're on the tag, use the docker image for the tag +if [[ ${commit_tag} == ${git_tag} ]]; then + # we're on the exact commit of the tag, use the docker image for the tag docker_tag=${git_tag//v/} echo ${docker_tag} exit 0 else - # we're on main or a branch, try to download the latest edge and see if sha matches + # we're on a random commit, pull the 'edge' docker image to compare commits + # if it's the latest commit from 'main' the SHA will match the 'revision' of the 'edge' docker image docker pull nginx/nginx-ingress:${docker_tag} >/dev/null 2>&1 DOCKER_SHA=$(docker inspect --format '{{ index .Config.Labels "org.opencontainers.image.revision" }}' nginx/nginx-ingress:${docker_tag}) if [[ ${DOCKER_SHA} == ${git_commit} ]]; then