-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
entrypoint.sh
56 lines (44 loc) · 1.75 KB
/
entrypoint.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/bin/sh
# shellcheck disable=SC2001
set -o errexit
GIT_TAG=$(echo "${INPUT_TAG_REF}" | sed -e 's|refs/tags/||')
IMAGE_NAME="docker.pkg.github.com/${INPUT_IMAGE_NAME}"
if [ -n "${INPUT_IMAGE_TAG}" ]; then
IMAGE_TAG="${INPUT_IMAGE_TAG}"
else
IMAGE_TAG=$(echo "${GIT_TAG}" | sed -e 's/^v//' | sed -e 's/+.*//')
fi
echo "Building ${IMAGE_NAME}:${IMAGE_TAG} based on Git tag ${GIT_TAG} ..."
echo "Creating build-version.txt file ..."
echo "${GIT_TAG}" > "${GITHUB_WORKSPACE}/build-version.txt"
echo "${INPUT_REGISTRY_PASSWORD}" | docker login -u github --password-stdin https://docker.pkg.github.com/v2/
git checkout "${GIT_TAG}"
set -- "-t" "${IMAGE_NAME}:${IMAGE_TAG}" \
"--label" "org.label-schema.schema-version=1.0" \
"--label" "org.label-schema.version=${IMAGE_TAG}" \
"--label" "org.label-schema.build-date=$(date '+%FT%TZ')" \
"--build-arg" "BUILD_DATE=$(date '+%FT%TZ')"
if [ -n "${INPUT_GIT_REPOSITORY_URL}" ]; then
set -- "$@" "--label" "org.label-schema.vcs-url=${INPUT_GIT_REPOSITORY_URL}"
fi
if [ -n "${INPUT_GIT_SHA}" ]; then
set -- "$@" "--label" "org.label-schema.vcs-ref=${INPUT_GIT_SHA}"
fi
BUILD_ENV_SCRIPT=${GITHUB_WORKSPACE}/.github/build-env.sh
if [ -f "${BUILD_ENV_SCRIPT}" ]; then
# shellcheck disable=SC1090
. "${BUILD_ENV_SCRIPT}"
IFS="$(printf '\n ')" && IFS="${IFS% }"
set -o noglob
for line in $(env | grep BUILD_ARG_); do
set -- "$@" '--build-arg' "$(echo "$line" | sed -E 's/(BUILD_ARG_)//g')"
done
echo "Build arguments: " "$@"
else
echo "Skipping build env script (none found at ${BUILD_ENV_SCRIPT})"
fi
docker build "$@" .
docker push "${IMAGE_NAME}:${IMAGE_TAG}"
echo "image_name=${IMAGE_NAME}" >> $GITHUB_OUTPUT
echo "image_tag=${IMAGE_TAG}" >> $GITHUB_OUTPUT
echo "git_tag=${GIT_TAG}" >> $GITHUB_OUTPUT