Skip to content

Commit 7ac12c7

Browse files
committed
Invalidate cloudfront cache for media deployments
1 parent 0557009 commit 7ac12c7

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

.github/workflows/deploy.config.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121
},
2222
"media" : {
2323
"region": "eu-west-2",
24+
"cloudfront-comment": "The CloudFront ID is used to invalidate the cache after deployment.",
25+
"cloudfront-id-staging": "E7XZICS0M3W1S",
26+
"cloudfront-id-live": "E2KTTVJ1I6I7D8",
2427
"syncs": [
2528
{
2629
"bucket-comment": "The bucket name is suffixed with -live or -staging depending on the branch.",

.github/workflows/deploy.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,22 @@ jobs:
262262
aws s3 sync "$source/" "s3://$bucket/$dest/" "${options_array[@]}"
263263
done
264264
265+
- name: Invalidate CloudFront cache
266+
run: |
267+
CONFIG='${{ needs.pre-check-media.outputs.config }}'
268+
CURRENT_BRANCH="${{ github.ref_name }}"
269+
if [ "$CURRENT_BRANCH" = "live" ]; then
270+
CLOUDFRONT_ID=$(echo "$CONFIG" | jq -r '.media["cloudfront-id-live"]')
271+
else
272+
CLOUDFRONT_ID=$(echo "$CONFIG" | jq -r '.media["cloudfront-id-staging"]')
273+
fi
274+
if [ -n "$CLOUDFRONT_ID" ] && [ "$CLOUDFRONT_ID" != "null" ]; then
275+
echo "Invalidating CloudFront cache for distribution $CLOUDFRONT_ID"
276+
aws cloudfront create-invalidation --distribution-id "$CLOUDFRONT_ID" --paths '/*'
277+
else
278+
echo "No CloudFront distribution ID found for branch $CURRENT_BRANCH. Skipping invalidation."
279+
fi
280+
265281
pre-check-vercel:
266282
needs: [deploy-to-book-server]
267283
if: always()

0 commit comments

Comments
 (0)