Skip to content

Commit 7208566

Browse files
committed
[DSC-2193] Add cloudfront cache invalidation
1 parent 942cecf commit 7208566

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

bitbucket-pipelines.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,28 @@ definitions:
184184
- git commit -am "Update TAG with ${BRANCH_NAME}-${HASH_COMMIT}"
185185
- git push
186186

187+
- step: &find-and-invalidate-cloudfront-dev
188+
name: Find and Invalidate CloudFront Cache
189+
image: amazon/aws-cli
190+
script:
191+
- aws configure set aws_access_key_id $AWS_ACCESS_KEY_ID
192+
- aws configure set aws_secret_access_key $AWS_SECRET_ACCESS_KEY
193+
- aws configure set default.region $AWS_REGION
194+
- export CLOUDFRONT_NAME=$(echo "$BITBUCKET_BRANCH" | awk -F'/' '{if(NF==1)val=$1;else if(NF==2)val=$2;else if(NF==3)val=$2;else val=$3;gsub(/_/, "-", val);print tolower(val)}')
195+
- export CLOUDFRONT_DISTRIBUTION_ID=$(aws cloudfront list-distributions --query "DistributionList.Items[?Comment=='dev--$CLOUDFRONT_NAME'].Id" --output text)
196+
- aws cloudfront create-invalidation --distribution-id $CLOUDFRONT_DISTRIBUTION_ID --paths "/*"
197+
198+
- step: &find-and-invalidate-cloudfront-staging
199+
name: Find and Invalidate CloudFront Cache
200+
image: amazon/aws-cli
201+
script:
202+
- aws configure set aws_access_key_id $AWS_ACCESS_KEY_ID
203+
- aws configure set aws_secret_access_key $AWS_SECRET_ACCESS_KEY
204+
- aws configure set default.region $AWS_REGION
205+
- export CLOUDFRONT_NAME=$(echo "$BITBUCKET_BRANCH" | awk -F'/' '{if(NF==1)val=$1;else if(NF==2)val=$2;else if(NF==3)val=$2;else val=$3;gsub(/_/, "-", val);print tolower(val)}')
206+
- export CLOUDFRONT_DISTRIBUTION_ID=$(aws cloudfront list-distributions --query "DistributionList.Items[?Comment=='staging--$CLOUDFRONT_NAME'].Id" --output text)
207+
- aws cloudfront create-invalidation --distribution-id $CLOUDFRONT_DISTRIBUTION_ID --paths "/*"
208+
187209
pipelines:
188210
custom:
189211
e2e-on-custom-backend:
@@ -196,21 +218,26 @@ pipelines:
196218
- step: *angular-build
197219
- step: *build-and-push
198220
- step: *deploy-on-dev
221+
- step: *find-and-invalidate-cloudfront-dev
199222
branches:
200223
'dspace-cris-2024_02_x':
201224
- step: *preliminary-operation
202225
- step: *angular-build
203226
- parallel: *parallel-run-tests
204227
- step: *build-and-push
205228
- step: *deploy-on-dev
229+
- step: *find-and-invalidate-cloudfront-dev
206230
- step: *deploy-on-staging
231+
- step: *find-and-invalidate-cloudfront-staging
207232
'prod/**':
208233
- step: *preliminary-operation
209234
- step: *angular-build
210235
- parallel: *parallel-run-tests
211236
- step: *build-and-push
212237
- step: *deploy-on-dev
238+
- step: *find-and-invalidate-cloudfront-dev
213239
- step: *deploy-on-staging
240+
- step: *find-and-invalidate-cloudfront-staging
214241
pull-requests:
215242
'**':
216243
- step: *preliminary-operation

0 commit comments

Comments
 (0)