Skip to content

Commit

Permalink
Merge pull request #15 from asicsdigital/add_cf_invalidation
Browse files Browse the repository at this point in the history
feat: add cf invalidation
  • Loading branch information
tyrantkhan authored Jul 13, 2019
2 parents 13ce134 + 0e94fd6 commit b5468b2
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
37 changes: 37 additions & 0 deletions 1.X/scripts/invalidate-cloudfront-cache
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/usr/bin/env bash
# shellcheck shell=bash

# Script for invalidating Cloudfront Cache. It expects an ENV var of CLOUDFRONT_ID.
# First argument is a space separated list files, the second is true or false
# which indicates that you would like this call to be blocking.
# Eg:
# ./invalidate-cloudfront-cache '/index.html /favicon.ico /js/index.js' true
# ./invalidate-cloudfront-cache '/*' false

set -e
set -o pipefail

if [[ "$CLOUDFRONT_ID" ]]; then
echo "triggering cloudfront cache invalidation"
COMMAND="aws cloudfront create-invalidation --distribution-id $CLOUDFRONT_ID --paths '$1'"
echo $COMMAND
RETVAL=$(eval $COMMAND)
echo $RETVAL | jq .
RETVAL_STATUS=$(echo $RETVAL| jq -r '.Invalidation.Status')
INVALIDATION_ID=$(echo $RETVAL| jq -r '.Invalidation.Id')
if [[ "$RETVAL_STATUS" != "InProgress" ]] ; then
echo "cloudfront invalidation not successful"
exit 1
elif [[ "$INVALIDATION_ID" && "$2" == "true" ]] ; then
echo "waiting for cache invalidation to complete..."
COMMAND="aws cloudfront wait invalidation-completed --distribution-id $CLOUDFRONT_ID --id $INVALIDATION_ID"
echo $COMMAND
RETVAL=$(eval $COMMAND)
echo "invalidation complete"
else
exit 0
fi
else
echo "MISSING CLOUDFRONT_ID"
exit 1
fi
8 changes: 8 additions & 0 deletions 1.X/tests/goss.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ file:
group: root
filetype: file
contains: []
/opt/hermes/bin/invalidate-cloudfront-cache:
exists: true
mode: "0755"
size: 1271
owner: root
group: root
filetype: file
contains: []
/opt/hermes/bin/goss:
exists: true
mode: "0755"
Expand Down

0 comments on commit b5468b2

Please sign in to comment.