From 6c29ae40257d0f60b198eeef45fc27be1b537ddc Mon Sep 17 00:00:00 2001 From: Pablo N Date: Tue, 11 Jul 2023 14:58:50 +0200 Subject: [PATCH 1/8] fix project bucket for docker --- tools/carto-download-customer-package.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/carto-download-customer-package.sh b/tools/carto-download-customer-package.sh index b2e25faa..37912ff0 100755 --- a/tools/carto-download-customer-package.sh +++ b/tools/carto-download-customer-package.sh @@ -124,7 +124,7 @@ if [ "${SELFHOSTED_MODE}" == "docker" ] ; then # shellcheck disable=SC1090 source "${CARTO_ENV}" cp "${CARTO_SA}" "${CARTO_SERVICE_ACCOUNT_FILE}" - CLIENT_STORAGE_BUCKET="${WORKSPACE_IMPORTS_BUCKET}" + CLIENT_STORAGE_BUCKET="${SELFHOSTED_GCP_PROJECT_ID}-client-storage" TENANT_ID="${SELFHOSTED_TENANT_ID}" CLIENT_ID="${TENANT_ID/#onp-}" # Remove onp- prefix SELFHOSTED_VERSION_CURRENT="${CARTO_SELFHOSTED_CUSTOMER_PACKAGE_VERSION}" From 057f4441ce8ab6636f5f56884fa3b839966a0e91 Mon Sep 17 00:00:00 2001 From: Pablo N Date: Tue, 11 Jul 2023 15:03:41 +0200 Subject: [PATCH 2/8] fixed quoting --- tools/carto-download-customer-package.sh | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tools/carto-download-customer-package.sh b/tools/carto-download-customer-package.sh index 37912ff0..42463754 100755 --- a/tools/carto-download-customer-package.sh +++ b/tools/carto-download-customer-package.sh @@ -138,15 +138,15 @@ elif [ "${SELFHOSTED_MODE}" == "k8s" ] ; then # Get information from YAML files (k8s) yq ".cartoSecrets.defaultGoogleServiceAccount.value" < "${CARTO_SECRETS}" | \ grep -v "^$" > "${CARTO_SERVICE_ACCOUNT_FILE}" - CLIENT_STORAGE_BUCKET=$(yq -r ".appConfigValues.workspaceImportsBucket" < "${CARTO_VALUES}") - TENANT_ID=$(yq -r ".cartoConfigValues.selfHostedTenantId" < "${CARTO_VALUES}") + CLIENT_STORAGE_BUCKET="$(yq -r ".appConfigValues.workspaceImportsBucket" < "${CARTO_VALUES}")" + TENANT_ID="$(yq -r ".cartoConfigValues.selfHostedTenantId" < "${CARTO_VALUES}")" CLIENT_ID="${TENANT_ID/#onp-}" # Remove onp- prefix - SELFHOSTED_VERSION_CURRENT=$(yq -r ".cartoConfigValues.customerPackageVersion" < "${CARTO_VALUES}") + SELFHOSTED_VERSION_CURRENT="$(yq -r ".cartoConfigValues.customerPackageVersion" < "${CARTO_VALUES}")" fi # Get information from JSON service account file -CARTO_SERVICE_ACCOUNT_EMAIL=$(jq -r ".client_email" < "${CARTO_SERVICE_ACCOUNT_FILE}") -CARTO_GCP_PROJECT=$(jq -r ".project_id" < "${CARTO_SERVICE_ACCOUNT_FILE}") +CARTO_SERVICE_ACCOUNT_EMAIL="$(jq -r ".client_email" < "${CARTO_SERVICE_ACCOUNT_FILE}")" +CARTO_GCP_PROJECT="$(jq -r ".project_id" < "${CARTO_SERVICE_ACCOUNT_FILE}")" # Download the latest customer package STEP="activating: service account credentials for: [${CARTO_SERVICE_ACCOUNT_EMAIL}]" @@ -155,8 +155,8 @@ if ( gcloud auth activate-service-account "${CARTO_SERVICE_ACCOUNT_EMAIL}" --key fi # Get latest customer package version -CUSTOMER_PACKAGE_FILE_LATEST=$(gsutil ls "gs://${CLIENT_STORAGE_BUCKET}/${CUSTOMER_PACKAGE_FOLDER}/${CUSTOMER_PACKAGE_NAME_PREFIX}-${CLIENT_ID}-*-*-*.zip") -SELFHOSTED_VERSION_LATEST=$(echo "${CUSTOMER_PACKAGE_FILE_LATEST}" | grep -Eo "${CLIENT_ID}-[0-9]+-[0-9]+-[0-9]+") +CUSTOMER_PACKAGE_FILE_LATEST="$(gsutil ls "gs://${CLIENT_STORAGE_BUCKET}/${CUSTOMER_PACKAGE_FOLDER}/${CUSTOMER_PACKAGE_NAME_PREFIX}-${CLIENT_ID}-*-*-*.zip")" +SELFHOSTED_VERSION_LATEST="$(echo "${CUSTOMER_PACKAGE_FILE_LATEST}" | grep -Eo "${CLIENT_ID}-[0-9]+-[0-9]+-[0-9]+")" SELFHOSTED_VERSION_LATEST="${SELFHOSTED_VERSION_LATEST/#${CLIENT_ID}-}" # Download package From 457af05ec11cc5a7a17fb5ab271b98c3035564ac Mon Sep 17 00:00:00 2001 From: Pablo N Date: Tue, 11 Jul 2023 15:06:14 +0200 Subject: [PATCH 3/8] verify customer package download uri --- tools/carto-download-customer-package.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tools/carto-download-customer-package.sh b/tools/carto-download-customer-package.sh index 42463754..bce4da6c 100755 --- a/tools/carto-download-customer-package.sh +++ b/tools/carto-download-customer-package.sh @@ -159,9 +159,13 @@ CUSTOMER_PACKAGE_FILE_LATEST="$(gsutil ls "gs://${CLIENT_STORAGE_BUCKET}/${CUSTO SELFHOSTED_VERSION_LATEST="$(echo "${CUSTOMER_PACKAGE_FILE_LATEST}" | grep -Eo "${CLIENT_ID}-[0-9]+-[0-9]+-[0-9]+")" SELFHOSTED_VERSION_LATEST="${SELFHOSTED_VERSION_LATEST/#${CLIENT_ID}-}" +# Double-check customer package download URI +[[ "${CUSTOMER_PACKAGE_FILE_LATEST}" != "gs://${CLIENT_STORAGE_BUCKET}/${CUSTOMER_PACKAGE_FOLDER}/${CUSTOMER_PACKAGE_NAME_PREFIX}-${CLIENT_ID}-${SELFHOSTED_VERSION_LATEST}.zip" ]] && \ + _error "customer package download URI mismatch" 7 + # Download package STEP="downloading: $(basename "${CUSTOMER_PACKAGE_FILE_LATEST}")" -if ( gsutil cp "gs://${CLIENT_STORAGE_BUCKET}/${CUSTOMER_PACKAGE_FOLDER}/${CUSTOMER_PACKAGE_NAME_PREFIX}-${CLIENT_ID}-${SELFHOSTED_VERSION_LATEST}.zip" ./ ) ; then +if ( gsutil cp "${CUSTOMER_PACKAGE_FILE_LATEST}" ./ ) ; then _success "${STEP}" && RC="0" ; else _error "${STEP}" 6 fi From 67274c456a73b935519cd4c739f0a27c316f7d81 Mon Sep 17 00:00:00 2001 From: Pablo N Date: Tue, 11 Jul 2023 18:01:45 +0200 Subject: [PATCH 4/8] normalize CLIENT_STORAGE_BUCKET for both docker & k8s --- tools/carto-download-customer-package.sh | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/tools/carto-download-customer-package.sh b/tools/carto-download-customer-package.sh index bce4da6c..ffa54f91 100755 --- a/tools/carto-download-customer-package.sh +++ b/tools/carto-download-customer-package.sh @@ -112,19 +112,19 @@ _info "selfhosted mode: ${SELFHOSTED_MODE}" # global CUSTOMER_PACKAGE_NAME_PREFIX="carto-selfhosted-${SELFHOSTED_MODE}-customer-package" +CARTO_ENV="${FILE_DIR}/customer.env" +CARTO_SA="${FILE_DIR}/key.json" +# Check that CARTO_ENV exist +_check_input_files "${CARTO_ENV}" +# Get information from customer.env file +# shellcheck disable=SC1090 +source "${CARTO_ENV}" if [ "${SELFHOSTED_MODE}" == "docker" ] ; then - # Check that required files exist - CARTO_ENV="${FILE_DIR}/customer.env" - CARTO_SA="${FILE_DIR}/key.json" ENV_SOURCE="$(basename "${CARTO_ENV}")" - _check_input_files "${CARTO_ENV}" + # Check that required files exist _check_input_files "${CARTO_SA}" - # Get information from customer.env file (docker) - # shellcheck disable=SC1090 - source "${CARTO_ENV}" cp "${CARTO_SA}" "${CARTO_SERVICE_ACCOUNT_FILE}" - CLIENT_STORAGE_BUCKET="${SELFHOSTED_GCP_PROJECT_ID}-client-storage" TENANT_ID="${SELFHOSTED_TENANT_ID}" CLIENT_ID="${TENANT_ID/#onp-}" # Remove onp- prefix SELFHOSTED_VERSION_CURRENT="${CARTO_SELFHOSTED_CUSTOMER_PACKAGE_VERSION}" @@ -138,12 +138,14 @@ elif [ "${SELFHOSTED_MODE}" == "k8s" ] ; then # Get information from YAML files (k8s) yq ".cartoSecrets.defaultGoogleServiceAccount.value" < "${CARTO_SECRETS}" | \ grep -v "^$" > "${CARTO_SERVICE_ACCOUNT_FILE}" - CLIENT_STORAGE_BUCKET="$(yq -r ".appConfigValues.workspaceImportsBucket" < "${CARTO_VALUES}")" TENANT_ID="$(yq -r ".cartoConfigValues.selfHostedTenantId" < "${CARTO_VALUES}")" CLIENT_ID="${TENANT_ID/#onp-}" # Remove onp- prefix SELFHOSTED_VERSION_CURRENT="$(yq -r ".cartoConfigValues.customerPackageVersion" < "${CARTO_VALUES}")" fi +# Use carto project GCP bucket for custoemr package +CLIENT_STORAGE_BUCKET="${SELFHOSTED_GCP_PROJECT_ID}-client-storage" + # Get information from JSON service account file CARTO_SERVICE_ACCOUNT_EMAIL="$(jq -r ".client_email" < "${CARTO_SERVICE_ACCOUNT_FILE}")" CARTO_GCP_PROJECT="$(jq -r ".project_id" < "${CARTO_SERVICE_ACCOUNT_FILE}")" From 7877ea0224ee00d61ee755452969ec644f7591ee Mon Sep 17 00:00:00 2001 From: Pablo N Date: Mon, 17 Jul 2023 14:00:58 +0200 Subject: [PATCH 5/8] fixed CLIENT_STORAGE_BUCKET for both docker & k8s --- tools/carto-download-customer-package.sh | 33 ++++++++++++------------ 1 file changed, 17 insertions(+), 16 deletions(-) mode change 100755 => 100644 tools/carto-download-customer-package.sh diff --git a/tools/carto-download-customer-package.sh b/tools/carto-download-customer-package.sh old mode 100755 new mode 100644 index ffa54f91..96bc0901 --- a/tools/carto-download-customer-package.sh +++ b/tools/carto-download-customer-package.sh @@ -55,7 +55,7 @@ EOF function _info() { # ARGV1 = message - echo -e "ℹ️ ${1}" + echo -e "ℹ️ ${1}" } function _success() { @@ -112,27 +112,27 @@ _info "selfhosted mode: ${SELFHOSTED_MODE}" # global CUSTOMER_PACKAGE_NAME_PREFIX="carto-selfhosted-${SELFHOSTED_MODE}-customer-package" -CARTO_ENV="${FILE_DIR}/customer.env" -CARTO_SA="${FILE_DIR}/key.json" -# Check that CARTO_ENV exist -_check_input_files "${CARTO_ENV}" -# Get information from customer.env file -# shellcheck disable=SC1090 -source "${CARTO_ENV}" if [ "${SELFHOSTED_MODE}" == "docker" ] ; then + CARTO_ENV="${FILE_DIR}/customer.env" + CARTO_SA="${FILE_DIR}/key.json" ENV_SOURCE="$(basename "${CARTO_ENV}")" # Check that required files exist + _check_input_files "${CARTO_ENV}" _check_input_files "${CARTO_SA}" + # Get information from customer.env file (docker) + # shellcheck disable=SC1090 + source "${CARTO_ENV}" cp "${CARTO_SA}" "${CARTO_SERVICE_ACCOUNT_FILE}" TENANT_ID="${SELFHOSTED_TENANT_ID}" CLIENT_ID="${TENANT_ID/#onp-}" # Remove onp- prefix + CLIENT_STORAGE_BUCKET="carto-tnt-${TENANT_ID}-client-storage" SELFHOSTED_VERSION_CURRENT="${CARTO_SELFHOSTED_CUSTOMER_PACKAGE_VERSION}" elif [ "${SELFHOSTED_MODE}" == "k8s" ] ; then - # Check that required files exist CARTO_VALUES="${FILE_DIR}/carto-values.yaml" CARTO_SECRETS="${FILE_DIR}/carto-secrets.yaml" ENV_SOURCE="$(basename "${CARTO_VALUES}")" + # Check that required files exist _check_input_files "${CARTO_VALUES}" _check_input_files "${CARTO_SECRETS}" # Get information from YAML files (k8s) @@ -140,17 +140,15 @@ elif [ "${SELFHOSTED_MODE}" == "k8s" ] ; then grep -v "^$" > "${CARTO_SERVICE_ACCOUNT_FILE}" TENANT_ID="$(yq -r ".cartoConfigValues.selfHostedTenantId" < "${CARTO_VALUES}")" CLIENT_ID="${TENANT_ID/#onp-}" # Remove onp- prefix + CLIENT_STORAGE_BUCKET="carto-tnt-${TENANT_ID}-client-storage" SELFHOSTED_VERSION_CURRENT="$(yq -r ".cartoConfigValues.customerPackageVersion" < "${CARTO_VALUES}")" fi -# Use carto project GCP bucket for custoemr package -CLIENT_STORAGE_BUCKET="${SELFHOSTED_GCP_PROJECT_ID}-client-storage" - # Get information from JSON service account file CARTO_SERVICE_ACCOUNT_EMAIL="$(jq -r ".client_email" < "${CARTO_SERVICE_ACCOUNT_FILE}")" CARTO_GCP_PROJECT="$(jq -r ".project_id" < "${CARTO_SERVICE_ACCOUNT_FILE}")" -# Download the latest customer package +# Activate SA credentials STEP="activating: service account credentials for: [${CARTO_SERVICE_ACCOUNT_EMAIL}]" if ( gcloud auth activate-service-account "${CARTO_SERVICE_ACCOUNT_EMAIL}" --key-file="${CARTO_SERVICE_ACCOUNT_FILE}" --project="${CARTO_GCP_PROJECT}" &>/dev/null ) ; then _success "${STEP}" ; else _error "${STEP}" 5 @@ -162,13 +160,16 @@ SELFHOSTED_VERSION_LATEST="$(echo "${CUSTOMER_PACKAGE_FILE_LATEST}" | grep -Eo " SELFHOSTED_VERSION_LATEST="${SELFHOSTED_VERSION_LATEST/#${CLIENT_ID}-}" # Double-check customer package download URI -[[ "${CUSTOMER_PACKAGE_FILE_LATEST}" != "gs://${CLIENT_STORAGE_BUCKET}/${CUSTOMER_PACKAGE_FOLDER}/${CUSTOMER_PACKAGE_NAME_PREFIX}-${CLIENT_ID}-${SELFHOSTED_VERSION_LATEST}.zip" ]] && \ - _error "customer package download URI mismatch" 7 +STEP="checking: customer package download URI" +if [[ "${CUSTOMER_PACKAGE_FILE_LATEST}" != "gs://${CLIENT_STORAGE_BUCKET}/${CUSTOMER_PACKAGE_FOLDER}/${CUSTOMER_PACKAGE_NAME_PREFIX}-${CLIENT_ID}-${SELFHOSTED_VERSION_LATEST}.zip" ]] ; then + _error "customer package download URI mismatch:\n a. ${CUSTOMER_PACKAGE_FILE_LATEST}\n b. gs://${CLIENT_STORAGE_BUCKET}/${CUSTOMER_PACKAGE_FOLDER}/${CUSTOMER_PACKAGE_NAME_PREFIX}-${CLIENT_ID}-${SELFHOSTED_VERSION_LATEST}.zip\n" 6 + # _success "${STEP}" ; else _error "${STEP}" 6 +fi # Download package STEP="downloading: $(basename "${CUSTOMER_PACKAGE_FILE_LATEST}")" if ( gsutil cp "${CUSTOMER_PACKAGE_FILE_LATEST}" ./ ) ; then - _success "${STEP}" && RC="0" ; else _error "${STEP}" 6 + _success "${STEP}" && RC="0" ; else _error "${STEP}" 7 fi # Print message From e82609c31c9d2ea04a0eb7521fbca0247b1cfd67 Mon Sep 17 00:00:00 2001 From: Pablo N Date: Mon, 17 Jul 2023 15:36:36 +0200 Subject: [PATCH 6/8] added release-candidate replacement --- tools/carto-download-customer-package.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/carto-download-customer-package.sh b/tools/carto-download-customer-package.sh index 96bc0901..a5ad3308 100644 --- a/tools/carto-download-customer-package.sh +++ b/tools/carto-download-customer-package.sh @@ -156,6 +156,7 @@ fi # Get latest customer package version CUSTOMER_PACKAGE_FILE_LATEST="$(gsutil ls "gs://${CLIENT_STORAGE_BUCKET}/${CUSTOMER_PACKAGE_FOLDER}/${CUSTOMER_PACKAGE_NAME_PREFIX}-${CLIENT_ID}-*-*-*.zip")" +CUSTOMER_PACKAGE_FILE_LATEST="${CUSTOMER_PACKAGE_FILE_LATEST//-rc-[0-9]/}" SELFHOSTED_VERSION_LATEST="$(echo "${CUSTOMER_PACKAGE_FILE_LATEST}" | grep -Eo "${CLIENT_ID}-[0-9]+-[0-9]+-[0-9]+")" SELFHOSTED_VERSION_LATEST="${SELFHOSTED_VERSION_LATEST/#${CLIENT_ID}-}" From 5a992b5b34bc7870e3c5744edeb9e02239d4dca7 Mon Sep 17 00:00:00 2001 From: Pablo N Date: Mon, 17 Jul 2023 15:38:46 +0200 Subject: [PATCH 7/8] removed uri debug --- tools/carto-download-customer-package.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tools/carto-download-customer-package.sh b/tools/carto-download-customer-package.sh index a5ad3308..ac62fea2 100644 --- a/tools/carto-download-customer-package.sh +++ b/tools/carto-download-customer-package.sh @@ -163,8 +163,7 @@ SELFHOSTED_VERSION_LATEST="${SELFHOSTED_VERSION_LATEST/#${CLIENT_ID}-}" # Double-check customer package download URI STEP="checking: customer package download URI" if [[ "${CUSTOMER_PACKAGE_FILE_LATEST}" != "gs://${CLIENT_STORAGE_BUCKET}/${CUSTOMER_PACKAGE_FOLDER}/${CUSTOMER_PACKAGE_NAME_PREFIX}-${CLIENT_ID}-${SELFHOSTED_VERSION_LATEST}.zip" ]] ; then - _error "customer package download URI mismatch:\n a. ${CUSTOMER_PACKAGE_FILE_LATEST}\n b. gs://${CLIENT_STORAGE_BUCKET}/${CUSTOMER_PACKAGE_FOLDER}/${CUSTOMER_PACKAGE_NAME_PREFIX}-${CLIENT_ID}-${SELFHOSTED_VERSION_LATEST}.zip\n" 6 - # _success "${STEP}" ; else _error "${STEP}" 6 + _success "${STEP}" ; else _error "${STEP}" 6 fi # Download package From 328bec882bcfc39d406d483af7bcefabccd76e26 Mon Sep 17 00:00:00 2001 From: Pablo N Date: Mon, 17 Jul 2023 15:41:45 +0200 Subject: [PATCH 8/8] fixed uri comparison --- tools/carto-download-customer-package.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/carto-download-customer-package.sh b/tools/carto-download-customer-package.sh index ac62fea2..5819dac0 100644 --- a/tools/carto-download-customer-package.sh +++ b/tools/carto-download-customer-package.sh @@ -162,7 +162,7 @@ SELFHOSTED_VERSION_LATEST="${SELFHOSTED_VERSION_LATEST/#${CLIENT_ID}-}" # Double-check customer package download URI STEP="checking: customer package download URI" -if [[ "${CUSTOMER_PACKAGE_FILE_LATEST}" != "gs://${CLIENT_STORAGE_BUCKET}/${CUSTOMER_PACKAGE_FOLDER}/${CUSTOMER_PACKAGE_NAME_PREFIX}-${CLIENT_ID}-${SELFHOSTED_VERSION_LATEST}.zip" ]] ; then +if [[ "${CUSTOMER_PACKAGE_FILE_LATEST}" == "gs://${CLIENT_STORAGE_BUCKET}/${CUSTOMER_PACKAGE_FOLDER}/${CUSTOMER_PACKAGE_NAME_PREFIX}-${CLIENT_ID}-${SELFHOSTED_VERSION_LATEST}.zip" ]] ; then _success "${STEP}" ; else _error "${STEP}" 6 fi