From 9f86332dfb05419a2755e364200365f641dd89d2 Mon Sep 17 00:00:00 2001 From: Miguel Varela Ramos Date: Tue, 8 Dec 2020 12:19:27 +0100 Subject: [PATCH 1/3] Improve dev UX by not requiring optional env variables to be set as empty in registry.sh --- dev/registry.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/dev/registry.sh b/dev/registry.sh index 095b88afe9..7abe015e5e 100755 --- a/dev/registry.sh +++ b/dev/registry.sh @@ -25,6 +25,11 @@ source $ROOT/dev/util.sh GCR_HOST=${GCR_HOST:-"gcr.io"} +# set variables to empty strings if they do not exist +GCP_PROJECT_ID=${GCP_PROJECT_ID:-} +AWS_ACCOUNT_ID=${AWS_ACCOUNT_ID:-} +AWS_REGION=${AWS_REGION:-} + provider="local" include_slim="false" positional_args=() From 8136977fac93427e85b03f0c1d83d017decb6e56 Mon Sep 17 00:00:00 2001 From: Miguel Varela Ramos Date: Tue, 8 Dec 2020 12:19:43 +0100 Subject: [PATCH 2/3] Add env validation to registry.sh --- dev/registry.sh | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/dev/registry.sh b/dev/registry.sh index 7abe015e5e..0ccc8de28a 100755 --- a/dev/registry.sh +++ b/dev/registry.sh @@ -187,6 +187,22 @@ function cleanup_ecr() { done } +function validate_env() { + local provider=$1 + + if [ "$provider" = "aws" ]; then + if [[ -z ${AWS_REGION} ]] || [[ -z ${AWS_ACCOUNT_ID} ]]; then + echo "error: environment variables AWS_REGION and AWS_ACCOUNT_ID should be exported in dev/config/env.sh" + exit 1 + fi + elif [ "$provider" = "gcp" ]; then + if [[ -z ${GCP_PROJECT_ID} ]]; then + echo "error: environment variables GCP_PROJECT_ID should be exported in dev/config/env.sh" + exit 1 + fi + fi +} + # export functions for parallel command export -f build_and_push export -f push @@ -195,6 +211,9 @@ export -f blue_echo export -f green_echo export -f registry_login +# validate environment is correctly set on env.sh +validate_env "$provider" + # usage: registry.sh clean --provider aws|gcp|local if [ "$cmd" = "clean" ]; then if [ "$provider" = "aws" ]; then From 55cc84fcff82f931585212f93124b872f383dd89 Mon Sep 17 00:00:00 2001 From: Miguel Varela Ramos Date: Tue, 8 Dec 2020 13:50:25 +0100 Subject: [PATCH 3/3] Address PR comments --- dev/registry.sh | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/dev/registry.sh b/dev/registry.sh index 0ccc8de28a..232db89f5c 100755 --- a/dev/registry.sh +++ b/dev/registry.sh @@ -24,8 +24,6 @@ source $ROOT/dev/config/env.sh source $ROOT/dev/util.sh GCR_HOST=${GCR_HOST:-"gcr.io"} - -# set variables to empty strings if they do not exist GCP_PROJECT_ID=${GCP_PROJECT_ID:-} AWS_ACCOUNT_ID=${AWS_ACCOUNT_ID:-} AWS_REGION=${AWS_REGION:-} @@ -191,12 +189,12 @@ function validate_env() { local provider=$1 if [ "$provider" = "aws" ]; then - if [[ -z ${AWS_REGION} ]] || [[ -z ${AWS_ACCOUNT_ID} ]]; then + if [ -z ${AWS_REGION} ] || [ -z ${AWS_ACCOUNT_ID} ]; then echo "error: environment variables AWS_REGION and AWS_ACCOUNT_ID should be exported in dev/config/env.sh" exit 1 fi elif [ "$provider" = "gcp" ]; then - if [[ -z ${GCP_PROJECT_ID} ]]; then + if [ -z ${GCP_PROJECT_ID} ]; then echo "error: environment variables GCP_PROJECT_ID should be exported in dev/config/env.sh" exit 1 fi