Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: docker automation #265

Merged
merged 4 commits into from
Sep 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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..."
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we change the message to Pushing $component ... ?

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Docker image should run under a non-root account, e.g. nobody (65534:65534) on alpine


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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Docker image should run under a non-root account, e.g. nobody (65534:65534) on alpine

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Docker image should run under a non-root account, e.g. nobody (65534:65534) on alpine


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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Docker image should run under a non-root account, e.g. nobody (65534:65534) on alpine


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"]