-
Notifications
You must be signed in to change notification settings - Fork 8
188 lines (157 loc) · 5.51 KB
/
build_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
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
name: Build & Deploy (manually)
on:
workflow_dispatch:
inputs:
branch:
description: 'Branch to (re)deploy from'
required: true
default: 'development'
type: choice
options:
- main
- development
- release/0.6.6
- release/0.6.7
- release/0.6.8
environment:
description: 'Environment to (re)deploy to'
type: environment
default: 'development'
required: true
jobs:
build_frontend:
name: build frontend
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v4
with:
ref: ${{ inputs.branch }}
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 18
- name: Install npm packages
run: |
cd frontend
npm install
- name: Build & bundle
run: |
cd frontend
unset CI # ignore React warnings
npm run build
build_backend:
name: build backend
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v4
with:
ref: ${{ inputs.branch }}
- name: Fetch submodules
run: |
cd backend
cd apps
git submodule update --init --recursive
git submodule update --remote
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: 3.11
- name: Create venv
run: |
cd backend
python3.11 -m venv venv
- name: Install packages
run: |
cd backend
source venv/bin/activate
pip install --upgrade pip
pip install -r requirements.txt
- name: Install ifcopenshell package (temp)
run: |
cd backend
source venv/bin/activate
# use version of ifcopenshell with desired schema parsing
# TODO: revert to pyPI when schema parsing is published in the future
wget -O /tmp/ifcopenshell_python.zip "https://s3.amazonaws.com/ifcopenshell-builds/ifcopenshell-python-311-v0.8.1-92b63a0-linux64.zip"
mkdir -p venv/lib/python3.11/site-packages
unzip -d venv/lib/python3.11/site-packages /tmp/ifcopenshell_python.zip
- name: Check Django config
run: |
cd backend
source venv/bin/activate
python3 manage.py check
- name: Run tests
run: |
cd backend
source venv/bin/activate
python3 manage.py test
deploy:
name: deploy to server (${{ inputs.environment }})
needs: [build_frontend, build_backend]
runs-on: ubuntu-latest
environment:
name: ${{ inputs.environment }}
steps:
- name: Configure SSH
run: |
mkdir -p ~/.ssh/
echo "$SSH_KEY" > ~/.ssh/ssh_host.key
chmod 600 ~/.ssh/ssh_host.key
cat >>~/.ssh/config <<END
Host ssh_host
HostName $SSH_HOST
User $SSH_USER
IdentityFile ~/.ssh/ssh_host.key
StrictHostKeyChecking no
END
env:
SSH_USER: ${{ secrets.SSH_USERNAME }}
SSH_KEY: ${{ secrets.SSH_PRIV_KEY }}
SSH_HOST: ${{ secrets.SSH_HOST }}
- name: Stop Docker containers
run: |
ssh ssh_host 'cd ${{ vars.REPO_CLONE_PATH }}
sudo make stop'
- name: Fetch sources & submodules
run: |
ssh ssh_host 'cd ${{ vars.REPO_CLONE_PATH }}
git pull && git checkout -q ${{ inputs.branch }} && git pull
sudo make fetch-modules'
- name: Checkout correct branches
run: |
ssh ssh_host 'cd ${{ vars.REPO_CLONE_PATH }}
cd ${{ vars.REPO_CLONE_PATH }}/backend/apps/ifc_validation/checks/ifc_gherkin_rules && git checkout -q ${{ inputs.branch }} && git pull
cd ./ifc_validation_models && git checkout -q ${{ inputs.branch }} && git pull
cd ${{ vars.REPO_CLONE_PATH }}/backend/apps/ifc_validation/checks/step_file_parser && git checkout -q master && git pull
cd ${{ vars.REPO_CLONE_PATH }}/backend/apps/ifc_validation_models && git checkout -q ${{ inputs.branch }} && git pull
cd ${{ vars.REPO_CLONE_PATH }}
./check-submodules.sh'
- name: Show repo & git status
run: |
ssh ssh_host 'cd ${{ vars.REPO_CLONE_PATH }}
echo "*** Validate repository"
git remote get-url origin && git rev-parse --abbrev-ref HEAD && git rev-parse --short HEAD
echo "*** git status"
git status'
- name: Show submodule status
run: |
ssh ssh_host 'cd ${{ vars.REPO_CLONE_PATH }} && \
./check-submodules.sh'
- name: Set VERSION
run: |
ssh ssh_host 'cd ${{ vars.REPO_CLONE_PATH }}
COMMIT_HASH=$(git rev-parse --short HEAD)
VERSION="${{ vars.VERSION }}"
echo "Set VERSION to ${VERSION}"
echo "Set COMMIT_HASH to ${COMMIT_HASH}"
echo "${VERSION}" > .VERSION'
- name: Build Docker images
run: |
ssh ssh_host 'cd ${{ vars.REPO_CLONE_PATH }}
sudo make rebuild'
- name: Start Docker containers
run: |
ssh ssh_host 'cd ${{ vars.REPO_CLONE_PATH }}
sudo docker compose -f ${{ vars.DOCKER_COMPOSE_FILE }} --env-file ${{ vars.ENV_FILE }} up -d'