Repository navigation
feat(deploy): run one hospital node per laptop from a provisioned kit - #9
Merged
Merged
Conversation
…a published image, a friend's guide
- deploy/node.yml: one `node` service from ghcr.io/denimworld12/medchain-node:${IMAGE_VERSION}, reading
`.env`, mounting ./data at DATA_PATH, ./pki read-only and ./config (engine settings), publishing
NODE_PORT on every interface. No container_name, no Compose DNS. Run from the kit folder with
`docker compose --project-directory . -f deploy/node.yml up`; without that flag it stops with a
message instead of mounting the wrong folders.
- deploy/hub.yml: directory, observer, Postgres on 127.0.0.1 only, dashboard; reads the directory kit.
- deploy/node.env.example and deploy/hub.env.example, each with a Tailscale block and a hotspot block
that differ only in addresses, using node/settings.py's variables.
- make hub, make node KIT=..., make node-native KIT=... (its own .venv-node from node/requirements.txt,
the kit's .env and folders in place of the container paths). The assessment models now default to
the repository's models/ (still /app/models in the image), so the native node finds them.
- scripts/provision.py: a hospital kit is now deploy/node.yml + a filled .env + pki/ + data/ (its slice)
+ config/node.yaml, validated as the container will load it; the directory kit carries a filled
hub.env for deploy/hub.yml. Kits use the published image (--image overrides it), so they no longer
bundle a build context, a compose file of their own or a direct-Postgres fallback.
- scripts/preflight.py runs inside the node's container with no arguments (NODE_PORT, TLS_CA) and says
why a neighbour is unreachable, e.g. a MagicDNS name the container cannot resolve. It ships in the image.
- .github/workflows/image.yml: linux/amd64 and linux/arm64 built on native runners, pushed by digest
and merged into one tag on a v* tag push or a manual run; pull requests touching the image only build it.
The Dockerfile bakes IMAGE_VERSION in.
- docs/MULTI_LAPTOP.md: the guide for a friend who has never used Docker, with the hotspot fallback
and a troubleshooting table grounded in the multi-laptop audit; the README's multi-machine section
describes the new kits.
…tal_joins_mid_run_then_a_middle_hospital_leaves_and_the_dashboard_follows, failing with KeyError on net[join_round - 1] (25 on gadmm_fp, 29 on qgadmm). The other 7 integration tests passed. Cause: a timing race in the test, not in this PR's code. The PR doesn't touch the node runtime, telemetry or dashboard, and the test passed on main. after_join waited for the dashboard to show 4 hospitals for the latest round (comm.hospitals_this_round). That count comes from chain_size, so one node's metrics row is enough. network_loss only includes a round once every member's metrics row has reached the observer, and each node pushes those rows from its own async queue (node/writer.py). So a lagging node's round join_round-1 row could still be in flight when the snapshot was taken. The 'hospital-d left' entry in the logs is the test's own cleanup after the crash. Fix (tests/integration/test_stack.py only): added a small loss_rounds(s) helper. after_join now also waits until network_loss includes join_round-1 and join_round, and after_leave waits for leave_round-1 and leave_round (same race). All existing assertions on the hospital counts are unchanged, so a real miscount still fails. Verified: the integration module still collects (9 tests, skipped without MEDCHAIN_STACK); ruff reports 7 warnings in test_stack.py, none on the changed lines. I could not run the live Docker stack locally: exited containers from another checkout outside this worktree use the same fixed container names, and I left them alone. CI on the PR is the real check. Not committed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Intent
The captain wants to actually test the multi-laptop setup with a friend soon. Phase 1 (TLS key pinning, rejoin-without-directory, settings wrapper, observer metrics push, preflight script) is merged. This is the next piece: the actual one-file deployment a friend can run, plus docs written for a non-developer. This follows the original phase spec's Step 3 (deployment files) and Step 6 (docs), and the Step 0 audit's P4 recommendation, both already on disk - read both before starting:
What those references say (the audit report lives outside this repo):
Audit P4, "Deployment split" (Step 3):
node, image ghcr.io/denimworld12/medchain-node:${IMAGE_VERSION}, env_file .env; mounts ./data:${DATA_PATH} (slice, checkpoints, audit.db) and ./pki:/pki:ro; ports "${NODE_PORT}:${NODE_PORT}" on all interfaces; no container_name and no Compose DNS assumptions; optional dns/extra_hosts hooks for MagicDNS trouble (H15).Audit section 4 rules that still hold: don't change the training maths; make up keeps working exactly as today; training never waits on the observer or dashboard; the directory is only for join/leave; no ngrok/relay, neighbours talk directly (Tailscale DERP relay allowed as a fallback); the target is 3 machines on a hotspot and the same run over Tailscale on different networks, with a node joining mid-run from the captain's laptop.
Audit failure modes the friend docs must account for: H14 the directory and neighbours must reach each node's port inbound (firewall); H15 Tailscale MagicDNS (*.ts.net) is often not resolvable inside Docker containers, Tailscale 100.x IPs avoid it, and preflight should test resolution from inside the container; H16 some phone hotspots isolate clients (AP isolation), so the hotspot fallback cannot work there; H5 Tailscale DERP relays and hotspots are slower than LAN (timeouts); a laptop that sleeps or restarts drops out and must rejoin; heartbeat freshness uses the observer's Postgres clock so clock skew does not mark nodes down; certificates are issued per address by provision.py.
Step 6 (docs): a guide a non-developer friend can follow to run one hospital node on their own laptop: install Docker Desktop and Tailscale, use the kit, run the preflight, start the node, keep the laptop awake, the hotspot fallback, troubleshooting.
What merged PR #8 already provides: node/settings.py (pydantic-settings) wraps the YAML loader, environment > YAML (NODE_CONFIG, optional) > defaults, with NODE_ID, BIND_HOST, NODE_PORT, ADVERTISE_ADDR (required with a directory; one NODE_PORT drives bind and advertised port), DIRECTORY_URL, DIRECTORY_CREDENTIAL_FILE, DIRECTORY_PUBLIC_KEY, DIRECTORY_TLS_PIN, OBSERVER_URL, OBSERVER_TOKEN/OBSERVER_TOKEN_FILE, OBSERVER_TLS_PIN, DATA_PATH, DATA_SLICE, CHECKPOINT_DIR, ALGORITHM, BITS, EPSILON, ROUND_TIMEOUT_S, ROUND_PAUSE_S, HTTP_CONNECT_TIMEOUT_S, HTTP_READ_TIMEOUT_S, TLS_CERT/TLS_KEY/TLS_CA, SIGNING_KEY, SHARED_SECRET, IMAGE_VERSION (MEDCHAIN_* names as aliases). TLS is pinned to each hospital's key as recorded in the directory's signed membership documents, not to the dialled hostname, so a node's address can change (hotspot) without new certificates; only the dashboard's relay still checks addresses. A node saves its membership and rejoins via its neighbours when the directory is down. observer/ is a FastAPI service taking POST /ingest batches with a bearer token into Postgres (nodes never hold Postgres credentials; Postgres on loopback). scripts/preflight.py (python scripts/preflight.py --node https://localhost: --ca pki/ca.crt) reads the local node's /status and reports each neighbour as direct, DERP-relayed or unreachable. A Makefile with make up and make lint, and scripts/provision.py kits (config, keys, a one-node compose file, README).
What Changed
deploy/node.yml, a single-service compose file usingghcr.io/denimworld12/medchain-node:${IMAGE_VERSION}. It mounts the kit'sdata/andpki/and publishesNODE_PORTon all interfaces. Also addsdeploy/hub.yml(directory, observer, Postgres on loopback only, dashboard) and.env.exampletemplates for both, each with a Tailscale block and a hotspot block.scripts/provision.pynow writes kits in this layout: a copy ofdeploy/node.yml, a.env,pki/,data/andconfig/. This replaces the per-kitdocker-compose.hospital.yaml, and provision checks each kit against the environment its container will see.make hub,make node KIT=...andmake node-native KIT=...;make upis unchanged.make node-nativebuilds a.venv-node, trainsmodels/heart-risk.joblibif it's missing, and runspython -m nodewith the kit's.envand its local paths. Model paths innode/config.pynow default to the repo'smodels/folder instead of/app/models. The image now includesscripts/preflight.py, which can run inside the container without arguments (it readsNODE_PORTandTLS_CA). When there's notailscalecommand it reports the path as "unknown", and when a neighbour is unreachable it prints the error..github/workflows/image.yml, which builds the node image for linux/amd64 and linux/arm64, each on its own native runner. It bakesIMAGE_VERSIONin as a build arg, env var and OCI label, and publishes a combined multi-arch tag to GHCR onv*tags or a manual run. Pull requests that touch the image only build it. Also addsdocs/MULTI_LAPTOP.md, a guide for non-developer friends (Docker Desktop, Tailscale, kit, preflight, keeping the laptop awake, hotspot fallback, troubleshooting), and updates the README. Unit tests for preflight and provision are updated to match.Risk Assessment
✅ Low: The round-1 fix is correct: hospital-d now appears in organiser step 1's --peers, matching step 3's
make node KIT=kits/hospital-d. A full pass found no defects in the rest of the deployment: node.yml/hub.yml, the provision kit layout, Makefile node/hub/node-native, the preflight container defaults and the multi-arch GHCR workflow;make upand docker-compose.yml are unchanged.Testing
I stood up a real hub (directory, observer, Postgres, dashboard) from deploy/hub.yml, using the node image built from this commit. Against it I ran four hospitals from provision.py kits: three through deploy/node.yml from unzipped kits, and one throughmake node-native. Live checks covered: - in-container preflight - a full training run - observer telemetry stored in Postgres - the dashboard (screenshot) - a mid-run join of hospital-d - rejoining while the directory is down - an address change made only in.envAll of these passed. The guard messages formake node,make node-nativeandmake hubalso work, and the targeted provision/preflight unit tests pass. I did not drive Tailscale/MagicDNS, real phone hotspots, or the GHCR multi-arch publish workflow, because there is no tailnet, hotspot or tag-push authority here.make upwas only checked with a dry run, so it is recorded as untested. I cleaned up all containers, the hub volumes, the test image,.venv-node,models/heart-risk.jobliband the caches.docker compose --project-directory . -f deploy/node.yml up -d; the node registers with the directory and joins the chainmake node-native KIT=...builds .venv-node, trains models/heart-risk.joblib, runs the node without Docker, joins the chain, and keeps checkpoints under DATA_PATH with the assess models loadedmake node KIT=kits/hospital-d; it is appended and joins the in-progress runmake upis still today's single-machinedocker compose up -d --build --waitwith docker-compose.yml unchangedmake -n up(a dry run) and by noting docker-compose.yml is not in the diff. It was not run live because the full single-ma…docker manifest inspecton the ima…Evidence: provision.py kit generation output
Evidence: Kit file layout (hospital-b, directory)
Evidence: Hub up (healthy services)
Evidence: make hub failing on host port 5432 conflict
Evidence: In-container preflight (no args)
Evidence: Preflight against native node from host
Evidence: Kit README start-training command
Evidence: All nodes completed run; kit data/ holds checkpoints, membership, audit.db
Evidence: Observer telemetry in Postgres (79 metrics rows per node)
Evidence: hospital-d provisioned into existing network
Evidence: hospital-d joins mid-run via make node
Evidence: Preflight flags a down neighbour as unreachable with reason (exit 1)
Evidence: Rejoin via neighbours with the directory down
Evidence: Hotspot-style .env switch: address change, pinned keys, training continues
Evidence: make guard messages and make -n up
Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
🔧 **Review** - 1 issue found → auto-fixed ✅
docs/MULTI_LAPTOP.md:250- In the organiser section, step 1's provision command lists only hospital-a, -b and -c in --peers. Step 3 then says to run the mid-run joiner withmake node KIT=kits/hospital-d. An organiser who follows the guide in order has no kits/hospital-d, somake nodestops in check-kit with "name a kit folder that has a .env", and the planned mid-run join from the captain's laptop can't start. README.md's version of the same command already includeshospital-d=...:8004. Fix: add hospital-d (e.g.hospital-d=sam-laptop.tail1234.ts.net:8004, the organiser's own laptop) to the --peers example in step 1, or tell the reader to provision it later with--hospital hospital-d.🔧 Fix applied.
✅ Re-checked - no issues remain.
deploy/hub.yml:31- deploy/hub.yml hardcodes Postgres on 127.0.0.1:5432. On an organiser laptop that already runs a local Postgres (as this test host does),make hubfails with "ports are not available ... 5432: bind: address already in use". There is no hub.env knob or troubleshooting entry for this. It worked after remapping the port with an override file. A POSTGRES_PORT variable could be added if organisers are likely to hit this.docker compose --project-directory . -f deploy/node.yml up -d; the node registers with the directory and joins the chainmake node-native KIT=...builds .venv-node, trains models/heart-risk.joblib, runs the node without Docker, joins the chain, and keeps checkpoints under DATA_PATH with the assess models loadedmake node KIT=kits/hospital-d; it is appended and joins the in-progress runmake upis still today's single-machinedocker compose up -d --build --waitwith docker-compose.yml unchangedmake -n up(a dry run) and by noting docker-compose.yml is not in the diff. It was not run live because the full single-ma…docker manifest inspecton the ima…python scripts/provision.py --peers hospital-a=IP:8001,hospital-b=IP:8002,hospital-c=IP:8003 --directory IP:8100 --out /tmp/nm-kits2 --zipthen unzip hospital-a/b zips into fresh foldersdocker build -f node/Dockerfile --build-arg IMAGE_VERSION=v1.0.0 -t medchain-node-nmtest:v1.0.0 .(stand-in for the unpublished GHCR image)make hub HUB_ENV=/tmp/nm-kits2/directory/hub.env(failed: host's own Postgres already on 5432), then the same compose command plus a postgres-port overridedocker compose --project-directory . -f deploy/node.yml up -dfrom the unzipped hospital-a and hospital-b kitsmake .venv-node/.installed models/heart-risk.joblibandmake node-native KIT=/tmp/nm-kits2/hospital-cdocker compose --project-directory . -f deploy/node.yml exec node python scripts/preflight.py(no args) and host-side preflight against the native nodeKit READMEcurl --cacert pki/ca.crt https://localhost:8002/round/start ...; /status on all nodes; psql query of observer metrics/nodes tables; dashboard screenshotprovision.py ... --hospital hospital-d --secret <secret>, copied hospitals.yaml to the hub kit,make node KIT=/tmp/nm-kits2/hospital-dstarted at round >= 10 of a live runStopped directory and hospital-a, ran in-container preflight, restarted hospital-a with the directory downEdited hospital-a's .env to the hotspot block (host.docker.internal addresses),up -d, checked neighbours still delivermake node,make node KIT=kits/hospital-zz,make node-native,make hub HUB_ENV=/nonexistent,make -n uppytest -q tests/unit/test_provision.py tests/unit/test_preflight.py✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.