diff --git a/.github/workflows/node-image.yml b/.github/workflows/node-image.yml new file mode 100644 index 0000000..1c47f37 --- /dev/null +++ b/.github/workflows/node-image.yml @@ -0,0 +1,54 @@ +name: node-image + +# Builds test/node, a real moip-toolkit node in a container (avahi-daemon included, +# no NDI runtime), and pushes ghcr.io/technotut/moipctl-node-test. It is a test fixture +# for trying moipctl on a cluster without hardware, not something to run in production. +on: + workflow_dispatch: + push: + branches: [main, 'test/**'] + paths: + - test/node/** + - external/moip-toolkit + - .github/workflows/node-image.yml + pull_request: + paths: + - test/node/** + - external/moip-toolkit + - .github/workflows/node-image.yml + +permissions: + contents: read + packages: write + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v7 + # Only the toolkit is compiled; the other submodule (utone-linux) is not needed. + - run: git submodule update --init --recursive external/moip-toolkit + - uses: docker/setup-buildx-action@v4 + - uses: docker/login-action@v4 + if: github.event_name != 'pull_request' + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + - id: meta + uses: docker/metadata-action@v6 + with: + images: ghcr.io/${{ github.repository }}-node-test + tags: | + type=ref,event=branch + type=sha + type=raw,value=latest,enable={{is_default_branch}} + - uses: docker/build-push-action@v7 + with: + context: . + file: test/node/Dockerfile + platforms: linux/amd64 + build-args: VERSION=${{ steps.meta.outputs.version }} + push: ${{ github.event_name != 'pull_request' }} + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} diff --git a/README.md b/README.md index d6a21ac..ee8c8a5 100644 --- a/README.md +++ b/README.md @@ -80,6 +80,20 @@ must only be reachable from the scouts (a separate port and a network policy). T Each node shows the scout that found it as `source`. +## Testing against a real node + +`test/node` builds a real moip-toolkit node into a container (the Go server and the Rust engine from the +`external/moip-toolkit` submodule, plus avahi-daemon so that it advertises `_moip._tcp` the way utone-linux does). +It has no NDI runtime (its licence does not allow redistributing it), so rx/tx/multiview fail in the engine, while +the API, the state stream, node info and the mDNS advertisement are real. CI publishes it as +`ghcr.io/technotut/moipctl-node-test`; `test/node/pod.yaml` runs one on VLAN 20 and one on VLAN 42. + +```bash +git submodule update --init --recursive external/moip-toolkit +podman build -f test/node/Dockerfile -t moipctl-node-test . +podman run -d --name node --hostname utone-test moipctl-node-test +``` + ## Container ```bash diff --git a/test/node/Dockerfile b/test/node/Dockerfile new file mode 100644 index 0000000..6e17f24 --- /dev/null +++ b/test/node/Dockerfile @@ -0,0 +1,43 @@ +# syntax=docker/dockerfile:1 +# A real moip-toolkit node in a container, for testing moipctl without hardware: +# the Go server and the Rust engine are built from the submodule +# external/moip-toolkit (the commit moipctl pins), and avahi-daemon runs next to +# them so that `moip web` advertises _moip._tcp exactly as it does on utone-linux. +# +# Not included: the NDI runtime (libndi.so.6). Its licence does not allow +# redistributing it, so rx/tx/multiview fail in the engine, while the API, the +# state stream, node info and the mDNS advertisement are the real thing. +# +# Build from the repository root, with the submodules fetched: +# git submodule update --init --recursive external/moip-toolkit +# podman build -f test/node/Dockerfile -t moipctl-node-test . + +# ---- Engine (Rust) ---- +FROM docker.io/library/rust:1-trixie AS engine +RUN apt-get update \ + && apt-get install -y --no-install-recommends libsdl2-dev libasound2-dev pkg-config \ + && rm -rf /var/lib/apt/lists/* +WORKDIR /src +COPY external/moip-toolkit/engine/ ./ +RUN --mount=type=cache,target=/usr/local/cargo/registry --mount=type=cache,target=/src/target \ + cargo build --release --locked \ + && cp target/release/moip-engine /moip-engine + +# ---- Server (Go) ---- +FROM docker.io/library/golang:1.24-trixie AS server +WORKDIR /src +COPY external/moip-toolkit/server/ ./ +ARG VERSION=test +RUN --mount=type=cache,target=/go/pkg/mod --mount=type=cache,target=/root/.cache/go-build \ + CGO_ENABLED=0 go build -trimpath -ldflags "-s -w -X main.version=${VERSION}" -o /moip ./cmd/moip + +# ---- Runtime ---- +FROM docker.io/library/debian:trixie-slim +RUN apt-get update \ + && apt-get install -y --no-install-recommends libsdl2-2.0-0 libasound2t64 avahi-daemon dbus iproute2 \ + && rm -rf /var/lib/apt/lists/* +COPY --from=engine /moip-engine /opt/moip/bin/moip-engine +COPY --from=server /moip /opt/moip/bin/moip +COPY test/node/entrypoint.sh /entrypoint.sh +EXPOSE 8000 +ENTRYPOINT ["/entrypoint.sh"] diff --git a/test/node/Dockerfile.dockerignore b/test/node/Dockerfile.dockerignore new file mode 100644 index 0000000..e206a4e --- /dev/null +++ b/test/node/Dockerfile.dockerignore @@ -0,0 +1,8 @@ +# The build context for test/node/Dockerfile: only the toolkit sources it compiles. +.git +bin +external/utone-linux +external/moip-toolkit/frontend +external/moip-toolkit/engine/target +external/moip-toolkit/.git +**/.git diff --git a/test/node/entrypoint.sh b/test/node/entrypoint.sh new file mode 100755 index 0000000..981376a --- /dev/null +++ b/test/node/entrypoint.sh @@ -0,0 +1,39 @@ +#!/bin/sh +# dbus and avahi-daemon, then the node. The pod's hostname becomes the node ID. +set -e + +# A pod's default route is eth0, but this node is meant to look like a host on a +# VLAN. A controller that reaches it through the router (the source address is the +# controller's node IP) would get its replies out of eth0 and never see them. So, +# for every other interface, answer from that interface's address through that +# VLAN's gateway. On these VLANs the gateway is the network address + 1. +gateway_for() { # 10.10.20.8/20 -> 10.10.16.1 + addr=${1%/*}; plen=${1#*/} + IFS=. read -r a b c d <> 24 & 255 )).$(( gw >> 16 & 255 )).$(( gw >> 8 & 255 )).$(( gw & 255 ))" +} + +if [ "${1:-}" = "--print-gateway" ]; then gateway_for "$2"; exit 0; fi + +table=100 +for dev in $(ls /sys/class/net); do + case "$dev" in lo | eth0) continue ;; esac + cidr=$(ip -4 -o addr show dev "$dev" | awk '{print $4}' | head -n 1) + [ -n "$cidr" ] || continue + gw=$(gateway_for "$cidr") + ip route add default via "$gw" dev "$dev" table $table + ip rule add from "${cidr%/*}" lookup $table + echo "entrypoint: replies from ${cidr%/*} leave through $dev via $gw" + table=$((table + 1)) +done + +mkdir -p /run/dbus +rm -f /run/dbus/pid /run/avahi-daemon/pid +dbus-daemon --system --fork +avahi-daemon -D --no-drop-root --no-chroot +exec /opt/moip/bin/moip web --host 0.0.0.0 --port 8000 "$@" diff --git a/test/node/pod.yaml b/test/node/pod.yaml new file mode 100644 index 0000000..2c77498 --- /dev/null +++ b/test/node/pod.yaml @@ -0,0 +1,48 @@ +# Two test nodes for a cluster that has vxlan-cni (kube-public/vxlan): one on VLAN 20 and one on +# VLAN 42. Each one advertises _moip._tcp from avahi-daemon inside the pod, so a moipctl scout on +# the same VLAN finds it. The pod name is the node ID. They stop by themselves after an hour. +# +# kubectl create namespace moipctl-verify +# kubectl -n moipctl-verify apply -f test/node/pod.yaml +# kubectl -n moipctl-verify delete -f test/node/pod.yaml +apiVersion: v1 +kind: Pod +metadata: + name: testnode-av + labels: { app: moipctl-testnode } + annotations: + k8s.v1.cni.cncf.io/networks: '[{ "name": "vxlan", "namespace": "kube-public", "interface": "av", "cni-args": { "vlan": 20 } }]' +spec: + activeDeadlineSeconds: 3600 + restartPolicy: Never + containers: + - name: node + image: ghcr.io/technotut/moipctl-node-test:main + securityContext: + capabilities: + add: ["NET_ADMIN"] # the entrypoint sets up routing for the VLAN interface + ports: + - { name: http, containerPort: 8000 } + readinessProbe: + httpGet: { path: /api/node/info, port: http } +--- +apiVersion: v1 +kind: Pod +metadata: + name: testnode-ent + labels: { app: moipctl-testnode } + annotations: + k8s.v1.cni.cncf.io/networks: '[{ "name": "vxlan", "namespace": "kube-public", "interface": "ent", "cni-args": { "vlan": 42 } }]' +spec: + activeDeadlineSeconds: 3600 + restartPolicy: Never + containers: + - name: node + image: ghcr.io/technotut/moipctl-node-test:main + securityContext: + capabilities: + add: ["NET_ADMIN"] # the entrypoint sets up routing for the VLAN interface + ports: + - { name: http, containerPort: 8000 } + readinessProbe: + httpGet: { path: /api/node/info, port: http }