Created
May 20, 2019 10:15
-
-
Save Aisuko/e23b2c7d02d98169345bb0489f78f6ed to your computer and use it in GitHub Desktop.
Build images with kaniko and local docker config authorization
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# !/usr/bin/env bash | |
# | |
# Auto build image use kaniko in container. | |
# Copyright (C) 2019 Bowen.Li urakiny@gmail.com | |
# | |
red='\033[0;31m' | |
green='\033[0;32m' | |
yellow='\033[0;33m' | |
plain='\033[0m' | |
cur_dir=$(pwd) | |
behavior=(Push-to-dockerhub Push-to-harbor Push-to-local) | |
build_select(){ | |
while true | |
do | |
echo "Which behavior you'd select:" | |
for ((i=1;i<=${#behavior[@]};i++ )); do | |
hint="${behavior[$i-1]}" | |
echo -e "${green}${i}${plain}) ${hint}" | |
done | |
read -p "Please enter a number (Default ${behavior[0]}):" selected | |
[ -z "${selected}" ] && selected="1" | |
case "${selected}" in | |
1|2|3) | |
echo | |
echo "You choose = ${behavior[${selected}-1]}" | |
echo | |
break | |
;; | |
*) | |
echo -e "[${red}Error${plain}] Please only enter a number [1-3]" | |
;; | |
esac | |
done | |
} | |
build_to_dockerhub(){ | |
# Build the image and push to Dockerhub. | |
docker run -v $(pwd):/workspace -v ${HOME}/.docker:/root/.docker -e DOCKER_CONFIG=/root/.docker gcr.io/kaniko-project/executor:latest /kaniko/executor --dockerfile=/workspace/Dockerfile --context dir:///workspace/ --destination=aisuko/skaffold --skip-tls-verify -v=debug | |
} | |
build_to_harbor(){ | |
# Build the image and push to own private harbor registry. | |
docker run -v $(pwd):/workspace -v ${HOME}/.docker:/root/.docker -e DOCKER_CONFIG=/root/.docker gcr.io/kaniko-project/executor:latest /kaniko/executor --dockerfile=/workspace/Dockerfile --context dir:///workspace/ --destination=10.116.18.93/base_images/skaffold --skip-tls-verify --insecure -v=debug | |
} | |
build_to_local_dir(){ | |
# Build the image with tag --no-push | |
docker run -v $(pwd):/workspace -v ${HOME}/.docker:/root/.docker -e DOCKER_CONFIG=/root/.docker gcr.io/kaniko-project/executor:latest /kaniko/executor --dockerfile=/workspace/Dockerfile --context dir:///workspace/ --destination=image --tarPath=/workspace/image.tar -v=debug | |
} | |
build_main(){ | |
if [ "${selected}" == "1" ]; then | |
build_to_dockerhub | |
elif [ "${selected}" == "2" ]; then | |
build_to_harbor | |
elif [ "${selected}" == "3" ]; then | |
build_to_local_dir | |
fi | |
echo | |
echo "Enjoy it!" | |
echo | |
} | |
build_image(){ | |
build_select | |
build_main | |
} | |
# | |
action=$1 | |
[ -z $1 ] && action=build | |
case "${action}" in | |
build|unbuild) | |
${action}_image | |
;; | |
*) | |
echo "Arguments error! [${action}]" | |
echo "Usage: $(basename $0) [build|unbuild]" | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment