-
Notifications
You must be signed in to change notification settings - Fork 46
493 lines (428 loc) · 16.8 KB
/
cicd.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
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
name: Tests and push to PyPi and DockerHub
on: push
jobs:
tests:
name: Run tests
runs-on: ubuntu-latest
strategy:
matrix:
python-version:
# This list must be kept in sync with setup.py.
- "3.8"
- "3.9"
- "3.10"
- "3.11"
- "3.12" # Reference version used to run integration tests;
# to keep in sync with 'if: ' statements in the rest
# of this file.
- "pypy3.10" # To keep in sync with other pypy releases referenced in the
# "Docker image tests" and "Push Docker image to Docker Hub"
# sections of this file.
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install bgpq3 / bgpq4
run: |
./tests/external_resources/install_bgpq3.sh
./tests/external_resources/install_bgpq4.sh
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install -r requirements-dev.txt
- name: Flake8
run: flake8
- name: Test CLI
if: ${{ matrix.python-version == '3.12' }}
run: ./tests/cli
env:
SECRET_PEERINGDB_API_KEY: ${{ secrets.SECRET_PEERINGDB_API_KEY }}
- name: Static tests
run: pytest -vs -x tests/static/
env:
TRAVIS: 1
SECRET_PEERINGDB_API_KEY: ${{ secrets.SECRET_PEERINGDB_API_KEY }}
- name: Config build tests
if: ${{ matrix.python-version != '3.12' }}
run: BUILD_ONLY=1 pytest -vs -x tests/live_tests/
env:
TRAVIS: 1
SECRET_PEERINGDB_API_KEY: ${{ secrets.SECRET_PEERINGDB_API_KEY }}
- name: Test external resources
if: ${{ matrix.python-version == '3.12' }}
run: pytest -vs tests/external_resources/
env:
TRAVIS: 1
SECRET_PEERINGDB_API_KEY: ${{ secrets.SECRET_PEERINGDB_API_KEY }}
- name: Fetch Docker images used by tests
if: ${{ matrix.python-version == '3.12' }}
run: |
echo "$DOCKER_PASSWORD" | docker login --username "$DOCKER_USERNAME" --password-stdin
docker pull pierky/bird:1.6.8
docker pull pierky/bird:2.15
docker pull pierky/bird:3.0-alpha2
docker pull pierky/openbgpd:8.0
docker pull pierky/openbgpd:8.4
docker pull pierky/exabgp:4.2.7
docker pull nlnetlabs/routinator:v0.13.2
env:
DOCKER_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
DOCKER_PASSWORD: ${{ secrets.DOCKERHUB_PASSWORD }}
- name: Integration tests
if: ${{ matrix.python-version == '3.12' }}
run: pytest -vs -x tests/live_tests/
env:
TRAVIS: 1
SECRET_PEERINGDB_API_KEY: ${{ secrets.SECRET_PEERINGDB_API_KEY }}
docker-image-tests:
name: Docker image tests
runs-on: ubuntu-latest
strategy:
matrix:
docker-image:
- base_image: python:3.12
target_image: latest
- base_image: pypy:3.10
target_image: latest-pypy3
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Build the image
run: >
docker build \
--build-arg base_image=${{ matrix.docker-image.base_image }} \
-t pierky/arouteserver:${{ matrix.docker-image.target_image }} \
-f docker/Dockerfile \
.
- name: Run PyTest
run: >
docker run \
-t \
--rm \
-e SECRET_PEERINGDB_API_KEY="${SECRET_PEERINGDB_API_KEY}" \
pierky/arouteserver:${{ matrix.docker-image.target_image }} \
bash -c 'pip install -r requirements-dev.txt && pytest -vsx tests/static'
env:
SECRET_PEERINGDB_API_KEY: ${{ secrets.SECRET_PEERINGDB_API_KEY }}
- name: Run CLI tests
run: >
docker run \
-t \
--rm \
-e DO_NOT_PERFORM_VALIDATION=1 \
-e SECRET_PEERINGDB_API_KEY="${SECRET_PEERINGDB_API_KEY}" \
-v $(pwd)/utils/fake_rtt_getter.sh:/arouteserver/utils/fake_rtt_getter.sh:ro \
pierky/arouteserver:${{ matrix.docker-image.target_image }} \
./tests/cli
env:
SECRET_PEERINGDB_API_KEY: ${{ secrets.SECRET_PEERINGDB_API_KEY }}
- name: Prep environment for configuration building tests
run: |
mkdir ~/arouteserver_configs
mkdir ~/arouteserver_html
- name: Build configuration for BIRD 1.x
run: >
docker run \
-t \
--rm \
-v $(pwd)/config.d/clients.yml:/root/clients.yml:ro \
-v ~/arouteserver_configs:/root/arouteserver_configs \
-e RS_ASN=65500 \
-e ROUTER_ID=192.0.2.123 \
-e LOCAL_PREFIXES=192.0.2.0/24,2001:db8::/32 \
-e IP_VER=4 \
-e DAEMON=bird \
-e VERSION=1.6.8 \
-e SECRET_PEERINGDB_API_KEY="${SECRET_PEERINGDB_API_KEY}" \
pierky/arouteserver:${{ matrix.docker-image.target_image }}
env:
SECRET_PEERINGDB_API_KEY: ${{ secrets.SECRET_PEERINGDB_API_KEY }}
- name: Validate BIRD 1.x configuration
run: >
docker run \
-t \
--rm \
-v ~/arouteserver_configs/bird4.cfg:/etc/bird/bird.cfg \
pierky/bird:1.6.8 \
bird \
-c /etc/bird/bird.cfg \
-d \
-p
- name: Build configuration for BIRD 2 (+ HTML representation)
run: >
docker run \
-t \
--rm \
-v $(pwd)/config.d/clients.yml:/root/clients.yml:ro \
-v ~/arouteserver_configs:/root/arouteserver_configs \
-v ~/arouteserver_html:/root/arouteserver_html \
-e RS_ASN=65500 \
-e ROUTER_ID=192.0.2.123 \
-e LOCAL_PREFIXES=192.0.2.0/24,2001:db8::/32 \
-e DAEMON=bird \
-e VERSION=2.0.7 \
-e SECRET_PEERINGDB_API_KEY="${SECRET_PEERINGDB_API_KEY}" \
pierky/arouteserver:${{ matrix.docker-image.target_image }}
env:
SECRET_PEERINGDB_API_KEY: ${{ secrets.SECRET_PEERINGDB_API_KEY }}
- name: Validate BIRD 2 configuration
run: >
docker run \
-t \
--rm \
-v ~/arouteserver_configs/bird.cfg:/etc/bird/bird.cfg \
pierky/bird:2.0.7 \
bird \
-c /etc/bird/bird.cfg \
-d \
-p
- name: Validate HTML representation
run: >
grep \
'Configuration of route server 192.0.2.123 at AS65500' \
~/arouteserver_html/bird.html &>/dev/null
- name: Build configuration for OpenBGPD (+ HTML representation)
run: >
docker run \
-t \
--rm \
-v $(pwd)/config.d/clients.yml:/root/clients.yml:ro \
-v ~/arouteserver_configs:/root/arouteserver_configs \
-v ~/arouteserver_html:/root/arouteserver_html \
-e RS_ASN=65500 \
-e ROUTER_ID=192.0.2.124 \
-e LOCAL_PREFIXES=192.0.2.0/24,2001:db8::/32 \
-e DAEMON=openbgpd \
-e VERSION=8.4 \
-e SECRET_PEERINGDB_API_KEY="${SECRET_PEERINGDB_API_KEY}" \
pierky/arouteserver:${{ matrix.docker-image.target_image }}
env:
SECRET_PEERINGDB_API_KEY: ${{ secrets.SECRET_PEERINGDB_API_KEY }}
- name: Validate OpenBGPD configuration
run: >
docker run \
-t \
--rm \
-v ~/arouteserver_configs/openbgpd.cfg:/etc/bgpd/bgpd.conf \
pierky/openbgpd:8.4 \
bgpd \
-f /etc/bgpd/bgpd.conf \
-d \
-n
- name: Validate HTML representation
run: >
grep \
'Configuration of route server 192.0.2.124 at AS65500' \
~/arouteserver_html/openbgpd.html &>/dev/null
- name: Build configuration using custom general.yml file
run: >
docker run \
-t \
--rm \
-v $(pwd)/config.d/clients.yml:/root/clients.yml:ro \
-v $(pwd)/examples/auto-config/bird-general.yml:/etc/arouteserver/general.yml:ro \
-v ~/arouteserver_configs:/root/arouteserver_configs \
-e DAEMON=bird \
-e VERSION=2.15 \
-e SECRET_PEERINGDB_API_KEY="${SECRET_PEERINGDB_API_KEY}" \
pierky/arouteserver:${{ matrix.docker-image.target_image }}
env:
SECRET_PEERINGDB_API_KEY: ${{ secrets.SECRET_PEERINGDB_API_KEY }}
- name: Validate configuration built using custom general.yml file
run: >
docker run \
-t \
--rm \
-v ~/arouteserver_configs/bird.cfg:/etc/bird/bird.cfg \
pierky/bird:2.15 \
bird \
-c /etc/bird/bird.cfg \
-d \
-p
- name: Build configuration using custom general.yml file with env vars and reject reasons communities
run: >
docker run \
-t \
--rm \
-v $(pwd)/config.d/clients.yml:/root/clients.yml:ro \
-v $(pwd)/tests/var/general-env-vars-and-reject-reasons.yml:/etc/arouteserver/general.yml:ro \
-v ~/arouteserver_configs:/root/arouteserver_configs \
-v ~/arouteserver_html:/root/arouteserver_html \
-e IP_VER=4 \
-e DAEMON=bird \
-e VERSION=1.6.8 \
-e RS_ASN=9999 \
-e ROUTER_ID=192.0.2.200 \
-e SECRET_PEERINGDB_API_KEY="${SECRET_PEERINGDB_API_KEY}" \
pierky/arouteserver:${{ matrix.docker-image.target_image }}
env:
SECRET_PEERINGDB_API_KEY: ${{ secrets.SECRET_PEERINGDB_API_KEY }}
- name: Validate configuration built using custom general.yml file with env vars and reject reasons communities
run: |
docker run \
-t \
--rm \
-v ~/arouteserver_configs/bird4.cfg:/etc/bird/bird.cfg \
pierky/bird:1.6.8 \
bird \
-c /etc/bird/bird.cfg \
-d \
-p
cat ~/arouteserver_configs/bird4.cfg | grep 'router id 192.0.2.200'
- name: Validate HTML representation
run: >
grep \
'Configuration of route server 192.0.2.200 at AS9999' \
~/arouteserver_html/bird.html &>/dev/null
- name: Build configuration using local files
run: >
docker run \
-t \
--rm \
-v $(pwd)/config.d/clients.yml:/root/clients.yml:ro \
-v ~/arouteserver_configs:/root/arouteserver_configs \
-e RS_ASN=65500 \
-e ROUTER_ID=192.0.2.123 \
-e LOCAL_PREFIXES=192.0.2.0/24,2001:db8::/32 \
-e IP_VER=4 \
-e DAEMON=bird \
-e VERSION=1.6.8 \
-e LOCAL_FILES="header footer" \
-e LOCAL_FILES_DIR=/var/pierky/test \
-e SECRET_PEERINGDB_API_KEY="${SECRET_PEERINGDB_API_KEY}" \
pierky/arouteserver:${{ matrix.docker-image.target_image }}
env:
SECRET_PEERINGDB_API_KEY: ${{ secrets.SECRET_PEERINGDB_API_KEY }}
- name: Verify that include statements are there
run: |
cat ~/arouteserver_configs/bird4.cfg | \
grep include | \
grep /var/pierky/test | \
egrep 'header.local|footer.local' | \
wc -l | \
grep 2
- name: Build configuration for 32bit ASN route-servers
run: >
docker run \
-t \
--rm \
-v $(pwd)/config.d/clients.yml:/root/clients.yml:ro \
-v ~/arouteserver_configs:/root/arouteserver_configs \
-e RS_ASN=99999999 \
-e PLACEHOLDER_16BIT_ASN=65333 \
-e ROUTER_ID=192.0.2.123 \
-e LOCAL_PREFIXES=192.0.2.0/24,2001:db8::/32 \
-e IP_VER=4 \
-e DAEMON=bird \
-e VERSION=1.6.8 \
-e SECRET_PEERINGDB_API_KEY="${SECRET_PEERINGDB_API_KEY}" \
pierky/arouteserver:${{ matrix.docker-image.target_image }}
env:
SECRET_PEERINGDB_API_KEY: ${{ secrets.SECRET_PEERINGDB_API_KEY }}
- name: Verify that the desired 16bit placeholder ASN is used
run: |
cat ~/arouteserver_configs/bird4.cfg | \
grep "if (65333, peer_as) ~ bgp_community then"
push_to_pypi:
name: Push to PyPi
needs: [tests, docker-image-tests]
runs-on: ubuntu-latest
permissions:
id-token: write
if: startsWith(github.ref, 'refs/tags/v')
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: 3.12
- name: Install dependencies
run: |
python -m pip install --upgrade pip
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
pip install --upgrade setuptools
- name: Build and push the release
run: |
pip install --upgrade packaging
python setup.py sdist
# All the tags go to PyPI test
- name: Publish distribution to Test PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://test.pypi.org/legacy/
# Only non-alpha releases go to the official PyPi
- name: Publish distribution to PyPI (official release)
if: contains(github.ref, 'alpha') != true
uses: pypa/gh-action-pypi-publish@release/v1
push_to_registry:
name: Push Docker image to Docker Hub
needs: [tests, docker-image-tests]
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/v')
steps:
- name: Check out the repo
uses: actions/checkout@v2
- name: Get the release
run: echo "::set-output name=CURRENT_RELEASE::$(python -c 'from pierky.arouteserver.version import __version__; print(__version__)')"
id: get_the_release
- name: Is it a stable?
run: echo "::set-output name=IS_STABLE_RELEASE::$(python -c 'from pierky.arouteserver.version import __version__; import re; import sys; re.match(r"^\d+\.\d+\.\d+$", __version__); sys.stdout.write(str(bool(re.match(r"^\d+\.\d+\.\d+$", __version__))))')"
id: is_stable_release
- name: Show the arguments
run: echo "Release ${{ steps.get_the_release.outputs.CURRENT_RELEASE }} - stable ${{ steps.is_stable_release.outputs.IS_STABLE_RELEASE }}"
- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Push to Docker Hub (current release, CPython)
uses: docker/build-push-action@v6
with:
push: true
file: ./docker/Dockerfile
build-args: |
base_image=python:3.12
tags: pierky/arouteserver:${{ steps.get_the_release.outputs.CURRENT_RELEASE }}
- name: Push to Docker Hub (current release, PyPy)
uses: docker/build-push-action@v6
with:
push: true
file: ./docker/Dockerfile
build-args: |
base_image=pypy:3.10
tags: pierky/arouteserver:${{ steps.get_the_release.outputs.CURRENT_RELEASE }}-pypy3
- name: Push to Docker Hub (latest, CPython)
# Only stable releases
if: steps.is_stable_release.outputs.IS_STABLE_RELEASE == 'True'
uses: docker/build-push-action@v6
with:
push: true
file: ./docker/Dockerfile
build-args: |
base_image=python:3.12
tags: pierky/arouteserver:latest
- name: Push to Docker Hub (latest, PyPy)
# Only stable releases
if: steps.is_stable_release.outputs.IS_STABLE_RELEASE == 'True'
uses: docker/build-push-action@v6
with:
push: true
file: ./docker/Dockerfile
build-args: |
base_image=pypy:3.9
tags: pierky/arouteserver:latest-pypy3
- name: Update Docker Hub description
uses: peter-evans/dockerhub-description@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
# This must be the DockerHub password, since AToW
# Docker Hub doesn't allow to use tokens to update
# the README.
# https://github.com/peter-evans/dockerhub-description/issues/10
password: ${{ secrets.DOCKERHUB_PASSWORD }}
repository: pierky/arouteserver
short-description: ARouteServer official Docker images
readme-filepath: ./docker/README.md