diff --git a/README.md b/README.md index d7e9f20..68409d8 100644 --- a/README.md +++ b/README.md @@ -46,6 +46,9 @@ docker login docker.io # Short form kubectl build -c . -d docker.io/some/image:latest +# Run debug shell +kubectl build -c . --no-push --debug + # Use cache building kubectl build --context . --destination docker.io/some/image:latest --cache --cache-repo docker.io/some/cache diff --git a/kubectl-build b/kubectl-build index 912e721..a3f98e9 100755 --- a/kubectl-build +++ b/kubectl-build @@ -3,7 +3,13 @@ set -e export DOCKER_CONFIG=${KUBECTL_BUILD_DOCKER_CONFIG:-${DOCKER_CONFIG:-$HOME/.docker/config.json}} export KUBECONFIG="${KUBECTL_BUILD_KUBECONFIG:-$KUBECONFIG}" kubectl=kubectl +version=1.6.0 +image="${KUBECTL_BUILD_IMAGE:-ghcr.io/kvaps/kaniko-executor:v1.6.0}" +name="${KUBECTL_BUILD_NAME_OVERRIDE:-kaniko-$(env LC_ALL=C tr -dc a-z0-9 &2 - exit 1 -fi + fi +} if [ "$KUBECTL_BUILD_KEEP_POD" != "true" ]; then - trap "EC=\$?; $kubectl delete pod "$name" --wait=false 2>/dev/null || true; exit \$EC" EXIT INT TERM + trap "ec=\$?; $kubectl delete pod "$name" --wait=false 2>/dev/null || true; exit \$ec" EXIT INT TERM fi echo "spawning \"$name\"" -if [ -n "$context" ] && [ "$context" != "tar://stdin" ]; then - tarf -C "$context" -czf - . | - $kubectl run --image "$image" --restart=Never --overrides="$overrides" -i "$name" $generator +if [ "$usetar" = "true" ]; then + pidfile=$(mktemp -u) + ( + tarf -C "$context" -czf - . + if [ "$debug" = true ]; then + sh -c 'echo $PPID' > "$pidfile" + trap 'stty icanon echo' EXIT + stty -icanon -echo + cat + fi + ) | ( + $kubectl run --image "$image" --restart=Never --overrides="$overrides" -i "$name" $generator || ec=$? + if [ "$debug" = true ]; then + kill $(cat "$pidfile") + fi + exit $ec + ) else $kubectl run --image "$image" --restart=Never --overrides="$overrides" -i "$name" $generator fi