Skip to content

Commit

Permalink
tools: add docker build/push script
Browse files Browse the repository at this point in the history
  • Loading branch information
gszr committed Sep 16, 2019
1 parent f6216ed commit 244f4cb
Showing 1 changed file with 122 additions and 0 deletions.
122 changes: 122 additions & 0 deletions tools/releases/docker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
#!/usr/bin/env bash

set -e

KUMA_DOCKER_REPO="kong-docker-kuma-docker.bintray.io"
KUMA_COMPONENTS=("kuma-cp" "kuma-dp" "kuma-injector" "kuma-tcp-echo")

function msg_green {
builtin echo -en "\033[1;32m"
echo "$@"
builtin echo -en "\033[0m"
}


function msg_red() {
builtin echo -en "\033[1;31m" >&2
echo "$@" >&2
builtin echo -en "\033[0m" >&2
}


function msg_yellow() {
builtin echo -en "\033[1;33m"
echo "$@"
builtin echo -en "\033[0m"
}


function msg() {
builtin echo -en "\033[1m"
echo "$@"
builtin echo -en "\033[0m"
}


function msg_err() {
msg_red $@
exit 1
}


function build {
for component in "${KUMA_COMPONENTS[@]}"; do
msg "Building $component..."
docker build --build-arg KUMA_ROOT=$(pwd) -t $KUMA_DOCKER_REPO/$component:$KUMA_VERSION \
-f tools/releases/dockerfiles/Dockerfile.$component .
docker tag $KUMA_DOCKER_REPO/$component:$KUMA_VERSION $KUMA_DOCKER_REPO/$component:latest
msg_green "... done!"
done
}


function docker_login {
docker login -u "$BINTRAY_USERNAME" -p "$BINTRAY_API_KEY" $KUMA_DOCKER_REPO
}


function docker_logout {
docker logout $KUMA_DOCKER_REPO
}


function push {
docker_login

for component in "${KUMA_COMPONENTS[@]}"; do
msg "Pushing kuma-cp..."
docker push $KUMA_DOCKER_REPO/$component:$KUMA_VERSION
docker push $KUMA_DOCKER_REPO/$component:latest
msg_green "... done!"
done

docker_logout
}


function usage {
echo "Usage: $0 [--build | --push ] --version <Kuma version>"
exit 0
}

function main {
while [[ $# -gt 0 ]]; do
flag=$1
case $flag in
--help)
usage
;;
--build)
op="build"
;;
--push)
op="push"
;;
--version)
KUMA_VERSION=$2
shift
;;
*)
usage
break
;;
esac
shift
done

[ -z "$BINTRAY_USERNAME" ] && msg_err "BINTRAY_USERNAME required"
[ -z "$BINTRAY_API_KEY" ] && msg_err "BINTRAY_API_KEY required"
[ -z "$KUMA_VERSION" ] && msg_err "Error: --version required"

case $op in
build)
build
;;
push)
push
;;
esac
}


main $@

0 comments on commit 244f4cb

Please sign in to comment.