-
Notifications
You must be signed in to change notification settings - Fork 13
305 lines (252 loc) · 8.58 KB
/
ci.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
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
name: CI
on:
push:
release:
types: [released]
env:
REGISTRY: "ghcr.io"
REGISTRY_BASE_URI: ghcr.io/nrel/alfalfa
jobs:
pre-commit:
name: Pre-commit checks
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Install Python
uses: actions/setup-python@v4
with:
python-version: "3.8"
- name: Run pre-commit
uses: pre-commit/[email protected]
with:
extra_args: --all-files
unit-tests:
name: Run unit tests
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Install Python
uses: actions/setup-python@v4
with:
python-version: "3.8"
- name: Install poetry
uses: abatilo/[email protected]
with:
# use a newer version of poetry in this test, but
# poetry in the dockerfile is a bit older because
# of a urllib3 issue
poetry-version: 1.3.1
- name: Install poetry dependencies
run: |
poetry install
- name: Runner Details
run: |
cat /etc/issue
python --version
- name: Start dependencies
run: |
printenv
docker compose up -d mongo redis minio mc goaws
- name: Run tests with pytest
run: |
poetry run pytest
simulation-tests:
name: Run simulation tests in worker
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Build
uses: docker/bake-action@v2
with:
files: docker-compose.yml, docker-compose.dev.yml
set: |
web.cache-from=type=gha,scope=web:${{ github.ref_name }}
worker.cache-from=type=gha,scope=worker:${{ github.ref_name }}
worker.output=type=docker
# only need to start the worker which saves time here because
# the webpack calling on the web container for .dev.yml can take some
# time.
- name: Build and run stack
env:
GIT_COMMIT: ${{ github.sha }}
run: |
printenv
docker compose -f docker-compose.yml -f docker-compose.dev.yml up -d worker mongo redis minio mc goaws
- name: Dump docker logs before tests
uses: jwalton/gh-docker-logs@v1
- name: Run job tests in Docker worker container
run: |
sleep 30
docker exec alfalfa-worker-1 bash -c "cd /alfalfa && poetry run pytest -m docker tests/jobs -o log_cli=true -o log_level=info"
- name: Dump docker logs on failure
if: failure()
uses: jwalton/gh-docker-logs@v1
integration-tests:
name: Run integration tests
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Install Python
uses: actions/setup-python@v4
with:
python-version: "3.8"
- name: Install poetry
uses: abatilo/[email protected]
with:
# use a newer version of poetry in this test, but
# poetry in the dockerfile is a bit older because
# of a urllib3 issue
poetry-version: 1.3.1
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Build
uses: docker/bake-action@v2
with:
files: docker-compose.yml
set: |
web.cache-from=type=gha,scope=web:${{ github.ref_name }}
web.output=type=docker
worker.cache-from=type=gha,scope=worker:${{ github.ref_name }}
worker.output=type=docker
- name: Run stack
env:
GIT_COMMIT: ${{ github.sha }}
run: |
printenv
docker compose up -d --scale worker=2
- name: Wait for web server
uses: nev7n/wait_for_response@v1
with:
url: "http://localhost/"
responseCode: 200
timeout: 120000
interval: 500
- name: Dump docker logs before tests
uses: jwalton/gh-docker-logs@v1
- name: Install dependencies
run: poetry install
- name: Run API tests with pytest
run: |
poetry run pytest --timeout=120 -m api
- name: Run integration tests with pytest
run: |
poetry run pytest --timeout=600 -m "integration"
- name: Run worker scale tests with pytest
run: |
poetry run pytest -m "scale"
- name: Dump docker logs on failure
if: failure()
uses: jwalton/gh-docker-logs@v1
integration-tests-historian:
name: Run integration tests with historian
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Install Python
uses: actions/setup-python@v4
with:
python-version: "3.8"
- name: Install poetry
uses: abatilo/[email protected]
with:
# use a newer version of poetry in this test, but
# poetry in the dockerfile is a bit older because
# of a urllib3 issue
poetry-version: 1.3.1
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Build
uses: docker/bake-action@v2
with:
load: true
files: docker-compose.yml, docker-compose.dev.yml, docker-compose.historian.yml
set: |
web.cache-from=type=gha,scope=web:${{ github.ref_name }}
web.output=type=docker
worker.cache-from=type=gha,scope=worker:${{ github.ref_name }}
worker.output=type=docker
grafana.cache-from=type=gha,scope=grafana:${{ github.ref_name }}
grafana.output=type=docker
- name: Build and run stack
env:
GIT_COMMIT: ${{ github.sha }}
run: |
export HISTORIAN_ENABLE=true
printenv
docker compose -f docker-compose.yml -f docker-compose.historian.yml up -d --scale worker=2
- name: Wait for web server
uses: nev7n/wait_for_response@v1
with:
url: "http://localhost/"
responseCode: 200
timeout: 120000
interval: 500
- name: Dump docker logs before tests
uses: jwalton/gh-docker-logs@v1
- name: Install dependencies
run: poetry install
- name: Run API tests with pytest
run: |
poetry run pytest --timeout=120 -m api
- name: Run integration tests with pytest
run: |
poetry run pytest --timeout=600 -m "integration"
- name: Run worker scale tests with pytest
run: |
poetry run pytest -m "scale"
- name: Dump docker logs on failure
if: failure()
uses: jwalton/gh-docker-logs@v1
publish:
needs: [pre-commit, unit-tests, simulation-tests, integration-tests, integration-tests-historian]
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Log into container registry
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Docker meta
uses: docker/metadata-action@v4
id: meta
with:
images: |
${{ env.REGISTRY_BASE_URI }}/worker
${{ env.REGISTRY_BASE_URI }}/web
${{ env.REGISTRY_BASE_URI }}/grafana
tags: |
type=ref,event=branch
type=sha
type=semver,pattern={{version}},enable=${{ github.event_name == 'release' }}
type=semver,pattern={{major}},enable=${{ github.event_name == 'release' }}
- name: Build
uses: docker/bake-action@v2
with:
files: |
docker-compose.yml
docker-compose.historian.yml
set: |
web.cache-from=type=gha,scope=web:${{ github.ref_name }}
worker.cache-from=type=gha,scope=worker:${{ github.ref_name }}
grafana.cache-from=type=gha,scope=grafana:${{ github.ref_name }}
web.cache-to=type=gha,mode=max,scope=web:${{ github.ref_name }}
worker.cache-to=type=gha,mode=max,scope=worker:${{ github.ref_name }}
grafana.cache-to=type=gha,mode=max,scope=grafana:${{ github.ref_name }}
load: true
- name: Tag and push images
run: ./.github/workflows/tag_push_docker.sh