-
Notifications
You must be signed in to change notification settings - Fork 2
44 lines (42 loc) · 1.31 KB
/
django.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
name: Django CI
on:
push:
branches: [ "main", "staging" ]
jobs:
build:
environment: ${{ github.ref_name }}
name: "Deploy to ${{ github.ref_name }}"
runs-on: ubuntu-latest
steps:
- name: Configure SSH
env:
SSH_USER: ${{ secrets.SSH_USER }}
SSH_KEY: ${{ secrets.SSH_KEY }}
SSH_HOST: ${{ secrets.SSH_HOST }}
run: |
mkdir -p ~/.ssh/
echo "$SSH_KEY" > ~/.ssh/server.key
chmod 600 ~/.ssh/server.key
cat >>~/.ssh/config <<END
Host server
HostName $SSH_HOST
User $SSH_USER
IdentityFile ~/.ssh/server.key
StrictHostKeyChecking no
END
- name: Deploy to Server
env:
ROOT_DIR: ${{ vars.ROOT_DIR }}
ENV_DIR: ${{ vars.ENV_DIR }}
BRANCH: ${{ github.ref_name }}
APP_NAME: ${{ vars.APP_NAME }}
run: |
ssh server "
cd $ROOT_DIR &&
git pull origin $BRANCH &&
source $ENV_DIR &&
pip install -r requirements/production.txt &&
python manage.py migrate --settings=config.settings.production &&
python manage.py collectstatic --noinput --settings=config.settings.production &&
supervisorctl restart $APP_NAME
"