Skip to content
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
62 changes: 62 additions & 0 deletions dev/export_images.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# 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 <region> <aws account id>
# e.g. ./dev/export_images.sh us-east-1 123456789

ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")"/.. >/dev/null && pwd)"

# CORTEX_VERSION
cortex_version=master

# user set variables
ecr_region=$1
aws_account_id=$2

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
echo "done ✓"
40 changes: 40 additions & 0 deletions docs/clusters/advanced/self-hosted-images.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# 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 using the release tag corresponding to your version (which you can check by running `cortex version`):

<!-- CORTEX_VERSION_README -->

```bash
export CORTEX_VERSION=0.33.0
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.

```bash
./cortex/dev/export_images.sh <AWS_REGION> <AWS_ACCOUNT_ID>
```

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

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.
1 change: 1 addition & 0 deletions docs/summary.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down