-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.sh
More file actions
65 lines (54 loc) · 1.75 KB
/
Copy pathdeploy.sh
File metadata and controls
65 lines (54 loc) · 1.75 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
#!/bin/bash
set -e
# --- Config ---
APP_NAME="storelab"
DOMAIN="vhu-storelab.io.vn"
echo "🔁 Pulling latest code..."
git pull origin main || true
echo "📦 Remove Docker containers..."
sudo docker compose down -v
echo "📦 Building Docker containers..."
sudo docker compose build --no-cache
echo "🚀 Starting containers..."
sudo docker compose up -d
# --- Nginx config ---
if [ ! -f /etc/nginx/sites-available/$APP_NAME ]; then
echo "🌐 Setting up Nginx..."
sudo bash -c "cat > /etc/nginx/sites-available/$APP_NAME <<EOF
server {
listen 80;
server_name $DOMAIN www.$DOMAIN;
location / {
proxy_pass http://localhost:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade \\\$http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host \\\$host;
proxy_cache_bypass \\\$http_upgrade;
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;
}
}
server {
listen 127.0.0.1:80;
server_name 127.0.0.1 localhost;
location / {
proxy_pass http://localhost:3000;
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;
}
}
EOF"
sudo ln -sf /etc/nginx/sites-available/$APP_NAME /etc/nginx/sites-enabled/
sudo nginx -t && sudo systemctl restart nginx
fi
# --- SSL cert ---
if [ ! -d /etc/letsencrypt/live/$DOMAIN ]; then
echo "🔐 Getting SSL certificate..."
sudo apt install -y certbot python3-certbot-nginx
sudo certbot --nginx -d $DOMAIN -d www.$DOMAIN
fi
echo "✅ Deploy completed! Visit: https://$DOMAIN"