|
1 | 1 | #!/usr/bin/env sh
|
2 | 2 | set -e
|
3 |
| -DOCKER_CONFIG=${DOCKER_CONFIG:-$HOME/.docker/config.json} |
| 3 | +export DOCKER_CONFIG=${KUBECTL_BUILD_DOCKER_CONFIG:-${DOCKER_CONFIG:-$HOME/.docker/config.json}} |
| 4 | +export KUBECONFIG="${KUBECTL_BUILD_KUBECONFIG:-$KUBECONFIG}" |
4 | 5 | kubectl=kubectl
|
5 | 6 | context=""
|
6 | 7 | generator=""
|
@@ -79,8 +80,8 @@ while [ $# -gt 0 ]; do
|
79 | 80 | done
|
80 | 81 |
|
81 | 82 | # Set the default context and namespace to avoid situations where the user switch them during the build process
|
82 |
| -[ "$nodefaultctx" = 1 ] || kubectl="$kubectl --context=$(kubectl config current-context)" |
83 |
| -[ "$nodefaultns" = 1 ] || kubectl="$kubectl --namespace=$(kubectl config view --minify --output 'jsonpath={.contexts..namespace}')" |
| 83 | +[ "$nodefaultctx" = 1 ] || kubectl="$kubectl --context=${KUBECTL_BUILD_CONTEXT:-$(kubectl config current-context)}" |
| 84 | +[ "$nodefaultns" = 1 ] || kubectl="$kubectl --namespace=${KUBECTL_BUILD_NAMESPACE:-$(kubectl config view --minify --output 'jsonpath={.contexts..namespace}')}" |
84 | 85 |
|
85 | 86 | if [ -n "$digestfile" ] || [ -n "$imagenamewithdigestfile" ]; then
|
86 | 87 | args="$args\"--image-name-with-digest-file=/dev/termination-log\""
|
|
96 | 97 | args="$args, \"--context=$context\" ]"
|
97 | 98 | fi
|
98 | 99 |
|
99 |
| -image="gcr.io/kaniko-project/executor:v1.5.1" |
100 |
| -name="kaniko-$(env LC_ALL=C tr -dc a-z0-9 </dev/urandom | head -c 6)" |
| 100 | +image="${KUBECTL_BUILD_IMAGE:-gcr.io/kaniko-project/executor:v1.5.1}" |
| 101 | +name="${KUBECTL_BUILD_NAME_OVERRIDE:-kaniko-$(env LC_ALL=C tr -dc a-z0-9 </dev/urandom | head -c 6)}" |
101 | 102 |
|
102 | 103 | overrides="$(
|
103 | 104 | cat <<EOT
|
104 | 105 | {
|
| 106 | + "metadata": ${KUBECTL_BUILD_METADATA_OVERRIDES:-"{}"}, |
105 | 107 | "spec": {
|
106 | 108 | "containers": [
|
107 | 109 | {
|
@@ -152,14 +154,16 @@ if [ -n "$context" ] && ([ ! -d "$context" ] && [ "$context" != "tar://stdin" ])
|
152 | 154 | exit 1
|
153 | 155 | fi
|
154 | 156 |
|
155 |
| -trap "EC=\$?; $kubectl delete pod "$name" --wait=false 2>/dev/null || true; exit \$EC" EXIT INT TERM |
| 157 | +if [ "$KUBECTL_BUILD_KEEP_POD" != "true" ]; then |
| 158 | + trap "EC=\$?; $kubectl delete pod "$name" --wait=false 2>/dev/null || true; exit \$EC" EXIT INT TERM |
| 159 | +fi |
156 | 160 |
|
157 | 161 | echo "spawning \"$name\""
|
158 | 162 | if [ -n "$context" ] && [ "$context" != "tar://stdin" ]; then
|
159 | 163 | tarf -C "$context" -czf - . |
|
160 |
| - $kubectl run --image "$image" --rm --restart=Never --overrides="$overrides" -i "$name" $generator |
| 164 | + $kubectl run --image "$image" --restart=Never --overrides="$overrides" -i "$name" $generator |
161 | 165 | else
|
162 |
| - $kubectl run --image "$image" --rm --restart=Never --overrides="$overrides" -i "$name" $generator |
| 166 | + $kubectl run --image "$image" --restart=Never --overrides="$overrides" -i "$name" $generator |
163 | 167 | fi
|
164 | 168 |
|
165 | 169 | # Retrieve digest file
|
|
0 commit comments