Skip to content

Commit

Permalink
add cloudfront invalidation to deploy
Browse files Browse the repository at this point in the history
  • Loading branch information
jdbass committed May 17, 2024
1 parent 4d8c59d commit 7127c1a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
13 changes: 12 additions & 1 deletion .github/workflows/deploy-production.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ jobs:
runs-on: ubuntu-latest
outputs:
bucket: ${{ steps.output-bucket-name.outputs.bucket }}
cloudfront_id: ${{ steps.output-cloudfront-distro.outputs.cloudfront_id }}
# env:
# TF_VAR_region: ${{ vars.AWS_REGION }}
# TF_VAR_environment: ${{ vars.ENV_SHORT_NAME }}
Expand Down Expand Up @@ -102,6 +103,13 @@ jobs:
output=$(terragrunt output bucket_name | tr -d '"')
echo bucket=$output >> $GITHUB_OUTPUT
- name: output-cloudfront-distro
id: output-cloudfront-distro
working-directory: ./tofu/environments/stage/services/frontend-infra
run: |
output=$(terragrunt output cloudfront_id)
echo cloudfront_id=$output >> $GITHUB_OUTPUT
release-production:
name: Release to Production
needs: deploy-iac
Expand Down Expand Up @@ -151,4 +159,7 @@ jobs:
# terragrunt apply tfplan

# - name: Deploy frontend to S3
# run: aws s3 sync ./frontend/frontend/dist "s3://${{ needs.deploy-iac.outputs.bucket }}"
# run: aws s3 sync ./frontend/frontend/dist "s3://${{ needs.deploy-iac.outputs.bucket }}"

- name: Invalidate Cloudfront cache
run: aws cloudfront create-invalidation --distribution-id ${{ needs.deploy-iac.outputs.cloudfront_id }} --paths "/*"
15 changes: 11 additions & 4 deletions .github/workflows/deploy-staging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ jobs:
runs-on: ubuntu-latest
outputs:
bucket: ${{ steps.output-bucket-name.outputs.bucket }}
cloudfront_id: ${{ steps.output-cloudfront-distro.outputs.cloudfront_id }}
env:
TF_VAR_region: ${{ vars.AWS_REGION }}
TF_VAR_environment: ${{ vars.ENV_SHORT_NAME }}
Expand Down Expand Up @@ -132,6 +133,13 @@ jobs:
output=$(terragrunt output bucket_name | tr -d '"')
echo bucket=$output >> $GITHUB_OUTPUT
- name: output-cloudfront-distro
id: output-cloudfront-distro
working-directory: ./tofu/environments/stage/services/frontend-infra
run: |
output=$(terragrunt output cloudfront_id)
echo cloudfront_id=$output >> $GITHUB_OUTPUT
deploy-frontend:
needs:
- detect-changes
Expand Down Expand Up @@ -168,10 +176,9 @@ jobs:
role-session-name: Appointment_GitHub_to_AWS_via_FederatedOIDC
aws-region: ${{ vars.AWS_REGION }}

# - name: Build frontend archive
# run: |
# zip -r frontend.zip frontend/dist
#
- name: Invalidate Cloudfront cache
run: aws cloudfront create-invalidation --distribution-id ${{ needs.deploy-iac.outputs.cloudfront_id }} --paths "/*"

- name: Archive Frontend
uses: actions/upload-artifact@v4
with:
Expand Down
4 changes: 4 additions & 0 deletions tofu/modules/services/frontend-infra/output.tf
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,7 @@ output "bucket_name" {
output "cloudfront_arn" {
value = aws_cloudfront_distribution.appointment.arn
}

output "cloudfront_id" {
value = aws_cloudfront_distribution.appointment.id
}

0 comments on commit 7127c1a

Please sign in to comment.