Skip to content

Add slim predictor images #992

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

Merged
merged 8 commits into from
May 1, 2020
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
49 changes: 38 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,37 @@ operator-stop:
# Docker images

registry-all:
@./dev/registry.sh update
@./dev/registry.sh update all
registry-all-local:
@./dev/registry.sh update all --skip-push
registry-all-slim:
@./dev/registry.sh update all --include-slim
registry-all-slim-local:
@./dev/registry.sh update all --include-slim --skip-push
registry-all-local-slim:
@./dev/registry.sh update all --include-slim --skip-push

registry-dev:
@./dev/registry.sh update dev
registry-dev-local:
@./dev/registry.sh update dev --skip-push
registry-dev-slim:
@./dev/registry.sh update dev --include-slim
registry-dev-slim-local:
@./dev/registry.sh update dev --include-slim --skip-push
registry-dev-local-slim:
@./dev/registry.sh update dev --include-slim --skip-push

registry-api:
@./dev/registry.sh update api
registry-api-local:
@./dev/registry.sh update api --skip-push
registry-api-slim:
@./dev/registry.sh update api --include-slim
registry-api-slim-local:
@./dev/registry.sh update api --include-slim --skip-push
registry-api-local-slim:
@./dev/registry.sh update api --include-slim --skip-push

registry-create:
@./dev/registry.sh create
Expand Down Expand Up @@ -137,13 +164,13 @@ test-examples:
###############

ci-build-images:
@./build/build-image.sh images/python-predictor-cpu python-predictor-cpu
@./build/build-image.sh images/python-predictor-gpu python-predictor-gpu
@./build/build-image.sh images/python-predictor-cpu python-predictor-cpu --include-slim
@./build/build-image.sh images/python-predictor-gpu python-predictor-gpu --include-slim
@./build/build-image.sh images/tensorflow-serving-cpu tensorflow-serving-cpu
@./build/build-image.sh images/tensorflow-serving-gpu tensorflow-serving-gpu
@./build/build-image.sh images/tensorflow-predictor tensorflow-predictor
@./build/build-image.sh images/onnx-predictor-cpu onnx-predictor-cpu
@./build/build-image.sh images/onnx-predictor-gpu onnx-predictor-gpu
@./build/build-image.sh images/tensorflow-predictor tensorflow-predictor --include-slim
@./build/build-image.sh images/onnx-predictor-cpu onnx-predictor-cpu --include-slim
@./build/build-image.sh images/onnx-predictor-gpu onnx-predictor-gpu --include-slim
@./build/build-image.sh images/operator operator
@./build/build-image.sh images/manager manager
@./build/build-image.sh images/downloader downloader
Expand All @@ -159,13 +186,13 @@ ci-build-images:
@./build/build-image.sh images/istio-galley istio-galley

ci-push-images:
@./build/push-image.sh python-predictor-cpu
@./build/push-image.sh python-predictor-gpu
@./build/push-image.sh python-predictor-cpu --include-slim
@./build/push-image.sh python-predictor-gpu --include-slim
@./build/push-image.sh tensorflow-serving-cpu
@./build/push-image.sh tensorflow-serving-gpu
@./build/push-image.sh tensorflow-predictor
@./build/push-image.sh onnx-predictor-cpu
@./build/push-image.sh onnx-predictor-gpu
@./build/push-image.sh tensorflow-predictor --include-slim
@./build/push-image.sh onnx-predictor-cpu --include-slim
@./build/push-image.sh onnx-predictor-gpu --include-slim
@./build/push-image.sh operator
@./build/push-image.sh manager
@./build/push-image.sh downloader
Expand Down
30 changes: 28 additions & 2 deletions build/build-image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,34 @@ ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")"/.. >/dev/null && pwd)"

CORTEX_VERSION=master

slim="false"
while [[ $# -gt 0 ]]; do
key="$1"
case $key in
--include-slim)
slim="true"
shift
;;
*)
positional_args+=("$1")
shift
;;
esac
done
set -- "${positional_args[@]}"

dir=$1
image=$2

docker build "$ROOT" -f $dir/Dockerfile -t cortexlabs/$image \
-t cortexlabs/$image:$CORTEX_VERSION
docker build "$ROOT" \
-f $dir/Dockerfile \
-t cortexlabs/${image} \
-t cortexlabs/${image}:${CORTEX_VERSION}

if [ "$slim" == "true"]; then
docker build "$ROOT" \
-f $dir/Dockerfile \
--build-arg SLIM=true \
-t cortexlabs/${image}-slim \
-t cortexlabs/${image}-slim:${CORTEX_VERSION}
fi
22 changes: 21 additions & 1 deletion build/push-image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,28 @@ set -euo pipefail

CORTEX_VERSION=master

slim="false"
while [[ $# -gt 0 ]]; do
key="$1"
case $key in
--include-slim)
slim="true"
shift
;;
*)
positional_args+=("$1")
shift
;;
esac
done
set -- "${positional_args[@]}"

image=$1

echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin

docker push cortexlabs/$image:$CORTEX_VERSION
docker push cortexlabs/${image}:${CORTEX_VERSION}

