diff --git a/oci/base/alpine-docker-dind/Dockerfile b/oci/base/alpine-docker-dind/Dockerfile index 4f82d52..5d176a4 100644 --- a/oci/base/alpine-docker-dind/Dockerfile +++ b/oci/base/alpine-docker-dind/Dockerfile @@ -8,6 +8,7 @@ RUN apk update && \ # Set environment variables for Docker daemon to listen on tcp and to disable TLS (adjust based on your security requirements) ENV DOCKER_TLS_CERTDIR="" ENV DOCKER_HOST=tcp://localhost:2375 +COPY fetch_build_tag.sh /opt/ # Expose the default Docker daemon port EXPOSE 2375 diff --git a/oci/base/alpine-docker-dind/fetch_build_tag.sh b/oci/base/alpine-docker-dind/fetch_build_tag.sh new file mode 100755 index 0000000..0af6e26 --- /dev/null +++ b/oci/base/alpine-docker-dind/fetch_build_tag.sh @@ -0,0 +1,26 @@ +#!/bin/bash + +# Configure git to allow all directories +git config --global --add safe.directory '*' + +# Get the latest tag containing the HEAD +TAG=$(git tag --contains HEAD | head -n 1) + +# Get the short commit ID +SHORT_COMMIT_ID=$(echo $GITHUB_SHA | cut -c1-7) + +# Get the current branch name +BRANCH_NAME=$(git branch --show-current) + +# Logic to set the build tag based on branch and tag status +if [[ "$BRANCH_NAME" == "main" ]]; then + echo "BUILD_TAG=latest" >> $GITHUB_ENV +elif [[ "$BRANCH_NAME" =~ ^release/ ]] && [[ -z "$TAG" ]]; then + PR_ID=$(git log | grep "Merge pull request" | head -n 1 | awk -F# '{print $2}' | awk '{print $1}') + echo "BUILD_TAG=PR-${PR_ID}-$SHORT_COMMIT_ID" >> $GITHUB_ENV +elif [[ "$BRANCH_NAME" =~ ^release/ ]] && [[ ! -z "$TAG" ]]; then + echo "BUILD_TAG=$TAG" >> $GITHUB_ENV +else + JIRA_TICKET=$(git branch | grep '^\*' | awk '{print $2}' | awk -F- '{print $1"-"$2}') + echo "BUILD_TAG=$JIRA_TICKET-$SHORT_COMMIT_ID" >> $GITHUB_ENV +fi