Deploy Nevus Infrastructure #8
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 Nevus Tool 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 }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Configure AWS credentials | |
| uses: aws-actions/configure-aws-credentials@v5.1.0 | |
| with: | |
| role-to-assume: arn:aws:iam::${{ secrets.AWS_ACCOUNT_ID }}:role/github-actions-cicd | |
| role-session-name: ${{ env.TIER }}-nevustool-deploy-${{ github.ref_name }} | |
| aws-region: ${{ env.AWS_REGION }} | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: "18" | |
| 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 React application | |
| run: | | |
| echo "Building React application for ${{ env.TIER }} environment..." | |
| cd client | |
| npm ci | |
| npm run build | |
| env: | |
| REACT_APP_PROJECT: nevustool | |
| - name: Deploy CloudFront + S3 Stack | |
| run: | | |
| cd infrastructure | |
| echo "Deploying CloudFront and S3 for ${{ env.TIER }} environment..." | |
| npx cdk deploy NevusToolStack-${{ env.TIER }} \ | |
| --require-approval never | |
| - name: Deploy Application to S3 | |
| run: | | |
| BUCKET_NAME=$(aws cloudformation describe-stacks \ | |
| --stack-name "${{ env.TIER }}-nevustool-cloudfront-s3" \ | |
| --query "Stacks[0].Outputs[?OutputKey=='BucketName'].OutputValue" \ | |
| --output text) | |
| if [ -z "$BUCKET_NAME" ] || [ "$BUCKET_NAME" = "None" ]; then | |
| echo "❌ S3 Bucket name not found in stack outputs." | |
| exit 1 | |
| fi | |
| echo "Deploying to S3 bucket: $BUCKET_NAME" | |
| aws s3 sync client/build/ s3://$BUCKET_NAME --delete | |
| - name: Invalidate CloudFront Cache | |
| run: | | |
| DISTRIBUTION_ID=$(aws cloudformation describe-stacks \ | |
| --stack-name "${{ env.TIER }}-nevustool-cloudfront-s3" \ | |
| --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 for distribution: $DISTRIBUTION_ID" | |
| 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: | | |
| echo "## Deployment Summary" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "✅ **Infrastructure Deployment Complete!**" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "- **Application**: Nevus Recognition Tool" >> $GITHUB_STEP_SUMMARY | |
| echo "- **Environment**: ${{ env.TIER }}" >> $GITHUB_STEP_SUMMARY | |
| echo "- **Region**: ${{ env.AWS_REGION }}" >> $GITHUB_STEP_SUMMARY | |
| echo "- **Stack**: ${{ env.TIER }}-nevustool-cloudfront-s3" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| WEBSITE_URL=$(aws cloudformation describe-stacks \ | |
| --stack-name "${{ env.TIER }}-nevustool-cloudfront-s3" \ | |
| --query "Stacks[0].Outputs[?OutputKey=='WebsiteUrl'].OutputValue" \ | |
| --output text) | |
| if [ ! -z "$WEBSITE_URL" ] && [ "$WEBSITE_URL" != "None" ]; then | |
| echo "- **Website URL**: $WEBSITE_URL" >> $GITHUB_STEP_SUMMARY | |
| fi |