if [ "$slim" == "true"]; then
docker push cortexlabs/${image}-slim:${CORTEX_VERSION}
fi
99 changes: 73 additions & 26 deletions dev/registry.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,30 @@ ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")"/.. >/dev/null && pwd)"
source $ROOT/dev/config/build.sh
source $ROOT/dev/util.sh

flag_include_slim="false"
flag_skip_push="false"
while [[ $# -gt 0 ]]; do
key="$1"
case $key in
--include-slim)
flag_include_slim="true"
shift
;;
--skip-push)
flag_skip_push="true"
shift
;;
*)
positional_args+=("$1")
shift
;;
esac
done
set -- "${positional_args[@]}"

cmd=${1:-""}
sub_cmd=${2:-""}

ecr_logged_in=false

function ecr_login() {
Expand All @@ -36,12 +60,17 @@ function ecr_login() {

function create_registry() {
aws ecr create-repository --repository-name=cortexlabs/python-predictor-cpu --region=$REGISTRY_REGION || true
aws ecr create-repository --repository-name=cortexlabs/python-predictor-cpu-slim --region=$REGISTRY_REGION || true
aws ecr create-repository --repository-name=cortexlabs/python-predictor-gpu --region=$REGISTRY_REGION || true
aws ecr create-repository --repository-name=cortexlabs/python-predictor-gpu-slim --region=$REGISTRY_REGION || true
aws ecr create-repository --repository-name=cortexlabs/tensorflow-serving-cpu --region=$REGISTRY_REGION || true
aws ecr create-repository --repository-name=cortexlabs/tensorflow-serving-gpu --region=$REGISTRY_REGION || true
aws ecr create-repository --repository-name=cortexlabs/tensorflow-predictor --region=$REGISTRY_REGION || true
aws ecr create-repository --repository-name=cortexlabs/tensorflow-predictor-slim --region=$REGISTRY_REGION || true
aws ecr create-repository --repository-name=cortexlabs/onnx-predictor-cpu --region=$REGISTRY_REGION || true
aws ecr create-repository --repository-name=cortexlabs/onnx-predictor-cpu-slim --region=$REGISTRY_REGION || true
aws ecr create-repository --repository-name=cortexlabs/onnx-predictor-gpu --region=$REGISTRY_REGION || true
aws ecr create-repository --repository-name=cortexlabs/onnx-predictor-gpu-slim --region=$REGISTRY_REGION || true
aws ecr create-repository --repository-name=cortexlabs/operator --region=$REGISTRY_REGION || true
aws ecr create-repository --repository-name=cortexlabs/manager --region=$REGISTRY_REGION || true
aws ecr create-repository --repository-name=cortexlabs/downloader --region=$REGISTRY_REGION || true
Expand All @@ -60,53 +89,71 @@ function create_registry() {
### HELPERS ###

function build() {
dir=$1
image=$2
tag=$3
local dir=$1
local image=$2
local tag=$3

blue_echo "Building $image:$tag..."
docker build $ROOT -f $dir/Dockerfile -t cortexlabs/$image:$tag -t $REGISTRY_URL/cortexlabs/$image:$tag
docker build $ROOT -f $dir/Dockerfile -t cortexlabs/$image:$tag -t $REGISTRY_URL/cortexlabs/$image:$tag "${@:4}"
green_echo "Built $image:$tag\n"
}

function build_base() {
dir=$1
image=$2
local dir=$1
local image=$2

blue_echo "Building $image..."
docker build $ROOT -f $dir/Dockerfile -t cortexlabs/$image:latest
green_echo "Built $image\n"
}

function cache_builder() {
dir=$1
image=$2
local dir=$1
local image=$2

blue_echo "Building $image-builder..."
docker build $ROOT -f $dir/Dockerfile -t cortexlabs/$image-builder:latest --target builder
green_echo "Built $image-builder\n"
}

function push() {
if [ "$flag_skip_push" == "true" ]; then
return
fi

ecr_login

image=$1
tag=$2
local image=$1
local tag=$2

blue_echo "Pushing $image:$tag..."
docker push $REGISTRY_URL/cortexlabs/$image:$tag
green_echo "Pushed $image:$tag\n"
}

function build_and_push() {
dir=$1
image=$2
tag=$3
local dir=$1
local image=$2
local tag=$3

build $dir $image $tag
push $image $tag
}

function build_and_push_slim() {
local dir=$1
local image=$2
local tag=$3

build $dir $image $tag
push $image $tag

if [ "$flag_include_slim" == "true" ]; then
build $dir "${image}-slim" $tag --build-arg SLIM=true
push ${image}-slim $tag
fi
}

function cleanup_local() {
echo "cleaning local repositories..."
docker container prune -f
Expand All @@ -129,9 +176,6 @@ function cleanup_ecr() {
done
}

cmd=${1:-""}
env=${2:-""}

if [ "$cmd" = "clean" ]; then
cleanup_local
cleanup_ecr
Expand All @@ -142,8 +186,9 @@ elif [ "$cmd" = "create" ]; then
elif [ "$cmd" = "update-manager-local" ]; then
build $ROOT/images/manager manager latest

# usage: registry.sh update all|dev|api [--include-slim] [--skip-push]
elif [ "$cmd" = "update" ]; then
if [ "$env" != "dev" ]; then
if [ "$sub_cmd" == "all" ]; then
build_and_push $ROOT/images/tensorflow-serving-cpu tensorflow-serving-cpu latest
build_and_push $ROOT/images/tensorflow-serving-gpu tensorflow-serving-gpu latest

Expand All @@ -161,16 +206,18 @@ elif [ "$cmd" = "update" ]; then
build_and_push $ROOT/images/istio-galley istio-galley latest
fi

cache_builder $ROOT/images/request-monitor request-monitor
build_and_push $ROOT/images/request-monitor request-monitor latest
if [[ "$sub_cmd" == "all" || "$sub_cmd" == "dev" ]]; then
cache_builder $ROOT/images/request-monitor request-monitor
build_and_push $ROOT/images/request-monitor request-monitor latest
build_and_push $ROOT/images/manager manager latest
build_and_push $ROOT/images/downloader downloader latest
fi

build_and_push $ROOT/images/manager manager latest
build_and_push $ROOT/images/python-predictor-cpu python-predictor-cpu latest
build_and_push $ROOT/images/python-predictor-gpu python-predictor-gpu latest
build_and_push $ROOT/images/tensorflow-predictor tensorflow-predictor latest
build_and_push $ROOT/images/onnx-predictor-cpu onnx-predictor-cpu latest
build_and_push $ROOT/images/onnx-predictor-gpu onnx-predictor-gpu latest
build_and_push $ROOT/images/downloader downloader latest
build_and_push_slim $ROOT/images/python-predictor-cpu python-predictor-cpu latest
build_and_push_slim $ROOT/images/python-predictor-gpu python-predictor-gpu latest
build_and_push_slim $ROOT/images/tensorflow-predictor tensorflow-predictor latest
build_and_push_slim $ROOT/images/onnx-predictor-cpu onnx-predictor-cpu latest
build_and_push_slim $ROOT/images/onnx-predictor-gpu onnx-predictor-gpu latest

cleanup_local
fi
6 changes: 3 additions & 3 deletions dev/versions.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ Note: it's ok if example training notebooks aren't upgraded, as long as the expo

## ONNX runtime

1. Update the version in `onnx-cpu.requirements.txt` and `onnx-gpu.requirements.txt` ([releases](https://github.com/microsoft/onnxruntime/releases))
1. Update the version in `images/onnx-predictor-cpu/Dockerfile` and `images/onnx-predictor-gpu/Dockerfile` ([releases](https://github.com/microsoft/onnxruntime/releases))
1. Update the version listed for `onnxruntime` in "Pre-installed Packages" in `onnx.md`
1. Search the codebase for the previous ONNX runtime version

Expand All @@ -130,7 +130,7 @@ Note: it's ok if example training notebooks aren't upgraded, as long as the expo

## Python packages

1. Update versions in `pkg/workloads/*/requirements.txt`
1. Update versions in `images/python-predictor-*/Dockerfile`, `images/tensorflow-predictor-*/Dockerfile`, and `images/onnx-predictor-*/Dockerfile`
1. Update the versions listed in "Pre-installed packages" in `python.md`, `onnx.md`, and `tensorflow.md`
1. Rerun all examples and check their logs

Expand Down Expand Up @@ -180,7 +180,7 @@ Note: overriding horizontal-pod-autoscaler-sync-period on EKS is currently not s
1. Update the version in `images/statsd/Dockerfile`
1. In this [GitHub Repo](https://github.com/aws-samples/amazon-cloudwatch-container-insights), set the tree to `master` and open [k8s-yaml-templates/cwagent-statsd/cwagent-statsd-daemonset.yaml](https://github.com/aws-samples/amazon-cloudwatch-container-insights/blob/master/k8s-yaml-templates/cwagent-statsd/cwagent-statsd-daemonset.yaml) and [k8s-yaml-templates/cwagent-statsd/cwagent-statsd-configmap.yaml](https://github.com/aws-samples/amazon-cloudwatch-container-insights/blob/master/k8s-yaml-templates/cwagent-statsd/cwagent-statsd-configmap.yaml)
1. Update `statsd.yaml` as necessary (this wasn't copy-pasted, so you may need to check the diff intelligently)
1. Update the datadog client version in `lib/requirements.txt`
1. Update the datadog client version in `serve/requirements.txt`

## aws-iam-authenticator

Expand Down
4 changes: 2 additions & 2 deletions images/downloader/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ RUN apt-get update -qq && apt-get install -y -q \
pip install --upgrade pip && \
rm -rf /root/.cache/pip*

COPY pkg/workloads/cortex/lib/requirements.txt /src/cortex/lib/requirements.txt
RUN pip install -r /src/cortex/lib/requirements.txt && \
COPY pkg/workloads/cortex/downloader/requirements.txt /src/cortex/downloader/requirements.txt
RUN pip install -r /src/cortex/downloader/requirements.txt && \
rm -rf /root/.cache/pip*

COPY pkg/workloads/cortex/consts.py /src/cortex/
Expand Down
Loading