Skip to content

Commit

Permalink
Invalidate docs CDN after every new deployment (#8794)
Browse files Browse the repository at this point in the history
Co-authored-by: Abhay Krishna Arunachalam <[email protected]>
  • Loading branch information
eks-distro-pr-bot and abhay-krishna authored Sep 19, 2024
1 parent 656158f commit f6e22fc
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 2 deletions.
5 changes: 4 additions & 1 deletion docs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion docs/amplify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ applications:
- make release
postBuild:
commands:
- make upload-checksum
- make upload-checksum invalidate-docs-cdn
artifacts:
baseDirectory: public
files:
Expand Down
File renamed without changes.
37 changes: 37 additions & 0 deletions docs/scripts/invalidate_docs_cdn.sh
Original file line number Diff line number Diff line change
@@ -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"

0 comments on commit f6e22fc

Please sign in to comment.