diff --git a/.github/workflows/deploy-production.yml b/.github/workflows/deploy-production.yml index d006fdbba..677eb8cf6 100644 --- a/.github/workflows/deploy-production.yml +++ b/.github/workflows/deploy-production.yml @@ -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 }} @@ -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 @@ -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 }}" \ No newline at end of file +# 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 "/*" \ No newline at end of file diff --git a/.github/workflows/deploy-staging.yml b/.github/workflows/deploy-staging.yml index efa86d480..45ece1502 100644 --- a/.github/workflows/deploy-staging.yml +++ b/.github/workflows/deploy-staging.yml @@ -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 }} @@ -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 @@ -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: diff --git a/tofu/modules/services/frontend-infra/output.tf b/tofu/modules/services/frontend-infra/output.tf index cc455bb84..a64278fd5 100644 --- a/tofu/modules/services/frontend-infra/output.tf +++ b/tofu/modules/services/frontend-infra/output.tf @@ -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 +} \ No newline at end of file