Skip to content

Commit 2d5f7fc

Browse files
authored
Support for tagging docker images with git hash they were built from (#299)
1 parent 0e4cbba commit 2d5f7fc

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

docker/benchbase/common-env.sh

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,10 @@ git_vers_tag=$(git tag -l --points-at HEAD | grep ^v | sort -V | tail -n1)
5252

5353
# We could also include a short tag to follow semantic versioning, but it adds
5454
# cleanup complexity, so we omit it for now.
55-
#git_rev_short=$(git rev-parse --revs-only --short HEAD)
55+
git_rev_short=''
56+
if [ "${WITH_GIT_SHORT_REV_TAG:-false}" == 'true' ]; then
57+
git_rev_short=$(git rev-parse --revs-only --short HEAD)
58+
fi
5659

5760
# Local image gets a :latest tag, always, for local dev/run convenience.
5861
image_tag_args="-t $imagename:latest"
@@ -70,6 +73,13 @@ if [ -n "$git_vers_tag" ]; then
7073
fi
7174
fi
7275

76+
if [ -n "$git_rev_short" ]; then
77+
image_tag_args+=" -t $imagename:$git_rev_short"
78+
if [ -n "$CONTAINER_REGISTRY_NAME" ]; then
79+
image_tag_args+=" -t $CONTAINER_REGISTRY_NAME/$imagename:$git_rev_short"
80+
fi
81+
fi
82+
7383
docker_build_args=''
7484
if ! docker buildx version >/dev/null 2>&1; then
7585
echo 'NOTE: docker buildkit is unavailable.' >&2

0 commit comments

Comments
 (0)