-
Notifications
You must be signed in to change notification settings - Fork 3
/
entrypoint.sh
122 lines (95 loc) · 2.99 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#!/bin/sh
set -e
KANIKO_CONTEXT="/github/workspace"
COMMAND="/kaniko/executor"
RED='\033[0;31m' # Red color for warning messages
NC='\033[0m' # No Color
ln -s $HOME/.docker /kaniko/.docker
if [ -n "$FILE" ]; then
KANIKO_FILE=${FILE}
elif [ -n "$INPUT_FILE" ]; then
KANIKO_FILE=${INPUT_FILE}
else
KANIKO_FILE="Dockerfile"
fi
if [ -n "$CONTEXT" ]; then
KANIKO_CONTEXT="${KANIKO_CONTEXT}/${CONTEXT}"
elif [ -n "$INPUT_CONTEXT" ]; then
KANIKO_CONTEXT="${KANIKO_CONTEXT}/${INPUT_CONTEXT}"
fi
COMMAND="${COMMAND} --context ${KANIKO_CONTEXT}"
if [ "$PUSH" == "false" ] || [ "$INPUT_PUSH" == "false" ]; then
COMMAND="${COMMAND} --no-push"
fi
COMMAND="${COMMAND} --dockerfile ${KANIKO_CONTEXT}/${KANIKO_FILE}"
if [ -n "$TAGS" ]; then
LOCAL_TAGS=$TAGS
elif [ -n "$INPUT_TAGS" ]; then
LOCAL_TAGS=$INPUT_TAGS
fi
for TAG in ${LOCAL_TAGS}; do
COMMAND="${COMMAND} --destination ${TAG}"
done
if [ -n "$LABELS" ]; then
LOCAL_LABELS=$LABELS
elif [ -n "$INPUT_LABELS" ]; then
LOCAL_LABELS=$INPUT_LABELS
fi
if [ -n "$BUILD_ARGS" ]; then
LOCAL_BUILD_ARGS=$BUILD_ARGS
elif [ -n "$INPUT_BUILD_ARGS" ]; then
LOCAL_BUILD_ARGS=$INPUT_BUILD_ARGS
fi
for ARG in $LOCAL_BUILD_ARGS; do
KEY=$(echo $ARG | cut -d "=" -f 1)
VALUE=$(echo $ARG | cut -d "=" -f 2)
COMMAND="${COMMAND} --build-arg ${KEY}=\"${VALUE}\""
done
OLDIFS="$IFS"
IFS=$'\n' # to iterate over labels
for LABEL in $LOCAL_LABELS; do
KEY=$(echo $LABEL | cut -d "=" -f 1)
VALUE=$(echo $LABEL | cut -d "=" -f 2)
COMMAND="${COMMAND} --label ${KEY}=\"${VALUE}\""
done
IFS="$OLDIFS"
if [ -n "$TAR_FILE" ]; then
KANIKO_TARFILE="${KANIKO_CONTEXT}/$TAR_FILE"
elif [ -n "$INPUT_TAR_FILE" ]; then
KANIKO_TARFILE="${KANIKO_CONTEXT}/$INPUT_TAR_FILE"
fi
if [ -n "$KANIKO_TARFILE" ]; then
COMMAND="${COMMAND} --tarPath ${KANIKO_TARFILE}"
fi
if [ -n "$CACHE_TTL" ]; then
KANIKO_CACHE_TTL=$CACHE_TTL
elif [ -n "$INPUT_CACHE_TTL" ]; then
KANIKO_CACHE_TTL=$INPUT_CACHE_TTL
else
KANIKO_CACHE_TTL="12h"
fi
if [ "$CACHE" == "true" ] || [ "$INPUT_CACHE" == "true" ]; then
COMMAND="${COMMAND} --cache=true --cache-ttl=${KANIKO_CACHE_TTL}"
fi
if [ -n "$SNAPSHOT_MODE" ]; then
KANIKO_SNAPSHOT_MODE=$SNAPSHOT_MODE
elif [ -n "$INPUT_SNAPSHOT_MODE" ]; then
KANIKO_SNAPSHOT_MODE=$INPUT_SNAPSHOT_MODE
else
KANIKO_SNAPSHOT_MODE="full"
fi
if [ -n "$KANIKO_SNAPSHOT_MODE" ]; then
COMMAND="${COMMAND} --snapshotMode=${KANIKO_SNAPSHOT_MODE}"
fi
if [ "$USE_NEW_RUN" == "true" ] || [ "$INPUT_USE_NEW_RUN" == "true" ]; then
COMMAND="${COMMAND} --use-new-run"
fi
if [ "$DEBUG_MODE" == "true" ] || [ "$INPUT_DEBUG_MODE" == "true" ]; then
echo -e "${RED}WARNING!!${NC} Debug mode has been set to true, some sensitive data used to build the image may will be exposed!!"
echo "Launching kaniko with the following parameters:"
echo "${COMMAND}"
else
echo "Launching kaniko..."
fi
alias kaniko_build="$COMMAND" # Workaroud to handle possible labels with white spaces
kaniko_build