docker-dind: add fetch_build_tag.sh
This commit is contained in:
parent
932e69d2b6
commit
64b0495563
@ -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
|
||||
|
||||
26
oci/base/alpine-docker-dind/fetch_build_tag.sh
Executable file
26
oci/base/alpine-docker-dind/fetch_build_tag.sh
Executable file
@ -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
|
||||
Loading…
Reference in New Issue
Block a user