Skip to content

Commit 90d2da0

Browse files
authored
Merge pull request srl-labs#343 from vrnetlab/topomachine-container-image
Build (with) topomachine container in CI
2 parents ec20226 + 94d0463 commit 90d2da0

File tree

7 files changed

+1067
-20
lines changed

7 files changed

+1067
-20
lines changed

.github/workflows/test.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,28 @@ jobs:
5353
if: always()
5454
run: make -C vr-bgp docker-test-clean
5555

56+
test-topomachine:
57+
runs-on: ubuntu-22.04
58+
steps:
59+
- uses: actions/checkout@v3
60+
61+
- name: Build topomachine
62+
run: |
63+
make topology-machine
64+
65+
- name: Test topomachine
66+
run: |
67+
make topology-machine-test
68+
69+
- name: Save topomachine logs
70+
if: always()
71+
run: |
72+
make -C topology-machine docker-test-save-logs
73+
74+
- name: Clean test topomachine containers
75+
if: always()
76+
run: make -C topology-machine docker-test-clean
77+
5678
test-vr:
5779
runs-on: ["self-hosted"]
5880
container:

.gitlab-ci.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ vr-xcon:
4949
vr-bgp:
5050
<<: *build-template
5151

52+
topology-machine:
53+
extends: .build
54+
5255
csr:
5356
<<: *build-template
5457

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
IMAGES_DIR=
2-
VRS = vr-xcon vr-bgp csr nxos nxos9kv routeros sros veos vmx vsr1000 vqfx vrp xrv xrv9k
2+
VRS = vr-xcon vr-bgp topology-machine csr nxos nxos9kv routeros sros veos vmx vsr1000 vqfx vrp xrv xrv9k
33
VRS_PUSH = $(VRS:=-push)
44
VRS_TEST = $(VRS:=-test)
55

topology-machine/Dockerfile

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM debian:bullseye
1+
FROM debian:bookworm
22
MAINTAINER Kristian Larsson <[email protected]>
33

