Deploy Infrastructure #15
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: Deploy Infrastructure | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| tier: | |
| description: "Environment to deploy to" | |
| required: true | |
| default: "dev" | |
| type: choice | |
| options: | |
| - dev | |
| - qa | |
| - stage | |
| - prod | |
| permissions: | |
| id-token: write | |
| contents: read | |
| jobs: | |
| deploy-infrastructure: | |
| runs-on: ubuntu-latest | |
| environment: ${{ inputs.tier }} | |
| env: | |
| TIER: ${{ inputs.tier }} | |
| AWS_REGION: us-east-1 | |
| AWS_ACCOUNT_ID: ${{ secrets.AWS_ACCOUNT_ID }} | |
| SSL_CERTIFICATE_ARN: ${{ secrets.SSL_CERTIFICATE_ARN }} | |
| NODE_OPTIONS: --openssl-legacy-provider | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Configure AWS credentials | |
| uses: aws-actions/[email protected] | |
| with: | |
| role-to-assume: arn:aws:iam::${{ secrets.AWS_ACCOUNT_ID }}:role/github-actions-cicd | |
| role-session-name: ${{ env.TIER }}-authorarranger-deploy-${{ github.ref_name }} | |
| aws-region: ${{ env.AWS_REGION }} | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: "20" | |
| cache: "npm" | |
| cache-dependency-path: infrastructure/package-lock.json | |
| - name: Install CDK and dependencies | |
| run: | | |
| npm install -g aws-cdk | |
| cd infrastructure | |
| npm ci | |
| - name: CDK Bootstrap | |
| run: | | |
| cd infrastructure | |
| npx cdk bootstrap --region ${{ env.AWS_REGION }} | |
| - name: Build Angular application | |
| run: | | |
| echo "Building Angular application for ${{ env.TIER }} environment..." | |
| npm ci | |
| npm run build | |
| - name: Deploy CloudFront Stack | |
| run: | | |
| cd infrastructure | |
| echo "Deploying CloudFront and S3 for ${{ env.TIER }} environment..." | |
| npx cdk deploy \ | |
| AuthorArrangerStack-${{ env.TIER }} \ | |
| --require-approval never | |
| - name: Invalidate CloudFront Cache | |
| run: | | |
| DISTRIBUTION_ID=$(aws cloudformation describe-stacks \ | |
| --stack-name "${{ env.TIER }}-author-arranger-website" \ | |
| --query "Stacks[0].Outputs[?OutputKey=='DistributionId'].OutputValue" \ | |
| --output text) | |
| if [ -z "$DISTRIBUTION_ID" ] || [ "$DISTRIBUTION_ID" = "None" ]; then | |
| echo "CloudFront Distribution ID not found. Redeploy CloudFront stack to get the output." | |
| exit 1 | |
| fi | |
| echo "Invalidating CloudFront cache..." | |
| aws cloudfront create-invalidation \ | |
| --distribution-id "$DISTRIBUTION_ID" \ | |
| --paths "/*" \ | |
| --output table \ | |
| --query "Invalidation.{Status:Status,CreateTime:CreateTime}" 2>/dev/null | |
| if [ $? -eq 0 ]; then | |
| echo "CloudFront cache invalidation successful" | |
| else | |
| echo "CloudFront cache invalidation failed" | |
| exit 1 | |
| fi | |
| - name: Deployment Summary | |
| run: | | |
| cd infrastructure | |
| echo "Infrastructure Deployment Complete!" | |
| echo "" | |
| echo "Environment: ${{ env.TIER }}" | |
| echo "Region: ${{ env.AWS_REGION }}" | |
| echo "" | |
| echo "Stack Outputs:" | |
| npx cdk output AuthorArrangerStack-${{ env.TIER }} --all 2>/dev/null || echo "Stack outputs not available yet" |