From 231cbb6f73495eab1a33cac39e9a8a36f4294fd3 Mon Sep 17 00:00:00 2001 From: bluewhale <67038286+BlueWhaleKo@users.noreply.github.com> Date: Sat, 23 Apr 2022 13:02:53 +0900 Subject: [PATCH] fix: export_images.sh (#2424) --- dev/export_images.sh | 16 ++++++++++++++-- docs/clusters/advanced/self-hosted-images.md | 2 ++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/dev/export_images.sh b/dev/export_images.sh index 59d90d5c3b..ae897d7dd3 100755 --- a/dev/export_images.sh +++ b/dev/export_images.sh @@ -1,3 +1,5 @@ +#!/bin/bash + # Copyright 2022 Cortex Labs, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -30,13 +32,23 @@ 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 + +if [[ -f $HOME/.docker/config.json && $(cat $HOME/.docker/config.json | grep "ecr-login" | wc -l) -ne 0 ]]; then + echo "skipping docker login because you are using ecr-login with Amazon ECR Docker Credential Helper" +else + aws ecr get-login-password --region $ecr_region | docker login --username AWS --password-stdin $destination_registry +fi source $ROOT/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 + repository_name=$destination_ecr_prefix/$image + if aws ecr describe-repositories --repository-names=$repository_name --region=$ecr_region >/dev/null 2>&1; then + echo "repository '$repository_name' already exists" + else + aws ecr create-repository --repository-name=$repository_name --region=$ecr_region | cat + fi done echo diff --git a/docs/clusters/advanced/self-hosted-images.md b/docs/clusters/advanced/self-hosted-images.md index 80ebca0700..cc84f54598 100644 --- a/docs/clusters/advanced/self-hosted-images.md +++ b/docs/clusters/advanced/self-hosted-images.md @@ -27,6 +27,8 @@ git clone --depth 1 --branch v$CORTEX_VERSION https://github.com/cortexlabs/cort Run the script below to export images to ECR in the same region and account as your cluster. +The script will automatically create ECR Repositories with prefix `cortexlabs` if they don't already exist. + 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