44
ENV DEBIAN_FRONTEND=noninteractive
@@ -8,21 +8,21 @@ RUN apt-get update -qy \
88
&& apt-get install -y \
99
python3-jinja2 \
1010
python3-yaml \
11-
apt-transport-https \
12-
ca-certificates \
1311
curl \
14-
gnupg2 \
15-
software-properties-common \
16-
&& curl -fsSL https://download.docker.com/linux/debian/gpg | apt-key add - \
17-
&& add-apt-repository \
18-
"deb [arch=amd64] https://download.docker.com/linux/debian \
19-
$(lsb_release -cs) \
20-
stable" \
21-
&& apt-get update -qy \
12+
# Install git & make so that we can use topomachine in CI to check for uncommitted topology and scripts changes
13+
git \
14+
make \
15+
&& install -m 0755 -d /etc/apt/keyrings \
16+
&& curl -fsSL https://download.docker.com/linux/debian/gpg -o /etc/apt/keyrings/docker.asc \
17+
&& chmod a+r /etc/apt/keyrings/docker.asc \
18+
&& echo \
19+
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/debian \
20+
$(. /etc/os-release && echo "$VERSION_CODENAME") stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null \
21+
&& apt-get update \
2222
&& apt-get -y install docker-ce \
2323
&& rm -rf /var/lib/apt/lists/*
2424

25-
ADD topomachine /
26-
ADD *example* /
25+
ADD topomachine /usr/local/bin
2726

28-
ENTRYPOINT ["/topomachine"]
27+
WORKDIR /data
28+
ENTRYPOINT ["/usr/local/bin/topomachine"]

topology-machine/Makefile

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,29 @@ all:
55

66
docker-push:
77
docker push $(REGISTRY)topomachine
8+
9+
ifeq ($(PNS),)
10+
PNS:=$(shell whoami | sed 's/[^[:alnum:]._-]\+/_/g')
11+
endif
12+
CNT_PREFIX?=$(PNS)-topomachine
13+
VOLUME_NAME?=$(CNT_PREFIX)-data
14+
15+
docker-test:
16+
# Do the (awkward) volume-copy dance to make sure we can run this test in GitLab
17+
# CI where the test script runs in a container with the hosts
18+
# /var/run/docker.sock mounted - sibling container.
19+
-docker rm -f $(CNT_PREFIX)
20+
-docker volume rm $(VOLUME_NAME)
21+
docker volume create $(VOLUME_NAME)
22+
docker create -v $(VOLUME_NAME):/data --name $(CNT_PREFIX) busybox
23+
for f in example*; do docker cp $$f $(CNT_PREFIX):/data; done
24+
docker rm $(CNT_PREFIX)
25+
docker run -v $(VOLUME_NAME):/data --rm $(REGISTRY)topomachine --build example-hltopo.json
26+
docker run -v $(VOLUME_NAME):/data --rm $(REGISTRY)topomachine --run example-lltopo.json --dry-run
27+
docker run -v $(VOLUME_NAME):/data --rm $(REGISTRY)topomachine --template example-lltopo.json example.template
28+
29+
docker-test-clean:
30+
docker volume rm $(VOLUME_NAME)
31+
32+
docker-test-save-logs:
33+
# nothing to do

topology-machine/README.md

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -177,16 +177,21 @@ The topomachine docker container can be used to generate the low level topology
177177
topology (--run), and to generate custom output using a jinja2 template
178178
(--template).
179179

180+
The topomachine binary is placed in `/usr/local/bin/topomachine` and is also set
181+
as an *ENTRYPOINT* for the container. The *WORKDIR* is set to `/data` so you can
182+
bind mount a host directory to `/data` and use `docker run ...` as a drop-in
183+
replacement for the topomachine command.
184+
180185
For example:
181186

182187
generate the low level topology:
183188
```
184-
$ docker run -t -v $(pwd):/data topomachine --build /data/example-hltopo.json > example-lltopo.json
189+
$ docker run -t -v $(pwd):/data topomachine --build example-hltopo.json > example-lltopo.json
185190
```
186191

187192
generate the docker run commands:
188193
```
189-
$ docker run -v $(pwd):/data topomachine --run /data/example-lltopo.json --dry-run
194+
$ docker run -v $(pwd):/data topomachine --run example-lltopo.json --dry-run
190195
The following commands would be executed:
191196
docker run --privileged -d --name ams-core-1 vrnetlab/vr-xrv:5.1.1.54U --foo bar 1
192197
docker run --privileged -d --name ams-core-2 vrnetlab/vr-xrv:5.1.1.54U --foo bar 1
@@ -204,14 +209,15 @@ docker run --rm --privileged -d --name vr-xcon --link ams-core-1:ams-core-1 --li
204209
docker run --privileged -d --name vr-xcon-hub-ams-mgmt --link ams-core-1:ams-core-1 --link ams-core-2:ams-core-2 --link ams-edge-1:ams-edge-1 --link fra-core-1:fra-core-1 --link fra-core-2:fra-core-2 --link fra-edge-1:fra-edge-1 --link kul-core-1:kul-core-1 --link par-core-1:par-core-1 --link par-core-2:par-core-2 --link par-edge-1:par-edge-1 --link png-edge-1:png-edge-1 --link sgp-core-1:sgp-core-1 vrnetlab/vr-xcon --hub ams-core-1/7 ams-core-2/7 ams-edge-1/3
205210
```
206211

207-
start the topology:
212+
To start the topology, topomachine needs access to the docker socket. Add the
213+
`-v /var/run/docker.sock:/var/run/docker.sock` option to the `docker run ...`:
208214
```
209-
$ docker run -v $(pwd):/data -v /var/run/docker.sock:/var/run/docker.sock topomachine --run /data/example-lltopo.json
215+
$ docker run -v $(pwd):/data -v /var/run/docker.sock:/var/run/docker.sock topomachine --run example-lltopo.json
210216
```
211217

212218
generate custom output using a jinja2 template:
213219
```
214-
$ docker run -t -v $(pwd):/data topomachine --template /data/example-lltopo.json /data/example.template
220+
$ docker run -t -v $(pwd):/data topomachine --template example-lltopo.json example.template
215221
infrastructure {
216222
base-config fra-edge-1 {
217223
numeric-id 101;

0 commit comments

Comments
 (0)