-
Notifications
You must be signed in to change notification settings - Fork 64
141 lines (126 loc) · 5.11 KB
/
deploy-bare-metal.yml
File metadata and controls
141 lines (126 loc) · 5.11 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
name: Login into host machine, build and start the app's daemon
on:
push:
branches:
- bare-metal-deploy
jobs:
build-frontend:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- uses: pnpm/action-setup@v4
name: Install pnpm
with:
version: 8
run_install: false
- name: Install Node.js
uses: actions/setup-node@v4
with:
node-version: 20
cache: "pnpm"
- name: Get pnpm store directory
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
- uses: actions/cache@v4
name: Setup pnpm cache
with:
path: ${{ env.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
- name: Install dependencies
working-directory: ./frontend
run: pnpm install
- name: Build frontend
working-directory: ./frontend
run: pnpm build
build-backend:
runs-on: ubuntu-latest
needs: build-frontend
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: 3.12
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install poetry
poetry install --only main
- name: Run Tests
env:
TEST: 1
run: |
poetry run python manage.py test
deploy:
runs-on: ubuntu-latest
needs: build-django
steps:
- uses: actions/checkout@master
- name: copy repo to host machine
uses: appleboy/scp-action@master
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
password: ${{ secrets.SSH_PASSWORD }}
port: 22
source: "poetry.lock,pyproject.toml,api,backend,config,core,frontend,manage.py"
target: "app_to_deploy"
- name: build the backend, the frontend and start the app's daemon
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
password: ${{ secrets.SSH_PASSWORD }}
port: 22
script: |
echo -e "======================== HOST DEPLOY STARTED ========================\n"
cd app_to_deploy
echo -e "~~~~~~~~~~~~~~~~~~~~~~~~ Changed directory into app_to_deploy ~~~~~~~~~~~~~~~~~~~~~~~~\n"
cd frontend
echo -e "~~~~~~~~~~~~~~~~~~~~~~~~ Changed directory into frontend ~~~~~~~~~~~~~~~~~~~~~~~~\n"
npm ci
echo -e "~~~~~~~~~~~~~~~~~~~~~~~~ Installed javascript dependencies successfully ~~~~~~~~~~~~~~~~~~~~~~~~\n"
rm .env
touch .env
echo 'NODE_ENV=production' >> .env
echo 'AUTH_TOKEN='${{ secrets.AUTH_KEY }} >> .env
echo 'GTAG_ID='${{ secrets.GTAG_ID }} >> .env
npx webpack
echo -e "~~~~~~~~~~~~~~~~~~~~~~~~ Built frontend successfully ~~~~~~~~~~~~~~~~~~~~~~~~\n"
cd ..
rm .env
touch .env
echo 'MODE=production' >> .env
echo 'SECRET_KEY='${{ secrets.SECRET_KEY }} >> .env
echo 'CDN_NAME='${{ secrets.CDN_NAME }} >> .env
echo 'CDN_API_KEY='${{ secrets.CDN_API_KEY }} >> .env
echo 'CDN_API_SECRET='${{ secrets.CDN_API_SECRET }} >> .env
echo 'DB_HOST='${{ secrets.DB_HOST }} >> .env
echo 'DB_NAME='${{ secrets.NAME }} >> .env
echo 'DB_USER=${{ secrets.DB_USER }}' >> .env
echo 'DB_PASSWORD=${{ secrets.DB_PASSWORD }}' >> .env
echo 'SMTP_HOST_USER='${{ secrets.SMTP_HOST_USER }} >> .env
echo 'SMTP_HOST_PASSWORD='${{ secrets.SMTP_HOST_PASSWORD }} >> .env
cd ..
cp -rf --no-target-directory app_to_deploy app
echo -e "~~~~~~~~~~~~~~~~~~~~~~~~ Replaced current running code with new one ~~~~~~~~~~~~~~~~~~~~~~~~\n"
cd app
python3 -m pip install --upgrade pip
pip install poetry
poetry install --only main
echo -e "~~~~~~~~~~~~~~~~~~~~~~~~ Installed python requirements successfully ~~~~~~~~~~~~~~~~~~~~~~~~\n"
poetry run python3 manage.py migrate
poetry run python3 manage.py collectstatic --no-input
poetry run python3 manage.py clearcache
echo ${{ secrets.SSH_PASSWORD }} | sudo -S rm /etc/supervisord.d/drt.ini
echo ${{ secrets.SSH_PASSWORD }} | sudo -S cp ./config/supervisor/drt.ini /etc/supervisord.d/
echo ${{ secrets.SSH_PASSWORD }} | sudo -S supervisorctl update
echo ${{ secrets.SSH_PASSWORD }} | sudo -S supervisorctl reread
echo ${{ secrets.SSH_PASSWORD }} | sudo -S supervisorctl status drt
rm .env
echo -e "~~~~~~~~~~~~~~~~~~~~~~~~ Gunicorn daemon is up ~~~~~~~~~~~~~~~~~~~~~~~~\n"
echo -e "======================== HOST DEPLOY IS DONE ========================\n"