Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[327482] carto-selfhosted-helm fix download customer package not working when using custom buckets #383

Merged
8 commits merged into from
Jul 31, 2023
Merged
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
35 changes: 21 additions & 14 deletions tools/carto-download-customer-package.sh
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ EOF

function _info() {
# ARGV1 = message
echo -e "ℹ️ ${1}"
echo -e "ℹ️ ${1}"
}

function _success() {
Expand Down Expand Up @@ -114,55 +114,62 @@ _info "selfhosted mode: ${SELFHOSTED_MODE}"
CUSTOMER_PACKAGE_NAME_PREFIX="carto-selfhosted-${SELFHOSTED_MODE}-customer-package"

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 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}"
CLIENT_STORAGE_BUCKET="${WORKSPACE_IMPORTS_BUCKET}"
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)
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}")
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}")
CLIENT_STORAGE_BUCKET="carto-tnt-${TENANT_ID}-client-storage"
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
# 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
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")"
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}-}"

# 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
_success "${STEP}" ; else _error "${STEP}" 6
fi

# 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
_success "${STEP}" && RC="0" ; else _error "${STEP}" 6
if ( gsutil cp "${CUSTOMER_PACKAGE_FILE_LATEST}" ./ ) ; then
_success "${STEP}" && RC="0" ; else _error "${STEP}" 7
fi

# Print message
Expand Down
Loading