Repository navigation
rebase: implement clusters for horizontal scaling - #11
Merged
Merged
Conversation
First steps towards running FodyCloud on several servers in several
regions (EU, Ethiopia, Cameroon…), each app living on one server.
Regions and nodes:
- migration 0003_regions.sql (additive): tables regions and nodes,
apps.node and deployments.node; NULL means the primary node, so the
previous release keeps working on the same schema;
- service/nodes.go: the primary node and region from the configuration
(FC_REGION, FC_REGION_LABEL, FC_NODE_NAME), remote nodes from
FC_NODES_FILE with their agent token hash, placement of a new app on
the least loaded active node of its region, heartbeats, draining;
- every Docker, build and database operation of the service goes
through the app's node (service.Runtimes, node.Runtime); the job
queue is claimed per node;
- internal/sample: docker stats and Traefik counters, taken per node,
so the monitor applies its rules node by node.
Node agent:
- internal/nodeapi: the control plane queues operations per node and
serves them on nodes.<domain> (long poll, streamed output, results,
cancellation, unreachable and restarted agents detected); the agent
runs them on its own server and keeps going through network failures;
- `fodycloud node` runs the agent (bearer fcn_ token over HTTPS).
Single-server installs behave as before: one region ("main"), the
primary node, no agent. The OpenTofu `region` variable names it.
Signed-off-by: Brady Fomegne <brady.fomegne@outlook.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
net-setup.sh adds two more TAPs (fctap1, fctap2) with fixed leases for 203.0.113.11 (et-1) and 203.0.113.12 (cm-1), and simulates intercontinental links to them with tc netem (+150 ms and +220 ms, 1% loss), restored by the dispatcher hook. --delegate-apps sends apps.fodycloud.internal to the nodes' own DNS servers, for the per-node DNS to come. The first VM's network and DNS are unchanged. net-teardown.sh removes the new connections too. Signed-off-by: Brady Fomegne <brady.fomegne@outlook.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ClaimJob could hand a queued deployment to a second worker while the
app's previous job was still building or deploying. Each deploy removes
the app's other containers, so the two could remove each other's new
container and leave the app with none while both said "running".
Claims are now serialized by a transaction-scoped advisory lock, and the
claiming UPDATE runs as its own statement, so its snapshot sees every
claim committed before it. A queued job waits while its app has a job
building or deploying.
Tests:
- internal/service/jobs_db_test.go runs against a real PostgreSQL
(FC_TEST_DATABASE_URL, skipped otherwise): one job per app, including
while deploying; 20 concurrent claimers over 20 rounds; per-node claims.
- scripts/check.sh starts the pinned postgres image with Docker or
Podman for them ("go test (database)").
- The e2e and cluster suites check that no two deployments of an app
ever overlapped (OVERLAPPING_JOBS_SQL in qemu/testlib.sh).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Brady Fomegne <brady.fomegne@outlook.com>
- The per-address login limit refills one try every 6 s; on a slow VM the first ten tries earn more, so try up to 20 times for the 429. - After the control plane restarts with Codeberg enabled, wait for the login page: Traefik routes to it about 2 s after it turns healthy. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Brady Fomegne <brady.fomegne@outlook.com>
- OpenTofu: a nodes map variable (default {}, so single-server installs
are unchanged). Each node gets its own bundle, apps-postgres password
and agent token; the control plane gets nodes.json and serves
nodes.<domain> only when nodes exist. Compose profiles: control
(postgres, valkey, control-plane) and node (node-agent).
- API: POST /v1/apps takes an optional region; an operation on a node
whose agent can't be reached returns 503 with a clear message.
- qemu: run-cluster.sh starts eu-1, et-1 and cm-1 (VM= in run-vm.sh and
destroy-vm.sh), net-setup.sh delays only traffic between the VMs, and
cluster-test.sh checks agents, placement, builds, storage, stop/start,
an unreachable agent, an interrupted build and cleanup on the nodes.
- Docs: API reference, troubleshooting, install and upgrade notes.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Brady Fomegne <brady.fomegne@outlook.com>
…download Railpack runs mise to resolve versions and downloads it from GitHub (about 20 MB, no checksum) when /tmp/railpack/mise/mise-<version> is missing: on every new server and recreated container. On slow links it timed out, and the student only saw "We couldn't detect how to build this repository". - Dockerfile: install mise 2026.10.14 (Railpack 0.43.0's core/mise/version.txt) at the path Railpack checks, verified against the release's sha256; its MIT license goes in /usr/share/licenses. - builder.Detect: when railpack prepare fails with a network error, stop (no subfolder retries) and return ErrAnalysisOffline with a message telling the student to analyse again or choose the stack by hand. - e2e and cluster tests check that only the shipped mise is present after an analysis, so a Railpack bump without mise fails. - Docs: troubleshooting row for the new message, upgrade note, pin rule. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Brady Fomegne <brady.fomegne@outlook.com>
With nodes, every server runs an authoritative DNS server for apps.<domain> (`fodycloud dns`, compose service apps-dns), so visitors reach an app on its own node, which gets its certificate by HTTP-01. - internal/appsdns: miekg/dns server (SOA, NS, A, NODATA for AAAA, REFUSED outside the zone, RFC 8482 for ANY, TTL 60, UDP and TCP). Records come from a JSON zone file, written by the control plane (service.AppsZone, every 10 s) and by node agents (GET /v1/zone with an ETag, every 15 s); the last valid file is kept. Unknown names get the control plane's IP. - The server uses the host network and binds each interface address, since a wildcard bind conflicts with systemd-resolved. - Waking on nodes: Traefik's catch-all goes to the agent, which forwards the visit to the control plane (/v1/wake/) with its token, the host and the visitor's IP; the wake and offline pages are the same everywhere. - Custom domains: the instructions and checks use the app's node IP. - OpenTofu: apps_dns (on by default with nodes, refused with DNS-01), the apps-dns profile, port 53 in the firewall, and NS plus glue records in dns_records instead of *.apps. - Tests: unit tests, AppsZone database test, smoke and cluster checks through real DNS delegation. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Brady Fomegne <brady.fomegne@outlook.com>
With several regions, students pick where each app runs, and the
dashboard preselects the one closest to them. Admins can close a region
to new apps and drain a server. Single-server installs see no change.
- Service: Regions with a ping URL, OpenRegions (open regions with an
active node, the control plane's first; the default for an app
created without a region), SetRegionStatus, and node reachability
(a heartbeat within 2 minutes) in the admin node list.
- Latency probes: each server answers https://<node>.ping.apps.<domain>/
with an empty 204, CORS for the dashboard only. The name is two labels
deep, so it never collides with an app; the zone holds it as a
<node>.ping record, and Traefik's ping router sends it to the control
plane or the agent, which answer locally. The CSP's connect-src
allows *.ping.apps.<domain>; app.js times the probes and preselects
the fastest region unless the student already chose one.
- Dashboard: a Region picker on the New app form (2+ open regions), the
region on the apps list and the app page, and a "Regions and servers"
card in the admin panel to close or open regions and drain or
activate servers.
- API: GET /v1/regions; GET /v1/admin/nodes, PUT /v1/admin/regions/{name}
and PUT /v1/admin/nodes/{name}. MCP: list_regions, and create_app
takes a region. CLI: admin nodes, set-region and set-node.
- Docs: new "Choose a region" and "Regions and servers" pages; API, MCP,
operations and privacy updates (LegalVersion is bumped in the last
multi-region phase).
- Tests: unit and database tests, and a cluster section covering the
probes over HTTPS, the picker, MCP, and closing and draining through
the API, the CLI and the panel.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Brady Fomegne <brady.fomegne@outlook.com>
Every server now sends a health report each minute (disk, memory, load, the apps' PostgreSQL and DNS, restart-looping apps, and the last backup and earliest certificate expiry written by the host scripts to /var/lib/fodycloud-host). Every 30 s the control plane builds a status snapshot per region (app hosting, builds, databases, backups) and for the platform (dashboard & API, email), with 90 days of daily history in status_daily. It is served at status.<domain>, /status.json, GET /v1/status and the MCP tool platform_status. The other servers keep a copy and serve it at <node>.status.apps.<domain>, with a banner when the control plane stops reporting. Admins get a Status page in the panel and GET /v1/admin/status with each server's health, stuck jobs and the email outbox, and post incidents and maintenance (panel and admin API). Students with apps in the affected regions see a dashboard banner; no email is sent. The public page is off by default (status_page); migration 0004 is additive, and agents of the previous release simply send no reports. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Brady Fomegne <brady.fomegne@outlook.com>
Students move their apps to another open region (dashboard Region
card, POST /v1/apps/{name}/move, MCP move_app with a confirmation),
at most once an hour. Admins move any app to any active server, to
empty a drained one (panel, POST /v1/admin/apps/{name}/move, CLI
admin move-app); admin moves are never on MCP.
A move is a deployment of kind move, run by the new server's worker:
it builds the running commit there while the old server serves, points
the app's name to the new server, stops the app (only with a volume or
database), streams its volume and database through the control plane
in 2 MiB chunks, waits 90 s for DNS caches so the new server gets its
certificate, deploys, then switches apps.node and the app's queued
jobs in one transaction. A failure starts the app again on the old
server and points its name back; leftovers on a server that couldn't
be reached are removed every 2 minutes (deployments.cleaned_at).
Rollbacks only offer images built on the app's current server.
Traefik requests a certificate only once per configuration change, so
a failed request left a name on the default certificate until the next
change. The control plane and the agents now check their own names
(never custom domains) and, after cert_retry_after (15m by default),
rewrite traefik/dynamic/fodycloud-cert-retry.yml so Traefik asks again.
Agents that stop polling during an operation now fail it after 2
minutes instead of hanging. Migration 0005 is additive; roll back to
the previous release only with no move in progress.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Brady Fomegne <brady.fomegne@outlook.com>
Only the main server copied its backups off-site: the other servers kept their apps' volumes and databases in local dumps, so losing a server lost its students' data, and their host scripts' alerts went to a control plane they don't run, so no one heard of their failures. Every server now runs restic to its own repository with its own password: the main server at <bucket> as before (its snapshots keep the host name fodycloud), each node at <bucket>/nodes/<node> in the main backup storage, or in its own storage with node_backup_s3 (for example in its region). A node's password (random_password.node_restic, output node_restic_passwords) can't decrypt the main repository, which holds the platform database. The backups output now lists each server's destination. Nodes alert the admins through their agent: `fodycloud node notify` posts to nodes.<domain>/v1/notify, which emails the admins with the node's name in the subject, at most 20 times an hour per node. A run that reached the off-site copy writes backup-offsite-ok, so the admin Status page tells "off-site" from "this server only". The test fixtures publish SeaweedFS on the main server for the nodes; its firewall accepts that port from the nodes only. The privacy policy says regional backups may be stored in another country. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Brady Fomegne <brady.fomegne@outlook.com>
…h regions The policies change with multi-region (version 2026-12-05): the terms cover regions, moves and the status page, the privacy policy the status page and the notices. Bumping LegalVersion used to reach no existing student, though the terms promise to announce changes before they apply. The control plane now announces each new version itself: on its first start with it, it records the announcement (legal_announcements, migration 0006), effective 30 days later when students accepted an earlier version and at once on a new platform, so each platform counts from its own upgrade. Students with a confirmed address get one email, 50 a minute, and the dashboard shows a banner until they select "Got it", which records the version. The policies show the recorded date; a "What changed" page lists the changes, and the earlier texts stay readable at /legal/<page>-2026-11-26. Moves started by admins now email the app's owner, as the terms say. Operators get a how-to for adding and removing a server in another region, a section on what a node holds in the security model, runbooks for a server that stops reporting and for stale DNS answers, and the upgrade notes. qemu/upgrade-test.sh installs eu-1 alone with an app, then adds the nodes as that how-to says; the e2e suite checks the announcement on one server. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Brady Fomegne <brady.fomegne@outlook.com>
- Deleting an account now removes what earlier moves left on other servers (through removeApp, shared with DeleteApp), and is refused while one of its apps is moving, which would recreate it. - A move no longer rebuilds a repository banned since it was queued: analyses, builds and moves get their repository through JobRepo. - A move whose commit can't be fetched says the commit is gone only when git says so; an unreachable forge reports git's error instead. - Posting or updating an incident recomputes the status page without counting one more snapshot in the 90-day history. - Stuck jobs on the admin Status page use each job's own time limit (build timeout + deploy, or build + move timeout) plus 5 minutes, instead of 30 minutes for every job, so moves aren't flagged early. - bootstrap.sh restarts the control plane or the agent when only its plans, servers list or node token changed, which it reads at startup; the upgrade test renames a region to cover it. Its pipes into grep -q no longer fail under pipefail. - A node agent running its maximum number of operations keeps polling; operations wait for a slot in their own goroutine, so the hub no longer fails them all as unreachable. - Clearer messages: a snapshot without a generation time, and an operation whose result was lost. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Brady Fomegne <brady.fomegne@outlook.com>
No behaviour change: the full fresh cycle (upgrade, cluster, smoke, e2e, plan) passes, and the rendered server files and compose configuration are unchanged but for comments and one renamed variable. - Background loops: internal/periodic (Every, Logged, Sleep, Retry) replaces the hand-written loops of the agent, control plane, worker, monitor and status page; internal/fsutil.WriteFileAtomic replaces the three copies for the zone, status copy and certretry files. - Node agent and hub: one request helper and httpError, one conditional GET (fetchIfChanged) and serveWithETag, named timeouts and limits in one place, Hub.call split, shared transfer chunk reading, dead aliases and exports removed, RestartingApps moved into node.Local. - Service: SQL helpers for "the app's node, or the primary" (nodeOf, appOnNode), upsertRegion, reachable, primaryFirst, parseHealth, markRunning (FinishJob and CompleteMove), EmptyApp (app deletion, move cleanup, the worker), named storage defaults; the status inputs and AdminStatus split into small functions, health read in one query. - Worker: one build step shared by builds and moves (ban check, timeout message), runMove split into its stages, DefaultMoveTimeout and DefaultDNSSettle in service. - Web, MCP, DNS: one admin action helper, dead Lookup removed, the MCP move_app text from DefaultDNSSettle, Web fields grouped. - OpenTofu: is_control and per-server SSH settings on local.servers, shared backup and S3 locals, nodes_json from local.servers, compose anchors for the platform image and environment, files/hostlib.sh (notify, host_record) for the host scripts, NODES_HOST_RULE renamed CONTROL_EXTRA_HOSTS, OpenTofu in generated headers (except those whose change would restart Traefik, the firewall or Docker on upgrade). - Tests: the cluster helpers live once in qemu/e2e/lib.sh, the cluster test uses one admin, the upgrade test leaves the policy banner checks to e2e/28-policies.sh, and 26-status.sh no longer shadows wait_status. - Docs: CLAUDE.md and internal/README.md describe the new packages and the per-server bundles. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Brady Fomegne <brady.fomegne@outlook.com>
|
Important Review skippedToo many files! This PR contains 190 files, which is 40 over the limit of 150. To get a review, reduce the PR to 150 files or fewer by splitting it into smaller PRs or changing its base branch. Upgrade to Team to raise the limit. This review couldn't start because sufficient usage credits or metered capacity aren't available. Add credits or update usage-based reviews in the billing tab, then retry.
|
| return r.hasCert(ctx, name) | ||
| } | ||
| d := &tls.Dialer{NetDialer: &net.Dialer{Timeout: 10 * time.Second}, | ||
| Config: &tls.Config{ServerName: name, InsecureSkipVerify: true}} //nolint:gosec // the chain isn't checked here, only which certificate Traefik has |
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.
What and why
#10
How it was tested
Checklist
scripts/check.shpasses.docs/in the same commit; changes to installing or running a platform updatedocs/operations/.git commit -s, see CONTRIBUTING.md).Changes
Multi-region hosting
FodyCloud can now spread apps across several servers in different regions.
Existing installations keep working on one server as before. Multi-region starts only when servers are added. The 3-server test cluster passed every test suite.