From 559d07ba0551eddefc511f3bdd496ae2fb73c1cd Mon Sep 17 00:00:00 2001 From: vishal Date: Tue, 27 Apr 2021 11:09:10 -0400 Subject: [PATCH 1/5] Add instructions to export images to private registry --- dev/export_images.sh | 46 ++++++++++++++++++++ docs/clusters/advanced/self-hosted-images.md | 39 +++++++++++++++++ docs/summary.md | 1 + 3 files changed, 86 insertions(+) create mode 100755 dev/export_images.sh create mode 100644 docs/clusters/advanced/self-hosted-images.md diff --git a/dev/export_images.sh b/dev/export_images.sh new file mode 100755 index 0000000000..5bea542a8d --- /dev/null +++ b/dev/export_images.sh @@ -0,0 +1,46 @@ +set -euo pipefail + +# usage: ./dev/export_images.sh +# e.g. ./dev/export_images.sh us-east-1 123456789 + +ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")"/.. >/dev/null && pwd)" + +# user set variables +ecr_region=$1 +aws_account_id=$2 # example account ID + +# CORTEX_VERSION +cortex_version=master +source_registry=quay.io/cortexlabs # this can also be docker.io/cortexlabs +destination_ecr_prefix="cortexlabs" + +destination_registry="${aws_account_id}.dkr.ecr.${ecr_region}.amazonaws.com/${destination_ecr_prefix}" +aws ecr get-login-password --region $ecr_region | docker login --username AWS --password-stdin $destination_registry + +source build/images.sh + +# create the image repositories +for image in "${all_images[@]}"; do + aws ecr create-repository --repository-name=$destination_ecr_prefix/$image --region=$ecr_region || true +done +echo + +cuda=("10.0" "10.1" "10.1" "10.2" "10.2" "11.0" "11.1") +cudnn=("7" "7" "8" "7" "8" "8" "8") + +# pull the images from source registry and push them to ECR +for image in "${all_images[@]}"; do + # copy the different cuda, cudnn variations of the python handler image + if [ "$image" = "python-handler-gpu" ]; then + for i in "${!cuda[@]}"; do + full_image="$image:$cortex_version-cuda${cuda[$i]}-cudnn${cudnn[$i]}" + echo "copying $full_image from $source_registry to $destination_registry" + skopeo copy --src-no-creds "docker://$source_registry/$full_image" "docker://$destination_registry/$full_image" + echo + done + else + echo "copying $image:$cortex_version from $source_registry to $destination_registry" + skopeo copy --src-no-creds "docker://$source_registry/$image:$cortex_version" "docker://$destination_registry/$image:$cortex_version" + echo + fi +done diff --git a/docs/clusters/advanced/self-hosted-images.md b/docs/clusters/advanced/self-hosted-images.md new file mode 100644 index 0000000000..1ba8cc63d7 --- /dev/null +++ b/docs/clusters/advanced/self-hosted-images.md @@ -0,0 +1,39 @@ +# Self-hosted Docker images + +Self-hosted Docker images can be useful for reducing the ingress costs, for accelerating image pulls, or for eliminating the dependency on Cortex's public container registry. + +In this guide, we'll use [ECR](https://aws.amazon.com/ecr/) as the destination container registry. When an ECR repository resides in the same region as your Cortex cluster, there are no costs incurred when pulling images. + +## Step 1 + +Make sure you have the [aws](https://docs.aws.amazon.com/cli/latest/userguide/install-cliv1.html), [docker](https://docs.docker.com/get-docker/) and [skopeo](https://github.com/containers/skopeo/blob/master/install.md) utilities installed. + +## Step 2 + +Export the `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY` environment variables in your current shell, or run `aws configure`. These credentials must have access to push to ECR. + +## Step 3 + +Clone the Cortex repo with the specific tag. + +``` +export CORTEX_VERSION=0.33.0 # you can get the complete version using `cortex version` +git clone --depth 1 --branch v$CORTEX_VERSION https://github.com/cortexlabs/cortex.git +``` + +## Step 4 + +Run the script below to export images to ECR in the same region and account as your cluster. + +Feel free to modify the script if you would like to export the images to a different registry such as a private docker hub. + +``` +cd ./cortex # navigate into the cortex folder +./dev/export_images.sh +``` + +You can now spin up a new cluster and deploy apis with images pointing to your registry. + +## Cleanup + +You can delete your ECR images from the [AWS ECR dashboard](https://console.aws.amazon.com/ecr/repositories) (set your region in the upper right corner). Make sure all of your Cortex clusters have been deleted before deleting any ECR images. \ No newline at end of file diff --git a/docs/summary.md b/docs/summary.md index f76824a174..ce6825df52 100644 --- a/docs/summary.md +++ b/docs/summary.md @@ -25,6 +25,7 @@ * Advanced * [Setting up kubectl](clusters/advanced/kubectl.md) * [Private Docker registry](clusters/advanced/registry.md) + * [Self hosted images](clusters/advanced/self-hosted-images.md) ## Workloads From acd06bd9433944b8894e7d689fe88dc4f7cd55b8 Mon Sep 17 00:00:00 2001 From: vishal Date: Tue, 27 Apr 2021 12:15:11 -0400 Subject: [PATCH 2/5] Linting nits --- dev/export_images.sh | 14 ++++++++++++++ docs/clusters/advanced/self-hosted-images.md | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/dev/export_images.sh b/dev/export_images.sh index 5bea542a8d..26c9a220f5 100755 --- a/dev/export_images.sh +++ b/dev/export_images.sh @@ -1,3 +1,17 @@ +# Copyright 2021 Cortex Labs, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + set -euo pipefail # usage: ./dev/export_images.sh diff --git a/docs/clusters/advanced/self-hosted-images.md b/docs/clusters/advanced/self-hosted-images.md index 1ba8cc63d7..a7c8300c67 100644 --- a/docs/clusters/advanced/self-hosted-images.md +++ b/docs/clusters/advanced/self-hosted-images.md @@ -36,4 +36,4 @@ You can now spin up a new cluster and deploy apis with images pointing to your r ## Cleanup -You can delete your ECR images from the [AWS ECR dashboard](https://console.aws.amazon.com/ecr/repositories) (set your region in the upper right corner). Make sure all of your Cortex clusters have been deleted before deleting any ECR images. \ No newline at end of file +You can delete your ECR images from the [AWS ECR dashboard](https://console.aws.amazon.com/ecr/repositories) (set your region in the upper right corner). Make sure all of your Cortex clusters have been deleted before deleting any ECR images. From 9c2bc5b6410afa72392cb16fb0f45a52676d60e3 Mon Sep 17 00:00:00 2001 From: David Eliahu Date: Tue, 27 Apr 2021 09:30:19 -0700 Subject: [PATCH 3/5] Update self-hosted-images.md --- docs/clusters/advanced/self-hosted-images.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/clusters/advanced/self-hosted-images.md b/docs/clusters/advanced/self-hosted-images.md index a7c8300c67..252092482e 100644 --- a/docs/clusters/advanced/self-hosted-images.md +++ b/docs/clusters/advanced/self-hosted-images.md @@ -6,7 +6,7 @@ In this guide, we'll use [ECR](https://aws.amazon.com/ecr/) as the destination c ## Step 1 -Make sure you have the [aws](https://docs.aws.amazon.com/cli/latest/userguide/install-cliv1.html), [docker](https://docs.docker.com/get-docker/) and [skopeo](https://github.com/containers/skopeo/blob/master/install.md) utilities installed. +Make sure you have the [aws](https://docs.aws.amazon.com/cli/latest/userguide/install-cliv1.html), [docker](https://docs.docker.com/get-docker/), and [skopeo](https://github.com/containers/skopeo/blob/master/install.md) utilities installed. ## Step 2 @@ -14,10 +14,10 @@ Export the `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY` environment variables ## Step 3 -Clone the Cortex repo with the specific tag. +Clone the Cortex repo using the release tag corresponding to your version: -``` -export CORTEX_VERSION=0.33.0 # you can get the complete version using `cortex version` +```bash +export CORTEX_VERSION=0.33.0 # you can get the complete version using `cortex version` git clone --depth 1 --branch v$CORTEX_VERSION https://github.com/cortexlabs/cortex.git ``` From bb425f0b4723e6b5ed7585b1d61c1719e6650f59 Mon Sep 17 00:00:00 2001 From: David Eliahu Date: Tue, 27 Apr 2021 09:46:36 -0700 Subject: [PATCH 4/5] Misc nits --- dev/export_images.sh | 14 ++++++++------ docs/clusters/advanced/self-hosted-images.md | 12 +++++++----- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/dev/export_images.sh b/dev/export_images.sh index 26c9a220f5..8db4acc676 100755 --- a/dev/export_images.sh +++ b/dev/export_images.sh @@ -19,15 +19,16 @@ set -euo pipefail ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")"/.. >/dev/null && pwd)" +# CORTEX_VERSION +cortex_version=master + # user set variables ecr_region=$1 -aws_account_id=$2 # example account ID +aws_account_id=$2 -# CORTEX_VERSION -cortex_version=master -source_registry=quay.io/cortexlabs # this can also be docker.io/cortexlabs -destination_ecr_prefix="cortexlabs" +source_registry=quay.io/cortexlabs # this can also be docker.io/cortexlabs +destination_ecr_prefix="cortexlabs" destination_registry="${aws_account_id}.dkr.ecr.${ecr_region}.amazonaws.com/${destination_ecr_prefix}" aws ecr get-login-password --region $ecr_region | docker login --username AWS --password-stdin $destination_registry @@ -44,7 +45,7 @@ cudnn=("7" "7" "8" "7" "8" "8" "8") # pull the images from source registry and push them to ECR for image in "${all_images[@]}"; do - # copy the different cuda, cudnn variations of the python handler image + # copy the different cuda/cudnn variations of the python handler image if [ "$image" = "python-handler-gpu" ]; then for i in "${!cuda[@]}"; do full_image="$image:$cortex_version-cuda${cuda[$i]}-cudnn${cudnn[$i]}" @@ -58,3 +59,4 @@ for image in "${all_images[@]}"; do echo fi done +echo "done ✓" diff --git a/docs/clusters/advanced/self-hosted-images.md b/docs/clusters/advanced/self-hosted-images.md index 252092482e..74a8bd84f5 100644 --- a/docs/clusters/advanced/self-hosted-images.md +++ b/docs/clusters/advanced/self-hosted-images.md @@ -14,10 +14,12 @@ Export the `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY` environment variables ## Step 3 -Clone the Cortex repo using the release tag corresponding to your version: +Clone the Cortex repo using the release tag corresponding to your version (which you can check by running `cortex version`): + + ```bash -export CORTEX_VERSION=0.33.0 # you can get the complete version using `cortex version` +export CORTEX_VERSION=0.33.0 git clone --depth 1 --branch v$CORTEX_VERSION https://github.com/cortexlabs/cortex.git ``` @@ -27,12 +29,12 @@ Run the script below to export images to ECR in the same region and account as y Feel free to modify the script if you would like to export the images to a different registry such as a private docker hub. -``` -cd ./cortex # navigate into the cortex folder +```bash +cd ./cortex ./dev/export_images.sh ``` -You can now spin up a new cluster and deploy apis with images pointing to your registry. +You can now configure Cortex to use your images when creating a cluster (see [here](../management/create.md) for how to specify cluster images) and/or when deploying APIs (see the configuration docs corresponding to your API type for how to specify API images). ## Cleanup From a9cf4cff96c0d6b8ce84f43f6c07bcdc4a012c6c Mon Sep 17 00:00:00 2001 From: David Eliahu Date: Tue, 27 Apr 2021 09:47:12 -0700 Subject: [PATCH 5/5] Update self-hosted-images.md --- docs/clusters/advanced/self-hosted-images.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/docs/clusters/advanced/self-hosted-images.md b/docs/clusters/advanced/self-hosted-images.md index 74a8bd84f5..b514510c2d 100644 --- a/docs/clusters/advanced/self-hosted-images.md +++ b/docs/clusters/advanced/self-hosted-images.md @@ -30,8 +30,7 @@ Run the script below to export images to ECR in the same region and account as y Feel free to modify the script if you would like to export the images to a different registry such as a private docker hub. ```bash -cd ./cortex -./dev/export_images.sh +./cortex/dev/export_images.sh ``` You can now configure Cortex to use your images when creating a cluster (see [here](../management/create.md) for how to specify cluster images) and/or when deploying APIs (see the configuration docs corresponding to your API type for how to specify API images).