forked from PentabyteDevAlign/DevAlign
-
Notifications
You must be signed in to change notification settings - Fork 0
138 lines (117 loc) Β· 4.43 KB
/
deploy-frontend.yml
File metadata and controls
138 lines (117 loc) Β· 4.43 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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
name: Deploy Frontend to EC2
on:
push:
branches:
- dev
paths:
- 'Frontend/**'
- '.github/workflows/deploy-frontend.yml'
jobs:
deploy-frontend:
name: Deploy Frontend with Nginx
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Deploy to Frontend EC2
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.FRONTEND_HOST }}
username: ubuntu
key: ${{ secrets.FRONTEND_SSH_KEY }}
script: |
echo "=========================================="
echo "π Starting Frontend Deployment"
echo "=========================================="
echo "π Frontend Server: 18.141.166.14"
echo ""
# Navigate to deployment directory
cd /var/www/frontend || exit 1
# Backup old version (if exists)
if [ -d "DevAlign" ]; then
echo "π¦ Backing up current version..."
rm -rf DevAlign-backup
cp -r DevAlign DevAlign-backup
echo "β
Backup created"
fi
# Clone or pull latest code from dev branch
if [ -d "DevAlign" ]; then
echo "π₯ Pulling latest changes from dev branch..."
cd DevAlign
git fetch origin dev
git reset --hard origin/dev
git pull origin dev
else
echo "π₯ Cloning repository..."
git clone -b dev https://github.com/PentabyteDevAlign/DevAlign.git
cd DevAlign
fi
echo "β
Code updated successfully"
echo ""
# Navigate to Frontend directory
cd Frontend
# Use .env.production from repository (it's already in the code)
echo "βοΈ Using production environment from repository..."
if [ -f ".env.production" ]; then
echo "β
Production environment file found in repository"
cat .env.production
else
echo "β οΈ Warning: .env.production not found in repository"
fi
echo ""
# Install dependencies
echo "π¦ Installing dependencies..."
npm install
echo "β
Dependencies installed"
echo ""
# Build for production
echo "π¨ Building frontend for production..."
npm run build
# Verify build was created
if [ ! -d "dist" ]; then
echo "β Build failed - dist folder not found!"
exit 1
fi
echo "β
Build complete"
echo ""
# Show build directory contents
echo "π Build output (dist/):"
ls -lh dist/ | head -10
echo ""
# Copy build to nginx serve directory
echo "π Deploying build to Nginx..."
sudo rm -rf /var/www/html/*
sudo cp -r dist/* /var/www/html/
echo "β
Build deployed to /var/www/html/"
echo ""
# Set proper permissions
echo "π Setting permissions..."
sudo chown -R www-data:www-data /var/www/html
sudo chmod -R 755 /var/www/html
echo "β
Permissions set"
echo ""
# Test Nginx configuration
echo "π Testing Nginx configuration..."
sudo nginx -t
# Reload Nginx
echo "π Reloading Nginx..."
sudo systemctl reload nginx
# Check Nginx status
echo ""
echo "π Nginx Status:"
sudo systemctl status nginx --no-pager | head -10
echo ""
echo "=========================================="
echo "β
Frontend Deployment Complete!"
echo "=========================================="
echo "π Frontend URL: http://18.141.166.14"
echo "π API Endpoint: http://13.250.231.18:5000"
echo ""
echo "π Check Nginx logs with:"
echo " sudo tail -f /var/log/nginx/access.log"
echo " sudo tail -f /var/log/nginx/error.log"
echo ""
echo "π Manage Nginx with:"
echo " sudo systemctl status nginx"
echo " sudo systemctl restart nginx"
echo "=========================================="