join: the console and the webmail on the host, too #25
No files matched your search
@@ -101,8 +101,9 @@ This is early. What is built:
|
||||
call the server from the browser, with no restart and nothing changed on
|
||||
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 2026.10.12.1 or newer.
|
||||
lists other front ends (`--replace` to put these in their place). Each
|
||||
front end goes in a container or on the host (`--console host`, `--webmail
|
||||
host`), as with `install`. Needs a 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
|
||||
@@ -149,9 +150,8 @@ 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: `join` in the interface (it is a command for now) and of
|
||||
front ends on the host, 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
|
||||
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
|
||||
@@ -192,6 +192,7 @@ is tested on a throwaway virtual machine rather than on anybody's desk:
|
||||
e2e/vm/run.sh e2e/cases/install-public.sh the same with real ports and certificates
|
||||
e2e/vm/run.sh e2e/cases/install-host.sh the server on the host, the rest beside it
|
||||
e2e/vm/run.sh e2e/cases/join.sh front ends joined to a server elsewhere
|
||||
e2e/vm/run.sh e2e/cases/join-host.sh the same on the host, behind nginx, no containers
|
||||
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
|
||||
|
||||
+3
-4
@@ -85,8 +85,8 @@ join flags:
|
||||
administrator; "-" reads it from standard input.
|
||||
INBUXA_JOIN_KEY works too, and keeps it out of
|
||||
the shell's history
|
||||
--console SHAPE container | skip (default: container)
|
||||
--webmail SHAPE container | skip (default: container)
|
||||
--console SHAPE container | host | skip (default: container)
|
||||
--webmail SHAPE container | host | skip (default: container)
|
||||
--domain NAME default: the server's name without its first label
|
||||
--console-host, --webmail-host, --email, --proxy, --dir, --local,
|
||||
--install-deps, --dry-run, --yes as for install
|
||||
@@ -368,8 +368,7 @@ func join(args []string) int {
|
||||
return 1
|
||||
}
|
||||
fmt.Println("\nChecking it works:")
|
||||
problems := apply.JoinVerify(ctx, res,
|
||||
p.Options.Shape(plan.Console) != plan.Skip, p.Options.Shape(plan.Webmail) != plan.Skip, log)
|
||||
problems := apply.JoinVerify(ctx, res, p.Options.Shape(plan.Console), p.Options.Shape(plan.Webmail), log)
|
||||
for _, why := range problems {
|
||||
fmt.Fprintln(os.Stderr, " problem: "+why)
|
||||
}
|
||||
|
||||
Executable
+145
@@ -0,0 +1,145 @@
|
||||
#!/bin/bash
|
||||
# SPDX-FileCopyrightText: 2026 Coffey Labs LLC
|
||||
# SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
#
|
||||
# inbuxa join with the front ends on the host: the console as files and the
|
||||
# webmail under systemd, behind the nginx this machine already runs
|
||||
# (--proxy snippets), for a server elsewhere. No container runtime is
|
||||
# installed at all. Two machines are played by one, as in join.sh.
|
||||
#
|
||||
# Run from the host with: e2e/vm/run.sh e2e/cases/join-host.sh
|
||||
set -uo pipefail
|
||||
|
||||
pass=0; fail=0
|
||||
ok() { echo " ok $*"; pass=$((pass+1)); }
|
||||
bad() { echo " FAIL $*"; fail=$((fail+1)); }
|
||||
|
||||
SERVER_DIR=/var/lib/inbuxa
|
||||
DIR=/var/lib/inbuxa-joined
|
||||
D=example.test
|
||||
SERVER=http://127.0.0.1:8081
|
||||
if [ -x /tmp/inbuxa-server-test ]; then
|
||||
export INBUXA_SERVER_BINARY=/tmp/inbuxa-server-test
|
||||
# A debug build needs a deeper stack than a release one, as the server's
|
||||
# own test suites do (RUST_MIN_STACK in its CI). A drop-in made before the
|
||||
# unit exists applies when it does.
|
||||
mkdir -p /etc/systemd/system/inbuxa-server.service.d
|
||||
printf '[Service]\nEnvironment=RUST_MIN_STACK=16777216\n' > /etc/systemd/system/inbuxa-server.service.d/test-build.conf
|
||||
fi
|
||||
|
||||
rt() { command -v docker >/dev/null 2>&1 && echo docker || echo podman; }
|
||||
compose() {
|
||||
if [ "$(rt)" = docker ]; then
|
||||
docker compose -f "$DIR/compose.yaml" "$@"
|
||||
else
|
||||
DOCKER_HOST=unix:///run/podman/podman.sock \
|
||||
/usr/local/lib/docker/cli-plugins/docker-compose -f "$DIR/compose.yaml" "$@"
|
||||
fi
|
||||
}
|
||||
jmap() { # jmap TOKEN-or-user:pass CAPABILITY JSON-CALLS
|
||||
local auth
|
||||
case "$1" in *:*) auth=(-u "$1") ;; *) auth=(-H "Authorization: Bearer $1") ;; esac
|
||||
curl -s "${auth[@]}" -H 'Content-Type: application/json' \
|
||||
-d "{\"using\":[\"urn:ietf:params:jmap:core\",\"$2\"],\"methodCalls\":$3}" "$SERVER/jmap/"
|
||||
}
|
||||
wait_server() { for _ in $(seq 1 60); do [ "$(curl -s -o /dev/null -w '%{http_code}' $SERVER/.well-known/jmap)" != 000 ] && return 0; sleep 2; done; return 1; }
|
||||
|
||||
echo "==> the server, on its own"
|
||||
OUT="$(/tmp/inbuxa install --local --domain example.test --server host --console skip --webmail skip --yes 2>&1)"; rc=$?
|
||||
if [ $rc -eq 0 ]; then ok "installed the server alone"; else
|
||||
bad "server install exit $rc"; echo "$OUT" | tail -15 | sed 's/^/ /'
|
||||
journalctl -u inbuxa-server -n 30 --no-pager -o cat | sed 's/^/ | /'
|
||||
echo; echo "==> $pass passed, $fail failed (stopped: no server to join)"; exit 1
|
||||
fi
|
||||
[ -n "${INBUXA_SERVER_BINARY:-}" ] && echo " (server: $(/usr/local/bin/inbuxa-server --version 2>&1 | head -1), from the build given)"
|
||||
|
||||
echo
|
||||
echo "==> an API key, as an administrator makes one in the console"
|
||||
# The console is a browser; here the server takes the administrator's
|
||||
# password for one restart, the way the installer's own setup does.
|
||||
AUSER=$(awk '/^administrator/ {print $2}' "$SERVER_DIR/credentials.txt")
|
||||
APASS=$(awk '/^administrator/{getline; print $2}' "$SERVER_DIR/credentials.txt")
|
||||
echo "INBUXA_HTTP_BASIC_AUTH=all" >> "$SERVER_DIR/server.env"
|
||||
systemctl restart inbuxa-server; wait_server
|
||||
EXPIRES=$(date -u -d '+1 hour' +%Y-%m-%dT%H:%M:%SZ)
|
||||
ANSWER=$(jmap "$AUSER:$APASS" urn:inbuxa:jmap:registry "[[\"x:ApiKey/set\",{\"create\":{\"k\":{\"description\":\"join test\",\"expiresAt\":\"$EXPIRES\",\"permissions\":{\"@type\":\"Inherit\"}}}},\"0\"]]")
|
||||
KEY=$(sed -n 's/.*"secret":"\([^"]*\)".*/\1/p' <<<"$ANSWER")
|
||||
sed -i '/^INBUXA_HTTP_BASIC_AUTH=/d' "$SERVER_DIR/server.env"
|
||||
systemctl restart inbuxa-server; wait_server
|
||||
[ -n "$KEY" ] && ok "an API key for the administrator" || { bad "no API key"; head -c 300 <<<"$ANSWER" | sed 's/^/ /'; }
|
||||
|
||||
ACCOUNT=$(curl -s -H "Authorization: Bearer $KEY" $SERVER/jmap/session | grep -o '"primaryAccounts":{[^}]*}' | sed -n 's/^"primaryAccounts":{"[^"]*":"\([^"]*\)".*/\1/p')
|
||||
[ -n "$ACCOUNT" ] || bad "no account id in the key's session"
|
||||
|
||||
# From here this is "another machine": no install recorded on it.
|
||||
mv /etc/inbuxa/install.json /etc/inbuxa/install.server.json
|
||||
|
||||
echo
|
||||
echo "==> joining, both front ends on the host, behind nginx"
|
||||
DEBIAN_FRONTEND=noninteractive apt-get install -y -qq nginx openssl >/dev/null 2>&1
|
||||
OUT="$(echo "$KEY" | /tmp/inbuxa join $SERVER --key - --domain $D --console host --webmail host --proxy snippets \
|
||||
--dir $DIR --install-deps --yes 2>&1)"; rc=$?
|
||||
echo "$OUT" | grep -v '^ |' | tail -20 | sed 's/^/ /'
|
||||
[ $rc -eq 0 ] && ok "joined (exit 0)" || bad "exit $rc"
|
||||
{ command -v docker || command -v podman; } >/dev/null 2>&1 && 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"
|
||||
systemctl is-active --quiet inbuxa-webmail && ok "inbuxa-webmail is running" || bad "inbuxa-webmail is not running"
|
||||
grep -q "name=\"api-base-url\" content=\"$SERVER\"" $DIR/console/index.html && ok "the console's files point at the server" || bad "the console's index.html"
|
||||
grep -q "^MAIL_SERVER_URL=$SERVER$" $DIR/webmail.env && ok "the webmail is told the server's address" || bad "webmail.env: $(grep MAIL_SERVER_URL $DIR/webmail.env)"
|
||||
grep -q "$KEY" <<<"$(cat $DIR/*.env $DIR/.env 2>/dev/null)" && bad "the API key was written down here" || ok "the API key was not kept"
|
||||
[ -f $DIR/proxy/nginx-inbuxa.conf ] && ok "it wrote the nginx configuration" || bad "no $DIR/proxy/nginx-inbuxa.conf"
|
||||
grep -q "the server lets the console call it" <<<"$OUT" && ok "it checked the console may call the server" || bad "no CORS check in the output"
|
||||
|
||||
echo
|
||||
echo "==> the server knows the front ends"
|
||||
FE=$(jmap "$KEY" urn:inbuxa:jmap '[["inbuxa:FrontEnds/get",{"accountId":"'"$ACCOUNT"'"},"0"]]')
|
||||
grep -q "\"adminUrl\":\"https://admin.$D\"" <<<"$FE" && ok "the console's address" || bad "adminUrl: $FE"
|
||||
grep -q "\"webmailUrl\":\"https://webmail.$D\"" <<<"$FE" && ok "the webmail's address" || bad "webmailUrl: $FE"
|
||||
grep -q '"webmailClientSecretSet":true' <<<"$FE" && ok "and a webmail secret" || bad "no webmail secret: $FE"
|
||||
|
||||
echo
|
||||
echo "==> behind nginx, from the configuration it wrote"
|
||||
mkdir -p /etc/ssl/inbuxa
|
||||
for n in 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}"; }
|
||||
via admin.$D https://admin.$D/ | grep -q "content=\"$SERVER\"" && ok "the console is served from its files" || bad "the console is not served"
|
||||
via webmail.$D https://webmail.$D/api/health | grep -q '"ok":true' && ok "the webmail is healthy through nginx" || bad "the webmail through nginx"
|
||||
|
||||
echo
|
||||
echo "==> a person signs in to the joined webmail, through nginx"
|
||||
USER=$(awk '/^first mailbox/ {print $3}' "$SERVER_DIR/credentials.txt")
|
||||
PASS=$(awk '/^first mailbox/{getline; print $2}' "$SERVER_DIR/credentials.txt")
|
||||
rm -f /tmp/jar
|
||||
LOC=$(via webmail.$D -o /dev/null -c /tmp/jar -w '%{redirect_url}' "https://webmail.$D/api/auth/oauth/start?username=$USER&remember=1")
|
||||
grep -q "^$SERVER/" <<<"$LOC" && ok "the webmail sends sign-in 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)")
|
||||
[ "$REDIRECT" = "https://webmail.$D/api/auth/callback" ] && ok "for its public address" || bad "redirect_uri $REDIRECT"
|
||||
ANSWER=$(curl -s -X POST $SERVER/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")
|
||||
[ -n "$AUTHCODE" ] && ok "the server takes the joined webmail's redirect" || { bad "the server's sign-in answered"; head -c 200 <<<"$ANSWER" | sed 's/^/ /'; }
|
||||
BACK=$(via webmail.$D -o /dev/null -b /tmp/jar -c /tmp/jar -w '%{redirect_url}' "$REDIRECT?code=$AUTHCODE&state=$STATE")
|
||||
grep -q "signin_error" <<<"$BACK" && bad "the webmail's code exchange failed (its secret?): $BACK" || ok "the webmail exchanges the code with the secret made here"
|
||||
CODE=$(via webmail.$D -o /tmp/login.json -b /tmp/jar -w '%{http_code}' -H 'X-Requested-With: ihasmail' https://webmail.$D/api/auth/session)
|
||||
[ "$CODE" = 200 ] && grep -q "urn:ietf:params:jmap:mail" /tmp/login.json && ok "signed in, with mail" || { bad "the session answered $CODE"; head -c 200 /tmp/login.json | sed 's/^/ /'; }
|
||||
|
||||
echo
|
||||
echo "==> status, and again"
|
||||
STATUS="$(/tmp/inbuxa status 2>&1)"
|
||||
for k in console webmail; do grep -q "$k.*installed as a host" <<<"$STATUS" && ok "status: the $k is a host install" || bad "status: $k"; done
|
||||
OUT="$(INBUXA_JOIN_KEY=$KEY /tmp/inbuxa join $SERVER --domain $D --console host --webmail host --proxy snippets --dir $DIR --yes 2>&1)"; rc=$?
|
||||
[ $rc -eq 0 ] && ok "joining again converges" || { bad "second join exit $rc"; echo "$OUT" | tail -6 | sed 's/^/ /'; }
|
||||
systemctl is-active --quiet inbuxa-webmail && ok "and the webmail is still running" || bad "the webmail stopped"
|
||||
|
||||
mv /etc/inbuxa/install.server.json /etc/inbuxa/install.json.server-kept 2>/dev/null
|
||||
echo
|
||||
echo "==> $pass passed, $fail failed"
|
||||
[ "$fail" -eq 0 ]
|
||||
@@ -75,8 +75,8 @@ type Log interface {
|
||||
Out() io.Writer
|
||||
}
|
||||
|
||||
// Run carries out p. The console and the webmail are containers for now, and
|
||||
// it says so rather than pretending a host install of either happened.
|
||||
// Run carries out p: each component in a container or on the host, as the
|
||||
// plan says.
|
||||
func Run(ctx context.Context, p plan.Plan, f host.Facts, log Log) (*Result, error) {
|
||||
o := p.Options
|
||||
if o.Shape(plan.Server) == plan.Skip {
|
||||
|
||||
+79
-30
@@ -86,11 +86,6 @@ func Join(ctx context.Context, p plan.Plan, f host.Facts, key string, log Log) (
|
||||
if o.Shape(plan.Server) != plan.Skip {
|
||||
return nil, errors.New("join installs front ends for a server elsewhere; the server itself is installed with install")
|
||||
}
|
||||
for _, c := range []plan.Component{plan.Console, plan.Webmail} {
|
||||
if o.Shape(c) == plan.Host {
|
||||
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 {
|
||||
return nil, errors.New("nothing to join: both the console and the webmail are skipped")
|
||||
}
|
||||
@@ -116,8 +111,13 @@ func Join(ctx context.Context, p plan.Plan, f host.Facts, key string, log Log) (
|
||||
}
|
||||
f = host.Survey(ctx)
|
||||
}
|
||||
if !f.Runtime.Usable {
|
||||
return nil, fmt.Errorf("the front ends run in containers, and containers are not usable here: %s", f.Runtime.Why)
|
||||
// Containers only for what runs in one: a front end in a container, or
|
||||
// the managed Caddy. The console as files and the webmail under systemd,
|
||||
// behind your own web server, need none.
|
||||
needContainers := o.Shape(plan.Console) == plan.Container || o.Shape(plan.Webmail) == plan.Container ||
|
||||
(!o.Local && o.Proxy == "caddy")
|
||||
if needContainers && !f.Runtime.Usable {
|
||||
return nil, fmt.Errorf("what runs in containers here can't: %s", f.Runtime.Why)
|
||||
}
|
||||
|
||||
consoleURL, webmailURL := joinURLs(o)
|
||||
@@ -131,6 +131,7 @@ func Join(ctx context.Context, p plan.Plan, f host.Facts, key string, log Log) (
|
||||
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",
|
||||
RemoteServerURL: o.ServerURL,
|
||||
ServerPublicURL: o.ServerURL,
|
||||
@@ -142,10 +143,13 @@ func Join(ctx context.Context, p plan.Plan, f host.Facts, key string, log Log) (
|
||||
Subnet: DefaultSubnet,
|
||||
ACMEDirectory: o.ACMEDirectory,
|
||||
}
|
||||
if stack.Console {
|
||||
if o.Shape(plan.Console) != plan.Skip {
|
||||
stack.ConsoleURL = consoleURL
|
||||
}
|
||||
if stack.Webmail {
|
||||
if o.Shape(plan.Console) == plan.Host {
|
||||
stack.ConsoleFiles = hostConsole{deploy: o.Dir}.dir()
|
||||
}
|
||||
if o.Shape(plan.Webmail) != plan.Skip {
|
||||
stack.WebmailURL = webmailURL
|
||||
}
|
||||
if o.ACMECARoot != "" {
|
||||
@@ -156,25 +160,62 @@ func Join(ctx context.Context, p plan.Plan, f host.Facts, key string, log Log) (
|
||||
}
|
||||
|
||||
log.Step("writing the deployment into %s", o.Dir)
|
||||
sec, err := compose.Write(o.Dir, &stack)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
var sec compose.Secrets
|
||||
if stack.Empty() {
|
||||
if sec, err = compose.EnsureSecrets(o.Dir); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
log.Info(".env (nothing runs in containers here)")
|
||||
} else {
|
||||
if sec, err = compose.Write(o.Dir, &stack); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
log.Info("compose.yaml, .env%s", map[bool]string{true: " and Caddyfile", false: ""}[stack.Proxy])
|
||||
}
|
||||
log.Info("compose.yaml, .env%s", map[bool]string{true: " and Caddyfile", false: ""}[stack.Proxy])
|
||||
|
||||
docker.UseRuntime(f.Runtime)
|
||||
cmp := docker.Compose{Dir: o.Dir, Runtime: f.Runtime}
|
||||
log.Step("fetching the images")
|
||||
if err := cmp.Run(ctx, "pull", "--quiet"); err != nil {
|
||||
return nil, err
|
||||
if !stack.Empty() {
|
||||
log.Step("fetching the images")
|
||||
if err := cmp.Run(ctx, "pull", "--quiet"); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
// On the host: the console's files, pointed at the server, and the
|
||||
// webmail's, with its unit and an environment naming the server. Both
|
||||
// in place before the server is told about them, so nothing it lists
|
||||
// is missing here.
|
||||
if o.Shape(plan.Console) == plan.Host {
|
||||
if err := (hostConsole{deploy: o.Dir, log: log}).Install(ctx, o.ServerURL); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
var hw *hostWebmail
|
||||
if o.Shape(plan.Webmail) == plan.Host {
|
||||
hw = &hostWebmail{deploy: o.Dir, log: log}
|
||||
if err := hw.Install(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if _, err := hw.WriteEnv(webmailEnv(o, stack, sec, hw.Version())); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
var proxyConfig string
|
||||
if !o.Local && o.Proxy == "snippets" {
|
||||
log.Step("writing the configuration for your web server")
|
||||
if proxyConfig, err = compose.WriteProxySnippets(o.Dir, stack); err != nil {
|
||||
return nil, fmt.Errorf("writing the proxy configuration: %w", err)
|
||||
}
|
||||
log.Info("%s/nginx-inbuxa.conf and %s/Caddyfile.fragment: load one into your web server", proxyConfig, proxyConfig)
|
||||
}
|
||||
|
||||
log.Step("registering these front ends with the server")
|
||||
update := map[string]any{}
|
||||
if stack.Console {
|
||||
if stack.ConsoleURL != "" {
|
||||
update["adminUrl"] = consoleURL
|
||||
}
|
||||
if stack.Webmail {
|
||||
if stack.WebmailURL != "" {
|
||||
update["webmailUrl"] = webmailURL
|
||||
update["webmailClientSecret"] = sec.WebmailOAuth
|
||||
}
|
||||
@@ -190,7 +231,7 @@ func Join(ctx context.Context, p plan.Plan, f host.Facts, key string, log Log) (
|
||||
// Every webmail request reaches the server from one address, this
|
||||
// machine's, and the server bans per address: exempted, a scanner
|
||||
// probing the webmail can't take everybody's webmail with it.
|
||||
if stack.Webmail {
|
||||
if stack.WebmailURL != "" {
|
||||
addresses := joinExemptAddresses(ctx, o, stack)
|
||||
if len(addresses) == 0 {
|
||||
log.Info("could not tell which address the server sees the webmail at; exempt it with --exempt-address, or in the console under the auto-ban's allowed addresses")
|
||||
@@ -210,8 +251,15 @@ func Join(ctx context.Context, p plan.Plan, f host.Facts, key string, log Log) (
|
||||
}
|
||||
|
||||
log.Step("starting the front ends")
|
||||
if err := cmp.Run(ctx, "up", "-d", "--remove-orphans"); err != nil {
|
||||
return nil, err
|
||||
if !stack.Empty() {
|
||||
if err := cmp.Run(ctx, "up", "-d", "--remove-orphans"); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
if hw != nil {
|
||||
if err := hw.Start(ctx); err != nil {
|
||||
return nil, withLogs(ctx, err, hw, "webmail")
|
||||
}
|
||||
}
|
||||
|
||||
st, err := state.Load()
|
||||
@@ -221,10 +269,11 @@ func Join(ctx context.Context, p plan.Plan, f host.Facts, key string, log Log) (
|
||||
}
|
||||
|
||||
return &Result{
|
||||
Dir: o.Dir,
|
||||
ConsoleURL: stack.ConsoleURL,
|
||||
WebmailURL: stack.WebmailURL,
|
||||
ServerURL: o.ServerURL,
|
||||
Dir: o.Dir,
|
||||
ConsoleURL: stack.ConsoleURL,
|
||||
WebmailURL: stack.WebmailURL,
|
||||
ServerURL: o.ServerURL,
|
||||
ProxyConfig: proxyConfig,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -252,14 +301,14 @@ func joinExemptAddresses(ctx context.Context, o plan.Options, stack compose.Stac
|
||||
// JoinVerify is join's last step: the front ends answer here, and the server
|
||||
// lets the console call it from the browser, which is the part only the
|
||||
// server can say.
|
||||
func JoinVerify(ctx context.Context, res *Result, console, webmail bool, log Log) []string {
|
||||
func JoinVerify(ctx context.Context, res *Result, console, webmail plan.Shape, log Log) []string {
|
||||
// Started a moment ago: give them the time to answer at all before
|
||||
// asking whether they answer correctly.
|
||||
for _, c := range []struct {
|
||||
want bool
|
||||
what string
|
||||
url string
|
||||
}{{console, "the console", "http://127.0.0.1:8082/"}, {webmail, "the webmail", "http://127.0.0.1:8080/api/health"}} {
|
||||
}{{console == plan.Container, "the console", "http://127.0.0.1:8082/"}, {webmail != plan.Skip, "the webmail", "http://127.0.0.1:8080/api/health"}} {
|
||||
if !c.want {
|
||||
continue
|
||||
}
|
||||
@@ -277,11 +326,11 @@ func JoinVerify(ctx context.Context, res *Result, console, webmail bool, log 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]},
|
||||
{Component: plan.Console, Shape: console},
|
||||
{Component: plan.Webmail, Shape: webmail},
|
||||
}}
|
||||
problems := Verify(ctx, res, o, false, log)
|
||||
if console {
|
||||
if console != plan.Skip {
|
||||
ctx, cancel := context.WithTimeout(ctx, 10*time.Second)
|
||||
defer cancel()
|
||||
req, _ := http.NewRequestWithContext(ctx, http.MethodOptions, res.ServerURL+"/jmap/session", nil)
|
||||
|
||||
@@ -65,3 +65,16 @@ func TestHostFrontEndsComeFromTheirReleases(t *testing.T) {
|
||||
t.Errorf("needs = %+v", p.Needs)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTheSurveyOffersWhatTheInstallerCanAdd(t *testing.T) {
|
||||
f := machine()
|
||||
f.Node = host.Node{} // only the installer's own Node is missing
|
||||
text := SurveyText(f)
|
||||
if !strings.Contains(text, "host (with --install-deps: the webmail runs on the installer's own Node") {
|
||||
t.Errorf("a webmail on the host is refused rather than offered:\n%s", text)
|
||||
}
|
||||
f.Systemd = false // and this, nothing installs
|
||||
if text := SurveyText(f); !strings.Contains(text, "host (no: a host install needs systemd") {
|
||||
t.Errorf("a machine without systemd is offered a host webmail:\n%s", text)
|
||||
}
|
||||
}
|
||||
+15
-2
@@ -82,9 +82,14 @@ func SurveyText(f host.Facts) string {
|
||||
for _, c := range []Component{Server, Console, Webmail} {
|
||||
var shapes []string
|
||||
for _, s := range []Shape{Container, Host} {
|
||||
if a := Available(f, c, s); a.OK {
|
||||
switch a := Available(f, c, s); {
|
||||
case a.OK:
|
||||
shapes = append(shapes, string(s))
|
||||
} else {
|
||||
case fixable(f, c, s):
|
||||
// Missing, not impossible: what --install-deps adds, said as
|
||||
// the offer it is, as the interface says it.
|
||||
shapes = append(shapes, fmt.Sprintf("%s (with --install-deps: %s)", s, a.Why))
|
||||
default:
|
||||
shapes = append(shapes, fmt.Sprintf("%s (no: %s)", s, a.Why))
|
||||
}
|
||||
}
|
||||
@@ -93,6 +98,14 @@ func SurveyText(f host.Facts) string {
|
||||
return b.String()
|
||||
}
|
||||
|
||||
// fixable is whether a shape this machine can't take as it is becomes one it
|
||||
// can once the installer adds what is missing: a plan with --install-deps
|
||||
// builds.
|
||||
func fixable(f host.Facts, c Component, s Shape) bool {
|
||||
_, err := Build(f, Options{Domain: "example.com", InstallDeps: true, Choices: []Choice{{Component: c, Shape: s}}})
|
||||
return err == nil
|
||||
}
|
||||
|
||||
func yes(b bool, t, f string) string {
|
||||
if b {
|
||||
return t
|
||||
|
||||
@@ -629,7 +629,7 @@ func (w *Wizard) viewComponents(width int) ([]string, string) {
|
||||
}
|
||||
body = append(body, "",
|
||||
" "+Dim("container: an image, run with this machine's docker or podman"),
|
||||
" "+Dim("host: the release binary under systemd (the server only, for now)"),
|
||||
" "+Dim("host: from its release, under systemd or as files a web server serves"),
|
||||
" "+Dim("skip: not on this machine"))
|
||||
return body, "↑↓: component ←→ or s/c/h: choose Enter: next Esc: back q: quit"
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user