-
Notifications
You must be signed in to change notification settings - Fork 0
110 lines (93 loc) · 3.41 KB
/
Copy pathdeploy.yml
File metadata and controls
110 lines (93 loc) · 3.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
name: Deploy to AWS
on:
workflow_run:
workflows:
- CI Build
types:
- completed
branches:
- main
workflow_dispatch:
concurrency:
group: production-deployment
cancel-in-progress: true
permissions:
contents: read
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 1
- name: Setup Node
uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0
with:
node-version: 24.x
cache: npm
- name: Install dependencies
run: npm ci
- name: Build application
run: npm run build:prod
- name: Upload build artifacts
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: devtoolbox-artifacts
path: dist/dev-tool-box/browser/
retention-days: 1
deploy:
needs: build
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
environment:
name: production
url: https://devtoolbox.raymondsplinter.com
env:
DEPLOY_URL: https://devtoolbox.raymondsplinter.com
AWS_REGION: eu-central-1
AWS_ROLE_ARN: ${{ secrets.AWS_ROLE_ARN }}
AWS_S3_BUCKET: ${{ secrets.S3_BUCKET }}
AWS_CLOUDFRONT_DISTRIBUTION_ID: ${{ secrets.CLOUDFRONT_DISTRIBUTION_ID }}
steps:
- name: Download build artifacts
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
name: devtoolbox-artifacts
path: dist/dev-tool-box/browser/
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@e6de054238d6b7531b4efff3b6587d9aade6a06c # v6.2.3
with:
aws-region: ${{ env.AWS_REGION }}
role-to-assume: ${{ env.AWS_ROLE_ARN }}
- name: Deploy application to S3
run: aws s3 sync dist/dev-tool-box/browser/ s3://${{ env.AWS_S3_BUCKET }}
- name: Invalidate CloudFront cache
id: invalidate
run: |
INVALIDATION_ID=$(aws cloudfront create-invalidation --distribution-id ${{ env.AWS_CLOUDFRONT_DISTRIBUTION_ID }} --paths "/*" --query 'Invalidation.Id' --output text)
echo "invalidation-id=$INVALIDATION_ID" >> $GITHUB_OUTPUT
- name: Wait for CloudFront invalidation
run: |
aws cloudfront wait invalidation-completed --distribution-id ${{ env.AWS_CLOUDFRONT_DISTRIBUTION_ID }} --id ${{ steps.invalidate.outputs.invalidation-id }}
echo "✅ CloudFront cache invalidation completed"
- name: Smoke test - Validate deployment
run: |
RESPONSE=$(curl -s -o /dev/null -w "%{http_code}" "$DEPLOY_URL")
echo "HTTP Response Code: $RESPONSE"
if [ "$RESPONSE" = "200" ]; then
echo "✅ Smoke test passed: Website is accessible at $DEPLOY_URL" >> $GITHUB_STEP_SUMMARY
else
echo "❌ Smoke test failed: HTTP $RESPONSE" >> $GITHUB_STEP_SUMMARY
exit 1
fi
- name: Deployment notification
if: success()
run: echo "✅ Deployment to production completed successfully" >> $GITHUB_STEP_SUMMARY
- name: Deployment failure notification
if: failure()
run: |
echo "❌ Deployment failed" >> $GITHUB_STEP_SUMMARY
exit 1