Skip to content

Commit f62ce19

Browse files
committed
Add instructions to export images to private registry (#2122)
(cherry picked from commit 74a2cb7)
1 parent cdabfe4 commit f62ce19

File tree

3 files changed

+103
-0
lines changed

3 files changed

+103
-0
lines changed

dev/export_images.sh

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# Copyright 2021 Cortex Labs, Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
set -euo pipefail
16+
17+
# usage: ./dev/export_images.sh <region> <aws account id>
18+
# e.g. ./dev/export_images.sh us-east-1 123456789
19+
20+
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")"/.. >/dev/null && pwd)"
21+
22+
# CORTEX_VERSION
23+
cortex_version=0.34.0
24+
25+
# user set variables
26+
ecr_region=$1
27+
aws_account_id=$2
28+
29+
source_registry=quay.io/cortexlabs # this can also be docker.io/cortexlabs
30+
31+
destination_ecr_prefix="cortexlabs"
32+
destination_registry="${aws_account_id}.dkr.ecr.${ecr_region}.amazonaws.com/${destination_ecr_prefix}"
33+
aws ecr get-login-password --region $ecr_region | docker login --username AWS --password-stdin $destination_registry
34+
35+
source build/images.sh
36+
37+
# create the image repositories
38+
for image in "${all_images[@]}"; do
39+
aws ecr create-repository --repository-name=$destination_ecr_prefix/$image --region=$ecr_region || true
40+
done
41+
echo
42+
43+
cuda=("10.0" "10.1" "10.1" "10.2" "10.2" "11.0" "11.1")
44+
cudnn=("7" "7" "8" "7" "8" "8" "8")
45+
46+
# pull the images from source registry and push them to ECR
47+
for image in "${all_images[@]}"; do
48+
# copy the different cuda/cudnn variations of the python handler image
49+
if [ "$image" = "python-handler-gpu" ]; then
50+
for i in "${!cuda[@]}"; do
51+
full_image="$image:$cortex_version-cuda${cuda[$i]}-cudnn${cudnn[$i]}"
52+
echo "copying $full_image from $source_registry to $destination_registry"
53+
skopeo copy --src-no-creds "docker://$source_registry/$full_image" "docker://$destination_registry/$full_image"
54+
echo
55+
done
56+
else
57+
echo "copying $image:$cortex_version from $source_registry to $destination_registry"
58+
skopeo copy --src-no-creds "docker://$source_registry/$image:$cortex_version" "docker://$destination_registry/$image:$cortex_version"
59+
echo
60+
fi
61+
done
62+
echo "done ✓"
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Self-hosted Docker images
2+
3+
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.
4+
5+
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.
6+
7+
## Step 1
8+
9+
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.
10+
11+
## Step 2
12+
13+
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.
14+
15+
## Step 3
16+
17+
Clone the Cortex repo using the release tag corresponding to your version (which you can check by running `cortex version`):
18+
19+
<!-- CORTEX_VERSION_README -->
20+
21+
```bash
22+
export CORTEX_VERSION=0.34.0
23+
git clone --depth 1 --branch v$CORTEX_VERSION https://github.com/cortexlabs/cortex.git
24+
```
25+
26+
## Step 4
27+
28+
Run the script below to export images to ECR in the same region and account as your cluster.
29+
30+
Feel free to modify the script if you would like to export the images to a different registry such as a private docker hub.
31+
32+
```bash
33+
./cortex/dev/export_images.sh <AWS_REGION> <AWS_ACCOUNT_ID>
34+
```
35+
36+
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).
37+
38+
## Cleanup
39+
40+
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.

docs/summary.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
* Advanced
2626
* [Setting up kubectl](clusters/advanced/kubectl.md)
2727
* [Private Docker registry](clusters/advanced/registry.md)
28+
* [Self hosted images](clusters/advanced/self-hosted-images.md)
2829

2930
## Workloads
3031

0 commit comments

Comments
 (0)