From 4c6e8cbd23a21183ce7d472d3184db06cc49f62e Mon Sep 17 00:00:00 2001 From: tedezed Date: Tue, 3 Oct 2023 12:05:29 +0200 Subject: [PATCH 1/3] New check --- tools/carto-download-customer-package.sh | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/tools/carto-download-customer-package.sh b/tools/carto-download-customer-package.sh index fc349e0..37e78ba 100755 --- a/tools/carto-download-customer-package.sh +++ b/tools/carto-download-customer-package.sh @@ -12,6 +12,13 @@ CUSTOMER_PACKAGE_NAME_PREFIX="carto-selfhosted-${SELFHOSTED_MODE}-customer-packa CUSTOMER_PACKAGE_FOLDER="customer-package" ########################################## +function _check_deps_gsutil_file() +{ + file_path=${1} + gsutil -q stat $file_path + return $? +} + function _check_deps() { for DEP in ${DEPENDENCIES} ; do @@ -161,8 +168,17 @@ 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}-}" +# Check if exist the latest stable release +STABLE_CUSTOMER_PACKAGE_DOWNLOAD_URL="gs://${CLIENT_STORAGE_BUCKET}/${CUSTOMER_PACKAGE_FOLDER}/${CUSTOMER_PACKAGE_NAME_PREFIX}-${CLIENT_ID}-${SELFHOSTED_VERSION_LATEST}.zip" +if _check_deps_gsutil_file ${STABLE_CUSTOMER_PACKAGE_DOWNLOAD_URL} +then + CUSTOMER_PACKAGE_DOWNLOAD_URL=${STABLE_CUSTOMER_PACKAGE_DOWNLOAD_URL} +else + _error "stable version ${SELFHOSTED_VERSION_LATEST} not found: ${STABLE_CUSTOMER_PACKAGE_DOWNLOAD_URL}" 404 +fi + # 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" ]] && \ +[[ "${CUSTOMER_PACKAGE_FILE_LATEST}" != "${CUSTOMER_PACKAGE_DOWNLOAD_URL}" ]] && \ _error "customer package download URI mismatch" 7 # Download package From 0f8bc447e7c551cd98e03cd9346f60fb4ac9890e Mon Sep 17 00:00:00 2001 From: tedezed Date: Tue, 3 Oct 2023 12:08:25 +0200 Subject: [PATCH 2/3] Rename _check_gsutil_file --- tools/carto-download-customer-package.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/carto-download-customer-package.sh b/tools/carto-download-customer-package.sh index 37e78ba..4af0c8e 100755 --- a/tools/carto-download-customer-package.sh +++ b/tools/carto-download-customer-package.sh @@ -12,7 +12,7 @@ CUSTOMER_PACKAGE_NAME_PREFIX="carto-selfhosted-${SELFHOSTED_MODE}-customer-packa CUSTOMER_PACKAGE_FOLDER="customer-package" ########################################## -function _check_deps_gsutil_file() +function _check_gsutil_file() { file_path=${1} gsutil -q stat $file_path @@ -170,7 +170,7 @@ SELFHOSTED_VERSION_LATEST="${SELFHOSTED_VERSION_LATEST/#${CLIENT_ID}-}" # Check if exist the latest stable release STABLE_CUSTOMER_PACKAGE_DOWNLOAD_URL="gs://${CLIENT_STORAGE_BUCKET}/${CUSTOMER_PACKAGE_FOLDER}/${CUSTOMER_PACKAGE_NAME_PREFIX}-${CLIENT_ID}-${SELFHOSTED_VERSION_LATEST}.zip" -if _check_deps_gsutil_file ${STABLE_CUSTOMER_PACKAGE_DOWNLOAD_URL} +if _check_gsutil_file ${STABLE_CUSTOMER_PACKAGE_DOWNLOAD_URL} then CUSTOMER_PACKAGE_DOWNLOAD_URL=${STABLE_CUSTOMER_PACKAGE_DOWNLOAD_URL} else From af800e916820b8727178469fc206e876225cfe05 Mon Sep 17 00:00:00 2001 From: tedezed Date: Wed, 4 Oct 2023 11:25:36 +0200 Subject: [PATCH 3/3] Fix download rc --- tools/carto-download-customer-package.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tools/carto-download-customer-package.sh b/tools/carto-download-customer-package.sh index 4af0c8e..8f35200 100755 --- a/tools/carto-download-customer-package.sh +++ b/tools/carto-download-customer-package.sh @@ -164,15 +164,18 @@ 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")" +CUSTOMER_PACKAGE_FILE_LATEST="$(gsutil ls "gs://${CLIENT_STORAGE_BUCKET}/${CUSTOMER_PACKAGE_FOLDER}/${CUSTOMER_PACKAGE_NAME_PREFIX}-${CLIENT_ID}-*-*-*.zip" | grep -v '\-rc\-')" 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}-}" +_info "latest version: ${SELFHOSTED_VERSION_LATEST}" + # Check if exist the latest stable release STABLE_CUSTOMER_PACKAGE_DOWNLOAD_URL="gs://${CLIENT_STORAGE_BUCKET}/${CUSTOMER_PACKAGE_FOLDER}/${CUSTOMER_PACKAGE_NAME_PREFIX}-${CLIENT_ID}-${SELFHOSTED_VERSION_LATEST}.zip" if _check_gsutil_file ${STABLE_CUSTOMER_PACKAGE_DOWNLOAD_URL} then CUSTOMER_PACKAGE_DOWNLOAD_URL=${STABLE_CUSTOMER_PACKAGE_DOWNLOAD_URL} + _info "download file: ${CUSTOMER_PACKAGE_DOWNLOAD_URL}" else _error "stable version ${SELFHOSTED_VERSION_LATEST} not found: ${STABLE_CUSTOMER_PACKAGE_DOWNLOAD_URL}" 404 fi