-
Notifications
You must be signed in to change notification settings - Fork 3
241 lines (205 loc) · 6.95 KB
/
ci_cd.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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
# For more information see:
# https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions
name: OPERANDI CI/CD
on:
push:
# branches: [ main ]
paths:
- .github/**
- src/**
- tests/**
- .*
- docker*
- Makefile
pull_request:
# branches: [ main ]
paths:
- .github/**
- src/**
- tests/**
- .*
- docker*
- Makefile
env:
REGISTRY: ghcr.io
REPO_NAME: ${{ github.repository }}
jobs:
build-native:
name: Native build of Operandi modules
strategy:
fail-fast: true
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11"]
os: [ubuntu-latest]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
ref: ${{ github.head_ref }}
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install operandi dependencies
run: |
sudo apt-get update && sudo apt-get -y install make
python3 -m pip install --upgrade pip setuptools
pip3 install -U pip wheel
pip install -r tests/requirements.txt
- name: Lint with flake8
run: |
python3 -m pip install flake8
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=12 --max-line-length=127 --statistics
- name: Install operandi modules
run: make install
run-operandi-tests:
name: Run operandi tests
needs: build-native
env:
ENV_FILE: ./.github/workflows/tests/.env
strategy:
fail-fast: false
matrix:
python-version: [ "3.8" ]
os: [ ubuntu-latest ]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
ref: ${{ github.head_ref }}
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install operandi dependencies
run: |
sudo apt-get update && sudo apt-get -y install make
python3 -m pip install --upgrade pip setuptools
pip3 install -U pip wheel
pip install -r tests/requirements.txt
- name: Install operandi modules
run: make install
- name: Import variables from env file
shell: bash
run: |
while read line; do
echo "$line" >> $GITHUB_ENV
done < ${{ env.ENV_FILE }}
- name: copy hpc ssh key
env:
SSH_KEY_HPC: ${{ secrets.OPERANDI_SSH_KEY_HPC }}
run: |
mkdir -p /home/runner/.ssh/
echo "$SSH_KEY_HPC" > /home/runner/.ssh/key_hpc
chmod 600 /home/runner/.ssh/key_hpc
- name: start RabbitMQ Server
run: docker compose -f ./docker-compose.yml --env-file ${{ env.ENV_FILE }} up -d operandi-rabbitmq
- name: start MongoDB
run: docker compose -f ./docker-compose.yml --env-file ${{ env.ENV_FILE }} up -d operandi-mongodb
- name: wait starting of RabbitMQ and MongoDB
run: sleep 45
- name: run utils tests
run: |
export $(shell sed 's/=.*//' ${{ env.ENV_FILE }})
pytest -p no:cacheprovider tests/tests_utils/test_*.py -v
- name: run broker tests
run: |
export $(shell sed 's/=.*//' ${{ env.ENV_FILE }})
pytest -p no:cacheprovider tests/tests_broker/test_*.py -v
- name: run server tests
run: |
export $(shell sed 's/=.*//' ${{ env.ENV_FILE }})
pytest -p no:cacheprovider tests/tests_server/test_*.py -v
- name: run harvester tests
run: |
export $(shell sed 's/=.*//' ${{ env.ENV_FILE }})
pytest -p no:cacheprovider tests/tests_harvester/test_*.py -v
- name: run integration tests
run: |
export $(shell sed 's/=.*//' ${{ env.ENV_FILE }})
pytest -p no:cacheprovider tests/integration_tests/test_*.py -s -v
build-and-push-docker-images:
name: Push ${{matrix.services.module}} to image registry
environment:
name: development
needs: run-operandi-tests
strategy:
fail-fast: true
matrix:
services: [
{ module: "broker", dockerfile: "Dockerfile_broker" },
{ module: "server", dockerfile: "Dockerfile_server" }
]
os: [ ubuntu-latest ]
runs-on: ${{ matrix.os }}
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
ref: ${{ github.head_ref }}
- name: Log in to the Container registry
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
uses: docker/metadata-action@v4
id: meta
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
images: ${{ env.REGISTRY }}/${{ env.REPO_NAME }}-${{matrix.services.module}}
- name: Build and push Docker image
uses: docker/build-push-action@v4
with:
context: ./src
file: ./src/${{matrix.services.dockerfile}}
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
deploy-development:
name: Deploy to development VM
environment:
name: development
needs: build-and-push-docker-images
runs-on: ubuntu-latest
steps:
- name: copy ssh key
env:
SSH_KEY: ${{ secrets.OPERANDI_SSH_KEY }}
run: |
mkdir -p ~/.ssh/
echo "$SSH_KEY" > ~/.ssh/key
chmod 600 ~/.ssh/key
- name: deploy
env:
SSH_USER: ${{ secrets.OPERANDI_SSH_USER }}
SSH_HOST: ${{ secrets.OPERANDI_SSH_HOST_DEV }}
run: ssh $SSH_USER@$SSH_HOST -o StrictHostKeyChecking=no -i ~/.ssh/key /home/$SSH_USER/operandi/start-operandi-docker.sh
deploy-production:
name: Deploy to live VM
environment:
name: production
needs: build-and-push-docker-images
runs-on: ubuntu-latest
steps:
- name: copy ssh key
env:
SSH_KEY: ${{ secrets.OPERANDI_SSH_KEY }}
run: |
mkdir -p ~/.ssh/
echo "$SSH_KEY" > ~/.ssh/key
chmod 600 ~/.ssh/key
- name: deploy
env:
SSH_USER: ${{ secrets.OPERANDI_SSH_USER }}
SSH_HOST: ${{ secrets.OPERANDI_SSH_HOST_PROD }}
run: ssh $SSH_USER@$SSH_HOST -o StrictHostKeyChecking=no -i ~/.ssh/key /home/$SSH_USER/start-operandi-docker.sh