From c9245077facac05ef26b86816a157a0d04b119f5 Mon Sep 17 00:00:00 2001 From: John Coffey Date: Mon, 12 Oct 2026 11:26:03 -0700 Subject: [PATCH 1/2] Phase 2: the console and the webmail on the host --console host and --webmail host install them without containers, from their releases' tarballs (inbuxa-admin #106, inbuxa-webmail #68), each checked against a checksum pinned in internal/release. - The console is files: unpacked into /console, root-owned and readable, and pointed at the server the way its image's entrypoint does (the api-base-url meta tag). The managed Caddy serves the directory, mounted read-only, or the operator's web server does from the configuration --proxy snippets writes; both with the image's rules (app routes fall back to index.html, hashed assets cached for good, index.html never). With --local or --proxy none nothing would serve it, and the plan says so. - The webmail is the /app its image runs, in /webmail, owned by root, under inbuxa-webmail.service as its own user on the installer's own Node (now 26, as its image) in /opt/inbuxa/node, on 127.0.0.1:8080, with the container's environment in /webmail.env. It can't write its own files, which is what its IMMUTABLE setting checks. The unit is ProtectSystem=strict. A server in a container is reached at its loopback port and sees it at the project network's gateway, which is what gets exempted from the auto-ban. - Both unpack beside the old copy and swap only when complete; a re-run skips an unchanged release and restarts the webmail only when what it reads at start changed. A webmail moved back into a container gives its port back first. status and export report them as host. With all three on the host and --proxy snippets, no container runtime is installed. The release pins are empty until those releases exist, and the host shapes say so; INBUXA_CONSOLE_TARBALL and INBUXA_WEBMAIL_TARBALL (and CONSOLE_TARBALL=, WEBMAIL_TARBALL= in e2e/vm/run.sh) install a local tarball meanwhile. Also: the "using docker" line no longer prints when nothing runs in a container; Verify takes the plan's options and checks a host console by its files. Tests: plan (console host needs a web server; host front ends wait for their releases; the webmail wants the installer's own Node), compose (console files, the webmail unit, Caddy on the host's network, the gateway exemption, nginx serving the directory), apply (api-base-url replaced or inserted, the webmail's environment, unpack's swap and marker). e2e: webmail-host.sh 18/18 (signing in included), all-host.sh 17/17 (no runtime, behind nginx), both with tarballs taken out of the current images as the release jobs will; install-local, install-host, install-public, proxy-snippets, interface, status-export and topology pass unchanged. --- README.md | 24 +- cmd/inbuxa/main.go | 9 +- e2e/cases/all-host.sh | 65 ++++ e2e/cases/webmail-host.sh | 71 ++++ e2e/vm/run.sh | 5 + internal/apply/apply.go | 87 ++++- internal/apply/frontends.go | 337 ++++++++++++++++++ internal/apply/frontends_test.go | 90 +++++ internal/apply/join.go | 8 +- internal/compose/compose.go | 27 +- internal/compose/compose_test.go | 34 ++ .../compose/templates/Caddyfile.fragment.tmpl | 15 +- internal/compose/templates/Caddyfile.tmpl | 17 +- internal/compose/templates/compose.yaml.tmpl | 10 +- .../compose/templates/nginx-inbuxa.conf.tmpl | 21 +- internal/deps/deps.go | 17 +- internal/discover/discover.go | 40 ++- internal/plan/plan.go | 43 ++- internal/plan/plan_test.go | 71 ++++ internal/release/release.go | 26 ++ internal/tui/install_test.go | 2 +- 21 files changed, 960 insertions(+), 59 deletions(-) create mode 100644 e2e/cases/all-host.sh create mode 100644 e2e/cases/webmail-host.sh create mode 100644 internal/apply/frontends.go create mode 100644 internal/apply/frontends_test.go create mode 100644 internal/plan/plan_test.go diff --git a/README.md b/README.md index 73840d1..91c1f85 100644 --- a/README.md +++ b/README.md @@ -80,8 +80,16 @@ This is early. What is built: data in `/server`, and a unit, `inbuxa-server.service`. During setup it is reachable from the machine itself and nowhere else; afterwards its plain HTTP is on loopback for the proxy and the webmail, 443 is left to - the proxy, and the unit will not start without a configuration file. The - console and the webmail run in containers beside it, or not at all. + the proxy, and the unit will not start without a configuration file. +- **`--console host`** -- the console's files from its release, checked + against a pinned checksum, unpacked into `/console` and pointed at the + server; the managed Caddy or your own web server (`--proxy snippets`) + serves them. Nothing runs, so there is nothing to start. +- **`--webmail host`** -- the webmail from its release, checked the same way, + in `/webmail`, owned by root and only read by the webmail, which runs + as its own user under `inbuxa-webmail.service` on the installer's own + Node 26 (in `/opt/inbuxa/node`), on 127.0.0.1:8080. With all three on the + host and `--proxy snippets`, no container runtime is installed at all. - **`join URL --key KEY`** -- the console and the webmail on this machine, for a mail server already running at URL on another one. It reaches that @@ -107,9 +115,9 @@ This is early. What is built: installing. It exits non-zero when they disagree, so a machine can be asked in a script whether it still matches itself. -Not built yet: host installs of the console and the webmail, `join` in the -interface (it is a command for now), `upgrade`, `uninstall`, and moving the -server between a container and the host. The design is in the inbuxa specification (§6.1 and +Not built yet: `join` in the interface (it is a command for now) and of +front ends on the host, `upgrade`, `uninstall`, and moving the server +between a container and the host. The design is in the inbuxa specification (§6.1 and the installer draft); the phases are there too. inbuxa install --local --domain example.test --install-deps --yes @@ -152,6 +160,8 @@ is tested on a throwaway virtual machine rather than on anybody's desk: e2e/vm/run.sh e2e/cases/join.sh front ends joined to a server elsewhere e2e/vm/run.sh e2e/cases/interface.sh the interface, driven key by key in a terminal e2e/vm/run.sh e2e/cases/proxy-snippets.sh behind nginx, from the configuration it writes + e2e/vm/run.sh e2e/cases/webmail-host.sh the webmail on the host, and signing in to it + e2e/vm/run.sh e2e/cases/all-host.sh everything on the host, behind nginx, no containers e2e/vm/run.sh e2e/cases/topology.sh growing and shrinking from a file e2e/vm/run.sh e2e/cases/status-export.sh intent against reality, and the file OLD_REF= e2e/vm/run.sh e2e/cases/upgrade-volumes.sh @@ -161,7 +171,9 @@ is tested on a throwaway virtual machine rather than on anybody's desk: `SERVER_BINARY=path/to/inbuxa e2e/vm/run.sh …` installs a server build instead of the release wherever a case installs the server on the host (the installer's `INBUXA_SERVER_BINARY`), for testing a server change before it -is released. +is released. `CONSOLE_TARBALL=` and `WEBMAIL_TARBALL=` do the same for the +console's and the webmail's release tarballs (`INBUXA_CONSOLE_TARBALL`, +`INBUXA_WEBMAIL_TARBALL`). Each case starts from a copy of the machine taken when it was new, so a run is free to break it and a failure is the installer's rather than the last diff --git a/cmd/inbuxa/main.go b/cmd/inbuxa/main.go index f741dc9..4874fcd 100644 --- a/cmd/inbuxa/main.go +++ b/cmd/inbuxa/main.go @@ -202,8 +202,7 @@ func install(args []string) int { return 1 } fmt.Println("\nChecking it works:") - problems := apply.Verify(context.Background(), res, true, - o.Shape(plan.Console) != plan.Skip, o.Shape(plan.Webmail) != plan.Skip, log) + problems := apply.Verify(context.Background(), res, p.Options, true, log) for _, why := range problems { fmt.Fprintln(os.Stderr, " problem: "+why) } @@ -395,7 +394,7 @@ func (installer) Run(ctx context.Context, p plan.Plan, f host.Facts, log apply.L } func (installer) Verify(ctx context.Context, res *apply.Result, o plan.Options, log apply.Log) []string { - return apply.Verify(ctx, res, true, o.Shape(plan.Console) != plan.Skip, o.Shape(plan.Webmail) != plan.Skip, log) + return apply.Verify(ctx, res, o, true, log) } // printer is apply's log on the flag path: steps as lines, everything a @@ -619,7 +618,7 @@ func exportCmd(args []string) int { switch { case st.Shapes[kind] != "": m.Components = append(m.Components, topology.Component{Kind: kind, Shape: st.Shapes[kind]}) - case kind == "server" && found.HostServer: + case (kind == "server" && found.HostServer) || (kind == "console" && found.HostConsole) || (kind == "webmail" && found.HostWebmail): m.Components = append(m.Components, topology.Component{Kind: kind, Shape: "host"}) case found.Services[kind] != "": m.Components = append(m.Components, topology.Component{Kind: kind, Shape: "container"}) @@ -702,7 +701,7 @@ func statusCmd() int { fmt.Printf(" %-8s installed as a %-9s %s\n", kind, shape, state) case intended: fmt.Printf(" %-8s installed as a %-9s missing from the deployment\n", kind, shape) - case kind == "server" && found.HostServer: + case (kind == "server" && found.HostServer) || (kind == "console" && found.HostConsole) || (kind == "webmail" && found.HostWebmail): fmt.Printf(" %-8s %-24s %s\n", kind, "on the host", state) default: fmt.Printf(" %-8s %-24s %s\n", kind, "in the deployment", state) diff --git a/e2e/cases/all-host.sh b/e2e/cases/all-host.sh new file mode 100644 index 0000000..f6c5d6d --- /dev/null +++ b/e2e/cases/all-host.sh @@ -0,0 +1,65 @@ +#!/bin/bash +# SPDX-FileCopyrightText: 2026 Coffey Labs LLC +# SPDX-License-Identifier: AGPL-3.0-or-later +# +# Everything on the host, nothing in a container: the server and the webmail +# under systemd, the console as files, behind the nginx this machine already +# runs (--proxy snippets). No container runtime is installed at all. +# +# Until the console's and the webmail's releases carry their tarballs, pass +# them: CONSOLE_TARBALL=… WEBMAIL_TARBALL=… e2e/vm/run.sh e2e/cases/all-host.sh +set -uo pipefail + +pass=0; fail=0 +ok() { echo " ok $*"; pass=$((pass+1)); } +bad() { echo " FAIL $*"; fail=$((fail+1)); } + +DIR=/var/lib/inbuxa +D=example.test +[ -f /tmp/inbuxa-console-test.tar.gz ] && export INBUXA_CONSOLE_TARBALL=/tmp/inbuxa-console-test.tar.gz +[ -f /tmp/inbuxa-webmail-test.tar.gz ] && export INBUXA_WEBMAIL_TARBALL=/tmp/inbuxa-webmail-test.tar.gz + +echo "==> a machine with nginx, and no container runtime" +DEBIAN_FRONTEND=noninteractive apt-get install -y -qq nginx openssl >/dev/null 2>&1 +systemctl is-active --quiet nginx && ok "nginx is running" || { bad "no nginx"; exit 1; } + +echo +echo "==> installing everything on the host" +OUT="$(/tmp/inbuxa install --domain $D --server host --console host --webmail host --proxy snippets --install-deps --yes 2>&1)"; rc=$? +echo "$OUT" | grep -v '^ |' | tail -16 | sed 's/^/ /' +[ $rc -eq 0 ] && ok "installed (exit 0)" || bad "exit $rc" +command -v docker >/dev/null || command -v podman >/dev/null && bad "a container runtime was installed" || ok "no container runtime was installed" +[ -f $DIR/compose.yaml ] && bad "there is a compose project" || ok "no compose project" +for u in inbuxa-server inbuxa-webmail; do systemctl is-active --quiet $u && ok "$u is running" || bad "$u is not running"; done +grep -q "name=\"api-base-url\" content=\"https://mail.$D\"" $DIR/console/index.html && ok "the console's files name https://mail.$D" || bad "the console's index.html" + +echo +echo "==> behind nginx, from the configuration it wrote" +mkdir -p /etc/ssl/inbuxa +for n in mail.$D admin.$D webmail.$D; do + openssl req -x509 -newkey ec -pkeyopt ec_paramgen_curve:P-256 -nodes -days 2 -subj "/CN=$n" \ + -keyout /etc/ssl/inbuxa/$n.key.pem -out /etc/ssl/inbuxa/$n.fullchain.pem 2>/dev/null +done +cp $DIR/proxy/nginx-inbuxa.conf /etc/nginx/conf.d/inbuxa.conf +nginx -t >/dev/null 2>&1 && ok "nginx -t accepts it" || { bad "nginx -t"; nginx -t 2>&1 | sed 's/^/ /'; } +systemctl reload nginx; sleep 3 +via() { curl -sk --resolve "$1:443:127.0.0.1" "${@:2}"; } +PAGE=$(via admin.$D https://admin.$D/) +grep -q "content=\"https://mail.$D\"" <<<"$PAGE" && ok "the console is served from its files" || bad "the console is not served" +CODE=$(via admin.$D -o /dev/null -w '%{http_code}' https://admin.$D/some/route/in/the/app) +[ "$CODE" = 200 ] && ok "and its routes fall back to the app" || bad "an app route answered $CODE" +ASSET=$(grep -o '/assets/[^"]*\.js' <<<"$PAGE" | head -1) +via admin.$D -D - -o /dev/null "https://admin.$D$ASSET" | grep -qi "cache-control: public, immutable" && ok "hashed assets are cached for good" || bad "no immutable cache on $ASSET" +via webmail.$D https://webmail.$D/api/health | grep -q '"ok":true' && ok "the webmail is healthy through nginx" || bad "the webmail through nginx" +CODE=$(via mail.$D -o /dev/null -w '%{http_code}' https://mail.$D/.well-known/jmap) +case "$CODE" in 30*|200|401) ok "the mail server through nginx ($CODE)" ;; *) bad "the server through nginx: $CODE" ;; esac + +echo +echo "==> status" +STATUS="$(/tmp/inbuxa status 2>&1)"; rc=$? +for k in server console webmail; do grep -q "$k.*installed as a host" <<<"$STATUS" && ok "status: the $k is a host install" || bad "status: $k"; done +[ $rc -eq 0 ] && ok "intent and reality agree" || { bad "status exit $rc"; echo "$STATUS" | sed 's/^/ /'; } + +echo +echo "==> $pass passed, $fail failed" +[ "$fail" -eq 0 ] diff --git a/e2e/cases/webmail-host.sh b/e2e/cases/webmail-host.sh new file mode 100644 index 0000000..e7a47fe --- /dev/null +++ b/e2e/cases/webmail-host.sh @@ -0,0 +1,71 @@ +#!/bin/bash +# SPDX-FileCopyrightText: 2026 Coffey Labs LLC +# SPDX-License-Identifier: AGPL-3.0-or-later +# +# The webmail on the host: a unit of its own on the installer's own Node, +# beside the server and the console in containers, on loopback. Checked as +# install-local checks a container webmail -- someone signs in to it -- and +# for what is particular to the host: the Node it runs on, the user it runs +# as, and that it can't write its own files. +# +# Until a webmail release carries its tarball, pass one: +# WEBMAIL_TARBALL=path e2e/vm/run.sh e2e/cases/webmail-host.sh +set -uo pipefail + +pass=0; fail=0 +ok() { echo " ok $*"; pass=$((pass+1)); } +bad() { echo " FAIL $*"; fail=$((fail+1)); } + +DIR=/var/lib/inbuxa +UNIT=inbuxa-webmail.service +[ -f /tmp/inbuxa-webmail-test.tar.gz ] && export INBUXA_WEBMAIL_TARBALL=/tmp/inbuxa-webmail-test.tar.gz +rt() { command -v docker >/dev/null 2>&1 && echo docker || echo podman; } + +echo "==> installing, the webmail on the host" +OUT="$(/tmp/inbuxa install --local --domain example.test --webmail host --install-deps --yes 2>&1)"; rc=$? +echo "$OUT" | grep -v '^ |' | tail -16 | sed 's/^/ /' +[ $rc -eq 0 ] && ok "installed (exit 0)" || { bad "exit $rc"; journalctl -u $UNIT -n 20 --no-pager -o cat | sed 's/^/ | /'; } + +echo +echo "==> the webmail is a host install" +systemctl is-active --quiet $UNIT && ok "$UNIT is running" || bad "$UNIT is not running" +PID=$(systemctl show -p MainPID --value $UNIT) +[ "$(ps -o user= -p "$PID" 2>/dev/null)" = inbuxa-webmail ] && ok "as the inbuxa-webmail user" || bad "as '$(ps -o user= -p "$PID" 2>/dev/null)'" +[ "$(readlink -f /proc/$PID/exe)" = /opt/inbuxa/node/bin/node ] && ok "on the installer's own Node: $(/opt/inbuxa/node/bin/node --version)" || bad "on $(readlink -f /proc/$PID/exe)" +/opt/inbuxa/node/bin/node --version | grep -q '^v26\.' && ok "which is Node 26, as its image" || bad "Node $(/opt/inbuxa/node/bin/node --version)" +[ "$(stat -c %U $DIR/webmail/server/dist/index.js)" = root ] && ok "its files are root's" || bad "its files are $(stat -c %U $DIR/webmail/server/dist/index.js)'s" +su -s /bin/sh inbuxa-webmail -c "touch $DIR/webmail/probe" 2>/dev/null && bad "it can write its own files" || ok "it can't write its own files (IMMUTABLE holds)" +[ "$(stat -c %a $DIR/webmail.env)" = 600 ] && ok "webmail.env is 600" || bad "webmail.env is $(stat -c %a $DIR/webmail.env)" +grep -q "^SESSION_FILE=$" $DIR/webmail.env && ok "sessions in memory (SESSION_FILE=)" || bad "SESSION_FILE is not empty" +$(rt) compose -f $DIR/compose.yaml ps --format '{{.Service}}' | grep -qx webmail && bad "a webmail container too" || ok "no webmail container" +curl -fsS http://127.0.0.1:8080/api/health | grep -q '"ok":true' && ok "it answers on 127.0.0.1:8080" || bad "no health on 8080" +[ "$(ss -ltnH 'sport = :8080' | awk '{print $4}')" = "127.0.0.1:8080" ] && ok "on loopback only" || bad "8080 is on $(ss -ltnH 'sport = :8080' | awk '{print $4}')" + +echo +echo "==> someone signs in to it" +USER=$(awk '/^first mailbox/ {print $3}' "$DIR/credentials.txt") +PASS=$(awk '/^first mailbox/{getline; print $2}' "$DIR/credentials.txt") +rm -f /tmp/jar +LOC=$(curl -s -o /dev/null -c /tmp/jar -w '%{redirect_url}' "http://127.0.0.1:8080/api/auth/oauth/start?username=$USER&remember=1") +grep -q "^http://127.0.0.1:8081/" <<<"$LOC" && ok "sign-in goes to the server" || bad "sign-in went to '${LOC:-nowhere}'" +q() { sed -n "s/.*[?&]$1=\([^&]*\).*/\1/p" <<<"$LOC"; } +urldecode() { printf '%b' "${1//%/\\x}"; } +STATE=$(q state); CHALLENGE=$(q code_challenge); REDIRECT=$(urldecode "$(q redirect_uri)") +ANSWER=$(curl -s -X POST http://127.0.0.1:8081/api/auth -H 'Content-Type: application/json' -H 'Accept: application/json' \ + -d "{\"type\":\"authCode\",\"accountName\":\"$USER\",\"accountSecret\":\"$PASS\",\"clientId\":\"ihasmail-inbuxa\",\"redirectUri\":\"$REDIRECT\",\"codeChallenge\":\"$CHALLENGE\",\"codeChallengeMethod\":\"S256\"}") +AUTHCODE=$(sed -n 's/.*"client_\{0,1\}[cC]ode":"\([^"]*\)".*/\1/p' <<<"$ANSWER") +BACK=$(curl -s -o /dev/null -b /tmp/jar -c /tmp/jar -w '%{redirect_url}' "$REDIRECT?code=$AUTHCODE&state=$STATE") +grep -q "signin_error" <<<"$BACK" && bad "the code exchange failed: $BACK" || ok "the webmail exchanges the code" +CODE=$(curl -s -o /tmp/login.json -b /tmp/jar -w '%{http_code}' -H 'X-Requested-With: ihasmail' http://127.0.0.1:8080/api/auth/session) +[ "$CODE" = 200 ] && grep -q "urn:ietf:params:jmap:mail" /tmp/login.json && ok "signed in, with mail" || bad "session answered $CODE" + +echo +echo "==> status, and running it again" +/tmp/inbuxa status 2>&1 | grep -q "webmail.*installed as a host" && ok "status: the webmail is a host install" || bad "status does not say so" +OUT="$(/tmp/inbuxa install --local --domain example.test --webmail host --yes 2>&1)"; rc=$? +[ $rc -eq 0 ] && ok "a second run converges" || { bad "second run exit $rc"; echo "$OUT" | tail -6 | sed 's/^/ /'; } +systemctl is-active --quiet $UNIT && ok "and the webmail is still running" || bad "the webmail stopped" + +echo +echo "==> $pass passed, $fail failed" +[ "$fail" -eq 0 ] diff --git a/e2e/vm/run.sh b/e2e/vm/run.sh index 5f3f8f2..a3459ed 100755 --- a/e2e/vm/run.sh +++ b/e2e/vm/run.sh @@ -45,6 +45,11 @@ if [ -n "${SERVER_BINARY:-}" ]; then vm_scp "$SERVER_BINARY" lab@127.0.0.1:/tmp/inbuxa-server-test >/dev/null vm_ssh 'chmod +x /tmp/inbuxa-server-test' fi +# The console's and the webmail's release tarballs, the same way, for host +# installs of them before a release carries them (INBUXA_CONSOLE_TARBALL and +# INBUXA_WEBMAIL_TARBALL in the case). +[ -z "${CONSOLE_TARBALL:-}" ] || vm_scp "$CONSOLE_TARBALL" lab@127.0.0.1:/tmp/inbuxa-console-test.tar.gz >/dev/null +[ -z "${WEBMAIL_TARBALL:-}" ] || vm_scp "$WEBMAIL_TARBALL" lab@127.0.0.1:/tmp/inbuxa-webmail-test.tar.gz >/dev/null [ -z "${OLD_REF:-}" ] || vm_scp "$LAB/inbuxa-old" lab@127.0.0.1:/tmp/inbuxa-old >/dev/null vm_scp "$ROOT/$CASE" lab@127.0.0.1:/tmp/case.sh >/dev/null vm_ssh 'chmod +x /tmp/inbuxa /tmp/case.sh; [ ! -f /tmp/inbuxa-old ] || chmod +x /tmp/inbuxa-old' diff --git a/internal/apply/apply.go b/internal/apply/apply.go index 42c147b..be4f715 100644 --- a/internal/apply/apply.go +++ b/internal/apply/apply.go @@ -24,6 +24,7 @@ import ( "math/big" "net/http" "os" + "os/exec" "path/filepath" "strings" "time" @@ -78,11 +79,6 @@ type Log interface { // it says so rather than pretending a host install of either happened. func Run(ctx context.Context, p plan.Plan, f host.Facts, log Log) (*Result, error) { o := p.Options - for _, c := range []plan.Component{plan.Console, plan.Webmail} { - if o.Shape(c) == plan.Host { - return nil, fmt.Errorf("host installs of the console and the webmail are not built yet: %s was asked for as a host install", c) - } - } if o.Shape(plan.Server) == plan.Skip { return nil, fmt.Errorf("this build installs the front ends only alongside a server it installs too; use join once that is built") } @@ -107,7 +103,9 @@ func Run(ctx context.Context, p plan.Plan, f host.Facts, log Log) (*Result, erro if needContainers && !f.Runtime.Usable { return nil, fmt.Errorf("after installing what was missing, containers still are not usable: %s", f.Runtime.Why) } - log.Info("using %s %s", f.Runtime.Kind, f.Runtime.Version) + if needContainers { + log.Info("using %s %s", f.Runtime.Kind, f.Runtime.Version) + } } dir := o.Dir @@ -124,6 +122,7 @@ func Run(ctx context.Context, p plan.Plan, f host.Facts, log Log) (*Result, erro WebmailHost: o.WebmailHost, Console: o.Shape(plan.Console) == plan.Container, Webmail: o.Shape(plan.Webmail) == plan.Container, + WebmailUnit: o.Shape(plan.Webmail) == plan.Host, Proxy: !o.Local && o.Proxy == "caddy", ServerImage: DefaultServerImage, ConsoleImage: DefaultConsoleImage, @@ -138,19 +137,19 @@ func Run(ctx context.Context, p plan.Plan, f host.Facts, log Log) (*Result, erro // Nothing is published and nothing is certified: the addresses are // the loopback binds, which is what the front ends are told to use. stack.ServerPublicURL = "http://127.0.0.1:8081" - if stack.Console { + if o.Shape(plan.Console) != plan.Skip { stack.ConsoleURL = "http://127.0.0.1:8082" } - if stack.Webmail { + if o.Shape(plan.Webmail) != plan.Skip { stack.WebmailURL = "http://127.0.0.1:8080" } } else { stack.MailPorts = []int{25, 465, 993, 995, 4190} stack.ServerPublicURL = "https://" + o.MailHost - if stack.Console { + if o.Shape(plan.Console) != plan.Skip { stack.ConsoleURL = "https://" + o.ConsoleHost } - if stack.Webmail { + if o.Shape(plan.Webmail) != plan.Skip { stack.WebmailURL = "https://" + o.WebmailHost } } @@ -188,6 +187,10 @@ func Run(ctx context.Context, p plan.Plan, f host.Facts, log Log) (*Result, erro } stack.ACMEDirectory = o.ACMEDirectory + if o.Shape(plan.Console) == plan.Host { + stack.ConsoleFiles = hostConsole{deploy: dir}.dir() + } + log.Step("writing the deployment into %s", dir) var sec compose.Secrets var err error @@ -244,6 +247,34 @@ func Run(ctx context.Context, p plan.Plan, f host.Facts, log Log) (*Result, erro log.Info("%s, %s", hostUnitPath, hs.envPath()) } + // The front ends on the host: in place before anything starts, the + // console's files because the proxy serves them from the moment it is + // up, the webmail because its unit starts with the rest of the stack. + var hw *hostWebmail + webmailEnvChanged := false + if o.Shape(plan.Webmail) != plan.Host { + // A webmail moved off the host gives its port back before a + // container wants it. + if _, err := os.Stat(webmailUnitPath); err == nil { + log.Info("stopping the webmail installed on the host, which is no longer asked for") + runQuiet(ctx, "systemctl", "disable", "--now", "--quiet", HostWebmailUnit) + } + } + if o.Shape(plan.Console) == plan.Host { + if err := (hostConsole{deploy: dir, log: log}).Install(ctx, stack.ServerPublicURL); err != nil { + return nil, err + } + } + if o.Shape(plan.Webmail) == plan.Host { + hw = &hostWebmail{deploy: dir, log: log} + if err := hw.Install(ctx); err != nil { + return nil, err + } + if webmailEnvChanged, err = hw.WriteEnv(webmailEnv(o, stack, sec, hw.Version())); err != nil { + return nil, err + } + } + // A machine that already runs this installation is converged, not set up // again. First boot happens once: bootstrap, the first administrator, the // first account, the ACME account. Running it a second time asks a @@ -252,6 +283,16 @@ func Run(ctx context.Context, p plan.Plan, f host.Facts, log Log) (*Result, erro // front end used to do, and why it could not. if existing, err := state.Load(); err == nil && existing.Installed() { res, err := converge(ctx, o, stack, cmp, hs, existing, f, log) + if err == nil && hw != nil { + // Its files may be new, or what it reads at start; or it may + // simply not be running. + active := exec.CommandContext(ctx, "systemctl", "is-active", "--quiet", HostWebmailUnit).Run() == nil + if webmailEnvChanged || !active || existing.Shapes["webmail"] != string(plan.Host) { + if err := hw.Start(ctx); err != nil { + return res, withLogs(ctx, err, hw, "webmail") + } + } + } if err == nil && !o.Local && o.Proxy == "snippets" { // What the web server is told follows what is installed here. if dir, err := compose.WriteProxySnippets(o.Dir, stack); err == nil { @@ -403,6 +444,11 @@ func Run(ctx context.Context, p plan.Plan, f host.Facts, log Log) (*Result, erro return res, err } } + if hw != nil { + if err := hw.Start(ctx); err != nil { + return res, withLogs(ctx, err, hw, "webmail") + } + } if err := waitFor(ctx, log, "the server to come back configured", 120*time.Second, func(ctx context.Context) error { _, err := srv.DomainID(ctx, o.Domain) @@ -723,7 +769,7 @@ func saveState(st *state.State, o plan.Options, f host.Facts, log Log) { } // Verify is the last step: does what was installed actually answer? -func Verify(ctx context.Context, res *Result, server, stackConsole, stackWebmail bool, log Log) []string { +func Verify(ctx context.Context, res *Result, o plan.Options, server bool, log Log) []string { var problems []string check := func(what, url string, want string) { ctx, cancel := context.WithTimeout(ctx, 10*time.Second) @@ -745,10 +791,25 @@ func Verify(ctx context.Context, res *Result, server, stackConsole, stackWebmail if server { check("the mail server", "http://127.0.0.1:8081/.well-known/jmap", "") } - if stackConsole { + switch o.Shape(plan.Console) { + case plan.Container: check("the console", "http://127.0.0.1:8082/", "api-base-url") + case plan.Host: + // Files, served by a web server that may not be loaded yet: what + // can be checked here is that they are in place and name the + // server. + index := filepath.Join(o.Dir, "console", "index.html") + b, err := os.ReadFile(index) + switch { + case err != nil: + problems = append(problems, "the console's files are missing: "+err.Error()) + case !strings.Contains(string(b), `name="api-base-url" content="`+res.ServerURL+`"`): + problems = append(problems, index+" does not point at "+res.ServerURL) + default: + log.Info("the console's files are in place, pointed at %s", res.ServerURL) + } } - if stackWebmail { + if o.Shape(plan.Webmail) != plan.Skip { check("the webmail", "http://127.0.0.1:8080/api/health", "\"ok\":true") } return problems diff --git a/internal/apply/frontends.go b/internal/apply/frontends.go new file mode 100644 index 0000000..49cf178 --- /dev/null +++ b/internal/apply/frontends.go @@ -0,0 +1,337 @@ +// SPDX-FileCopyrightText: 2026 Coffey Labs LLC +// SPDX-License-Identifier: AGPL-3.0-or-later + +package apply + +// The console and the webmail on the host, beside a server in a container, +// on the host, or (later) elsewhere. +// +// The console is static files: unpacked into /console, given the +// server's address the way its image's entrypoint does, and served by the +// managed Caddy or by the operator's web server from the configuration +// written for it. Nothing runs. +// +// The webmail is the /app its image runs, on the installer's own Node, under +// a unit of its own, as a user of its own that can't write a byte of its own +// files -- which is what its IMMUTABLE setting checks for, as a read-only +// container root would give it. + +import ( + "context" + "fmt" + "net/http" + "os" + "os/exec" + "path/filepath" + "regexp" + "runtime" + "sort" + "strings" + "time" + + "git.coffeylabs.org/inbuxa/inbuxa-installer/internal/compose" + "git.coffeylabs.org/inbuxa/inbuxa-installer/internal/deps" + "git.coffeylabs.org/inbuxa/inbuxa-installer/internal/host" + "git.coffeylabs.org/inbuxa/inbuxa-installer/internal/plan" + "git.coffeylabs.org/inbuxa/inbuxa-installer/internal/release" +) + +const ( + HostWebmailUnit = "inbuxa-webmail.service" + HostWebmailUser = "inbuxa-webmail" + + webmailUnitPath = "/etc/systemd/system/" + HostWebmailUnit + releaseMarker = ".inbuxa-release" // what was unpacked, so a converge can skip it +) + +// fetchRelease puts a release tarball at a temporary path: the file named by +// the override variable when it is set (a build to test, said loudly), or +// the release download, checked against its pinned checksum. +func fetchRelease(ctx context.Context, log Log, what, override, url, sum string) (path, marker string, cleanup func(), err error) { + if p := os.Getenv(override); p != "" { + log.Info("%s from %s instead of the release, as %s says (no checksum)", what, p, override) + return p, "local:" + p, func() {}, nil + } + if sum == "" { + return "", "", nil, fmt.Errorf("there is no %s release with files to install for %s", what, runtime.GOARCH) + } + work, err := os.MkdirTemp("", "inbuxa-"+what+"-") + if err != nil { + return "", "", nil, err + } + cleanup = func() { os.RemoveAll(work) } + path = filepath.Join(work, what+".tar.gz") + if err := deps.FetchVerified(ctx, log.Out(), url, sum, path, 0o644); err != nil { + cleanup() + return "", "", nil, err + } + return path, sum, cleanup, nil +} + +// unpack replaces dest with the tarball's contents, owned by root and +// readable by everyone, and only once they are all there: a failure part way +// leaves the previous version in place. +func unpack(ctx context.Context, tarball, dest, marker string) error { + next, old := dest+".new", dest+".old" + os.RemoveAll(next) + os.RemoveAll(old) + if err := os.MkdirAll(next, 0o755); err != nil { + return err + } + if err := runQuiet(ctx, "tar", "-xzf", tarball, "-C", next, "--no-same-owner"); err != nil { + os.RemoveAll(next) + return fmt.Errorf("unpacking %s: %w", filepath.Base(tarball), err) + } + if err := runQuiet(ctx, "chmod", "-R", "u=rwX,go=rX", next); err != nil { + return err + } + if err := os.WriteFile(filepath.Join(next, releaseMarker), []byte(marker+"\n"), 0o644); err != nil { + return err + } + if _, err := os.Stat(dest); err == nil { + if err := os.Rename(dest, old); err != nil { + return err + } + } + if err := os.Rename(next, dest); err != nil { + return err + } + return os.RemoveAll(old) +} + +func unpacked(dest, marker string) bool { + b, err := os.ReadFile(filepath.Join(dest, releaseMarker)) + return err == nil && strings.TrimSpace(string(b)) == marker && !strings.HasPrefix(marker, "local:") +} + +// ---- the console ---- + +type hostConsole struct { + deploy string + log Log +} + +func (c hostConsole) dir() string { return filepath.Join(c.deploy, "console") } + +var apiBaseMeta = regexp.MustCompile(`]*>`) + +// Install puts the console's files in place and points them at the server. +func (c hostConsole) Install(ctx context.Context, serverURL string) error { + marker := release.ConsoleSHA256 + if os.Getenv("INBUXA_CONSOLE_TARBALL") != "" { + marker = "local:" + os.Getenv("INBUXA_CONSOLE_TARBALL") + } + if !unpacked(c.dir(), marker) { + c.log.Step("installing the console's files") + path, mark, cleanup, err := fetchRelease(ctx, c.log, "console", "INBUXA_CONSOLE_TARBALL", release.ConsoleTarball(), release.ConsoleSHA256) + if err != nil { + return err + } + defer cleanup() + if err := os.MkdirAll(c.deploy, 0o750); err != nil { + return err + } + if err := unpack(ctx, path, c.dir(), mark); err != nil { + return err + } + } + if err := setAPIBase(filepath.Join(c.dir(), "index.html"), serverURL); err != nil { + return err + } + // The web server reads them, whoever it runs as. + if err := os.Chmod(c.deploy, 0o711); err != nil { + return err + } + c.log.Info("%s, pointed at %s", c.dir(), serverURL) + return nil +} + +// setAPIBase does what the console image's entrypoint does at start: names +// the server the page talks to, in a meta tag, replacing one that is there. +func setAPIBase(index, url string) error { + b, err := os.ReadFile(index) + if err != nil { + return fmt.Errorf("the console's index.html: %w", err) + } + tag := `` + html := string(b) + if apiBaseMeta.MatchString(html) { + html = apiBaseMeta.ReplaceAllLiteralString(html, tag) + } else { + html = strings.Replace(html, "", ""+tag, 1) + } + return os.WriteFile(index, []byte(html), 0o644) +} + +// ---- the webmail ---- + +type hostWebmail struct { + deploy string + log Log +} + +func (w hostWebmail) dir() string { return filepath.Join(w.deploy, "webmail") } +func (w hostWebmail) envPath() string { return filepath.Join(w.deploy, "webmail.env") } + +// Install puts the webmail's files, its user and its unit in place. It does +// not start it: it can only sign anyone in once the server is set up. +func (w hostWebmail) Install(ctx context.Context) error { + arch := runtime.GOARCH + marker := release.WebmailSHA256[arch] + if os.Getenv("INBUXA_WEBMAIL_TARBALL") != "" { + marker = "local:" + os.Getenv("INBUXA_WEBMAIL_TARBALL") + } + if !unpacked(w.dir(), marker) { + w.log.Step("installing the webmail on this machine") + path, mark, cleanup, err := fetchRelease(ctx, w.log, "webmail", "INBUXA_WEBMAIL_TARBALL", release.WebmailTarball(arch), release.WebmailSHA256[arch]) + if err != nil { + return err + } + defer cleanup() + if err := os.MkdirAll(w.deploy, 0o750); err != nil { + return err + } + if err := unpack(ctx, path, w.dir(), mark); err != nil { + return err + } + w.log.Info("%s (owned by root: the webmail reads it and can't change it)", w.dir()) + } + if err := exec.CommandContext(ctx, "getent", "passwd", HostWebmailUser).Run(); err != nil { + if err := runQuiet(ctx, "useradd", "--system", "--user-group", "--no-create-home", + "--home-dir", w.dir(), "--shell", nologin(), HostWebmailUser); err != nil { + return fmt.Errorf("creating the %s user: %w", HostWebmailUser, err) + } + w.log.Info("user %s (system, no login)", HostWebmailUser) + } + if err := os.Chmod(w.deploy, 0o711); err != nil { + return err + } + return w.writeUnit(ctx) +} + +// Version is what the unpacked webmail says it is, which it reports as +// IHASMAIL_VERSION, as its image does. +func (w hostWebmail) Version() string { + b, _ := os.ReadFile(filepath.Join(w.dir(), "VERSION")) + return strings.TrimSpace(string(b)) +} + +// WriteEnv writes the webmail's environment, the same as its container's, +// and says whether it changed. Empty values are written: SESSION_FILE= is how +// the webmail is told to keep sessions in memory only. +func (w hostWebmail) WriteEnv(vars map[string]string) (bool, error) { + keys := make([]string, 0, len(vars)) + for k := range vars { + keys = append(keys, k) + } + sort.Strings(keys) + var b strings.Builder + b.WriteString("# Written by the inbuxa installer: the webmail's environment.\n") + b.WriteString("# Read by " + HostWebmailUnit + " at each start.\n") + for _, k := range keys { + fmt.Fprintf(&b, "%s=%s\n", k, vars[k]) + } + return writeIfChanged(w.envPath(), b.String(), 0o600) +} + +func (w hostWebmail) writeUnit(ctx context.Context) error { + unit := fmt.Sprintf(`# Written by the inbuxa installer. Changes here are replaced on its next run. +[Unit] +Description=inbuxa webmail +Documentation=https://docs.inbuxa.org/ +After=network-online.target inbuxa-server.service +Wants=network-online.target + +[Service] +Type=simple +User=%s +Group=%s +EnvironmentFile=%s +ExecStart=%s %s/server/dist/index.js +WorkingDirectory=%s +# It writes nothing: sessions are in memory (SESSION_FILE= in its +# environment), and its own files are root's. +NoNewPrivileges=true +ProtectSystem=strict +ProtectHome=true +PrivateTmp=true +PrivateDevices=true +Restart=on-failure +RestartSec=5 + +[Install] +WantedBy=multi-user.target +`, HostWebmailUser, HostWebmailUser, w.envPath(), host.OwnPath, w.dir(), w.dir()) + changed, err := writeIfChanged(webmailUnitPath, unit, 0o644) + if err != nil { + return err + } + if changed { + if err := runQuiet(ctx, "systemctl", "daemon-reload"); err != nil { + return err + } + } + return runQuiet(ctx, "systemctl", "enable", "--quiet", HostWebmailUnit) +} + +// Start (re)starts the webmail and waits for it to say it is healthy. +func (w hostWebmail) Start(ctx context.Context) error { + if err := runQuiet(ctx, "systemctl", "restart", HostWebmailUnit); err != nil { + return err + } + return waitFor(ctx, w.log, "the webmail", 60*time.Second, func(ctx context.Context) error { + req, _ := http.NewRequestWithContext(ctx, http.MethodGet, "http://127.0.0.1:8080/api/health", nil) + resp, err := (&http.Client{Timeout: 5 * time.Second}).Do(req) + if err != nil { + return err + } + resp.Body.Close() + if resp.StatusCode != http.StatusOK { + return fmt.Errorf("answered %s", resp.Status) + } + return nil + }) +} + +// Logs is the webmail's last lines from the journal. +func (w hostWebmail) Logs(ctx context.Context, _ string, lines int) string { + out, _ := exec.CommandContext(ctx, "journalctl", "-u", HostWebmailUnit, + "-n", fmt.Sprint(lines), "--no-pager", "-o", "cat").CombinedOutput() + return string(out) +} + +// webmailEnv is the webmail's environment on the host: what its compose +// service is given, plus what its image bakes in (NODE_ENV, STATIC_DIR, its +// version). It listens on loopback only, where the proxy reaches it, and +// reaches a server on this machine at its loopback port whichever shape the +// server is. +func webmailEnv(o plan.Options, stack compose.Stack, sec compose.Secrets, version string) map[string]string { + server := "http://127.0.0.1:8081" + if stack.RemoteServerURL != "" { + server = strings.TrimRight(stack.RemoteServerURL, "/") + } + env := map[string]string{ + "NODE_ENV": "production", + "HOST": "127.0.0.1", + "PORT": "8080", + "STATIC_DIR": filepath.Join(o.Dir, "webmail", "web", "dist"), + "IHASMAIL_VERSION": version, + "MAIL_SERVER_URL": server, + "APP_SECRET": sec.AppSecret, + "APP_NAME": "inbuxa", + "IMMUTABLE": "1", + "SESSION_FILE": "", + "TRUST_PROXY": "1", + "IMAGE_PROXY": "1", + "OAUTH_CLIENT_ID": "ihasmail-inbuxa", + "OAUTH_CLIENT_SECRET": sec.WebmailOAuth, + "PUBLIC_URL": stack.WebmailURL, + } + if stack.ConsoleURL != "" { + env["ADMIN_URL"] = stack.ConsoleURL + } + if !o.Local { + env["PUSH_URL"] = stack.WebmailURL + } + return env +} diff --git a/internal/apply/frontends_test.go b/internal/apply/frontends_test.go new file mode 100644 index 0000000..b012e1a --- /dev/null +++ b/internal/apply/frontends_test.go @@ -0,0 +1,90 @@ +// SPDX-FileCopyrightText: 2026 Coffey Labs LLC +// SPDX-License-Identifier: AGPL-3.0-or-later + +package apply + +import ( + "context" + "os" + "os/exec" + "path/filepath" + "strings" + "testing" + + "git.coffeylabs.org/inbuxa/inbuxa-installer/internal/compose" + "git.coffeylabs.org/inbuxa/inbuxa-installer/internal/plan" +) + +func TestSetAPIBaseReplacesOrInserts(t *testing.T) { + dir := t.TempDir() + index := filepath.Join(dir, "index.html") + os.WriteFile(index, []byte(`x`), 0o644) + if err := setAPIBase(index, "https://mail.example.org"); err != nil { + t.Fatal(err) + } + b, _ := os.ReadFile(index) + if strings.Count(string(b), "api-base-url") != 1 || !strings.Contains(string(b), `content="https://mail.example.org"`) { + t.Errorf("replace: %s", b) + } + os.WriteFile(index, []byte(`x`), 0o644) + setAPIBase(index, "https://mail.example.org") + b, _ = os.ReadFile(index) + if !strings.Contains(string(b), ``) { + t.Errorf("insert: %s", b) + } +} + +func TestTheWebmailOnTheHostReachesALocalServerOnLoopback(t *testing.T) { + o := plan.Options{Dir: "/var/lib/inbuxa", Domain: "example.org"} + s := compose.Stack{Server: true, WebmailURL: "https://webmail.example.org", ConsoleURL: "https://admin.example.org"} + env := webmailEnv(o, s, compose.Secrets{AppSecret: "a", WebmailOAuth: "w"}, "2026.10.12+gabc") + for k, want := range map[string]string{ + "MAIL_SERVER_URL": "http://127.0.0.1:8081", "HOST": "127.0.0.1", "PORT": "8080", + "STATIC_DIR": "/var/lib/inbuxa/webmail/web/dist", "IHASMAIL_VERSION": "2026.10.12+gabc", + "OAUTH_CLIENT_SECRET": "w", "PUSH_URL": "https://webmail.example.org", "ADMIN_URL": "https://admin.example.org", + "IMMUTABLE": "1", + } { + if env[k] != want { + t.Errorf("%s = %q, want %q", k, env[k], want) + } + } + if v, ok := env["SESSION_FILE"]; !ok || v != "" { + t.Error("SESSION_FILE must be there and empty: sessions in memory") + } + s.RemoteServerURL = "https://mail.example.org/" + if got := webmailEnv(o, s, compose.Secrets{}, "")["MAIL_SERVER_URL"]; got != "https://mail.example.org" { + t.Errorf("joined: MAIL_SERVER_URL = %q", got) + } +} + +func TestUnpackReplacesOnlyWhenComplete(t *testing.T) { + work := t.TempDir() + src := filepath.Join(work, "src") + os.MkdirAll(filepath.Join(src, "sub"), 0o755) + os.WriteFile(filepath.Join(src, "sub", "f"), []byte("new"), 0o600) + tarball := filepath.Join(work, "t.tar.gz") + if out, err := exec.Command("tar", "-czf", tarball, "-C", src, ".").CombinedOutput(); err != nil { + t.Fatal(string(out)) + } + dest := filepath.Join(work, "dest") + os.MkdirAll(dest, 0o755) + os.WriteFile(filepath.Join(dest, "old"), []byte("old"), 0o644) + if err := unpack(context.Background(), tarball, dest, "abc"); err != nil { + t.Fatal(err) + } + if _, err := os.Stat(filepath.Join(dest, "old")); err == nil { + t.Error("the previous version's files survived") + } + if fi, err := os.Stat(filepath.Join(dest, "sub", "f")); err != nil || fi.Mode().Perm()&0o044 != 0o044 { + t.Errorf("not readable by all: %v %v", fi, err) + } + if !unpacked(dest, "abc") || unpacked(dest, "def") { + t.Error("the release marker is wrong") + } + if err := unpack(context.Background(), filepath.Join(work, "missing.tar.gz"), dest, "zzz"); err == nil { + t.Error("a bad tarball was accepted") + } + if !unpacked(dest, "abc") { + t.Error("a failed unpack disturbed what was there") + } +} diff --git a/internal/apply/join.go b/internal/apply/join.go index 90da312..5279fee 100644 --- a/internal/apply/join.go +++ b/internal/apply/join.go @@ -88,7 +88,7 @@ func Join(ctx context.Context, p plan.Plan, f host.Facts, key string, log Log) ( } for _, c := range []plan.Component{plan.Console, plan.Webmail} { if o.Shape(c) == plan.Host { - return nil, fmt.Errorf("host installs of the console and the webmail are not built yet: %s was asked for as a host install", c) + return nil, fmt.Errorf("join installs the console and the webmail in containers for now: %s was asked for as a host install", c) } } if o.Shape(plan.Console) == plan.Skip && o.Shape(plan.Webmail) == plan.Skip { @@ -276,7 +276,11 @@ func JoinVerify(ctx context.Context, res *Result, console, webmail bool, log Log return nil }) } - problems := Verify(ctx, res, false, console, webmail, log) + o := plan.Options{Dir: res.Dir, Choices: []plan.Choice{ + {Component: plan.Console, Shape: map[bool]plan.Shape{true: plan.Container, false: plan.Skip}[console]}, + {Component: plan.Webmail, Shape: map[bool]plan.Shape{true: plan.Container, false: plan.Skip}[webmail]}, + }} + problems := Verify(ctx, res, o, false, log) if console { ctx, cancel := context.WithTimeout(ctx, 10*time.Second) defer cancel() diff --git a/internal/compose/compose.go b/internal/compose/compose.go index 7a07159..bd836f0 100644 --- a/internal/compose/compose.go +++ b/internal/compose/compose.go @@ -51,6 +51,13 @@ type Stack struct { // only the browser talks to the server from it. HostServer bool + // ConsoleFiles is where the console's files are when it is installed on + // the host rather than run as a container: a web server serves the + // directory. WebmailUnit is the webmail as a systemd unit on this + // machine, listening on 127.0.0.1:8080. + ConsoleFiles string + WebmailUnit bool + // RemoteServerURL is a mail server on another machine, which the front // ends here were joined to (`inbuxa join`). Nothing here serves its // names; the webmail reaches it at this address. @@ -151,12 +158,18 @@ func Write(dir string, s *Stack) (Secrets, error) { if err := s.Addresses(); err != nil { return sec, err } - if s.HostServer { + switch { + case s.HostServer: // Everything that talks to the server is on the host's network and // arrives from loopback, which is the address the server is told to // exempt from the auto-ban. s.WebmailIP, s.CaddyIP = "127.0.0.1", "127.0.0.1" - } else if s.WebmailOnHost() { + case s.WebmailUnit: + // A server in a container is reached from the host at its published + // loopback port, and sees those requests come from the project + // network's gateway. + s.WebmailIP, s.CaddyIP = s.GatewayIP, s.GatewayIP + case s.WebmailOnHost(): s.WebmailIP = "127.0.0.1" } @@ -246,6 +259,14 @@ func (s Stack) WebmailServerURL() string { return "http://server:8080" } +// CaddyOnHost is whether the managed Caddy shares the host's network: when +// something it proxies listens on the host's loopback, outside the project. +func (s Stack) CaddyOnHost() bool { return s.HostServer || s.WebmailUnit } + +// ServesWebmail is whether there is a webmail here for a proxy to serve, in +// either shape. +func (s Stack) ServesWebmail() bool { return s.Webmail || s.WebmailUnit } + // ServesServer is whether Caddy here serves the mail server's names: not when // the server is on another machine, whose own proxy does. func (s Stack) ServesServer() bool { return s.Server || s.HostServer } @@ -268,7 +289,7 @@ func isLoopback(url string) bool { } func (s Stack) pick(project, host string) string { - if s.HostServer { + if s.CaddyOnHost() { return host } return project diff --git a/internal/compose/compose_test.go b/internal/compose/compose_test.go index 9a6b694..657515e 100644 --- a/internal/compose/compose_test.go +++ b/internal/compose/compose_test.go @@ -171,3 +171,37 @@ func TestProxySnippetsLeaveOutWhatIsNotHere(t *testing.T) { t.Error("a webmail that isn't installed is in the nginx configuration") } } + +func TestFrontEndsOnTheHost(t *testing.T) { + s := stack(false) // the server in a container + s.Console, s.Webmail = false, false + s.ConsoleFiles, s.WebmailUnit = "/var/lib/inbuxa/console", true + c, k := render(t, s) + for _, bad := range []string{"\n console:\n", "\n webmail:\n"} { + if strings.Contains(c, bad) { + t.Errorf("compose.yaml still runs %q", bad) + } + } + for _, want := range []string{"network_mode: host", "/var/lib/inbuxa/console:/srv/console:ro", "\n server:\n"} { + if !strings.Contains(c, want) { + t.Errorf("compose.yaml lacks %q", want) + } + } + for _, want := range []string{"root * /srv/console", "try_files {path} /index.html", "file_server", "reverse_proxy 127.0.0.1:8080", "reverse_proxy 127.0.0.1:8081"} { + if !strings.Contains(k, want) { + t.Errorf("Caddyfile lacks %q", want) + } + } + // A server in a container sees host processes at the gateway + if s.WebmailIP != "172.31.253.1" || s.CaddyIP != "172.31.253.1" { + t.Errorf("exempts %s and %s, not the gateway", s.WebmailIP, s.CaddyIP) + } + out, err := WriteProxySnippets(t.TempDir(), *s) + if err != nil { + t.Fatal(err) + } + nginx, _ := os.ReadFile(filepath.Join(out, "nginx-inbuxa.conf")) + if !strings.Contains(string(nginx), "root /var/lib/inbuxa/console;") || !strings.Contains(string(nginx), "proxy_pass http://127.0.0.1:8080;") { + t.Errorf("nginx-inbuxa.conf:\n%s", nginx) + } +} diff --git a/internal/compose/templates/Caddyfile.fragment.tmpl b/internal/compose/templates/Caddyfile.fragment.tmpl index 76807e2..9503cc7 100644 --- a/internal/compose/templates/Caddyfile.fragment.tmpl +++ b/internal/compose/templates/Caddyfile.fragment.tmpl @@ -41,7 +41,20 @@ reverse_proxy 127.0.0.1:8082 } {{- end}} -{{- if .Webmail}} +{{- if .ConsoleFiles}} + +# The console, installed on this machine as files. +{{.ConsoleHost}} { + encode zstd gzip + root * {{.ConsoleFiles}} + try_files {path} /index.html + header /assets/* Cache-Control "public, max-age=31536000, immutable" + @page not path /assets/* + header @page Cache-Control "no-cache" + file_server +} +{{- end}} +{{- if .ServesWebmail}} {{.WebmailHost}} { encode zstd gzip diff --git a/internal/compose/templates/Caddyfile.tmpl b/internal/compose/templates/Caddyfile.tmpl index 6e98c02..901cde0 100644 --- a/internal/compose/templates/Caddyfile.tmpl +++ b/internal/compose/templates/Caddyfile.tmpl @@ -19,7 +19,7 @@ acme_ca_root /etc/caddy/acme-ca-root.pem {{- end}} } -{{- if .Webmail}} +{{- if .ServesWebmail}} # The webmail. Push arrives as Server-Sent Events, so responses are flushed as # they are written rather than buffered. @@ -39,6 +39,21 @@ reverse_proxy {{.ConsoleUpstream}} } {{- end}} +{{- if .ConsoleFiles}} + +# The console, installed on this machine as files and served from them: a +# single-page app, so any path that is not a file is the app's own route. +# Hashed assets are cached for a year; index.html, which names them, never. +{{.ConsoleHost}} { + encode zstd gzip + root * /srv/console + try_files {path} /index.html + header /assets/* Cache-Control "public, max-age=31536000, immutable" + @page not path /assets/* + header @page Cache-Control "no-cache" + file_server +} +{{- end}} {{- if .ServesServer}} diff --git a/internal/compose/templates/compose.yaml.tmpl b/internal/compose/templates/compose.yaml.tmpl index 4e36399..4eb0ecb 100644 --- a/internal/compose/templates/compose.yaml.tmpl +++ b/internal/compose/templates/compose.yaml.tmpl @@ -147,7 +147,7 @@ services: {{- if .Server}} depends_on: [server] {{- end}} -{{- if .HostServer}} +{{- if .CaddyOnHost}} # On the host's network: it holds 80 and 443 itself, and reaches the # server, the webmail and the console on loopback. network_mode: host @@ -161,16 +161,20 @@ services: - ./Caddyfile:/etc/caddy/Caddyfile:ro - caddy-data:/data - caddy-config:/config +{{- if .ConsoleFiles}} + # The console, installed on the host as files, served from here. + - {{.ConsoleFiles}}:/srv/console:ro +{{- end}} {{- if .ACMECARoot}} - ./acme-ca-root.pem:/etc/caddy/acme-ca-root.pem:ro {{- end}} -{{- if not .HostServer}} +{{- if not .CaddyOnHost}} networks: stack: ipv4_address: {{.CaddyIP}} {{- end}} {{- end}} -{{- if or .Server .Console (and .Webmail (not .WebmailOnHost)) (and .Proxy (not .HostServer))}} +{{- if or .Server .Console (and .Webmail (not .WebmailOnHost)) (and .Proxy (not .CaddyOnHost))}} networks: stack: diff --git a/internal/compose/templates/nginx-inbuxa.conf.tmpl b/internal/compose/templates/nginx-inbuxa.conf.tmpl index 49bef25..83f9698 100644 --- a/internal/compose/templates/nginx-inbuxa.conf.tmpl +++ b/internal/compose/templates/nginx-inbuxa.conf.tmpl @@ -59,7 +59,7 @@ server { } } {{- end}} -{{- if .Console}} +{{- if or .Console .ConsoleFiles}} # The console: static files. It talks to the mail server from the browser, # so nothing here proxies the API. @@ -78,13 +78,30 @@ server { ssl_certificate /etc/ssl/inbuxa/{{.ConsoleHost}}.fullchain.pem; ssl_certificate_key /etc/ssl/inbuxa/{{.ConsoleHost}}.key.pem; +{{- if .ConsoleFiles}} + # Installed on this machine as files: served from them. Any path that + # is not a file is the app's own route; hashed assets are cached for a + # year, and index.html, which names them, never. + root {{.ConsoleFiles}}; + location / { + try_files $uri $uri/ /index.html; + } + location /assets/ { + expires 1y; + add_header Cache-Control "public, immutable"; + } + location = /index.html { + add_header Cache-Control "no-cache"; + } +{{- else}} location / { proxy_pass http://127.0.0.1:8082; proxy_set_header Host $host; } +{{- end}} } {{- end}} -{{- if .Webmail}} +{{- if .ServesWebmail}} # The webmail. Push arrives as Server-Sent Events: flushed as written, and # held open. diff --git a/internal/deps/deps.go b/internal/deps/deps.go index f812e52..08114ae 100644 --- a/internal/deps/deps.go +++ b/internal/deps/deps.go @@ -47,7 +47,8 @@ import ( // commit: the pair is the point. const ( composeVersion = "v5.5.1" - nodeVersion = "v22.23.2" + nodeVersion = "v26.11.1" // the webmail's image runs Node 26 + NodeMajor = 26 ) var composeSHA = map[string]string{ @@ -56,8 +57,8 @@ var composeSHA = map[string]string{ } var nodeSHA = map[string]string{ - "amd64": "d60acfe00a2932254bb0ad20e01b0d74397a0875595de719654b214f4b03f307", - "arm64": "fff4078c5def658577f92c88db7db3bc0072924bfb93fe52c1e744a54e94abb8", + "amd64": "3883bfc73f9a680ca4eab04b196068aaaab1373ffa77d8fc1a4408222495b651", + "arm64": "0945e2cde6aa0f54d980f03874dfe5cf3a549ce714c7fb9019e591ce0accf282", } // Need is one missing thing, and what the installer would do about it. @@ -82,7 +83,10 @@ func For(f host.Facts, wantContainers, wantHostWebmail bool) []Need { if wantContainers { needs = append(needs, runtimeNeeds(f)...) } - if wantHostWebmail && (!f.Node.Present || f.Node.Major < 22) { + // The webmail on the host runs on the installer's own Node, in + // /opt/inbuxa/node, whatever else the machine has: the version it was + // released against, and nothing the system's package manager can move. + if wantHostWebmail && (f.Node.Path != host.OwnPath || f.Node.Major != NodeMajor) { needs = append(needs, nodeNeed(f)) } var out []Need @@ -233,6 +237,11 @@ func nodeNeed(f host.Facts) Need { if err := fetchVerified(ctx, log, url, sum, tmp, 0o644); err != nil { return err } + // A different version unpacked over the old one would leave + // the old one's files behind it. + if err := os.RemoveAll("/opt/inbuxa/node"); err != nil { + return err + } if err := os.MkdirAll("/opt/inbuxa/node", 0o755); err != nil { return err } diff --git a/internal/discover/discover.go b/internal/discover/discover.go index e0c9f93..060e3e0 100644 --- a/internal/discover/discover.go +++ b/internal/discover/discover.go @@ -28,15 +28,17 @@ import ( // Found is what this machine turns out to be running. type Found struct { - Dir string // the deployment directory, when there is one - Domain string // read back from the deployment - MailHost string // - Services map[string]string // component -> running|stopped|absent - Compose []string // services the compose file declares - Runtime string // what is running them - Proxy bool // the deployment includes a proxy - Credential bool // credentials.txt is there - HostServer bool // the server runs on the host, under systemd + Dir string // the deployment directory, when there is one + Domain string // read back from the deployment + MailHost string // + Services map[string]string // component -> running|stopped|absent + Compose []string // services the compose file declares + Runtime string // what is running them + Proxy bool // the deployment includes a proxy + Credential bool // credentials.txt is there + HostServer bool // the server runs on the host, under systemd + HostConsole bool // the console is files on the host + HostWebmail bool // the webmail runs on the host, under systemd } // HostServerUnit is the unit a host install of the server runs as. @@ -48,10 +50,17 @@ const ( // HostServer is whether the server is installed here as a host install, and // whether systemd has it running. func HostServer(ctx context.Context) (installed, active bool) { - if _, err := os.Stat(HostServerUnitPath); err != nil { + return hostUnit(ctx, HostServerUnit) +} + +// HostWebmailUnit is the unit a host install of the webmail runs as. +const HostWebmailUnit = "inbuxa-webmail.service" + +func hostUnit(ctx context.Context, unit string) (installed, active bool) { + if _, err := os.Stat("/etc/systemd/system/" + unit); err != nil { return false, false } - return true, exec.CommandContext(ctx, "systemctl", "is-active", "--quiet", HostServerUnit).Run() == nil + return true, exec.CommandContext(ctx, "systemctl", "is-active", "--quiet", unit).Run() == nil } // Dirs are where a deployment may be. The first is what this installer @@ -74,6 +83,10 @@ func Run(ctx context.Context, f host.Facts, dirs ...string) Found { found.HostServer = true found.Services["server"] = map[bool]string{true: "running", false: "stopped"}[active] } + if installed, active := hostUnit(ctx, HostWebmailUnit); installed { + found.HostWebmail = true + found.Services["webmail"] = map[bool]string{true: "running", false: "stopped"}[active] + } for _, dir := range dirs { for _, marker := range []string{"compose.yaml", "server.env"} { if _, err := os.Stat(filepath.Join(dir, marker)); err == nil && found.Dir == "" { @@ -88,6 +101,11 @@ func Run(ctx context.Context, f host.Facts, dirs ...string) Found { if _, err := os.Stat(filepath.Join(found.Dir, "credentials.txt")); err == nil { found.Credential = true } + // The console on the host is files: in place is all it can be. + if _, err := os.Stat(filepath.Join(found.Dir, "console", "index.html")); err == nil { + found.HostConsole = true + found.Services["console"] = "running" + } b, err := os.ReadFile(filepath.Join(found.Dir, "compose.yaml")) if err != nil { diff --git a/internal/plan/plan.go b/internal/plan/plan.go index 0763347..2a1f2e9 100644 --- a/internal/plan/plan.go +++ b/internal/plan/plan.go @@ -10,7 +10,10 @@ package plan import ( + "errors" "fmt" + "os" + "path/filepath" "runtime" "strings" @@ -184,10 +187,22 @@ func Available(f host.Facts, c Component, s Shape) Availability { } return Availability{OK: true} case Console: - return Availability{Why: "not built yet: the console runs in a container for now"} + // Static files a web server serves: nothing runs, nothing to check + // on the machine but that there are files to install. + if release.ConsoleSHA256 == "" && os.Getenv("INBUXA_CONSOLE_TARBALL") == "" { + return Availability{Why: "no console release with files to install yet; run the console as a container"} + } + return Availability{OK: true} case Webmail: - // Phase 2: a unit with a pinned Node (deps already fetches one). - return Availability{Why: "not built yet: the webmail runs in a container for now"} + if _, ok := release.WebmailSHA256[runtime.GOARCH]; !ok && os.Getenv("INBUXA_WEBMAIL_TARBALL") == "" { + return Availability{Why: "no webmail release with files to install yet for " + runtime.GOARCH + "; run the webmail as a container"} + } + // Its own Node, which the installer fetches (deps): missing is an + // offer, not a refusal. + if f.Node.Path != host.OwnPath || f.Node.Major != deps.NodeMajor { + return Availability{Why: fmt.Sprintf("the webmail runs on the installer's own Node %d, in %s, which isn't there yet", deps.NodeMajor, filepath.Dir(filepath.Dir(host.OwnPath)))} + } + return Availability{OK: true} } } return Availability{Why: "unknown shape"} @@ -235,6 +250,12 @@ func Build(f host.Facts, o Options) (Plan, error) { if chosen == 0 { return p, fmt.Errorf("nothing chosen: pick at least one component") } + // The console on the host is files, and files need a web server: the + // managed Caddy, or yours with the configuration written for it. + if o.Shape(Console) == Host && (o.Local || o.Proxy == "none") { + return p, errors.New("the console on the host is static files, served by a web server: choose --proxy caddy or --proxy snippets, or run the console as a container" + + map[bool]string{true: " (a loopback evaluation has no web server)", false: ""}[o.Local]) + } // The proxy the installer manages is Caddy in a container, whatever the // server is: a server on the host still needs a runtime for it. if !o.Local && o.Proxy == "caddy" { @@ -342,8 +363,8 @@ func Build(f host.Facts, o Options) (Plan, error) { p.Steps = append(p.Steps, Step{ Title: "Install the console on this machine", Detail: []string{ - "files: " + o.Dir + "/console (static, served by the proxy)", - "no service: it is a page, not a program", + fmt.Sprintf("files: %s/console, from console release %s, checked against its pinned checksum", o.Dir, or(release.ConsoleVersion, "(a local tarball)")), + "served by " + map[string]string{"caddy": "the managed Caddy", "snippets": "your web server, from the configuration written for it"}[o.Proxy] + "; no service of its own: it is a page, not a program", }, }) } @@ -364,9 +385,10 @@ func Build(f host.Facts, o Options) (Plan, error) { p.Steps = append(p.Steps, Step{ Title: "Install the webmail on this machine", Detail: []string{ - "files: " + o.Dir + "/webmail, from the release tarball", + fmt.Sprintf("files: %s/webmail, from webmail release %s, checked against its pinned checksum; owned by root, read-only to the webmail", o.Dir, or(release.WebmailVersion, "(a local tarball)")), + fmt.Sprintf("Node %d: the installer's own, in /opt/inbuxa/node", deps.NodeMajor), "user: inbuxa-webmail (system, no login)", - "unit: /etc/systemd/system/inbuxa-webmail.service, listening on 127.0.0.1:8080", + "unit: /etc/systemd/system/inbuxa-webmail.service, listening on 127.0.0.1:8080; its environment in " + o.Dir + "/webmail.env", }, }) } @@ -552,3 +574,10 @@ func joinInts(n []int) string { } return strings.Join(out, ", ") } + +func or(a, b string) string { + if a != "" { + return a + } + return b +} diff --git a/internal/plan/plan_test.go b/internal/plan/plan_test.go new file mode 100644 index 0000000..23658d1 --- /dev/null +++ b/internal/plan/plan_test.go @@ -0,0 +1,71 @@ +// SPDX-FileCopyrightText: 2026 Coffey Labs LLC +// SPDX-License-Identifier: AGPL-3.0-or-later + +package plan + +import ( + "strings" + "testing" + + "git.coffeylabs.org/inbuxa/inbuxa-installer/internal/host" +) + +func machine() host.Facts { + return host.Facts{ + Root: true, Systemd: true, + Runtime: host.Runtime{Kind: "docker", Present: true, Usable: true, Compose: "v2"}, + Glibc: host.Glibc{Version: "2.41", Major: 2, Minor: 41}, + Node: host.Node{Present: true, Path: host.OwnPath, Version: "26.11.1", Major: 26}, + } +} + +func shapes(server, console, webmail Shape) []Choice { + return []Choice{{Server, server}, {Console, console}, {Webmail, webmail}} +} + +func TestTheConsoleOnTheHostNeedsAWebServer(t *testing.T) { + t.Setenv("INBUXA_CONSOLE_TARBALL", "/tmp/console.tar.gz") + f := machine() + for _, tc := range []struct { + local bool + proxy string + ok bool + }{ + {false, "caddy", true}, {false, "snippets", true}, {false, "none", false}, {true, "", false}, + } { + o := Options{Domain: "example.org", Local: tc.local, Proxy: tc.proxy, Choices: shapes(Container, Host, Container)} + _, err := Build(f, o) + if (err == nil) != tc.ok { + t.Errorf("local=%v proxy=%q: err = %v", tc.local, tc.proxy, err) + } + if err != nil && !strings.Contains(err.Error(), "web server") { + t.Errorf("the refusal does not say why: %v", err) + } + } +} + +func TestHostFrontEndsWaitForTheirReleases(t *testing.T) { + f := machine() + if a := Available(f, Console, Host); a.OK || !strings.Contains(a.Why, "no console release") { + t.Errorf("console host with no release: %+v", a) + } + if a := Available(f, Webmail, Host); a.OK || !strings.Contains(a.Why, "no webmail release") { + t.Errorf("webmail host with no release: %+v", a) + } + t.Setenv("INBUXA_WEBMAIL_TARBALL", "/tmp/webmail.tar.gz") + if a := Available(f, Webmail, Host); !a.OK { + t.Errorf("webmail host with a tarball and Node 26: %+v", a) + } + f.Node = host.Node{Present: true, Path: "/usr/bin/node", Major: 26} + if a := Available(f, Webmail, Host); a.OK || !strings.Contains(a.Why, "own Node") { + t.Errorf("the system's Node was accepted for the webmail: %+v", a) + } + // ...and the installer offers to fetch its own + p, err := Build(f, Options{Domain: "example.org", InstallDeps: true, Choices: shapes(Container, Container, Host)}) + if err != nil { + t.Fatal(err) + } + if len(p.Needs) != 1 || p.Needs[0].Name != "node" { + t.Errorf("needs = %+v", p.Needs) + } +} diff --git a/internal/release/release.go b/internal/release/release.go index b44d94c..691b4b5 100644 --- a/internal/release/release.go +++ b/internal/release/release.go @@ -31,3 +31,29 @@ func ServerTarball(arch string) string { return fmt.Sprintf("https://git.coffeylabs.org/inbuxa/inbuxa-server/releases/download/v%s/inbuxa-linux-%s.tar.gz", ServerVersion, arch) } + +// The console and the webmail as files, for host installs. Their releases +// attach these since inbuxa-admin #106 and inbuxa-webmail #68; a version +// with an empty checksum has none to install, and the host shape is +// unavailable until one does. INBUXA_CONSOLE_TARBALL and +// INBUXA_WEBMAIL_TARBALL name a local file instead, for testing. +const ( + ConsoleVersion = "" + ConsoleSHA256 = "" + WebmailVersion = "" +) + +// WebmailSHA256 is the SHA-256 of each architecture's webmail tarball. +var WebmailSHA256 = map[string]string{} + +// ConsoleTarball is where the console's release tarball is. +func ConsoleTarball() string { + return fmt.Sprintf("https://git.coffeylabs.org/inbuxa/inbuxa-admin/releases/download/v%s/inbuxa-admin.tar.gz", ConsoleVersion) +} + +// WebmailTarball is where the webmail's release tarball for an +// architecture is. Its tags are inbuxa-v. +func WebmailTarball(arch string) string { + return fmt.Sprintf("https://git.coffeylabs.org/inbuxa/inbuxa-webmail/releases/download/inbuxa-v%s/inbuxa-webmail-linux-%s.tar.gz", + WebmailVersion, arch) +} diff --git a/internal/tui/install_test.go b/internal/tui/install_test.go index a123b4d..80c9539 100644 --- a/internal/tui/install_test.go +++ b/internal/tui/install_test.go @@ -147,7 +147,7 @@ func TestWhatCannotBeBuiltIsRefusedOnItsScreen(t *testing.T) { press(w, KeyDown) // the console w.Update(Key{Kind: KeyRune, Rune: 'h'}) // on the host: not built press(w, KeyEnter) - if w.screen != screenComponents || !strings.Contains(w.message, "not built yet") { + if w.screen != screenComponents || !strings.Contains(w.message, "can't be a host install") { t.Errorf("a console host install got through: screen %d, %q", w.screen, w.message) } w.Update(Key{Kind: KeyRune, Rune: 'c'}) -- 2.54.0 From a6f3e63da5b37bc227f3b21be49142895f4af426 Mon Sep 17 00:00:00 2001 From: John Coffey Date: Mon, 12 Oct 2026 11:53:38 -0700 Subject: [PATCH 2/2] Pin the releases with files, and server 2026.10.12.1 console v2026.10.12.2 and webmail inbuxa-v2026.10.12-g6e1a1cb are the first releases to carry their tarballs; their checksums are pinned, from the releases' SHA256SUMS and checked against downloads (the webmail's two architectures are identical inside, with no native code). The console's and the webmail's images follow the same constants, so a container and a host install of either are the same release. Server 2026.10.12.1 (upstream 0.16.26, with inbuxa:FrontEnds) replaces 2026.10.12, checksums pinned the same way; still glibc 2.39. join's refusal of an older server, and the README, name it. The interface's components screen now also asks the whole plan, so a choice the machine could make but the other choices rule out -- the console as files on loopback, with no web server to serve them -- is refused there, not first at the plan. All e2e cases on the real downloads, no overrides: webmail-host 18/18, all-host 17/17, join 24/24 (against the released server), install-host 43/43, install-local 26/26, install-public 20/20, proxy-snippets 13/13, interface 22/22, status-export 16/16, topology 28/28. --- README.md | 4 ++-- internal/apply/apply.go | 4 ++-- internal/apply/join_test.go | 2 +- internal/jmap/frontends.go | 2 +- internal/plan/plan_test.go | 12 ++++-------- internal/release/release.go | 17 ++++++++++------- internal/tui/install.go | 6 ++++++ internal/tui/install_test.go | 16 ++++++++++------ 8 files changed, 36 insertions(+), 27 deletions(-) diff --git a/README.md b/README.md index 91c1f85..23adedb 100644 --- a/README.md +++ b/README.md @@ -102,7 +102,7 @@ This is early. What is built: that machine by hand. It asks first, dry runs included, and refuses with the reason when the key is wrong, the server is too old, or it already lists other front ends (`--replace` to put these in their place). Needs a - server release newer than 2026.10.12. + server release 2026.10.12.1 or newer. - **`plan -f` / `apply -f` / `export`** -- a whole installation described in one file, however many machines. Each machine acts on its own part and @@ -133,7 +133,7 @@ CA, with no internet and no public name involved. Each release has static binaries for linux/amd64 and linux/arm64, and a SHA256SUMS to check them against: - V=v2026.10.12.1 # the newest: https://git.coffeylabs.org/inbuxa/inbuxa-installer/releases/latest + V=v2026.10.12.3 # the newest: https://git.coffeylabs.org/inbuxa/inbuxa-installer/releases/latest curl -fLO https://git.coffeylabs.org/inbuxa/inbuxa-installer/releases/download/$V/inbuxa-linux-amd64 curl -fLO https://git.coffeylabs.org/inbuxa/inbuxa-installer/releases/download/$V/SHA256SUMS sha256sum --check --ignore-missing SHA256SUMS diff --git a/internal/apply/apply.go b/internal/apply/apply.go index be4f715..c82cba2 100644 --- a/internal/apply/apply.go +++ b/internal/apply/apply.go @@ -46,8 +46,8 @@ import ( // theirs. const ( DefaultServerImage = release.ServerImage - DefaultConsoleImage = "registry.coffeylabs.org/inbuxa/inbuxa-admin:2026.10.12" - DefaultWebmailImage = "registry.coffeylabs.org/inbuxa/inbuxa-webmail:2026.10.9-g62936ab" + DefaultConsoleImage = "registry.coffeylabs.org/inbuxa/inbuxa-admin:" + release.ConsoleVersion + DefaultWebmailImage = "registry.coffeylabs.org/inbuxa/inbuxa-webmail:" + release.WebmailVersion DefaultCaddyImage = "docker.io/library/caddy:2-alpine" DefaultSubnet = "172.31.253.0/24" ) diff --git a/internal/apply/join_test.go b/internal/apply/join_test.go index 697a851..b3559b4 100644 --- a/internal/apply/join_test.go +++ b/internal/apply/join_test.go @@ -78,7 +78,7 @@ func TestJoinCheck(t *testing.T) { {"a fresh server takes them", map[string]any{"environmentWebmailClientSecret": false}, "good-key", false, ""}, {"the same addresses again", map[string]any{"adminUrl": "https://admin.example.com", "webmailUrl": "https://webmail.example.com"}, "good-key", false, ""}, {"a wrong key", map[string]any{}, "bad-key", false, "API key"}, - {"a server too old", nil, "good-key", false, "newer than"}, + {"a server too old", nil, "good-key", false, "or newer"}, {"another console listed", map[string]any{"adminUrl": "https://other.example.com"}, "good-key", false, "--replace"}, {"another console, replaced", map[string]any{"adminUrl": "https://other.example.com"}, "good-key", true, ""}, {"another webmail listed", map[string]any{"webmailUrl": "https://mail-ui.example.com"}, "good-key", false, "--replace"}, diff --git a/internal/jmap/frontends.go b/internal/jmap/frontends.go index ca55787..99fb363 100644 --- a/internal/jmap/frontends.go +++ b/internal/jmap/frontends.go @@ -31,7 +31,7 @@ type FrontEnds struct { } // ErrNoFrontEnds is a server too old to have inbuxa:FrontEnds. -var ErrNoFrontEnds = errors.New("this server has no inbuxa:FrontEnds; it needs a release newer than 2026.10.12") +var ErrNoFrontEnds = errors.New("this server has no inbuxa:FrontEnds; it needs release 2026.10.12.1 or newer") // AccountID is the signed-in account's id, which inbuxa: methods name. func (c *Client) AccountID(ctx context.Context) (string, error) { diff --git a/internal/plan/plan_test.go b/internal/plan/plan_test.go index 23658d1..9b377b8 100644 --- a/internal/plan/plan_test.go +++ b/internal/plan/plan_test.go @@ -44,17 +44,13 @@ func TestTheConsoleOnTheHostNeedsAWebServer(t *testing.T) { } } -func TestHostFrontEndsWaitForTheirReleases(t *testing.T) { +func TestHostFrontEndsComeFromTheirReleases(t *testing.T) { f := machine() - if a := Available(f, Console, Host); a.OK || !strings.Contains(a.Why, "no console release") { - t.Errorf("console host with no release: %+v", a) + if a := Available(f, Console, Host); !a.OK { + t.Errorf("console host with a pinned release: %+v", a) } - if a := Available(f, Webmail, Host); a.OK || !strings.Contains(a.Why, "no webmail release") { - t.Errorf("webmail host with no release: %+v", a) - } - t.Setenv("INBUXA_WEBMAIL_TARBALL", "/tmp/webmail.tar.gz") if a := Available(f, Webmail, Host); !a.OK { - t.Errorf("webmail host with a tarball and Node 26: %+v", a) + t.Errorf("webmail host with a pinned release and Node 26: %+v", a) } f.Node = host.Node{Present: true, Path: "/usr/bin/node", Major: 26} if a := Available(f, Webmail, Host); a.OK || !strings.Contains(a.Why, "own Node") { diff --git a/internal/release/release.go b/internal/release/release.go index 691b4b5..520396f 100644 --- a/internal/release/release.go +++ b/internal/release/release.go @@ -12,7 +12,7 @@ package release import "fmt" // ServerVersion is the inbuxa-server release this installer installs. -const ServerVersion = "2026.10.12" +const ServerVersion = "2026.10.12.1" // ServerImage is that release as a container image. const ServerImage = "registry.coffeylabs.org/inbuxa/inbuxa-server:" + ServerVersion @@ -22,8 +22,8 @@ const ServerImage = "registry.coffeylabs.org/inbuxa/inbuxa-server:" + ServerVers // rather than fetched beside the download: a checksum that arrives with the // file only proves the file arrived. var ServerSHA256 = map[string]string{ - "amd64": "12e1b83363c3ad5bc1601a93a8a5ee47be139e7a7206c71c6015c148a1cc93db", - "arm64": "f76d6c5412d386d45f91f8adb86cd037fccb023cf9604be91e43c65f622fa465", + "amd64": "14b343c04fa05d2ff637774d332ca7738f16179817b0ed9936ee4d551ef34fa4", + "arm64": "0f5ad50b0ec0587057ec058f4856d6674ad2971d210f264eaa98f60b90e8e64e", } // ServerTarball is where the release's tarball for an architecture is. @@ -38,13 +38,16 @@ func ServerTarball(arch string) string { // unavailable until one does. INBUXA_CONSOLE_TARBALL and // INBUXA_WEBMAIL_TARBALL name a local file instead, for testing. const ( - ConsoleVersion = "" - ConsoleSHA256 = "" - WebmailVersion = "" + ConsoleVersion = "2026.10.12.2" + ConsoleSHA256 = "73583f5220bc5199a799e1f71d00e5f26e4a1171fc10ec6171c1b0348e878b85" + WebmailVersion = "2026.10.12-g6e1a1cb" // its tag is inbuxa-v ) // WebmailSHA256 is the SHA-256 of each architecture's webmail tarball. -var WebmailSHA256 = map[string]string{} +var WebmailSHA256 = map[string]string{ + "amd64": "399d2575a2d9426b0b28d9b64f35ca44602b4bd2817e23a7a29c7dc22a978a3f", + "arm64": "33a2cc435168739efb34e202124ff5526b7445f8de8ba8f62dc23dd3d0a94e7f", +} // ConsoleTarball is where the console's release tarball is. func ConsoleTarball() string { diff --git a/internal/tui/install.go b/internal/tui/install.go index 54b66c0..f38cc64 100644 --- a/internal/tui/install.go +++ b/internal/tui/install.go @@ -437,6 +437,12 @@ func (w *Wizard) componentsProblem() string { if w.shapes[plan.Server] == plan.Skip { return "Front ends for a server on another machine are installed with inbuxa join, not here: keep the server, or quit and use join." } + // What each choice can do on its own is above; what the choices can't + // do together -- a console of files on loopback, with no web server to + // serve them -- only the whole plan says. + if _, err := plan.Build(w.Facts, withDeps(w.Options())); err != nil { + return err.Error() + } return "" } diff --git a/internal/tui/install_test.go b/internal/tui/install_test.go index 80c9539..02b0b80 100644 --- a/internal/tui/install_test.go +++ b/internal/tui/install_test.go @@ -140,15 +140,19 @@ func TestTheServerOnTheHost(t *testing.T) { func TestWhatCannotBeBuiltIsRefusedOnItsScreen(t *testing.T) { w := NewWizard(debian13(true), &fakeInstaller{}) press(w, KeyEnter) - typeText(w, "example.org") - for i := 0; i < len(w.fields); i++ { - press(w, KeyEnter) + for w.focus < len(w.fields)-1 { + press(w, KeyDown) + } + w.Update(Key{Kind: KeyRune, Rune: ' '}) // loopback: no web server + press(w, KeyEnter) + if w.screen != screenComponents { + t.Fatalf("not at the components: %q", w.message) } press(w, KeyDown) // the console - w.Update(Key{Kind: KeyRune, Rune: 'h'}) // on the host: not built + w.Update(Key{Kind: KeyRune, Rune: 'h'}) // on the host: files, and nothing to serve them press(w, KeyEnter) - if w.screen != screenComponents || !strings.Contains(w.message, "can't be a host install") { - t.Errorf("a console host install got through: screen %d, %q", w.screen, w.message) + if w.screen != screenComponents || !strings.Contains(w.message, "web server") { + t.Errorf("a console host install on loopback got through: screen %d, %q", w.screen, w.message) } w.Update(Key{Kind: KeyRune, Rune: 'c'}) press(w, KeyUp) -- 2.54.0