-
Notifications
You must be signed in to change notification settings - Fork 0
93 lines (80 loc) · 2.75 KB
/
Copy pathdeploy.yaml
File metadata and controls
93 lines (80 loc) · 2.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
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
name: Deploy to EC2
on:
push:
branches:
- main
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Archive Repository
run: |
tar -czf deploy.tar.gz \
--exclude='node_modules' \
--exclude='.next' \
--exclude='venv' \
--exclude='dataset' \
--exclude='__pycache__' \
--exclude='.git' \
--exclude='outputs' \
--exclude='.pytest_cache' \
--exclude='.mypy_cache' \
--exclude='.ruff_cache' \
.
- name: Copy Archive to EC2
uses: appleboy/scp-action@v0.1.7
with:
host: ${{ secrets.EC2_HOST }}
username: ${{ secrets.EC2_USERNAME }}
key: ${{ secrets.EC2_SSH_KEY }}
port: ${{ secrets.EC2_PORT }}
source: "deploy.tar.gz"
target: "/tmp"
- name: Deploy and Restart Services
uses: appleboy/ssh-action@v1.0.3
with:
host: ${{ secrets.EC2_HOST }}
username: ${{ secrets.EC2_USERNAME }}
key: ${{ secrets.EC2_SSH_KEY }}
port: ${{ secrets.EC2_PORT }}
script: |
mkdir -p ~/agrinn
# Extract over existing repository safely (preserves venv/models)
tar -xzf /tmp/deploy.tar.gz -C ~/agrinn/
rm /tmp/deploy.tar.gz
# Build Frontend natively on EC2
cd ~/agrinn/apps/web
npm install
npm run build
# Restart Frontend PM2
pm2 delete agrinn-web || true
PORT=3000 pm2 start npm --name agrinn-web -- start
pm2 save
# Setup Backend Dependencies
cd ~/agrinn/apps/api
if [ ! -d "venv" ]; then
python3 -m venv venv
fi
source venv/bin/activate
pip install -r requirements.txt
# Restart Backend Systemd Service
if [ ! -f /etc/systemd/system/agrinn-api.service ]; then
sudo bash -c "cat > /etc/systemd/system/agrinn-api.service << 'EOF'
[Unit]
Description=AgriNN FastAPI Backend
After=network.target
[Service]
User=$USER
WorkingDirectory=/home/$USER/agrinn/apps/api
Environment=\"PATH=/home/$USER/agrinn/apps/api/venv/bin\"
ExecStart=/home/$USER/agrinn/apps/api/venv/bin/uvicorn app.main:app --host 0.0.0.0 --port 8000
Restart=always
[Install]
WantedBy=multi-user.target
EOF"
sudo systemctl daemon-reload
sudo systemctl enable agrinn-api
fi
sudo systemctl restart agrinn-api