-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy-frontend.sh.template
More file actions
executable file
·78 lines (63 loc) · 2.24 KB
/
deploy-frontend.sh.template
File metadata and controls
executable file
·78 lines (63 loc) · 2.24 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
#!/bin/bash
# Frontend Deployment Script for HRI 3.0
# Builds and deploys the React app to AWS S3 + CloudFront
set -e # Exit on error
# Configuration - Update these values for your AWS setup
S3_BUCKET="your-hri-frontend-bucket" # e.g., "hri-news-app"
CLOUDFRONT_DISTRIBUTION_ID="" # e.g., "E1234567890ABC" (optional)
AWS_REGION="us-east-2"
echo "🚀 Starting HRI Frontend Deployment..."
echo "================================="
# Check if AWS CLI is installed
if ! command -v aws &> /dev/null; then
echo "❌ Error: AWS CLI is not installed"
echo "Install it from: https://aws.amazon.com/cli/"
exit 1
fi
# Check if bucket name is configured
if [ "$S3_BUCKET" = "your-hri-frontend-bucket" ]; then
echo "❌ Error: Please update S3_BUCKET in this script"
echo "Edit deploy-frontend.sh and set your S3 bucket name"
exit 1
fi
# Install dependencies
echo "📦 Installing dependencies..."
npm install
# Build the app
echo "🔨 Building production bundle..."
npm run build
if [ ! -d "dist" ]; then
echo "❌ Error: Build failed - dist/ directory not found"
exit 1
fi
# Deploy to S3
echo "☁️ Uploading to S3 bucket: $S3_BUCKET..."
aws s3 sync dist/ s3://$S3_BUCKET \
--delete \
--region $AWS_REGION \
--cache-control "public, max-age=31536000" \
--exclude "index.html" \
--exclude "*.map"
# Upload index.html separately with no-cache
aws s3 cp dist/index.html s3://$S3_BUCKET/index.html \
--region $AWS_REGION \
--cache-control "no-cache, no-store, must-revalidate" \
--content-type "text/html"
echo "✅ Files uploaded to S3"
# Invalidate CloudFront cache (optional)
if [ -n "$CLOUDFRONT_DISTRIBUTION_ID" ]; then
echo "🔄 Invalidating CloudFront cache..."
aws cloudfront create-invalidation \
--distribution-id $CLOUDFRONT_DISTRIBUTION_ID \
--paths "/*" \
--no-cli-pager
echo "✅ CloudFront cache invalidated"
else
echo "⚠️ CloudFront distribution ID not set - skipping cache invalidation"
fi
echo "================================="
echo "✨ Deployment complete!"
echo "Your app is live at: https://$S3_BUCKET.s3.$AWS_REGION.amazonaws.com/index.html"
if [ -n "$CLOUDFRONT_DISTRIBUTION_ID" ]; then
echo "Or via CloudFront (may take a few minutes to update)"
fi