Skip to content

Commit

Permalink
Publish charts to GCS
Browse files Browse the repository at this point in the history
Part of: RE-359
  • Loading branch information
rail committed Jan 9, 2024
1 parent 0111734 commit aa552f4
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 16 deletions.
14 changes: 13 additions & 1 deletion build/make.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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}"
Expand Down
43 changes: 28 additions & 15 deletions build/release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"

0 comments on commit aa552f4

Please sign in to comment.