-
Notifications
You must be signed in to change notification settings - Fork 36
/
entrypoint.sh
executable file
·55 lines (42 loc) · 1.64 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
#!/bin/sh
DOCKER_TOKEN=$1
DOCKER_IMAGE_NAME=$2
DOCKER_IMAGE_TAG=$3
EXTRACT_TAG_FROM_GIT_REF=$4
DOCKERFILE=$5
BUILD_CONTEXT=$6
PULL_IMAGE=$7
DOCKER_IMAGE_TAGS=$8
DOCKER_IMAGE_PLATFORM=$9
CUSTOM_DOCKER_BUILD_ARGS=${10}
if [ "$(echo ${EXTRACT_TAG_FROM_GIT_REF})" == 'true' ]; then
DOCKER_IMAGE_TAG=$(echo ${GITHUB_REF} | sed -e "s/refs\/tags\///g")
fi
DOCKER_IMAGE_NAME=$(echo ghcr.io/${GITHUB_REPOSITORY}/${DOCKER_IMAGE_NAME} | tr '[:upper:]' '[:lower:]')
DOCKER_IMAGE_NAME_WITH_TAG=$(echo ${DOCKER_IMAGE_NAME}:${DOCKER_IMAGE_TAG} | tr '[:upper:]' '[:lower:]')
docker buildx create --use # Creating builder instance to support cross-platform builds
docker login -u publisher -p ${DOCKER_TOKEN} ghcr.io
if [ "$(echo ${PULL_IMAGE})" == 'true' ]; then
if [ "$(echo ${DOCKER_IMAGE_PLATFORM})" != '' ]; then
docker pull ${DOCKER_IMAGE_NAME_WITH_TAG} --platform ${DOCKER_IMAGE_PLATFORM} || docker pull ${DOCKER_IMAGE_NAME} --platform ${DOCKER_IMAGE_PLATFORM} || true
else
docker pull ${DOCKER_IMAGE_NAME_WITH_TAG} || docker pull ${DOCKER_IMAGE_NAME} || true
fi
fi
set -- -t ${DOCKER_IMAGE_NAME_WITH_TAG}
if [ "$(echo ${DOCKERFILE})" != 'Dockerfile' ]; then
set -- $(echo ${@}) -f ${DOCKERFILE}
fi
if [ "$(echo ${DOCKER_IMAGE_PLATFORM})" != '' ]; then
set -- $(echo ${@}) --platform ${DOCKER_IMAGE_PLATFORM}
fi
if [ "$(echo ${CUSTOM_DOCKER_BUILD_ARGS})" != '' ]; then
set -- ${@} ${CUSTOM_DOCKER_BUILD_ARGS}
fi
set -- ${@} ${BUILD_CONTEXT}
for tag in ${DOCKER_IMAGE_TAGS}
do
DOCKER_IMAGE_NAME_WITH_TAG=$(echo ${DOCKER_IMAGE_NAME}:${tag} | tr '[:upper:]' '[:lower:]')
set -- -t ${DOCKER_IMAGE_NAME_WITH_TAG} ${@}
done
docker buildx build --push ${@}