Merge pull request #35 from svc-design/build-ci-image-docker-dind

docker-dind: add fetch_build_tag.sh
This commit is contained in:
shenlan 2024-04-28 00:02:06 +08:00 committed by GitHub
commit 635410d4ee
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 27 additions and 0 deletions

View File

@ -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

View 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