Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@
bin
external
*.md
frontend/node_modules
internal/ui/dist
frontend/dist
18 changes: 18 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,21 @@ jobs:
run: test -z "$(gofmt -l cmd internal)" || { gofmt -l cmd internal; exit 1; }
- run: go vet ./...
- run: go test -race ./...

frontend:
runs-on: ubuntu-latest
defaults:
run:
working-directory: frontend
steps:
- uses: actions/checkout@v7
- uses: actions/setup-node@v7
with:
node-version: 22
cache: npm
cache-dependency-path: frontend/package-lock.json
- run: npm ci
- run: npm test
- run: npm run typecheck
- name: Build
run: npm run build
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
bin/
/internal/ui/dist/*
!/internal/ui/dist/.gitkeep
14 changes: 12 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
# syntax=docker/dockerfile:1
# moipctl: a single static binary. The submodules under external/ are not
# needed to build it, so they are not part of the build context.
# moipctl: a single static binary with the web UI embedded. The submodules under
# external/ are not needed to build it, so they are not part of the build context.

# ---- Web UI (Vue, built with Vite) ----
FROM docker.io/library/node:22-bookworm-slim AS web
WORKDIR /src/frontend
COPY frontend/package.json frontend/package-lock.json ./
RUN npm ci
COPY frontend/ ./
RUN npm run build

# ---- Build ----
FROM docker.io/library/golang:1.24-bookworm AS build
Expand All @@ -9,6 +17,8 @@ COPY go.mod go.sum ./
RUN --mount=type=cache,target=/go/pkg/mod go mod download
COPY cmd/ cmd/
COPY internal/ internal/
# the web UI is embedded in the binary
COPY --from=web /src/frontend/dist/ internal/ui/dist/
ARG VERSION=dev
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 /moipctl ./cmd/moipctl \
Expand Down
14 changes: 13 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
VERSION ?= $(shell git describe --tags --always --dirty 2>/dev/null || echo dev)
NPM ?= npm

.PHONY: build test vet
.PHONY: all build frontend test vet ui-check
# The binary embeds internal/ui/dist: run `make frontend` first to have the web UI in it.
all: frontend build
build:
go build -ldflags "-X main.version=$(VERSION)" -o bin/moipctl ./cmd/moipctl
# Build the web UI (needs Node.js) and put it where the binary embeds it from. .gitkeep stays.
frontend:
cd frontend && $(NPM) ci && $(NPM) run build
find internal/ui/dist -mindepth 1 ! -name .gitkeep -delete
cp -r frontend/dist/. internal/ui/dist/
test:
go test ./...
cd frontend && $(NPM) test && $(NPM) run typecheck
vet:
go vet ./...
# Try the web UI against fake nodes in headless Chrome (needs `make all` first, python3, node and google-chrome).
ui-check:
test/ui/run.sh
33 changes: 30 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ DJ and AV networks can reach, is not attached to any node VLAN.
| Path | Content |
|---|---|
| `cmd/moipctl/` | entry point |
| `internal/` | controller packages |
| `internal/` | controller packages (`internal/ui` embeds the built web UI) |
| `frontend/` | the web UI: Vue 3, Vite and Tailwind |
| `test/ui/` | fake nodes and a headless-Chrome check of the web UI |
| `external/moip-toolkit/` | submodule, pinned to the commit utone-linux bundles |
| `external/utone-linux/` | submodule |

Expand All @@ -41,7 +43,8 @@ Keep `external/moip-toolkit` and utone-linux's `opt/moip-toolkit` on the same co

## API

Errors are `{"detail": "..."}`.
Errors are `{"detail": "..."}`. Writes (POST, PUT) must send `Content-Type: application/json`, and a write that names another
origin is refused: the API has no authentication, so this keeps a web page that an operator happens to have open from driving it.

| Method | Path | Description |
|---|---|---|
Expand All @@ -54,10 +57,34 @@ Errors are `{"detail": "..."}`.
`role/action` is one of `rx/{start,switch,stop}`, `tx/{start,stop}`, `multiview/{start,stop}`, `signage/{start,stop}`.

```bash
curl -X POST localhost:8080/api/bulk/rx/switch \
curl -X POST localhost:8080/api/bulk/rx/switch -H 'Content-Type: application/json' \
-d '{"nodes": ["utone-a1b2c3", "utone-d4e5f6"], "body": {"sender_name": "CAM1 (OBS)"}}'
```

## Web UI

`/` is a web UI in the look of moip-toolkit's: one compact card per node (receiver, sender, multi-view, signage, CPU and RAM) and
the NDI sources the nodes see. Tick nodes, then **Show on N selected nodes**: a running receiver is switched, a stopped one is
started, and a toast gives the result per node, failures with their reason. A card can also stop its receiver, sender or
multi-view, start or stop signage, and rename the node. It follows `/api/events`, so it updates by itself; a node that moipctl
cannot reach is shown as such and cannot be operated.

The UI is built from `frontend/` (Vue 3, Vite, Tailwind with the same theme as moip-toolkit) and embedded in the binary:

```bash
make all # make frontend (npm ci, build, copy to internal/ui/dist) + make build
make test # Go tests, the frontend's logic tests and its type check
make ui-check # drive the UI in headless Chrome against fake nodes (needs python3, node and google-chrome)
cd frontend && npm run dev # development server; proxies /api to a moipctl on :8080
```

Without `make frontend` the binary still builds and `/` says so; the Docker image always has the UI.

There is no authentication, so the UI is protected the way the API is: by the network (see Discovery), and against the
browser itself. Every write must be JSON and may not come from another origin, so another web page cannot drive moipctl from an
operator's browser. The page loads no inline script or style (the Content-Security-Policy allows only this origin), and text
from the network (aliases, hostnames, NDI source names) is only ever shown as text, never as HTML.

## Discovery

`moip web` advertises `_moip._tcp` through avahi-daemon with the TXT records `id`, `hostname` and `version`
Expand Down
3 changes: 3 additions & 0 deletions frontend/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
dist
*.log
15 changes: 15 additions & 0 deletions frontend/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>MoIP Controller</title>
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
<!-- an external script, not an inline one, so that the Content-Security-Policy needs no 'unsafe-inline' -->
<script src="/theme.js"></script>
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/main.ts"></script>
</body>
</html>
Loading