From f49da3deac9b4d70d8d42f49a3dfda8afa887228 Mon Sep 17 00:00:00 2001 From: Dan Notestein Date: Tue, 28 Nov 2023 21:08:12 +0000 Subject: [PATCH] Add labels to the docker image --- scripts/ci-helpers/build_instance.sh | 58 +++++++++++++++++++++++++++- 1 file changed, 56 insertions(+), 2 deletions(-) diff --git a/scripts/ci-helpers/build_instance.sh b/scripts/ci-helpers/build_instance.sh index a8ec34d35a..f5f89293bd 100755 --- a/scripts/ci-helpers/build_instance.sh +++ b/scripts/ci-helpers/build_instance.sh @@ -104,23 +104,77 @@ SOURCE_DIR=$(git rev-parse --show-superproject-working-tree --show-toplevel | he HIVE_SUBDIR=$(realpath --relative-base="$SOURCE_DIR" "$HIVE_ROOT") export DOCKER_BUILDKIT=1 +BUILD_TIME="$(date -uIseconds)" +GIT_COMMIT_SHA="$CI_COMMIT_SHA" +if [ -z "$GIT_COMMIT_SHA" ]; then + GIT_COMMIT_SHA="$(git rev-parse HEAD || true)" + if [ -z "$GIT_COMMIT_SHA" ]; then + GIT_COMMIT_SHA="[unknown]" + fi +fi +GIT_CURRENT_BRANCH="$CI_COMMIT_BRANCH" +if [ -z "$GIT_CURRENT_BRANCH" ]; then + GIT_CURRENT_BRANCH="$(git branch --show-current || true)" + if [ -z "$GIT_CURRENT_BRANCH" ]; then + GIT_CURRENT_BRANCH="$(git describe --abbrev=0 --all | sed 's/^.*\///' || true)" + if [ -z "$GIT_CURRENT_BRANCH" ]; then + GIT_CURRENT_BRANCH="[unknown]" + fi + fi +fi + +GIT_LAST_LOG_MESSAGE="$CI_COMMIT_MESSAGE" +if [ -z "$GIT_LAST_LOG_MESSAGE" ]; then + GIT_LAST_LOG_MESSAGE="$(git log -1 --pretty=%B || true)" + if [ -z "$GIT_LAST_LOG_MESSAGE" ]; then + GIT_LAST_LOG_MESSAGE="[unknown]" + fi +fi + + +GIT_LAST_COMMITTER="$CI_COMMIT_AUTHOR" +if [ -z "$GIT_LAST_COMMITTER" ]; then + GIT_LAST_COMMITTER="$(git log -1 --pretty="%an <%ae>" || true)" + if [ -z "$GIT_LAST_COMMITTER" ]; then + GIT_LAST_COMMITTER="[unknown]" + fi +fi + +GIT_LAST_COMMIT_DATE="$CI_COMMIT_TIMESTAMP" +if [ -z "$GIT_LAST_COMMIT_DATE" ]; then + GIT_LAST_COMMIT_DATE="$(git log -1 --pretty="%aI" || true)" + if [ -z "$GIT_LAST_COMMIT_DATE" ]; then + GIT_LAST_COMMIT_DATE="[unknown]" + fi +fi docker build --target=base_instance \ --build-arg CI_REGISTRY_IMAGE="$REGISTRY" \ --build-arg BUILD_HIVE_TESTNET=$BUILD_HIVE_TESTNET \ --build-arg HIVE_CONVERTER_BUILD=$HIVE_CONVERTER_BUILD \ - --build-arg BUILD_IMAGE_TAG="$BUILD_IMAGE_TAG" \ + --build-arg BUILD_IMAGE_TAG=$BUILD_IMAGE_TAG \ + --build-arg BUILD_TIME="$BUILD_TIME" \ + --build-arg GIT_COMMIT_SHA="$GIT_COMMIT_SHA" \ + --build-arg GIT_CURRENT_BRANCH="$GIT_CURRENT_BRANCH" \ + --build-arg GIT_LAST_LOG_MESSAGE="$GIT_LAST_LOG_MESSAGE" \ + --build-arg GIT_LAST_COMMITTER="$GIT_LAST_COMMITTER" \ + --build-arg GIT_LAST_COMMIT_DATE="$GIT_LAST_COMMIT_DATE" \ --tag "${REGISTRY}base_instance:${BUILD_IMAGE_TAG}" \ --tag "${REGISTRY}${IMAGE_TAG_PREFIX}base_instance:${BUILD_IMAGE_TAG}" \ --build-arg HIVE_SUBDIR="$HIVE_SUBDIR" \ -f Dockerfile "$SOURCE_DIR" - docker build --target=instance \ --build-arg CI_REGISTRY_IMAGE="$REGISTRY" \ --build-arg BUILD_HIVE_TESTNET=$BUILD_HIVE_TESTNET \ --build-arg HIVE_CONVERTER_BUILD=$HIVE_CONVERTER_BUILD \ --build-arg BUILD_IMAGE_TAG="$BUILD_IMAGE_TAG" \ + --build-arg BUILD_TIME="$BUILD_TIME" \ + --build-arg GIT_COMMIT_SHA="$GIT_COMMIT_SHA" \ + --build-arg GIT_CURRENT_BRANCH="$GIT_CURRENT_BRANCH" \ + --build-arg GIT_LAST_LOG_MESSAGE="$GIT_LAST_LOG_MESSAGE" \ + --build-arg GIT_LAST_COMMITTER="$GIT_LAST_COMMITTER" \ + --build-arg GIT_LAST_COMMIT_DATE="$GIT_LAST_COMMIT_DATE" \ --tag "${REGISTRY}${IMAGE_TAG_PREFIX}instance:${BUILD_IMAGE_TAG}" \ --build-arg HIVE_SUBDIR="$HIVE_SUBDIR" \ -f Dockerfile "$SOURCE_DIR"