-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.sh
More file actions
256 lines (221 loc) · 8.56 KB
/
Copy pathdeploy.sh
File metadata and controls
256 lines (221 loc) · 8.56 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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
#!/bin/bash
# ==============================================================
# Voice Resume Backend - VPS Deployment Script
# ==============================================================
# Run this script on your VPS after uploading the application files
# Usage: chmod +x deploy.sh && sudo ./deploy.sh
# ==============================================================
set -e # Exit on any error
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
echo -e "${BLUE}================================================${NC}"
echo -e "${BLUE} Voice Resume Backend - VPS Deployment Script ${NC}"
echo -e "${BLUE}================================================${NC}"
echo ""
# Check if running as root
if [ "$EUID" -ne 0 ]; then
echo -e "${RED}Please run as root (sudo ./deploy.sh)${NC}"
exit 1
fi
# Configuration
APP_USER="voiceresume"
APP_DIR="/home/$APP_USER/app"
DOMAIN="server.voiceresume.xyz"
# ==============================================================
# Step 1: System Update & Dependencies
# ==============================================================
echo -e "${GREEN}[1/8] Updating system and installing dependencies...${NC}"
apt update && apt upgrade -y
apt install -y python3.12 python3.12-venv python3-pip nginx certbot python3-certbot-nginx git curl wget unzip build-essential libffi-dev libssl-dev
# Install TeX Live for PDF generation
echo -e "${GREEN}[1/8] Installing TeX Live (this may take a while)...${NC}"
apt install -y texlive-full latexmk || {
echo -e "${YELLOW}Full TeX Live failed, trying minimal install...${NC}"
apt install -y texlive-latex-base texlive-latex-extra texlive-fonts-recommended texlive-fonts-extra latexmk
}
# ==============================================================
# Step 2: Create Application User
# ==============================================================
echo -e "${GREEN}[2/8] Setting up application user...${NC}"
if ! id "$APP_USER" &>/dev/null; then
useradd -m -s /bin/bash $APP_USER
echo -e "${GREEN}Created user: $APP_USER${NC}"
else
echo -e "${YELLOW}User $APP_USER already exists${NC}"
fi
# ==============================================================
# Step 3: Setup Application Directory
# ==============================================================
echo -e "${GREEN}[3/8] Setting up application directory...${NC}"
mkdir -p $APP_DIR
mkdir -p $APP_DIR/logs
mkdir -p $APP_DIR/uploads
mkdir -p $APP_DIR/outputs
mkdir -p $APP_DIR/temp
mkdir -p $APP_DIR/static
# Set ownership
chown -R $APP_USER:$APP_USER /home/$APP_USER
# ==============================================================
# Step 4: Python Virtual Environment
# ==============================================================
echo -e "${GREEN}[4/8] Setting up Python virtual environment...${NC}"
cd $APP_DIR
# Create venv if it doesn't exist
if [ ! -d "venv" ]; then
python3.12 -m venv venv
echo -e "${GREEN}Created virtual environment${NC}"
fi
# Activate and install dependencies
source venv/bin/activate
pip install --upgrade pip setuptools wheel
if [ -f "requirements.txt" ]; then
pip install -r requirements.txt
echo -e "${GREEN}Installed Python dependencies${NC}"
else
echo -e "${YELLOW}Warning: requirements.txt not found${NC}"
fi
# Verify RenderCV
python -c "import rendercv; print('RenderCV version:', rendercv.__version__)" || {
echo -e "${YELLOW}RenderCV not installed, installing...${NC}"
pip install rendercv
}
deactivate
# ==============================================================
# Step 5: Configure Systemd Service
# ==============================================================
echo -e "${GREEN}[5/8] Configuring systemd service...${NC}"
# Copy service file
if [ -f "$APP_DIR/voiceresume.service" ]; then
cp $APP_DIR/voiceresume.service /etc/systemd/system/
else
# Create service file if not exists
cat > /etc/systemd/system/voiceresume.service << 'EOF'
[Unit]
Description=Voice Resume Backend - AI CV Generator
After=network.target
[Service]
User=voiceresume
Group=voiceresume
WorkingDirectory=/home/voiceresume/app
Environment="PATH=/home/voiceresume/app/venv/bin"
EnvironmentFile=/home/voiceresume/app/.env
ExecStart=/home/voiceresume/app/venv/bin/gunicorn --config gunicorn.conf.py app:app
ExecReload=/bin/kill -s HUP $MAINPID
KillMode=mixed
TimeoutStopSec=10
PrivateTmp=true
Restart=always
RestartSec=10
[Install]
WantedBy=multi-user.target
EOF
fi
# Reload systemd
systemctl daemon-reload
systemctl enable voiceresume
echo -e "${GREEN}Systemd service configured${NC}"
# ==============================================================
# Step 6: Configure Nginx
# ==============================================================
echo -e "${GREEN}[6/8] Configuring Nginx...${NC}"
# Copy nginx config
if [ -f "$APP_DIR/nginx.voiceresume.conf" ]; then
cp $APP_DIR/nginx.voiceresume.conf /etc/nginx/sites-available/voiceresume
else
echo -e "${YELLOW}Warning: nginx config not found, creating basic config...${NC}"
cat > /etc/nginx/sites-available/voiceresume << EOF
upstream voiceresume_backend {
server 127.0.0.1:5000;
}
server {
listen 80;
server_name $DOMAIN;
location / {
proxy_pass http://voiceresume_backend;
proxy_http_version 1.1;
proxy_set_header Host \$host;
proxy_set_header X-Real-IP \$remote_addr;
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto \$scheme;
}
location /socket.io/ {
proxy_pass http://voiceresume_backend/socket.io/;
proxy_http_version 1.1;
proxy_set_header Upgrade \$http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host \$host;
}
client_max_body_size 50M;
}
EOF
fi
# Enable site
ln -sf /etc/nginx/sites-available/voiceresume /etc/nginx/sites-enabled/
rm -f /etc/nginx/sites-enabled/default
# Test nginx config
nginx -t && systemctl reload nginx
echo -e "${GREEN}Nginx configured${NC}"
# ==============================================================
# Step 7: SSL Certificate
# ==============================================================
echo -e "${GREEN}[7/8] Setting up SSL certificate...${NC}"
echo -e "${YELLOW}Note: Make sure your domain DNS is pointing to this server!${NC}"
read -p "Do you want to install SSL certificate for $DOMAIN? (y/n) " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
certbot --nginx -d $DOMAIN --non-interactive --agree-tos --email admin@$DOMAIN || {
echo -e "${YELLOW}SSL installation failed. You can run it manually later:${NC}"
echo -e "${YELLOW} sudo certbot --nginx -d $DOMAIN${NC}"
}
fi
# ==============================================================
# Step 8: Start Application
# ==============================================================
echo -e "${GREEN}[8/8] Starting application...${NC}"
# Check if .env exists
if [ ! -f "$APP_DIR/.env" ]; then
echo -e "${YELLOW}Warning: .env file not found!${NC}"
echo -e "${YELLOW}Please copy .env.production.example to .env and configure it:${NC}"
echo -e "${YELLOW} cp $APP_DIR/.env.production.example $APP_DIR/.env${NC}"
echo -e "${YELLOW} nano $APP_DIR/.env${NC}"
else
# Start the application
systemctl start voiceresume
sleep 2
systemctl status voiceresume --no-pager
fi
# ==============================================================
# Setup Firewall
# ==============================================================
echo -e "${GREEN}Configuring firewall...${NC}"
ufw allow OpenSSH
ufw allow 'Nginx Full'
ufw --force enable
# ==============================================================
# Final Summary
# ==============================================================
echo ""
echo -e "${BLUE}================================================${NC}"
echo -e "${BLUE} Deployment Complete! ${NC}"
echo -e "${BLUE}================================================${NC}"
echo ""
echo -e "${GREEN}✓ Application installed at: $APP_DIR${NC}"
echo -e "${GREEN}✓ Systemd service: voiceresume${NC}"
echo -e "${GREEN}✓ Nginx configured for: $DOMAIN${NC}"
echo ""
echo -e "${YELLOW}Next Steps:${NC}"
echo -e "1. Configure your .env file: ${BLUE}nano $APP_DIR/.env${NC}"
echo -e "2. Restart the application: ${BLUE}sudo systemctl restart voiceresume${NC}"
echo -e "3. Check status: ${BLUE}sudo systemctl status voiceresume${NC}"
echo -e "4. View logs: ${BLUE}sudo journalctl -u voiceresume -f${NC}"
echo ""
echo -e "${GREEN}Your API will be available at:${NC}"
echo -e " https://$DOMAIN"
echo -e " https://$DOMAIN/health"
echo -e " https://$DOMAIN/admin/"
echo ""
echo -e "${BLUE}================================================${NC}"