-
Notifications
You must be signed in to change notification settings - Fork 0
106 lines (90 loc) · 2.93 KB
/
auto-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
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
name: CI/CD Pipeline
on:
push:
branches:
- master
jobs:
build:
name: Build and Test
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.9
- name: Install dependencies
run: |
python -m venv serenadoit .
source serenadoit/bin/activate
pip install -r requirements.txt
deploy:
name: Deploy to Server
runs-on: ubuntu-latest
needs: build
steps:
- name: Checkout Repository
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.SERVER_HOST }}
username: ${{ secrets.SERVER_USERNAME }}
key: ${{ secrets.SERVER_SSH_KEY }}
port: ${{ secrets.SERVER_PORT }}
script: |
cd serenadoit
git stash
git pull origin master
git stash pop
rm -rf ~/node/static/styles/ ~/node/static/scripts/ ~/node/static/images/
cp -r ./static ~/node/
- name: Initialize database
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.SERVER_HOST }}
username: ${{ secrets.SERVER_USERNAME }}
key: ${{ secrets.SERVER_SSH_KEY }}
port: ${{ secrets.SERVER_PORT }}
script: |
cd serenadoit/uploads
python ../src/db_manager.py
- name: Test python code
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.SERVER_HOST }}
username: ${{ secrets.SERVER_USERNAME }}
key: ${{ secrets.SERVER_SSH_KEY }}
port: ${{ secrets.SERVER_PORT }}
script: |
cd serenadoit
source serenadoit/bin/activate
python -m unittest discover -s tests -p 'test_*.py'
- name: Install dependencies and restart server
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.SERVER_HOST }}
username: ${{ secrets.SERVER_USERNAME }}
key: ${{ secrets.SERVER_SSH_KEY }}
port: ${{ secrets.SERVER_PORT }}
script: |
cd serenadoit
python -m venv serenadoit .
source serenadoit/bin/activate
pip install -r requirements.txt
kill $(ps aux | grep "^${{ secrets.SERVER_USERNAME }}" | grep '[g]unicorn' | awk '{print $2}') || true
- name: SSH to server and deploy
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.SERVER_HOST }}
username: ${{ secrets.SERVER_USERNAME }}
key: ${{ secrets.SERVER_SSH_KEY }}
port: ${{ secrets.SERVER_PORT }}
script: |
cd serenadoit
source serenadoit/bin/activate
gunicorn -w 4 -b 0.0.0.0:10410 run_prod:app --error-logfile logs/error.log --access-logfile logs/access.log -D
- name: Wait before checking deployment
run: sleep 5s
- name: Check deployment
run: |
ps aux | grep "^$USER" | grep '[g]unicorn' || true