forked from HurricanKai/Publish-Docker-Github-Action
-
Notifications
You must be signed in to change notification settings - Fork 0
/
entrypoint.sh
executable file
·65 lines (52 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
57
58
59
60
61
62
63
64
65
#!/bin/sh
set -e
if [ -z "${INPUT_NAME}" ]; then
echo "Unable to find the repository name. Did you set with.name?"
exit 1
fi
if [ -z "${INPUT_USERNAME}" ]; then
echo "Unable to find the username. Did you set with.username?"
exit 1
fi
if [ -z "${INPUT_PASSWORD}" ]; then
echo "Unable to find the password. Did you set with.password?"
exit 1
fi
BRANCH=$(echo ${GITHUB_REF} | sed -e "s/refs\/heads\///g")
if [ "${BRANCH}" == "master" ]; then
BRANCH="latest"
fi;
# if contains /refs/tags/
if [ $(echo ${GITHUB_REF} | sed -e "s/refs\/tags\///g") != ${GITHUB_REF} ]; then
BRANCH="latest"
fi;
echo ${INPUT_PASSWORD} | docker login -u ${INPUT_USERNAME} --password-stdin ${INPUT_REGISTRY}
DOCKERNAME="${INPUT_NAME}:${BRANCH}"
BUILDPARAMS="${INPUT_EXTRA_BUILD_PARAMS}"
if [ ! -z "${INPUT_DOCKERNAME_APPENDIX}" ]; then
DOCKERNAME="$DOCKERNAME${INPUT_DOCKERNAME_APPENDIX}"
fi
if [ ! -z "${INPUT_DOCKERFILE}" ]; then
BUILDPARAMS="$BUILDPARAMS -f ${INPUT_DOCKERFILE}"
fi
if [ ! -z "${INPUT_CACHE}" ]; then
docker pull ${DOCKERNAME}
BUILDPARAMS="$BUILDPARAMS --cache-from ${DOCKERNAME}"
fi
if [ "${INPUT_SNAPSHOT}" == "true" ]; then
timestamp=`date +%Y%m%d%H%M%S`
shortSha=$(echo "${GITHUB_SHA}" | cut -c1-6)
SHA_DOCKER_NAME="${INPUT_NAME}:${timestamp}${shortSha}"
docker build $BUILDPARAMS -t ${DOCKERNAME} -t ${SHA_DOCKER_NAME} .
docker push ${DOCKERNAME}
docker push ${SHA_DOCKER_NAME}
elif [ "${INPUT_TAGGING}" == "true" ]; then
DOCKER_TAG=$(echo ${GITHUB_REF} | sed -e 's/refs\/tags\/v//')
docker build $BUILDPARAMS -t ${INPUT_NAME}:latest -t ${INPUT_NAME}:${DOCKER_TAG} .
docker push ${INPUT_NAME}:latest
docker push ${INPUT_NAME}:${DOCKER_TAG}
else
docker build $BUILDPARAMS -t ${DOCKERNAME} .
docker push ${DOCKERNAME}
fi
docker logout