From aa552f44f826c5b15540088b21d70ee136c21d7d Mon Sep 17 00:00:00 2001 From: Rail Aliiev Date: Tue, 9 Jan 2024 13:14:50 -0500 Subject: [PATCH] Publish charts to GCS Part of: RE-359 --- build/make.sh | 14 +++++++++++++- build/release.sh | 43 ++++++++++++++++++++++++++++--------------- 2 files changed, 41 insertions(+), 16 deletions(-) diff --git a/build/make.sh b/build/make.sh index ae10de22..06e0222b 100755 --- a/build/make.sh +++ b/build/make.sh @@ -3,6 +3,18 @@ set -euxo pipefail charts_hostname="${CHARTS_HOSTNAME:-charts.cockroachdb.com}" +case $charts_hostname in + charts.cockroachdb.com) + gcs_bucket=cockroach-helm-charts-prod + ;; + charts-test.cockroachdb.com) + gcs_bucket=cockroach-helm-charts-test + ;; + *) + echo "uknown host $charts_hostname" + exit 1 + ;; +esac HELM_INSTALL_DIR=$PWD/bin mkdir -p "$HELM_INSTALL_DIR" @@ -15,7 +27,7 @@ artifacts_dir="build/artifacts/" mkdir -p "$artifacts_dir" # Grab the current index.yaml to merge into the new index.yaml. -curl -fsSL "https://s3.amazonaws.com/${charts_hostname}/index.yaml" > "${artifacts_dir}/old-index.yaml" +curl -fsSL "https://storage.googleapis.com/$gcs_bucket/index.yaml" > "${artifacts_dir}/old-index.yaml" # Build the charts $HELM_INSTALL_DIR/helm package cockroachdb --destination "${artifacts_dir}" diff --git a/build/release.sh b/build/release.sh index d5f72a48..6d999288 100755 --- a/build/release.sh +++ b/build/release.sh @@ -3,22 +3,35 @@ set -euo pipefail charts_hostname="${CHARTS_HOSTNAME:-charts.cockroachdb.com}" +case $charts_hostname in + charts.cockroachdb.com) + lb_name=cockroach-helm-charts-prod-default + gcs_bucket=cockroach-helm-charts-prod + google_credentials="$GCS_CREDENTIALS_PROD" + ;; + charts-test.cockroachdb.com) + lb_name=cockroach-helm-charts-test-default + gcs_bucket=cockroach-helm-charts-test + google_credentials="$GCS_CREDENTIALS_PROD" + ;; + *) + echo "uknown host $charts_hostname" + exit 1 + ;; +esac -if [ -n "${DISTRIBUTION_ID-}" ] ; then - distribution_id="${DISTRIBUTION_ID}" -elif [ "${charts_hostname-}" = "charts.cockroachdb.com" ] ; then - distribution_id="E2PBFCZT8WAC7B" -elif [ "${charts_hostname-}" = "charts-test.cockroachdb.com" ] ; then - distribution_id="E20WB6NQP118CN" -fi +remove_files_on_exit() { + rm -f .google-credentials.json +} -# Push the new chart file and updated index.yaml file to S3 -# We rely on the aws-cli version installed system-wide. -AWS_ACCESS_KEY_ID="${AWS_ACCESS_KEY_ID}" AWS_SECRET_ACCESS_KEY="${AWS_SECRET_ACCESS_KEY}" \ - aws s3 sync "build/artifacts/" "s3://${charts_hostname}" --exclude old-index.yaml +trap remove_files_on_exit EXIT + +echo "${google_credentials}" > .google-credentials.json +gcloud auth activate-service-account --key-file=.google-credentials.json + +# Push the new chart file and updated index.yaml file to GCS. +# We rely on the gcloud CLI version installed system-wide. +gsutil rsync "build/artifacts/" "gs://${gcs_bucket}/" -x old-index.yaml # Invalidate any cached version of index.yaml (so this version is immediately available) -if [ -n "${distribution_id}" ] ; then - AWS_ACCESS_KEY_ID="${AWS_ACCESS_KEY_ID}" AWS_SECRET_ACCESS_KEY="${AWS_SECRET_ACCESS_KEY}" \ - aws cloudfront create-invalidation --distribution-id "${distribution_id}" --paths /index.yaml -fi +gcloud compute url-maps invalidate-cdn-cache $lb_name --path "/index.yaml"