forked from machine-learning-apps/gpr-docker-publish
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathentrypoint.sh
71 lines (54 loc) · 1.72 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
66
67
68
69
70
71
#!/bin/sh
#Publish Docker Container To GitHub Package Registry
####################################################
# exit when any command fails
set -e
#check inputs
if [[ -z "$INPUT_USERNAME" ]]; then
echo "Set the USERNAME input."
exit 1
fi
if [[ -z "$INPUT_PASSWORD" ]]; then
echo "Set the PASSWORD input."
exit 1
fi
if [[ -z "$INPUT_OWNER_NAME" ]]; then
echo "Set the OWNER_NAME input."
exit 1
fi
if [[ -z "$INPUT_REPO_NAME" ]]; then
echo "Set the REPO_NAME input."
exit 1
fi
if [[ -z "$INPUT_IMAGE_NAME" ]]; then
echo "Set the IMAGE_NAME input."
exit 1
fi
if [[ -z "$INPUT_DOCKERFILE_PATH" ]]; then
echo "Set the DOCKERFILE_PATH input."
exit 1
fi
if [[ -z "$INPUT_BUILD_CONTEXT" ]]; then
echo "Set the BUILD_CONTEXT input."
exit 1
fi
# The following environment variables will be provided by the environment automatically: GITHUB_REPOSITORY, GITHUB_SHA
# send credentials through stdin (it is more secure)
echo ${INPUT_PASSWORD} | docker login -u ${INPUT_USERNAME} --password-stdin docker.pkg.github.com
# Set Local Variables
BASE_NAME="docker.pkg.github.com/${INPUT_OWNER_NAME}/${INPUT_REPO_NAME}/${INPUT_IMAGE_NAME}"
TAG_NAME="${BASE_NAME}:${RELEASE_VERSION}"
# Add Arguments For Caching
BUILDPARAMS=""
if [ "${INPUT_CACHE}" == "true" ]; then
# try to pull container if exists
if docker pull ${BASE_NAME} 2>/dev/null; then
echo "Attempting to use ${BASE_NAME} as build cache."
BUILDPARAMS=" --cache-from ${BASE_NAME}"
fi
fi
# Build The Container
docker build $BUILDPARAMS -t ${TAG_NAME} -f ${INPUT_DOCKERFILE_PATH} ${INPUT_BUILD_CONTEXT}
docker push ${TAG_NAME}
echo "::set-output name=IMAGE_TAG_NAME::${TAG_NAME}"
echo "::set-output name=IMAGE_URL::https://github.com/${GITHUB_REPOSITORY}/packages"