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

Update docker build script to optionally publish images to DockerHub #283

Merged
merged 8 commits into from
Sep 3, 2017
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
40 changes: 0 additions & 40 deletions RPythonDockerfile

This file was deleted.

8 changes: 4 additions & 4 deletions bench/build_bench_docker_images.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ fi

docker build -t clipper/py-rpc:$tag -f ./RPCDockerfile ./
if [ $# -eq 0 ]; then
time docker build build --build-arg CODE_VERSION=$tag -t clipper/sum-bench:$tag -f SumBenchDockerfile ./
time docker build build --build-arg CODE_VERSION=$tag -t clipper/noop-bench:$tag -f NoopBenchDockerfile ./
time docker build build --build-arg CODE_VERSION=$tag -t clipper/sum-bench:$tag -f dockerfiles/SumBenchDockerfile ./
time docker build build --build-arg CODE_VERSION=$tag -t clipper/noop-bench:$tag -f dockerfiles/NoopBenchDockerfile ./
else
echo $1
echo $2
echo $3
echo $4
time docker build build --build-arg CODE_VERSION=$tag -t clipper/sum-bench:$tag -f SumBenchDockerfile ./ --build-arg MODEL_NAME="$1" --build-arg MODEL_VERSION="$2"
time docker build build --build-arg CODE_VERSION=$tag -t clipper/noop-bench:$tag -f NoopBenchDockerfile ./ --build-arg MODEL_NAME="$3" --build-arg MODEL_VERSION="$4"
time docker build build --build-arg CODE_VERSION=$tag -t clipper/sum-bench:$tag -f dockerfiles/SumBenchDockerfile ./ --build-arg MODEL_NAME="$1" --build-arg MODEL_VERSION="$2"
time docker build build --build-arg CODE_VERSION=$tag -t clipper/noop-bench:$tag -f dockerfiles/NoopBenchDockerfile ./ --build-arg MODEL_NAME="$3" --build-arg MODEL_VERSION="$4"
fi

cd -
142 changes: 107 additions & 35 deletions bin/build_docker_images.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
#!/usr/bin/env bash

# This script builds all the Clipper Docker images and publishes the useful ones to
# Docker Hub (images that we don't publish are things like the unittest image and the
# shared dependency base that don't really make sense to distribute on their own).
# Each image that is built is tagged with two tags:
# + The current Git SHA: <image_name>:git_hash
# + The current version as read from VERSION.txt: <image_name>:version
# For the images that we publish, both tags will be pushed.


set -e
set -u
set -o pipefail
Expand All @@ -10,39 +19,102 @@ unset CDPATH
# the script.
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"


# Let the user start this script from anywhere in the filesystem.
cd $DIR/..

tag=$(<VERSION.txt)

# Build the Clipper Docker images
time docker build -t clipper/lib_base:$tag -f ./ClipperLibBaseDockerfile ./
time docker build --build-arg CODE_VERSION=$tag -t clipper/query_frontend:$tag -f QueryFrontendDockerfile ./
time docker build --build-arg CODE_VERSION=$tag -t clipper/management_frontend:$tag -f ManagementFrontendDockerfile ./
time docker build --build-arg CODE_VERSION=$tag -t clipper/unittests:$tag -f ClipperTestsDockerfile ./

# Tag and push the latest version of the Clipper Docker images to the container registry
# for the Kubernetes testing cluster
docker tag clipper/query_frontend:$tag 568959175238.dkr.ecr.us-west-1.amazonaws.com/clipper/query_frontend:$tag
docker push 568959175238.dkr.ecr.us-west-1.amazonaws.com/clipper/query_frontend:$tag
docker tag clipper/management_frontend:$tag 568959175238.dkr.ecr.us-west-1.amazonaws.com/clipper/management_frontend:$tag
docker push 568959175238.dkr.ecr.us-west-1.amazonaws.com/clipper/management_frontend:$tag
cd -

# Build Spark JVM Container
cd $DIR/../containers/jvm
time docker build -t clipper/spark-scala-container:$tag -f SparkScalaContainerDockerfile ./
cd -

# Build the Python model containers
cd $DIR/..

# first build base image
time docker build -t clipper/py-rpc:$tag -f ./RPCDockerfile ./
time docker build --build-arg CODE_VERSION=$tag -t clipper/sum-container:$tag -f ./SumDockerfile ./
time docker build --build-arg CODE_VERSION=$tag -t clipper/noop-container:$tag -f ./NoopDockerfile ./
time docker build --build-arg CODE_VERSION=$tag -t clipper/python-closure-container:$tag -f ./PyClosureContainerDockerfile ./
time docker build --build-arg CODE_VERSION=$tag -t clipper/pyspark-container:$tag -f ./PySparkContainerDockerfile ./
time docker build --build-arg CODE_VERSION=$tag -t clipper/tf_cifar_container:$tag -f ./TensorFlowCifarDockerfile ./
cd -
CLIPPER_ROOT=$DIR/..
cd $CLIPPER_ROOT

# Initialize tags
version_tag=$(<VERSION.txt)
sha_tag=`git rev-parse --verify --short HEAD`

namespace="clipper"

# We build images with the SHA tag to try to prevent clobbering other images
# being built from different branches on the same machine. This is particularly
# useful for running these scripts on the Jenkins build cluster.
create_image () {
local image=$1 # Param: The name of the image to build

local dockerfile=$2 # the Dockerfile name within the
# <clipper_root>/dockerfiles directory

local public=$3 # Push the built images to Docker Hub under
# the clipper namespace. Must have credentials.

echo "Building $namespace/$image:$sha_tag from file $dockerfile"
time docker build --build-arg CODE_VERSION=$sha_tag -t $namespace/$image:$sha_tag \
-f dockerfiles/$dockerfile $CLIPPER_ROOT
docker tag $namespace/$image:$sha_tag $namespace/$image:$version_tag

if [ "$publish" = true ] && [ "$public" = true ] ; then
echo "Publishing $namespace/$image:$sha_tag"
docker push $namespace/$image:$sha_tag
echo "Publishing $namespace/$image:$version_tag"
docker push $namespace/$image:$version_tag
fi
}


# Build the Clipper Docker images.
build_images () {
# True and false indicate whether or not to publish the image. We publish public images.
local private=false
local public=true

########################$$####### WARNING: #################################
# Some of these images depend on each other prior images. Do not change
# the order in which the images are built
###########################################################################

# Build Clipper core images
create_image lib_base ClipperLibBaseDockerfile $private
create_image query_frontend QueryFrontendDockerfile $public
create_image management_frontend ManagementFrontendDockerfile $public
create_image unittests ClipperTestsDockerfile $private

# Build containers
create_image spark-scala-container SparkScalaContainerDockerfile $public

# First build Python base image
create_image py-rpc RPCDockerfile $public
create_image sum-container SumDockerfile $private
create_image noop-container NoopDockerfile $public
create_image python-closure-container PyClosureContainerDockerfile $public
create_image pyspark-container PySparkContainerDockerfile $public
create_image tf_cifar_container TensorFlowCifarDockerfile $public
}

usage () {
cat <<EOF
usage: build docker_images.sh [--publish]

Build and optionally publish the Clipper Docker images.

Options:

-p, --publish Publish images to DockerHub
-h, --help Display this message and exit.

$@
EOF
}


if [ "$#" == 0 ]
then
args="--nopublish"
else
args=$1
fi

case $args in
-p | --publish ) publish=true
build_images
;;
-n | --nopublish ) publish=false
build_images
;;
-h | --help ) usage
;;
* ) usage
esac
11 changes: 11 additions & 0 deletions bin/run_ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,16 @@ DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
cd $DIR/..
tag=$(<VERSION.txt)

