-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.sh
More file actions
95 lines (79 loc) · 2.36 KB
/
Copy pathdeploy.sh
File metadata and controls
95 lines (79 loc) · 2.36 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
#!/bin/bash
# GTMFlow — EC2 deployment script
# Run once on your AWS machine: bash deploy.sh
set -e
APP_DIR="$(cd "$(dirname "$0")" && pwd)"
echo "==> Detecting OS..."
if [ -f /etc/debian_version ]; then
PKG="apt"
sudo apt update -y
sudo apt install -y python3 python3-venv redis-server nginx
elif [ -f /etc/amazon-linux-release ] || [ -f /etc/system-release ]; then
PKG="yum"
sudo yum install -y python3 redis nginx
fi
echo "==> Starting Redis..."
sudo systemctl enable redis && sudo systemctl start redis
echo "==> Setting up Python venv..."
cd "$APP_DIR"
python3 -m venv .venv
source .venv/bin/activate
pip install --upgrade pip -q
pip install . -q
echo "==> Setting up .env..."
if [ ! -f .env ]; then
cp .env.example .env
echo ""
echo " !! .env created from .env.example"
echo " !! Edit it now: nano $APP_DIR/.env"
echo " !! Then re-run: bash deploy.sh"
exit 1
fi
echo "==> Running database migrations..."
"$APP_DIR/.venv/bin/alembic" upgrade head
echo "==> Installing systemd services..."
USER_NAME=$(whoami)
sudo tee /etc/systemd/system/gtmflow-web.service > /dev/null <<EOF
[Unit]
Description=GTMFlow Web Server
After=network.target
[Service]
User=$USER_NAME
WorkingDirectory=$APP_DIR
EnvironmentFile=$APP_DIR/.env
ExecStart=$APP_DIR/.venv/bin/uvicorn app.main:app --host 127.0.0.1 --port 8000
Restart=always
RestartSec=5
[Install]
WantedBy=multi-user.target
EOF
sudo tee /etc/systemd/system/gtmflow-worker.service > /dev/null <<EOF
[Unit]
Description=GTMFlow RQ Worker
After=network.target redis.service
[Service]
User=$USER_NAME
WorkingDirectory=$APP_DIR
EnvironmentFile=$APP_DIR/.env
ExecStart=$APP_DIR/.venv/bin/rq worker pipeline
Restart=always
RestartSec=5
[Install]
WantedBy=multi-user.target
EOF
sudo systemctl daemon-reload
sudo systemctl enable gtmflow-web gtmflow-worker
sudo systemctl restart gtmflow-web gtmflow-worker
echo "==> Configuring Nginx..."
sudo cp "$APP_DIR/nginx.conf" /etc/nginx/conf.d/gtmflow.conf
sudo nginx -t && sudo systemctl enable nginx && sudo systemctl restart nginx
echo ""
echo "=========================================="
echo " GTMFlow deployed successfully!"
echo ""
echo " Health check:"
echo " curl http://localhost/health"
echo ""
echo " Zoho webhook URL:"
echo " http://$(curl -s http://169.254.169.254/latest/meta-data/public-ipv4)/webhook/zoho"
echo "=========================================="