Hosting: how approved sites get onto web servers

Every server that hosts websites works the same way, whether it is the builder's own server or a separate one: its deployer gets the approved versions from the builder every 30 seconds (HTTPS and a token, or the internal network on the builder's own server), checks each against its SHA-256 checksum, keeps a local copy and installs it. Caddy serves the sites, the forms service sends their contact form mails.

                     ┌──────── builder: approved versions (bundles) ────────┐
                     │     GET /api/hosting/bundles  (token per server)     │
                     └────────────▲──────────────────────────▲──────────────┘
  internal network,               │                          │  HTTPS, token from
  token file written              │                          │  Admin → Web servers
  by the builder                  │                          │
  ┌───────────────────────────────┴────┐      ┌──────────────┴─────────────────────┐
  │ "This server" (deploy/server)      │      │ web server (deploy/web), any number│
  │ deployer ─► sites/ ─► Caddy, forms │      │ deployer ─► sites/ ─► Caddy, forms │
  └────────────────────────────────────┘      └────────────────────────────────────┘

A website needs nothing from the builder while it runs: it is finished static pages plus the forms service. The builder writes a new version when you approve one, when a client publishes an entry and when a scheduled entry goes live.

Three set-ups

Set-upFolderWhen
Everything on one serverdeploy/serverthe start; nothing to configure, This server appears in Admin → Web servers automatically
Everything on one server, plus web serversdeploy/server + deploy/webthe websites also run elsewhere; if one server fails, the other keeps them online
Builder and websites separatedeploy/builder + deploy/webthe editor on its own server; any number of web servers

What an outage means

DownWebsitesContact formsEditing (designers, clients)New versions
Builder serveronline on the web serverswork therenot possiblefollow automatically when it is back
A web serveronline on the other web servers (see failover)on the otherspossibleinstalled on it when it is back

Every web server keeps its own copy of the approved versions (bundles/); it restarts and reinstalls everything without the builder.

Everything on one server

Install the builder on your server and … and deploy.md. The builder writes the token of This server to hosting/token on its first start; the deployer in the same stack reads it and gets the versions over the internal Docker network. The deployer cannot see the builder's data (database, uploads, drafts).

Adding a web server

Requirements as in Install the builder on your server and …: Linux with Docker, ports 80/443 open, a GitHub token to build the image.

  1. In the builder: Admin → Web servers → Add a web server, with a name like web-2 (Hetzner Falkenstein). The token (BUILDER_TOKEN=wbs_…) is shown once; only its hash is stored.

  2. On the web server (Docker installed, install.md § 2):

    git clone https://github.com/marcus-zitzelsbergerit/Website-Builder.git
    cd Website-Builder
    read -s GOUTILS_TOKEN && export GOUTILS_TOKEN
    deploy/install.sh web                     # asks for the builder's address, the token, mail settings
    

    The installer writes deploy/web/.env, creates the folders, checks that the builder answers, builds the newest release, starts it and checks it. Contact forms are sent from the web server, so it asks for the mail settings (GRAPH_FROM with the MSGRAPH_* app, or SMTP_*), as on the builder's server. By hand: copy deploy/web/.env.example to .env, fill it in, mkdir -p data sites caddy && sudo chown 65532:65532 data sites caddy, build and start.

  3. Admin → Web servers shows it online and all N current within a minute.

  4. Point the sites' DNS to it (install.md § 3), or set up failover.

Revoke stops a web server from getting new versions; it keeps serving what it has. To replace a lost token, add the server again. This server cannot be revoked: its token is the file hosting/token (delete it and restart the stack to get a new one).

Builder on its own server

Use deploy/builder instead of deploy/server on the builder's server: it runs only the builder and a Caddy for its domain (fixed Caddyfile), no deployer. All websites run on web servers (deploy/web).

cd Website-Builder
read -s GOUTILS_TOKEN && export GOUTILS_TOKEN
deploy/install.sh builder                 # domain, Microsoft 365, first administrator

Moving from deploy/server: add the web server(s) and switch the sites' DNS to them first, so the sites stay online; then stop deploy/server, copy its data/ and .env to deploy/builder and start it there.

Failover between web servers

Every web server serves the same sites. To keep them online when one fails, visitors must reach another one:

  • Floating IP (e.g. Hetzner, servers in the same location): the sites' DNS points to the floating IP; move it to the other server when one fails (by hand or with a small health-check script). Certificates work unchanged, because only one server receives traffic.
  • DNS with health checks (e.g. Cloudflare Load Balancing, Bunny DNS, Route 53 failover): the DNS answers with a healthy server. Let's Encrypt checks a domain by connecting to it, so a server without traffic cannot get its certificate in advance: keep the certificates in sync (shared Caddy storage), or let Caddy prove the domain through the DNS provider's API (a Caddy build with that provider's DNS module).

Two plain A records (DNS round robin) are not a failover: browsers keep trying the dead server.

Security

  • A token only reads the approved versions (the same files the websites publish) and reports status. It cannot sign in, edit or see drafts, accounts or unpublished uploads.
  • BUILDER_URL must be https://; plain http is only accepted to localhost or a container name (the internal network of deploy/server). The token is sent with every request.
  • Every version is checked against its SHA-256 checksum before it is installed, and unpacked with checked file names, sizes and domains.
  • A web server holds no CMS data; rebuild it from scratch at any time. Back up the builder (deploy.md § Backups).