# Build docker images
./bin/build_docker_images.sh

# Tag and push the latest version of the Clipper Docker images to the container registry
# for the Kubernetes testing cluster
docker tag clipper/query_frontend:$tag 568959175238.dkr.ecr.us-west-1.amazonaws.com/clipper/query_frontend:$tag
docker push 568959175238.dkr.ecr.us-west-1.amazonaws.com/clipper/query_frontend:$tag
docker tag clipper/management_frontend:$tag 568959175238.dkr.ecr.us-west-1.amazonaws.com/clipper/management_frontend:$tag
docker push 568959175238.dkr.ecr.us-west-1.amazonaws.com/clipper/management_frontend:$tag

# Run tests
docker run --rm --network=host -v /var/run/docker.sock:/var/run/docker.sock -v /tmp:/tmp \
-v /home/jenkins/.docker:/root/.docker clipper/unittests:$tag
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# This ARG isn't used but prevents warnings in the build script
ARG CODE_VERSION
FROM ubuntu:16.04

RUN apt-get update && apt-get install -y g++ automake autoconf autoconf-archive libtool libboost-all-dev \
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ARG CODE_VERSION=develop
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm guessing that we're removing these default arguments because the images build script, in conjunction with VERSION.txt are intended to be the point of control for image versioning?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Exactly. And removing the default makes sure that the build fails if we forget a build arg instead of silently building with "develop"

