-
Notifications
You must be signed in to change notification settings - Fork 0
63 lines (52 loc) · 1.88 KB
/
deploy.yml
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
name: Deploy to Server
on:
push:
branches:
- dev
- main
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Set deployment parameters
id: vars
run: |
if [ "${{ github.ref_name }}" == "dev" ]; then
echo "DEPLOY_DIR=OpenAssistants-dev" >> $GITHUB_ENV
echo "ASGI_SERVER=dev_uvicorn" >> $GITHUB_ENV
elif [ "${{ github.ref_name }}" == "main" ]; then
echo "DEPLOY_DIR=OpenAssistants-main" >> $GITHUB_ENV
echo "ASGI_SERVER=main_uvicorn" >> $GITHUB_ENV
fi
- name: Add SSH Key
run: |
echo "${{ secrets.SSH_PRIVATE_KEY }}" > private_key.pem
chmod 600 private_key.pem
- name: Deploy to Server
env:
DEPLOY_DIR: ${{ env.DEPLOY_DIR }}
ASGI_SERVER: ${{ env.ASGI_SERVER }}
run: |
ssh -i private_key.pem -o StrictHostKeyChecking=no [email protected] <<EOF
# Navigate to the deployment directory
cd /home/ubuntu/$DEPLOY_DIR
# Fetch and reset code
git fetch origin
git reset --hard origin/${{ github.ref_name }}
# Activate virtual environment
if [ -f "venv/bin/activate" ]; then
source venv/bin/activate
else
python3 -m venv venv
source venv/bin/activate
fi
# Install requirements
pip install -r requirements.txt
# Django commands
python manage.py migrate --noinput || { echo "Migrations failed"; exit 1; }
python manage.py collectstatic --noinput || { echo "Collectstatic failed"; exit 1; }
# Restart the server
sudo supervisorctl restart $ASGI_SERVER
EOF