feat: always-on remote node — MCP over HTTP, TLS/token, Docker, CI, sqlc (#9)
Deploys knox as a headless, always-on replica so agents keep their memory when the laptop is off. Closes #8. **Supersedes #5** (its hardening commit is merged in here; close #5 after this lands). ## What changed **MCP transport + SDK** - Moves from `mark3labs/mcp-go` v0.17 (stdio only, five releases behind) to the official `modelcontextprotocol/go-sdk` v1.8. Tool inputs are typed structs, so schemas are generated instead of hand-built. - Adds `knox mcp --http` (Streamable HTTP). stdio remains the default. **Transport security without a public name** - `KNOX_AUTH_TOKEN` guards gossip and MCP HTTP; `KNOX_TLS_CERT/KEY` serve TLS; `knox tls init` mints a self-signed cert whose SANs are whatever addresses clients dial. Verified: 401 without the token, 200 with, cert valid for the overlay IP. **Daemon hygiene** - SIGTERM shuts down the gossip and metrics servers. - `--version` reports the VCS revision. - `KNOX_LOCAL_SOURCES=none` makes a node ingest nothing but still derive. - Default watch dirs skip paths that do not exist. **Deployment topology fixes** (all found by actually running a replica) - `KNOX_LISTEN_ADDR` split from `KNOX_PEER_ADDR`: a container cannot bind the host's overlay IP, and previously the gossip server silently failed to start. - Reconcile now fires on push and on startup, not only on pull. Three separate bugs left `entries` empty on a push-only node. - Pushes batch by byte budget, not just row count — 500 content-heavy rows exceeded the 4 MiB body limit and the log stalled permanently at 3,000 observations. - Threads and snippets derive on replicas: gating them with the ingesters left the server holding 11.5k observations and 4.9k entries but 2 of 28 threads. **Packaging + CI** - Multi-stage Dockerfile (static, non-root, `/data` volume). - Gitea workflow builds on the dhg.lol daemon through the runner socket, tags `:latest` + `:<sha>`, and restarts the stack when installed. BuildKit cache mounts keep module downloads warm. **sqlc pilot** - Schema extracted to `internal/db/schema.sql` (embedded); read paths behind the MCP tools are generated. - The pilot found real drift: `entries.created_at` existed only as a runtime `ALTER`. It is now declared in the schema, and `sqlcdb_pilot_test.go` fails if generated code disagrees with `db.Open`. - FTS5 stays hand-written: sqlc ignores `CREATE VIRTUAL TABLE`, so `MATCH`/`bm25` cannot be generated. ## Verification - `go vet ./...`, `go test ./...`, `gofmt` clean - `scripts/conformance.sh` — official MCP suite, exit 0 against `conformance-baseline.yml` (documents the capabilities knox does not implement: resources, prompts, completions, fixture tools) - Live: both containers healthy on dhg.lol, ports bound only to the ZeroTier address, 11,553 observations / 4,943 entries replicated and reconciled ## Deploy Infrastructure lives in `tf-net/apps/knox` (separate repo); this branch is what is currently running in production. Reviewed-on: #9 Co-authored-by: David Gwilliam <dhgwilliam@gmail.com> Co-committed-by: David Gwilliam <dhgwilliam@gmail.com>
This commit was merged in pull request #9.
This commit is contained in:
@@ -0,0 +1,95 @@
|
||||
name: build
|
||||
|
||||
# Build the knox image on the dhg.lol daemon through the runner's docker socket.
|
||||
#
|
||||
# The registry on the host requires htpasswd auth, and the established pattern
|
||||
# for self-built apps here is a locally-tagged image consumed with
|
||||
# `pull_policy: never` (see apps/plant-dashboard). Building against the host
|
||||
# daemon keeps that contract and means a knox change needs no registry
|
||||
# credentials at all.
|
||||
#
|
||||
# act_runner runs JS actions (actions/checkout) with whatever `node` is on the
|
||||
# job container's PATH, so each job installs one before checkout.
|
||||
#
|
||||
# Deployment stays with tf-net: this workflow only makes the new image available
|
||||
# and restarts the stack when the app is already installed.
|
||||
|
||||
on:
|
||||
push:
|
||||
paths:
|
||||
- "**/*.go"
|
||||
- "go.mod"
|
||||
- "go.sum"
|
||||
- "Dockerfile"
|
||||
- ".dockerignore"
|
||||
- ".gitea/workflows/build.yml"
|
||||
workflow_dispatch:
|
||||
|
||||
concurrency:
|
||||
group: knox-build
|
||||
cancel-in-progress: true
|
||||
|
||||
jobs:
|
||||
test:
|
||||
runs-on: ubuntu-latest
|
||||
container:
|
||||
image: golang:1.27-alpine
|
||||
steps:
|
||||
- name: Install node for JS actions
|
||||
run: apk add --no-cache nodejs
|
||||
- uses: actions/checkout@v4
|
||||
# act_runner injects ACTIONS_CACHE_URL, so this hits the runner-local
|
||||
# cache server (config: cache.dir) instead of re-downloading modules.
|
||||
- uses: actions/cache@v4
|
||||
with:
|
||||
path: |
|
||||
~/go/pkg/mod
|
||||
~/.cache/go-build
|
||||
key: go-${{ hashFiles('go.sum') }}
|
||||
restore-keys: go-
|
||||
- run: go vet ./... && go test ./...
|
||||
|
||||
image:
|
||||
needs: test
|
||||
runs-on: ubuntu-latest
|
||||
container:
|
||||
image: docker:27-cli
|
||||
# The runner already injects /var/run/docker.sock (declaring it again is a
|
||||
# duplicate mount error). CasaOS keeps app definitions under
|
||||
# /var/lib/casaos/apps, which is whitelisted in the runner's valid_volumes;
|
||||
# mount it at /apps so the restart step sees the installed compose file.
|
||||
volumes:
|
||||
- /var/lib/casaos/apps:/apps
|
||||
env:
|
||||
IMAGE: docker.notsosm.art/knox
|
||||
steps:
|
||||
- name: Install node for JS actions
|
||||
run: apk add --no-cache nodejs git
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Check the daemon
|
||||
run: docker version --format '{{.Server.Version}}'
|
||||
|
||||
- name: Build image on the host daemon
|
||||
run: |
|
||||
set -eu
|
||||
git config --global --add safe.directory "$GITHUB_WORKSPACE" || true
|
||||
# .git is present in the checkout, so the binary records the commit
|
||||
# it was built from (`knox --version`).
|
||||
docker build \
|
||||
--label "org.opencontainers.image.revision=${{ github.sha }}" \
|
||||
-t "$IMAGE:latest" \
|
||||
-t "$IMAGE:${GITHUB_SHA}" \
|
||||
.
|
||||
docker run --rm "$IMAGE:latest" --version
|
||||
|
||||
- name: Restart the app if it is installed
|
||||
run: |
|
||||
set -eu
|
||||
if [ ! -f /apps/knox/docker-compose.yml ]; then
|
||||
echo "apps/knox is not installed yet; image built, skipping restart"
|
||||
exit 0
|
||||
fi
|
||||
cd /apps/knox
|
||||
docker compose up -d
|
||||
docker compose ps
|
||||
Reference in New Issue
Block a user