From f6e22fc8212a39c42405f65021977ccb92bf6f28 Mon Sep 17 00:00:00 2001 From: EKS Distro PR Bot <75336432+eks-distro-pr-bot@users.noreply.github.com> Date: Wed, 18 Sep 2024 20:40:42 -0400 Subject: [PATCH] Invalidate docs CDN after every new deployment (#8794) Co-authored-by: Abhay Krishna Arunachalam --- docs/Makefile | 5 +++- docs/amplify.yml | 2 +- docs/{ => scripts}/deploy-docs.sh | 0 docs/scripts/invalidate_docs_cdn.sh | 37 +++++++++++++++++++++++++++++ 4 files changed, 42 insertions(+), 2 deletions(-) rename docs/{ => scripts}/deploy-docs.sh (100%) create mode 100755 docs/scripts/invalidate_docs_cdn.sh diff --git a/docs/Makefile b/docs/Makefile index 25b8647f24ca..80418449a478 100644 --- a/docs/Makefile +++ b/docs/Makefile @@ -47,7 +47,7 @@ zip: clean build ## Create zip file of assets to upload cd public && zip -r --quiet ../$(DOCS_ARCHIVE) ./ deploy: zip ## Deploy docs to Amplify - bash ./deploy-docs.sh public.zip + bash ./scripts/deploy-docs.sh public.zip serve: submodule build ## Boot the development server. hugo server --buildFuture --baseURL http://127.0.0.1 @@ -82,3 +82,6 @@ compute-checksum: ## Compute docs checksum upload-checksum: compute-checksum ## Upload the checksum to artifacts bucket aws s3 cp DOCS_CHECKSUM s3://$(ARTIFACTS_BUCKET) --acl public-read + +invalidate-docs-cdn: + scripts/invalidate_docs_cdn.sh diff --git a/docs/amplify.yml b/docs/amplify.yml index 884b7b4454cb..01eaeba34944 100644 --- a/docs/amplify.yml +++ b/docs/amplify.yml @@ -7,7 +7,7 @@ applications: - make release postBuild: commands: - - make upload-checksum + - make upload-checksum invalidate-docs-cdn artifacts: baseDirectory: public files: diff --git a/docs/deploy-docs.sh b/docs/scripts/deploy-docs.sh similarity index 100% rename from docs/deploy-docs.sh rename to docs/scripts/deploy-docs.sh diff --git a/docs/scripts/invalidate_docs_cdn.sh b/docs/scripts/invalidate_docs_cdn.sh new file mode 100755 index 000000000000..fbeec6c802fd --- /dev/null +++ b/docs/scripts/invalidate_docs_cdn.sh @@ -0,0 +1,37 @@ +#!/usr/bin/env bash +# Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +set -o errexit +set -o nounset +set -o pipefail + +SANITIZED_BRANCH_NAME=$(echo $AWS_BRANCH | tr -d '.-') +DISTRIBUTION_ID_PARAMETER=$(aws ssm describe-parameters --no-shared --query "Parameters[?contains(Name, '${SANITIZED_BRANCH_NAME}')].Name" --output text) +DISTRIBUTION_ID=$(aws ssm get-parameter --name $DISTRIBUTION_ID_PARAMETER --with-decryption --query "Parameter.Value" --output text) +echo "Invalidating distribution $DISTRIBUTION_ID" + +COMPLETED_STATUS="Completed" +INVALIDATION_RESPONSE=$(aws cloudfront create-invalidation --distribution-id $DISTRIBUTION_ID --paths "/*") +INVALIDATION_ID=$(echo $INVALIDATION_RESPONSE | jq -r '.Invalidation.Id') +INVALIDATION_STATUS=$(echo $INVALIDATION_RESPONSE | jq -r '.Invalidation.Status') + +until [[ "$INVALIDATION_STATUS" == "$COMPLETED_STATUS" ]]; do + echo "Invalidation status: $INVALIDATION_STATUS" + sleep 5 + + GET_RESPONSE=$(aws cloudfront get-invalidation --distribution-id $DISTRIBUTION_ID --id $INVALIDATION_ID) + INVALIDATION_STATUS=$(echo $GET_RESPONSE | jq -r '.Invalidation.Status') +done +echo "Invalidation status: $INVALIDATION_STATUS"