Continuous Deployment #11
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Continuous Deployment | |
| on: | |
| workflow_run: | |
| workflows: ["Continuous Integration"] | |
| types: | |
| - completed | |
| jobs: | |
| staging-deployment: | |
| name: staging-deployment | |
| runs-on: ubuntu-latest | |
| permissions: | |
| id-token: write | |
| steps: | |
| - name: Configure AWS Credentials | |
| uses: aws-actions/configure-aws-credentials@v5.1.0 | |
| with: | |
| aws-region: us-east-1 | |
| role-to-assume: arn:aws:iam::968225077300:role/nsse-github-frontend-role | |
| - uses: actions/download-artifact@v5 | |
| with: | |
| name: ${{ github.event.workflow_run.head_sha }} | |
| path: ./dist | |
| github-token: ${{ secrets.GITHUB_TOKEN }} | |
| run-id: ${{ github.event.workflow_run.id }} | |
| - name: Deploy to S3 | |
| run: aws s3 sync ./dist s3://staging.devopsnanuvemweek.com --delete | |
| - name: Invalidate CloudFront Cache | |
| run: aws cloudfront create-invalidation --distribution-id E33HQF0B2XJLCM --paths "/*" | |
| point-production-to-staging: | |
| name: point-production-to-staging | |
| needs: [staging-deployment] | |
| runs-on: ubuntu-latest | |
| environment: production | |
| permissions: | |
| id-token: write | |
| steps: | |
| - name: Configure AWS Credentials | |
| uses: aws-actions/configure-aws-credentials@v5.1.0 | |
| with: | |
| aws-region: us-east-1 | |
| role-to-assume: arn:aws:iam::968225077300:role/nsse-github-frontend-role | |
| - name: Shift Production to Staging Bucket | |
| run: | | |
| aws cloudfront get-distribution-config --id E64GVY5C1BYGC > dist.json | |
| jq '.DistributionConfig.DefaultCacheBehavior.TargetOriginId = "staging.devopsnanuvemweek.com.s3.us-east-1.amazonaws.com"' dist.json > new-dist.json | |
| aws cloudfront update-distribution \ | |
| --id E64GVY5C1BYGC \ | |
| --distribution-config "$(jq '.DistributionConfig' new-dist.json)" \ | |
| --if-match "$(jq '.ETag' -r new-dist.json)" | |
| - name: Invalidate CloudFront Cache | |
| run: aws cloudfront create-invalidation --distribution-id E64GVY5C1BYGC --paths "/*" |