Skip to content

Commit

Permalink
Merge pull request #265 from Kong/ci/docker-automation
Browse files Browse the repository at this point in the history
ci: docker automation
  • Loading branch information
Dhruvkaran Mehta authored Sep 17, 2019
2 parents 84db88f + 11fb466 commit 8206bd5
Show file tree
Hide file tree
Showing 7 changed files with 178 additions and 2 deletions.
16 changes: 15 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -333,15 +333,29 @@ jobs:
<<: *go-defaults
steps:
- checkout
- setup_remote_docker
- restore_cache:
keys:
- go.mod/{{ checksum "go.sum" }}
- run:
name: Build packages
name: "Install Docker client"
command: |
VER="17.03.0-ce"
curl -L -o /tmp/docker-$VER.tgz https://download.docker.com/linux/static/stable/x86_64/docker-$VER.tgz
tar -xz -C /tmp -f /tmp/docker-$VER.tgz
mv /tmp/docker/docker /usr/bin
- run:
name: Build Packages
command: ./tools/releases/distros.sh --package --version $CIRCLE_TAG --sha $CIRCLE_SHA1
- run:
name: Push Packages
command: ./tools/releases/distros.sh --release --version $CIRCLE_TAG
- run:
name: Build Docker
command: ./tools/releases/docker.sh --build --version $CIRCLE_TAG
- run:
name: Push Docker
command: ./tools/releases/docker.sh --push --version $CIRCLE_TAG

#
# Below, the tag filter needs to be in all jobs
Expand Down
2 changes: 1 addition & 1 deletion tools/releases/distros.sh
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ function get_envoy() {
--write-out %{http_code} --silent --output /dev/null \
"https://kong.bintray.com/envoy/envoy-1.11.0-$distro")

[ "$status" -ne "200" ] && msg_err "Error: failed downloading Envoy"
[ "$status" -ne "200" ] && msg_err "Error: failed downloading Envoy" || true
}


Expand Down
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 $@
12 changes: 12 additions & 0 deletions tools/releases/dockerfiles/Dockerfile.kuma-cp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM alpine:3.10

ADD $KUMA_ROOT/build/artifacts-linux-amd64/kuma-cp/kuma-cp /usr/bin

RUN mkdir -p /etc/kuma
ADD $KUMA_ROOT/pkg/config/app/kuma-cp/kuma-cp.defaults.yaml /etc/kuma

RUN mkdir /kuma
COPY $KUMA_ROOT/tools/releases/templates/LICENSE /kuma
COPY $KUMA_ROOT/tools/releases/templates/README /kuma

ENTRYPOINT ["kuma-cp"]
10 changes: 10 additions & 0 deletions tools/releases/dockerfiles/Dockerfile.kuma-dp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# using Envoy's base to inherit the Envoy binary
FROM envoyproxy/envoy-alpine:latest

ADD $KUMA_ROOT/build/artifacts-linux-amd64/kuma-dp/kuma-dp /usr/bin

RUN mkdir /kuma
COPY $KUMA_ROOT/tools/releases/templates/LICENSE /kuma
COPY $KUMA_ROOT/tools/releases/templates/README /kuma

ENTRYPOINT ["kuma-dp"]
9 changes: 9 additions & 0 deletions tools/releases/dockerfiles/Dockerfile.kuma-injector
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM alpine:3.10

ADD $KUMA_ROOT/build/artifacts-linux-amd64/kuma-injector/kuma-injector /usr/bin

RUN mkdir /kuma
COPY $KUMA_ROOT/tools/releases/templates/LICENSE /kuma
COPY $KUMA_ROOT/tools/releases/templates/README /kuma

ENTRYPOINT ["kuma-injector"]
9 changes: 9 additions & 0 deletions tools/releases/dockerfiles/Dockerfile.kuma-tcp-echo
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM alpine:3.10

ADD $KUMA_ROOT/build/artifacts-linux-amd64/kuma-tcp-echo/kuma-tcp-echo /usr/bin

RUN mkdir /kuma
COPY $KUMA_ROOT/tools/releases/templates/LICENSE /kuma
COPY $KUMA_ROOT/tools/releases/templates/README /kuma

ENTRYPOINT ["kuma-tcp-echo"]

0 comments on commit 8206bd5

Please sign in to comment.