ARG CODE_VERSION
FROM clipper/lib_base:${CODE_VERSION}

# install docker
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ARG CODE_VERSION=develop
ARG CODE_VERSION
FROM clipper/lib_base:${CODE_VERSION}

COPY ./ /clipper
Expand Down
2 changes: 1 addition & 1 deletion NoopBenchDockerfile → dockerfiles/NoopBenchDockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ARG CODE_VERSION=develop
ARG CODE_VERSION
FROM clipper/py-rpc:${CODE_VERSION}

COPY containers/python/noop_container.py /container/
Expand Down
2 changes: 1 addition & 1 deletion NoopDockerfile → dockerfiles/NoopDockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ARG CODE_VERSION=develop
ARG CODE_VERSION
FROM clipper/py-rpc:${CODE_VERSION}

MAINTAINER Dan Crankshaw <dscrankshaw@gmail.com>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ARG CODE_VERSION=develop
ARG CODE_VERSION
FROM clipper/py-rpc:${CODE_VERSION}

COPY clipper_admin/clipper_admin/python_container_conda_deps.txt /lib/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ARG CODE_VERSION=develop
ARG CODE_VERSION
FROM clipper/py-rpc:${CODE_VERSION}

COPY clipper_admin/clipper_admin/python_container_conda_deps.txt /lib/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ARG CODE_VERSION=develop
ARG CODE_VERSION
FROM clipper/lib_base:${CODE_VERSION}

# Build Clipper
Expand Down
14 changes: 14 additions & 0 deletions dockerfiles/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Dockerfiles for the Clipper project.

Note that while these Dockerfiles are in the `dockerfiles` subdirectory, they must be built with the root
of the Clipper repo as the build context. For example:

*From within this directory*
```
docker build -t <tag> -f QueryFrontendDockerfile ../
```

*From the Clipper root directory*
```
docker build -t <tag> -f dockerfiles/QueryFrontendDockerfile ./
```
2 changes: 2 additions & 0 deletions RPCDockerfile → dockerfiles/RPCDockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# This ARG isn't used but prevents warnings in the build script
ARG CODE_VERSION
FROM continuumio/anaconda:latest

MAINTAINER Dan Crankshaw <dscrankshaw@gmail.com>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# This ARG isn't used but prevents warnings in the build script
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we also add this note to RPCDockerfile and ClipperLibBaseDockerfile ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

ARG CODE_VERSION
FROM openjdk:8-jdk

# First set up maven
Expand All @@ -24,7 +26,7 @@ RUN mkdir -p /usr/share/maven /usr/share/maven/ref \
ENV MAVEN_HOME /usr/share/maven
ENV MAVEN_CONFIG /root/.m2

COPY . /root/container
COPY ./containers/jvm/ /root/container

WORKDIR /root/container

Expand Down
2 changes: 1 addition & 1 deletion SumBenchDockerfile → dockerfiles/SumBenchDockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ARG CODE_VERSION=develop
ARG CODE_VERSION
FROM clipper/py-rpc:${CODE_VERSION}

COPY containers/python/sum_container.py /container/
Expand Down
2 changes: 1 addition & 1 deletion SumDockerfile → dockerfiles/SumDockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ARG CODE_VERSION=develop
ARG CODE_VERSION
FROM clipper/py-rpc:${CODE_VERSION}

COPY containers/python/sum_container.py /container/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ARG CODE_VERSION=develop
ARG CODE_VERSION
FROM clipper/py-rpc:${CODE_VERSION}

MAINTAINER Dan Crankshaw <dscrankshaw@gmail.com>
Expand Down