-
Notifications
You must be signed in to change notification settings - Fork 9
82 lines (70 loc) · 2.54 KB
/
frontend.yml
File metadata and controls
82 lines (70 loc) · 2.54 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
name: Frontend Deployment to AWS S3 & CloudFront(CDN)
on:
push:
branches:
- main
- master
paths:
- 'frontend/**'
workflow_dispatch:
jobs:
deploy:
name: frontend
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '18'
cache: 'npm'
cache-dependency-path: frontend/package-lock.json
- name: Install dependencies
working-directory: ./frontend
run: npm ci
- name: Build frontend
working-directory: ./frontend
env:
VITE_BACKEND_URI: ${{ secrets.VITE_BACKEND_URI }}
VITE_POSTHOG_API_KEY: ${{ secrets.VITE_POSTHOG_API_KEY }}
VITE_POSTHOG_SECURE_PATH: ${{ secrets.VITE_POSTHOG_SECURE_PATH }}
VITE_PUBLIC_POSTHOG_HOST: ${{ secrets.VITE_PUBLIC_POSTHOG_HOST || 'https://us.i.posthog.com' }}
run: npm run build
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_REGION || 'us-east-1' }}
- name: Deploy to S3
working-directory: ./frontend
run: |
aws s3 sync dist/ s3://${{ secrets.AWS_S3_BUCKET_NAME }} \
--delete \
--cache-control "public, max-age=31536000, immutable" \
--exclude "*.html" \
--exclude "*.json"
# Upload HTML files with no-cache
aws s3 sync dist/ s3://${{ secrets.AWS_S3_BUCKET_NAME }} \
--delete \
--cache-control "no-cache, no-store, must-revalidate" \
--exclude "*" \
--include "*.html" \
--include "*.json"
- name: Invalidate CloudFront cache
env:
CLOUDFRONT_DIST_ID: ${{ secrets.AWS_CLOUDFRONT_DISTRIBUTION_ID }}
run: |
if [ -n "$CLOUDFRONT_DIST_ID" ]; then
aws cloudfront create-invalidation \
--distribution-id "$CLOUDFRONT_DIST_ID" \
--paths "/*"
else
echo "Skipping CloudFront invalidation: Distribution ID not set"
fi
- name: Deployment summary
run: |
echo "Frontend deployed successfully!"
echo "S3 Bucket: ${{ secrets.AWS_S3_BUCKET_NAME }}"
echo "CloudFront Distribution: ${{ secrets.AWS_CLOUDFRONT_DISTRIBUTION_ID }}"