Skip to content

Commit 509b209

Browse files
authored
Merge pull request #20 from topcoder-platform/dev
invalidate cache command enabled in cloudfront
2 parents 9aa6b56 + 4a8716c commit 509b209

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

master_deploy.sh

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ ebstemplate=""
7070
#AWS_S3_BUCKET=""
7171
#AWS_S3_SOURCE_SYNC_PATH=""
7272
CFCACHE="false"
73+
# AWS_CLOUD_FRONT_ID=""
7374

7475
# Variables for Lambda
7576
#AWS_LAMBDA_DEPLOY_TYPE=""
@@ -696,6 +697,42 @@ deploy_s3bucket() {
696697
done;
697698
}
698699

700+
check_invalidation_status() {
701+
INVALIDATE_ID=$1
702+
counter=0
703+
echo "invalidating cache with ID $INVALIDATE_ID"
704+
sleep 60
705+
invalidatestatus=`aws cloudfront get-invalidation --distribution-id $AWS_CLOUD_FRONT_ID --id $INVALIDATE_ID | $JQ '.Invalidation.Status'`
706+
707+
while [[ $invalidatestatus != *"Completed"* ]]
708+
do
709+
echo $invalidatestatus
710+
echo "Waiting for 15 sec and try to check the invalidation status..."
711+
sleep 15
712+
invalidatestatus=`aws cloudfront get-invalidation --distribution-id $AWS_CLOUD_FRONT_ID --id $INVALIDATE_ID | $JQ '.Invalidation.Status'`
713+
counter=`expr $counter + 1`
714+
if [[ $counter -gt $COUNTER_LIMIT ]] ; then
715+
echo "Invalidation does not complete with in 180 seconds. Please check the GUI mode."
716+
exit 1
717+
fi
718+
done
719+
echo "Invalidation completed"
720+
}
721+
722+
invalidate_cf_cache()
723+
{
724+
if [ "$CFCACHE" = "true" ]; then
725+
if [ -z $AWS_CLOUD_FRONT_ID ]; then
726+
echo "Based on header applicaiton has invalidated"
727+
echo "Skipped which is based on AWS cloudfront ID.Kindly raise request to configure cloud front ID in deployment configuration"
728+
else
729+
#aws cloudfront create-invalidation --distribution-id $AWS_CLOUD_FRONT_ID --paths '/*'
730+
INVALIDATE_ID=`aws cloudfront create-invalidation --distribution-id $AWS_CLOUD_FRONT_ID --paths '/*' | $JQ '.Invalidation.Id'`
731+
check_invalidation_status "$INVALIDATE_ID"
732+
fi
733+
fi
734+
}
735+
699736
download_envfile()
700737
{
701738
Buffer_seclist=$(echo $SEC_LIST | sed 's/,/ /g' )
@@ -1127,6 +1164,7 @@ main()
11271164
if [ "$DEPLOYMENT_TYPE" == "CFRONT" ]
11281165
then
11291166
deploy_s3bucket
1167+
invalidate_cf_cache
11301168
fi
11311169

11321170
if [ "$DEPLOYMENT_TYPE" == "LAMBDA" ]

0 commit comments

Comments
 (0)