Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

Installer: Caddy in its own container, sign-in settings only when set, the first admin's link, and quieter runs

milind-sonic8aa88635218
diff --git a/deploy/e2e/run.sh b/deploy/e2e/run.sh
index 80f529ec84..a12754dfd7 100755
--- a/deploy/e2e/run.sh
+++ b/deploy/e2e/run.sh
@@ -2,7 +2,9 @@
# The server installer (deploy/install.sh) on a stock Ubuntu 24.04 host with Docker, run as a person runs it: the checks
# alone, then a real install of the published image, a second run, an uninstall that keeps the data, and an install on
# top of that data. The host has no domain of its own, so the DNS check is shown to fail and is then skipped, and no
-# certificate can be issued: the installer must say exactly that, with the server healthy behind Caddy.
+# public certificate can be issued: the installer must say exactly that, with the server healthy behind Caddy. The name
+# ends in .internal, for which Caddy issues a certificate of its own CA at once, so HTTPS through Caddy is checked too:
+# after every way the server restarts without Caddy, and after the documented backup and restore.
# The files the installer places (update.sh, the sandbox's host preparation) come from this checkout. Where the image
# runs the hardened profile the bots' sandbox must be on and hold: a bot cannot read config.json. With
# OMB_INSTALL_IMAGE set (the workflow builds this checkout's image and serves it from a registry on the runner), that
@@ -12,7 +14,7 @@ set -euo pipefail
ROOT=$(cd "$(dirname "$0")/../.." && pwd)
OUT=${OUT:-$(mktemp -d)}
mkdir -p "$OUT"
-DOMAIN=installer-e2e.invalid
+DOMAIN=installer-e2e.internal
DIR=/opt/openmausbot
SETTINGS=(OMB_INSTALL_SKIP_DNS=1 OMB_INSTALL_HTTPS_WAIT_S=20 "OMB_INSTALL_SOURCE=file://$ROOT")
# Without a version asked for: what a person's later run is, which must keep the version update.sh pinned.
@@ -33,6 +35,29 @@ fail() {
fi
exit 1
}
+# HTTPS through Caddy, with its own CA's certificate: the server's health answers, and a request through Caddy is a
+# remote one (it must pair), never a local one.
+through_caddy() { # what happened
+ local _
+ for _ in $(seq 1 60); do
+ if curl -sk --max-time 5 --resolve "$DOMAIN:443:127.0.0.1" "https://$DOMAIN/api/health" 2>/dev/null | grep -qx '{"app":"openmausbot"}' &&
+ [ "$(curl -sk -o /dev/null -w '%{http_code}' --max-time 5 --resolve "$DOMAIN:443:127.0.0.1" "https://$DOMAIN/api/bots")" = 403 ]; then
+ echo "HTTPS through Caddy answers after: $1"
+ return 0
+ fi
+ sleep 2
+ done
+ (cd "$DIR" && sudo docker compose ps) || true
+ fail "HTTPS through Caddy did not come back after: $1"
+}
+healthy_again() {
+ local _
+ for _ in $(seq 1 60); do
+ [ "$(sudo docker inspect --format '{{.State.Health.Status}}' "$(cd "$DIR" && sudo docker compose ps -q omb)" 2>/dev/null)" = healthy ] && return 0
+ sleep 3
+ done
+ fail "the server did not become healthy again"
+}
contains() { # file words what
grep -qF -- "$2" "$1" || fail "$3: $(tail -n 20 "$1")"
}
@@ -50,6 +75,7 @@ install_until_https() { # evidence-file [the install command, when not the usual
[ "$(sudo docker inspect --format '{{.State.Health.Status}}' "$(cd "$DIR" && sudo docker compose ps -q omb)")" = healthy ] || fail "the server is not healthy"
(cd "$DIR" && sudo docker compose exec -T omb curl -sf http://127.0.0.1:8799/api/health) | grep -q openmausbot || fail "the server does not answer inside its container"
curl -sS -o /dev/null -w '%{http_code}' --max-time 10 -H "Host: $DOMAIN" http://127.0.0.1/ | grep -qx 308 || fail "Caddy does not redirect port 80 to HTTPS"
+ through_caddy "the install"
}
step "the checks alone, with a name that points nowhere: one thing to fix, nothing changed"
@@ -114,6 +140,34 @@ else
echo "this checkout has no deploy/update.sh; nothing to place"
fi
+step "HTTPS comes back by itself whenever the server restarts without Caddy"
+# Caddy used to share the server's network, and stayed in the old, dead one after each of these, with 443 refused.
+(cd "$DIR" && sudo docker compose restart >/dev/null 2>&1) && healthy_again && through_caddy "docker compose restart"
+before=$(sudo docker inspect -f '{{.RestartCount}}' "$(cd "$DIR" && sudo docker compose ps -q omb)")
+launcher=$(sudo docker top "$(cd "$DIR" && sudo docker compose ps -q omb)" -eo pid,args | awk '/server-launcher/ { print $1; exit }')
+[ -n "$launcher" ] || fail "no server process to kill"
+sudo kill -9 "$launcher"
+sleep 5
+healthy_again && through_caddy "kill -9 of the server process"
+[ "$(sudo docker inspect -f '{{.RestartCount}}' "$(cd "$DIR" && sudo docker compose ps -q omb)")" -gt "$before" ] || fail "Docker did not restart the killed server"
+(cd "$DIR" && sudo docker compose stop omb >/dev/null 2>&1 && sudo docker compose start omb >/dev/null 2>&1) && healthy_again && through_caddy "stop omb, then start omb"
+
+step "the documented backup and restore, each with the whole project stopped and started"
+echo before-backup | sudo tee "$DIR/data/e2e-backup" >/dev/null
+# docs/deploy-vps.md, "Back up", with the installer: exactly as written there.
+(cd /opt/openmausbot && sudo docker compose stop && sudo sh -c 'umask 077; tar --warning=no-file-ignored -czf "backup-$(date -u +%Y%m%dT%H%M%SZ).tgz" data .env'; sudo docker compose start) >"$OUT/backup.txt" 2>&1
+archive=$(cd "$DIR" && sudo sh -c 'ls backup-*.tgz' | head -n 1)
+[ -n "$archive" ] || fail "the backup made no archive: $(cat "$OUT/backup.txt")"
+grep -q "socket ignored" "$OUT/backup.txt" && fail "tar listed sockets: $(cat "$OUT/backup.txt")"
+[ "$(sudo stat -c %a "$DIR/$archive")" = 600 ] || fail "the archive is readable by others"
+healthy_again && through_caddy "the backup"
+echo after-backup | sudo tee "$DIR/data/e2e-backup" >/dev/null
+(cd /opt/openmausbot && sudo docker compose stop && sudo sh -c "set -e; tar -tzf $archive data/ >/dev/null; rm -rf data.before-restore; mv data data.before-restore; tar -xzpf $archive data"; sudo docker compose start) >"$OUT/restore.txt" 2>&1
+[ "$(sudo cat "$DIR/data/e2e-backup")" = before-backup ] || fail "the restore did not put the data back: $(cat "$OUT/restore.txt")"
+[ "$(sudo stat -c '%u:%a' "$DIR/data")" = "$(sudo stat -c '%u:%a' "$DIR/data.before-restore")" ] || fail "the restore changed the data folder's owner or mode"
+sudo rm -rf "$DIR/data.before-restore" "$DIR/$archive"
+healthy_again && through_caddy "the restore"
+
step "the first admin's sign-in link, made the way the installer says"
(cd "$DIR" && sudo docker compose exec -T omb openmausbot pair --label "First admin") >"$OUT/pair.txt" 2>&1 || fail "pair failed: $(cat "$OUT/pair.txt")"
grep -q "https://$DOMAIN/pair#code=" "$OUT/pair.txt" || fail "pair printed no link for $DOMAIN"
@@ -136,6 +190,57 @@ install_until_https "$OUT/pinned.txt" "${PLAIN_INSTALL[@]}"
contains "$OUT/pinned.txt" "version: the one update.sh pinned here" "the installer did not keep the pin"
sudo grep -qx "OMB_IMAGE=$pin" "$DIR/.env" || fail "the installer overwrote the pinned version"
+step "an install from before, with Caddy in the server's network, moves to the new layout when the installer runs"
+sudo tee "$DIR/compose.yaml" >/dev/null <<'OLD'
+name: openmausbot
+services:
+ omb:
+ image: ${OMB_IMAGE:?run the installer again}
+ restart: unless-stopped
+ init: true
+ shm_size: 512m
+ volumes:
+ - ./data:/data
+ ports:
+ - "80:80"
+ - "443:443"
+ environment:
+ OMB_PORT: "8799"
+ OMB_WEBHOOK_PORT: "8800"
+ OMB_WEBHOOK_PUBLIC_URL: https://${DOMAIN}
+ OMB_PUBLIC_URL: https://${DOMAIN}
+ OMB_SERVER_NAME: ${OMB_SERVER_NAME:-${DOMAIN}}
+ healthcheck:
+ test: ["CMD-SHELL", "curl -sf http://127.0.0.1:8799/api/health | grep -q openmausbot"]
+ interval: 30s
+ timeout: 5s
+ retries: 3
+ caddy:
+ image: caddy:2
+ restart: unless-stopped
+ network_mode: "service:omb"
+ depends_on:
+ omb:
+ condition: service_healthy
+ environment:
+ DOMAIN: ${DOMAIN}
+ volumes:
+ - ./Caddyfile:/etc/caddy/Caddyfile:ro
+ - ./caddy/data:/data
+ - ./caddy/config:/config
+OLD
+sudo sed -i 's#unix//run/openmausbot/hooks.sock#127.0.0.1:8800#; s#unix//run/openmausbot/http.sock#127.0.0.1:8799#' "$DIR/Caddyfile"
+(cd "$DIR" && sudo docker compose up -d --remove-orphans >/dev/null 2>&1) && healthy_again
+(cd "$DIR" && sudo docker compose restart >/dev/null 2>&1) && healthy_again
+if curl -sk --max-time 5 --resolve "$DOMAIN:443:127.0.0.1" "https://$DOMAIN/api/health" >/dev/null 2>&1; then
+ echo "(the layout from before happened to come back after this restart)"
+else
+ echo "the layout from before: HTTPS refused after docker compose restart, as found on a real server"
+fi
+install_until_https "$OUT/migrated.txt" "${PLAIN_INSTALL[@]}"
+sudo grep -q network_mode "$DIR/compose.yaml" && fail "the run left Caddy in the server's network"
+(cd "$DIR" && sudo docker compose restart >/dev/null 2>&1) && healthy_again && through_caddy "docker compose restart, once moved"
+
step "uninstall: the server stops, the data stays"
sudo sh "$ROOT/deploy/install.sh" --uninstall | tee "$OUT/uninstall.txt"
contains "$OUT/uninstall.txt" "Your data is kept in $DIR/data" "uninstall did not say where the data is"
diff --git a/deploy/install.sh b/deploy/install.sh
index 2558b3b188..cb7361706f 100755
--- a/deploy/install.sh
+++ b/deploy/install.sh
@@ -153,6 +153,18 @@ compose() {
(cd "$INSTALL_DIR" && docker compose "$@")
}
+# Compose's own progress lines (Pulling, Creating, Started) go to a file, and reach the terminal only when it fails.
+compose_quietly() {
+ compose_log=$(mktemp)
+ if compose "$@" >"$compose_log" 2>&1; then
+ rm -f "$compose_log"
+ return 0
+ fi
+ cat "$compose_log" >&2
+ rm -f "$compose_log"
+ return 1
+}
+
env_value() { # name: its value in the install's .env, or nothing
[ -r "$INSTALL_DIR/.env" ] || return 0
sed -n "s/^$1=//p" "$INSTALL_DIR/.env" | tail -n 1
@@ -461,6 +473,43 @@ registry_ask() { # tag
done
}
+registry_get() { # path-under-the-repository media-types: the registry's answer, the pull token on curl's standard input
+ printf 'header = "Authorization: Bearer %s"\n' "$REGISTRY_TOKEN" | curl -K - -fsSL --max-time 20 -H "Accept: $2" "https://ghcr.io/v2/$IMAGE_REPO/$1" 2>/dev/null
+}
+
+# Whether the image a tag or digest names runs the bots' sandbox (OMB_IMAGE=server in its settings), read from the
+# registry without downloading it: yes, no, or nothing when the registry did not say.
+registry_sandbox() { # tag or sha256:digest
+ [ -n "$REGISTRY_TOKEN" ] || REGISTRY_TOKEN=$(registry_token || true)
+ [ -n "$REGISTRY_TOKEN" ] || return 0
+ case "$(uname -m)" in aarch64 | arm64) platform=arm64 ;; *) platform=amd64 ;; esac
+ answer=$(registry_get "manifests/$1" "application/vnd.oci.image.index.v1+json, application/vnd.docker.distribution.manifest.list.v2+json, application/vnd.oci.image.manifest.v1+json, application/vnd.docker.distribution.manifest.v2+json" | tr -d ' \n\r\t') || return 0
+ case "$answer" in
+ *'"manifests":['*)
+ # An index: one manifest per platform. Each entry ends with its platform, so the entries split at "},{".
+ digest=$(printf '%s' "$answer" | sed 's/},{/}\
+{/g' | grep "\"architecture\":\"$platform\"" | grep '"os":"linux"' | sed -n 's/.*"digest":"\(sha256:[0-9a-f]\{64\}\)".*/\1/p' | head -n 1)
+ [ -n "$digest" ] || return 0
+ answer=$(registry_get "manifests/$digest" "application/vnd.oci.image.manifest.v1+json, application/vnd.docker.distribution.manifest.v2+json" | tr -d ' \n\r\t') || return 0
+ ;;
+ esac
+ config=$(printf '%s' "$answer" | sed -n 's/.*"config":{[^}]*"digest":"\(sha256:[0-9a-f]\{64\}\)".*/\1/p')
+ [ -n "$config" ] || return 0
+ case "$(registry_get "blobs/$config" "application/vnd.oci.image.config.v1+json, application/vnd.docker.container.image.v1+json")" in
+ '') ;;
+ *'"OMB_IMAGE=server"'*) echo yes ;;
+ *) echo no ;;
+ esac
+}
+
+# Says, before anything is downloaded, when the version chosen would run without the bots' sandbox.
+note_sandbox() { # tag or sha256:digest
+ [ "$SANDBOX" = yes ] || return 0
+ if [ "$(registry_sandbox "$1" || true)" = no ]; then
+ note "This version has no bots' sandbox, so bots would run beside the server, able to read its settings, keys and each other's files. That is only for a server you alone sign in to; run this again once a version with the sandbox is out."
+ fi
+}
+
newest_release() {
curl -fsS --max-time 15 "$RELEASES_URL" 2>/dev/null | sed -n 's/.*"tag_name": *"\(v[0-9][0-9.]*\)".*/\1/p' | head -n 1
}
@@ -497,6 +546,7 @@ check_version() {
if [ "$REGISTRY_STATUS" = 200 ]; then
IMAGE="ghcr.io/$IMAGE_REPO:stable"
ok "version: the stable channel"
+ note_sandbox stable
return
fi
if [ "$REGISTRY_STATUS" != 404 ]; then
@@ -519,6 +569,7 @@ check_version() {
fi
IMAGE="ghcr.io/$IMAGE_REPO:$release"
ok "version: $release, the newest release"
+ note_sandbox "$release"
}
preflight() {
@@ -582,8 +633,10 @@ write_file() { # path, with the content on standard input: replaced in one step
write_compose() {
write_file "$INSTALL_DIR/compose.yaml" <<'COMPOSE'
# Written by MausBot's installer (deploy/install.sh), and written again each time it runs: put your own settings in
-# .env beside this file, which the installer keeps. Caddy shares the server's network, so the server itself only
-# listens on loopback.
+# .env beside this file, which the installer keeps. The server only listens on loopback inside its container, and on
+# two Unix sockets in the `edge` volume, which Caddy, in its own container, reaches it through. A request on a socket is
+# always a remote one to the server. Caddy does not share the server's network: a server that restarted on its own came
+# back in a new one, and left Caddy refusing HTTPS in the old one.
name: openmausbot
services:
omb:
@@ -593,19 +646,20 @@ services:
shm_size: 512m
volumes:
- ./data:/data
- ports:
- - "80:80"
- - "443:443"
+ - edge:/run/openmausbot
environment:
OMB_PORT: "8799"
OMB_WEBHOOK_PORT: "8800"
+ OMB_TUNNEL_SOCKET: /run/openmausbot/http.sock
+ OMB_WEBHOOK_SOCKET: /run/openmausbot/hooks.sock
OMB_WEBHOOK_PUBLIC_URL: https://${DOMAIN}
OMB_PUBLIC_URL: https://${DOMAIN}
OMB_SERVER_NAME: ${OMB_SERVER_NAME:-${DOMAIN}}
- OMB_SIGNIN_EMAILS: ${OMB_SIGNIN_EMAILS:-}
- OMB_SIGNIN_MEMBER_EMAILS: ${OMB_SIGNIN_MEMBER_EMAILS:-}
- OMB_SIGNIN_SMTP_URL: ${OMB_SIGNIN_SMTP_URL:-}
- OMB_SIGNIN_SMTP_FROM: ${OMB_SIGNIN_SMTP_FROM:-}
+ # Passed only when .env sets them: an empty one would still be set, and Settings' own lists are used when not.
+ OMB_SIGNIN_EMAILS:
+ OMB_SIGNIN_MEMBER_EMAILS:
+ OMB_SIGNIN_SMTP_URL:
+ OMB_SIGNIN_SMTP_FROM:
healthcheck:
test: ["CMD-SHELL", "curl -sf http://127.0.0.1:8799/api/health | grep -q openmausbot"]
interval: 30s
@@ -615,7 +669,9 @@ services:
caddy:
image: caddy:2
restart: unless-stopped
- network_mode: "service:omb"
+ ports:
+ - "80:80"
+ - "443:443"
depends_on:
omb:
condition: service_healthy
@@ -623,8 +679,18 @@ services:
DOMAIN: ${DOMAIN}
volumes:
- ./Caddyfile:/etc/caddy/Caddyfile:ro
+ - edge:/run/openmausbot
- ./caddy/data:/data
- ./caddy/config:/config
+
+volumes:
+ # The two sockets: in memory, made afresh by the server at each start. Not under /data, which every bot's sandbox
+ # sees; the sandbox has its own /run.
+ edge:
+ driver_opts:
+ type: tmpfs
+ device: tmpfs
+ o: mode=1777,size=1m
COMPOSE
}
@@ -637,7 +703,7 @@ write_caddyfile() {
# own per-hook secrets), so it sits outside any login. The path is passed
# through unchanged: the receiver routes on /hooks/<id>.
handle /hooks/* {
- reverse_proxy 127.0.0.1:8800
+ reverse_proxy unix//run/openmausbot/hooks.sock
}
handle {
@@ -647,9 +713,12 @@ write_caddyfile() {
# }
# and set both variables in .env (hash with `caddy hash-password`,
# every `$` doubled for Compose).
- reverse_proxy 127.0.0.1:8799 {
+ reverse_proxy unix//run/openmausbot/http.sock {
# SSE: stream events as they arrive
flush_interval -1
+ # Compression is `encode`'s job above; the server would gzip its
+ # JSON on its socket otherwise, as for the phone tunnel.
+ header_up -Accept-Encoding
}
}
}
@@ -873,12 +942,12 @@ install_server() {
write_caddyfile
write_settings
say "Downloading MausBot..."
- compose pull -q || fail "MausBot could not be downloaded (Docker's message is above). Check this server's outbound HTTPS, then run this again."
+ compose_quietly pull -q || fail "MausBot could not be downloaded (Docker's message is above). Check this server's outbound HTTPS, then run this again."
place_update
prepare_sandbox
prepare_data
say "Starting MausBot..."
- compose up -d --remove-orphans >/dev/null || fail "MausBot could not be started (Docker's message is above). Fix that, then run this again."
+ compose_quietly up -d --remove-orphans || fail "MausBot could not be started (Docker's message is above). Fix that, then run this again."
wait_healthy || fail "MausBot started but did not report healthy within $HEALTH_WAIT_S seconds. Its log: cd $INSTALL_DIR && sudo docker compose logs omb --tail 50"
check_sandbox_runs
say "Waiting for the HTTPS certificate of $DOMAIN..."
@@ -914,12 +983,29 @@ connect_server() {
[ "$status" = 0 ] || fail "MausBot is installed and running here, but connecting it did not finish (the reason is above). Nothing needs reinstalling: fix that and run this again with a new code."
}
+# The first admin's one-time sign-in link, as `openmausbot pair` prints it: its code line (until when it works) and the
+# link. Nothing when the server would not make one.
+first_admin_link() {
+ made=$(compose exec -T omb openmausbot pair --label "First admin" 2>/dev/null) || return 1
+ lines=$(printf '%s\n' "$made" | grep -E '^(Pairing code|Link) ' || true)
+ case "$lines" in *"Link "*"https://$DOMAIN/pair#code="*) printf '%s\n' "$lines" | sed 's/^/ /' ;; *) return 1 ;; esac
+}
+
finish() {
say ""
say "MausBot is running at https://$DOMAIN"
say ""
- say "To sign in as the first admin, make a one-time link on this server and open it in your browser:"
- say " cd $INSTALL_DIR && sudo docker compose exec omb openmausbot pair --label \"First admin\""
+ pair_command="cd $INSTALL_DIR && sudo docker compose exec omb openmausbot pair --label \"First admin\""
+ # Only to a terminal: in a log, the link would let whoever reads it sign in as the admin until it is used or expires.
+ if [ -t 1 ] && link=$(first_admin_link); then
+ say "To sign in as the first admin, open this one-time link in your browser. Anyone who has it can use it, once:"
+ say "$link"
+ say "To make another: $pair_command"
+ else
+ say "To sign in as the first admin, make a one-time link on this server and open it in your browser:"
+ say " $pair_command"
+ [ -t 1 ] || say "(The link is not made here because this output is not a terminal: a log must not hold a link that signs in as the admin.)"
+ fi
admins=$(env_value OMB_SIGNIN_EMAILS)
if [ -n "$admins" ]; then
say "Or open https://$DOMAIN/pair and sign in with an emailed code as: $admins"
@@ -966,7 +1052,7 @@ run_uninstall() {
[ -f "$INSTALL_DIR/compose.yaml" ] || fail "MausBot isn't installed in $INSTALL_DIR, so there is nothing to stop."
command -v docker >/dev/null 2>&1 || fail "Docker isn't installed here, so MausBot isn't running. Your data is in $INSTALL_DIR/data."
say "Stopping MausBot..."
- compose down --remove-orphans >/dev/null || fail "MausBot could not be stopped (Docker's message is above)."
+ compose_quietly down --remove-orphans || fail "MausBot could not be stopped (Docker's message is above)."
say "MausBot is stopped and its containers are removed."
say "Your data is kept in $INSTALL_DIR/data, your settings in $INSTALL_DIR/.env and the HTTPS certificates in $INSTALL_DIR/caddy."
say "To start it again: $(command_line "--domain $(env_value DOMAIN)")"
diff --git a/scripts/server-installer.test.ts b/scripts/server-installer.test.ts
index b2d0d29572..a7f5261c4a 100644
--- a/scripts/server-installer.test.ts
+++ b/scripts/server-installer.test.ts
@@ -60,6 +60,12 @@ esac`,
curl: `echo "curl $*" >> "$FAKE_LOG"
blocked() { case " \${FAKE_BLOCKED:-} " in *" $1 "*) return 0 ;; esac; return 1; }
case "$*" in
+ *"-K - -fsSL"*) cat >> "$FAKE_LOG.stdin"
+ case "$*" in
+ */manifests/sha256:*) printf '%s' "\${FAKE_MANIFEST:-}" ;;
+ */manifests/*) printf '%s' "\${FAKE_INDEX:-}" ;;
+ */blobs/*) printf '%s' "\${FAKE_CONFIG:-}" ;;
+ esac ;;
*"-K -"*) cat >> "$FAKE_LOG.stdin"
if blocked ghcr.io; then exit 7; fi
case "$*" in */manifests/stable) printf '%s' "$FAKE_STABLE" ;; *) printf '%s' "$FAKE_RELEASE_STATUS" ;; esac ;;
@@ -314,10 +320,37 @@ describe.skipIf(!posix)("deploy/install.sh", () => {
"docker compose exec -T omb node dist-server/bot-box/box-check.js --public=none",
]);
expect(result.stdout).toContain(` cd ${result.install} && sudo docker compose exec omb openmausbot pair --label "First admin"`);
+ // Not a terminal, as here: the admin's sign-in link is not made, so no log holds it, and the output says why.
+ expect(result.stdout).toContain("(The link is not made here because this output is not a terminal");
+ expect(result.docker.some((call) => call.includes("openmausbot pair"))).toBe(false);
expect(result.stdout).toContain("Or open https://maus.example.com/pair and sign in with an emailed code as: [email protected]");
expect(result.stdout).toContain(`Your data: ${result.install}/data`);
});
+ it("says, before anything is downloaded, when the version it would install has no bots' sandbox", () => {
+ const digest = (n: string) => `sha256:${n.repeat(64)}`;
+ const registry = (config: string) => ({ env: {
+ FAKE_INDEX: JSON.stringify({ manifests: [
+ { mediaType: "application/vnd.oci.image.manifest.v1+json", digest: digest("a"), size: 1, platform: { architecture: "arm64", os: "linux" } },
+ { mediaType: "application/vnd.oci.image.manifest.v1+json", digest: digest("b"), size: 1, platform: { architecture: "amd64", os: "linux" } },
+ { mediaType: "application/vnd.oci.image.manifest.v1+json", digest: digest("c"), size: 1, platform: { architecture: "unknown", os: "unknown" } },
+ ] }, null, 2),
+ FAKE_MANIFEST: JSON.stringify({ config: { mediaType: "application/vnd.oci.image.config.v1+json", digest: digest("d"), size: 1 }, layers: [] }),
+ FAKE_CONFIG: JSON.stringify({ config: { Env: ["PATH=/usr/bin", "HOME=/data", ...(config ? [config] : [])] } }),
+ } });
+ const without = run(["--check", "--domain", "maus.example.com"], registry(""));
+ expect(without.stdout).toContain(" ok version: v0.1.151, the newest release\n note This version has no bots' sandbox");
+ expect(without.calls.filter((call) => call.includes("-fsSL")).map((call) => call.replace(/^.* (\S+)$/, "$1"))).toEqual([
+ "https://ghcr.io/v2/milind-soni/openmausbot/manifests/v0.1.151",
+ `https://ghcr.io/v2/milind-soni/openmausbot/manifests/${digest("b")}`,
+ `https://ghcr.io/v2/milind-soni/openmausbot/blobs/${digest("d")}`,
+ ]);
+ expect(run(["--check", "--domain", "maus.example.com"], registry("OMB_IMAGE=server")).stdout).not.toContain("no bots' sandbox");
+ // Asked for no sandbox, or a registry that does not say: nothing to add.
+ expect(run(["--check", "--domain", "maus.example.com", "--no-sandbox"], registry("")).stdout).not.toContain("no bots' sandbox");
+ expect(run(["--check", "--domain", "maus.example.com"]).stdout).not.toContain("no bots' sandbox");
+ });
+
it("uses the stable channel once it is published, and never the latest tag", () => {
const result = run(["--domain", "maus.example.com"], { env: { FAKE_STABLE: "200" } });
expect(result.stdout).toContain(" ok version: the stable channel");
@@ -545,12 +578,17 @@ describe.skipIf(!posix)("deploy/install.sh", () => {
expect(readFileSync(join(result.install, "Caddyfile"), "utf8")).toBe(caddyfile.slice(caddyfile.indexOf("{$DOMAIN} {")));
const manual = readFileSync(join(ROOT, "deploy", "docker-compose.yml"), "utf8");
const written = readFileSync(join(result.install, "compose.yaml"), "utf8");
- const settings = (text: string) => [...text.matchAll(/^ {6}(OMB_[A-Z_]+: .*)$/gm)].map((match) => match[1]);
+ const settings = (text: string) => [...text.matchAll(/^ {6}(OMB_[A-Z_]+:.*)$/gm)].map((match) => match[1]);
expect(settings(written)).toEqual(settings(manual));
- for (const line of ['test: ["CMD-SHELL", "curl -sf http://127.0.0.1:8799/api/health | grep -q openmausbot"]', 'network_mode: "service:omb"', "init: true", "shm_size: 512m", '- "80:80"', '- "443:443"']) {
+ // The sign-in lists and mail server are passed only when .env sets them: an empty one would still be set.
+ for (const name of ["OMB_SIGNIN_EMAILS", "OMB_SIGNIN_MEMBER_EMAILS", "OMB_SIGNIN_SMTP_URL", "OMB_SIGNIN_SMTP_FROM"]) expect(settings(written)).toContain(`${name}:`);
+ for (const line of ['test: ["CMD-SHELL", "curl -sf http://127.0.0.1:8799/api/health | grep -q openmausbot"]', "init: true", "shm_size: 512m", '- "80:80"', '- "443:443"',
+ "- edge:/run/openmausbot", "type: tmpfs"]) {
expect(written).toContain(line);
expect(manual).toContain(line);
}
+ // Caddy in the server's network stayed in the old one whenever the server restarted alone, with HTTPS refused.
+ for (const text of [written, manual]) expect(text).not.toContain("network_mode");
expect(written).toContain("- ./data:/data");
expect(written).not.toContain("build:");
});