[docs] Previews (the API for Fabrica, names, the token from the team vault), Ianitor anywhere (Linux, Docker, Windows Server in Caddy mode, NixOS), team sign-in in api.md, the Custos ticket's T4 part; release 0.2.0: the pipeline builds and tests the Linux tarball, the Windows zip and the image; the NixOS previews option; Docker and Linux smoke scripts
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
// This Source Code Form is subject to the terms of the Mozilla Public
|
||||
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
|
||||
// The Windows Server release zip (Caddy mode, T4): ianitor-control.exe (release build without
|
||||
// the test hooks), the built web UI and deploy/windows/install.ps1, in
|
||||
// target/dist/ianitor-<version>-windows-x86_64.zip. Caddy is not in it: install.ps1 fetches the
|
||||
// pinned version and checks its SHA-512.
|
||||
//
|
||||
// cargo build --release -p ianitor-control --no-default-features
|
||||
// pnpm --filter web build
|
||||
// node scripts/package-windows.mjs
|
||||
|
||||
import { cpSync, existsSync, mkdirSync, readFileSync, rmSync } from "node:fs";
|
||||
import { join } from "node:path";
|
||||
import { execFileSync } from "node:child_process";
|
||||
|
||||
const root = new URL("..", import.meta.url).pathname.replace(/^\/([A-Za-z]:)/, "$1");
|
||||
const version = /^version = "([^"]+)"/m.exec(readFileSync(join(root, "Cargo.toml"), "utf8"))?.[1];
|
||||
if (!version) throw new Error("no version in Cargo.toml");
|
||||
const target = process.env.CARGO_TARGET_DIR || join(root, "target");
|
||||
const exe = join(target, "release", "ianitor-control.exe");
|
||||
const web = join(root, "apps", "web", "dist");
|
||||
for (const p of [exe, web]) if (!existsSync(p)) throw new Error(`missing ${p}: build it first`);
|
||||
|
||||
const name = `ianitor-${version}-windows-x86_64`;
|
||||
const out = join(root, "target", "dist");
|
||||
const stage = join(out, name);
|
||||
rmSync(stage, { recursive: true, force: true });
|
||||
mkdirSync(stage, { recursive: true });
|
||||
cpSync(exe, join(stage, "ianitor-control.exe"));
|
||||
cpSync(web, join(stage, "web"), { recursive: true });
|
||||
cpSync(join(root, "deploy", "windows", "install.ps1"), join(stage, "install.ps1"));
|
||||
cpSync(join(root, "LICENSE"), join(stage, "LICENSE"));
|
||||
const zip = join(out, `${name}.zip`);
|
||||
rmSync(zip, { force: true });
|
||||
execFileSync("powershell", ["-NoProfile", "-Command", `Compress-Archive -Path '${stage}\\*' -DestinationPath '${zip}'`], { stdio: "inherit" });
|
||||
rmSync(stage, { recursive: true, force: true });
|
||||
console.log(zip);
|
||||
@@ -0,0 +1,89 @@
|
||||
#!/usr/bin/env bash
|
||||
# This Source Code Form is subject to the terms of the Mozilla Public
|
||||
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
#
|
||||
# Docker end to end (T4): deploy/docker/compose.yaml with the image, a throw-away Domi root,
|
||||
# a branch build in another container, Fabrica's client (scripts/preview.sh) with a
|
||||
# previews-only token, the preview through edge (Pingora) from the host, close. Ports 28080 and
|
||||
# 28443 on 127.0.0.1; everything is removed at the end (containers, volumes, the network).
|
||||
#
|
||||
# scripts/smoke-docker.sh <image> <ianitor-control binary for the offline root> <work dir>
|
||||
set -euo pipefail
|
||||
|
||||
IMAGE=$1 CTL=$2 WORK=$3
|
||||
REPO=$(cd "$(dirname "$0")/.." && pwd)
|
||||
P=ianitor-smoke
|
||||
export COMPOSE_PROJECT_NAME=$P IANITOR_IMAGE=$IMAGE IANITOR_HTTP_PORT=28080 IANITOR_HTTPS_PORT=28443
|
||||
export IANITOR_ADMIN_HOST=ianitor.smoke.test IANITOR_TLS=domi IANITOR_DOMI_ROOT=/var/lib/ianitor/domi-root.crt
|
||||
export IANITOR_PREVIEW_DOMAIN=pv.smoke.test IANITOR_PREVIEW_UPSTREAMS=app:8080
|
||||
DC=(docker compose -f "$REPO/deploy/docker/compose.yaml")
|
||||
step() { echo "== $*"; }
|
||||
ok() { echo " ok: $*"; }
|
||||
fail() { echo "FAILED: $*" >&2; exit 1; }
|
||||
cleanup() {
|
||||
"${DC[@]}" down -v --remove-orphans >/dev/null 2>&1 || true
|
||||
docker rm -f $P-app >/dev/null 2>&1 || true
|
||||
}
|
||||
trap cleanup EXIT
|
||||
[ ! -e "$WORK" ] || fail "$WORK exists; give a new folder"
|
||||
mkdir -p "$WORK"
|
||||
# In edge's network namespace: the loopback API (curl and jq from a throw-away Alpine).
|
||||
inside() { docker run --rm -i --network container:$P-edge-1 alpine:3.20 sh -c "apk add -q curl jq >/dev/null && $1"; }
|
||||
|
||||
step "a throw-away Domi root (offline step)"
|
||||
printf 'smoke-test-offline-passphrase' > "$WORK/pass"
|
||||
"$CTL" ca init --out "$WORK/root" --passphrase-file "$WORK/pass" >/dev/null 2>&1 || fail "ca init"
|
||||
docker volume create ${P}_state >/dev/null
|
||||
docker run --rm -i -v ${P}_state:/v alpine:3.20 sh -c 'cat > /v/domi-root.crt && chown 10001:10001 /v /v/domi-root.crt' < "$WORK/root/domi-root.crt"
|
||||
ok "root in the state volume"
|
||||
|
||||
step "docker compose up"
|
||||
"${DC[@]}" up -d >/dev/null 2>&1 || fail "compose up"
|
||||
for i in $(seq 60); do inside "curl -s -o /dev/null http://127.0.0.1:7878/" 2>/dev/null && break; sleep 2; done
|
||||
ADMIN=$("${DC[@]}" exec -T control ianitor-control token create --name smoke --config /var/lib/ianitor/control.toml 2>/dev/null | tail -n1)
|
||||
FABRICA=$("${DC[@]}" exec -T control ianitor-control token create --name fabrica --scope previews --config /var/lib/ianitor/control.toml 2>/dev/null | tail -n1)
|
||||
[ -n "$ADMIN" ] && [ -n "$FABRICA" ] || fail "tokens"
|
||||
ok "control up, tokens made"
|
||||
|
||||
step "the intermediate, signed offline"
|
||||
rid=$(inside "curl -s -X POST -H 'Authorization: Bearer $ADMIN' http://127.0.0.1:7878/api/v1/certs/intermediate/renewal | jq -r .request_id")
|
||||
inside "curl -s -H 'Authorization: Bearer $ADMIN' http://127.0.0.1:7878/api/v1/pki-requests/$rid/csr" > "$WORK/int.csr"
|
||||
"$CTL" ca sign --root "$WORK/root" --csr "$WORK/int.csr" --out "$WORK/int.crt" --yes --passphrase-file "$WORK/pass" >/dev/null 2>&1 || fail "ca sign"
|
||||
"${DC[@]}" exec -T control sh -c 'cat > /tmp/int.crt && ianitor-control pki install /tmp/int.crt --config /var/lib/ianitor/control.toml' < "$WORK/int.crt" >/dev/null 2>&1 || fail "pki install"
|
||||
"${DC[@]}" restart control >/dev/null 2>&1
|
||||
for i in $(seq 60); do
|
||||
inside "curl -s -H 'Authorization: Bearer $ADMIN' http://127.0.0.1:7878/api/v1/hosts" 2>/dev/null | grep -q ianitor.smoke.test && break
|
||||
sleep 2
|
||||
done
|
||||
ok "intermediate installed; admin host added"
|
||||
|
||||
step "a branch build in its own container"
|
||||
docker run -d --name $P-app --network ${P}_default --network-alias app python:3.12-alpine \
|
||||
sh -c 'mkdir /s && echo "hello from fix-42" > /s/index.html && python -m http.server 8080 --directory /s' >/dev/null
|
||||
sleep 3
|
||||
|
||||
step "Fabrica opens the preview (scripts/preview.sh, previews-only token)"
|
||||
url=$(inside "IANITOR_URL=http://127.0.0.1:7878 IANITOR_PREVIEW_TOKEN=$FABRICA sh -s -- open shop fix-42 http://app:8080 3600" < "$REPO/scripts/preview.sh")
|
||||
[ "$url" = "https://fix-42--shop.pv.smoke.test/" ] || fail "preview URL: $url"
|
||||
ok "preview URL $url"
|
||||
body=$(curl -sS --cacert "$WORK/root/domi-root.crt" --resolve fix-42--shop.pv.smoke.test:28443:127.0.0.1 https://fix-42--shop.pv.smoke.test:28443/ || true)
|
||||
[ "$body" = "hello from fix-42" ] || fail "the preview through edge: $body"
|
||||
ok "the preview answers through edge (Pingora) from the host, with a Domi certificate"
|
||||
code=$(curl -s -o /dev/null -w '%{http_code}' --cacert "$WORK/root/domi-root.crt" --resolve ianitor.smoke.test:28443:127.0.0.1 https://ianitor.smoke.test:28443/api/v1/team || true)
|
||||
[ "$code" = 401 ] || fail "admin host: $code"
|
||||
ok "the admin host reaches control and needs a sign-in (401)"
|
||||
code=$(inside "curl -s -o /dev/null -w '%{http_code}' -H 'Authorization: Bearer $FABRICA' http://127.0.0.1:7878/api/v1/hosts")
|
||||
[ "$code" = 403 ] || fail "preview token on hosts: $code"
|
||||
ok "the preview token cannot read the hosts (403)"
|
||||
|
||||
step "closed on merge"
|
||||
inside "IANITOR_URL=http://127.0.0.1:7878 IANITOR_PREVIEW_TOKEN=$FABRICA sh -s -- close shop fix-42" < "$REPO/scripts/preview.sh" >/dev/null
|
||||
for i in $(seq 45); do
|
||||
code=$(curl -s -o /dev/null -w '%{http_code}' --cacert "$WORK/root/domi-root.crt" --resolve fix-42--shop.pv.smoke.test:28443:127.0.0.1 https://fix-42--shop.pv.smoke.test:28443/ || true)
|
||||
[ "$code" != 200 ] && break
|
||||
sleep 2
|
||||
done
|
||||
[ "$code" != 200 ] || fail "still served after close"
|
||||
ok "gone after close ($code)"
|
||||
echo "SMOKE PASSED"
|
||||
@@ -0,0 +1,100 @@
|
||||
#!/usr/bin/env bash
|
||||
# This Source Code Form is subject to the terms of the Mozilla Public
|
||||
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
#
|
||||
# Plain Linux with systemd, end to end (T4): a Debian container with systemd as PID 1 stands in
|
||||
# for a fresh server. deploy/linux/install.sh installs the release tarball (IANITOR_TARBALL, no
|
||||
# download), a throw-away Domi root signs the intermediate, a branch build runs on 127.0.0.1,
|
||||
# Fabrica's client (scripts/preview.sh) opens the preview with a previews-only token, and the
|
||||
# preview answers through edge (Pingora, under systemd) on a published port; then it is closed.
|
||||
# The container and its image are removed at the end.
|
||||
#
|
||||
# scripts/smoke-linux.sh <dist dir with the tarball and install.sh> <ianitor-control binary> <work dir>
|
||||
set -euo pipefail
|
||||
|
||||
DIST=$1 CTL=$2 WORK=$3
|
||||
REPO=$(cd "$(dirname "$0")/.." && pwd)
|
||||
C=ianitor-smoke-linux
|
||||
step() { echo "== $*"; }
|
||||
ok() { echo " ok: $*"; }
|
||||
fail() { echo "FAILED: $*" >&2; docker exec $C journalctl --no-pager -n 60 -u ianitor-control -u ianitor-edge 2>/dev/null || true; exit 1; }
|
||||
cleanup() { docker rm -f $C >/dev/null 2>&1 || true; docker rmi -f $C:latest >/dev/null 2>&1 || true; }
|
||||
trap cleanup EXIT
|
||||
[ ! -e "$WORK" ] || fail "$WORK exists; give a new folder"
|
||||
mkdir -p "$WORK"
|
||||
tarball=$(ls "$DIST"/ianitor-*-linux-x86_64.tar.gz | head -n1)
|
||||
[ -f "$tarball" ] && [ -f "$DIST/install.sh" ] || fail "no tarball or install.sh in $DIST"
|
||||
version=$(basename "$tarball" | sed 's/^ianitor-\(.*\)-linux-x86_64.tar.gz$/\1/')
|
||||
|
||||
step "a fresh Debian with systemd"
|
||||
docker build -q -t $C:latest - >/dev/null <<'EOF'
|
||||
FROM debian:bookworm-slim
|
||||
RUN apt-get update && apt-get install -y --no-install-recommends systemd systemd-sysv dbus git curl jq python3 ca-certificates \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
STOPSIGNAL SIGRTMIN+3
|
||||
CMD ["/sbin/init"]
|
||||
EOF
|
||||
docker run -d --name $C --privileged --cgroupns=host -v /sys/fs/cgroup:/sys/fs/cgroup:rw \
|
||||
--tmpfs /run --tmpfs /run/lock -p 127.0.0.1:38443:443 $C:latest >/dev/null
|
||||
for i in $(seq 30); do docker exec $C systemctl is-system-running 2>/dev/null | grep -qE 'running|degraded' && break; sleep 1; done
|
||||
ok "systemd is up"
|
||||
|
||||
step "a throw-away Domi root (offline step)"
|
||||
printf 'smoke-test-offline-passphrase' > "$WORK/pass"
|
||||
"$CTL" ca init --out "$WORK/root" --passphrase-file "$WORK/pass" >/dev/null 2>&1 || fail "ca init"
|
||||
docker exec $C mkdir -p /etc/ianitor
|
||||
docker cp "$WORK/root/domi-root.crt" $C:/etc/ianitor/domi-root.crt
|
||||
docker cp "$tarball" $C:/tmp/
|
||||
docker cp "$DIST/install.sh" $C:/tmp/install.sh
|
||||
|
||||
step "install.sh (the one line, with the tarball given instead of downloaded)"
|
||||
docker exec -e IANITOR_TARBALL=/tmp/$(basename "$tarball") -e IANITOR_ADMIN_HOST=ianitor.smoke.test -e IANITOR_TLS=domi \
|
||||
-e IANITOR_DOMI_ROOT=/etc/ianitor/domi-root.crt -e IANITOR_PREVIEW_DOMAIN=pv.smoke.test \
|
||||
-e IANITOR_PREVIEW_UPSTREAMS=127.0.0.1:20000-29999 $C sh /tmp/install.sh > "$WORK/install.log" 2>&1 \
|
||||
|| { cat "$WORK/install.log"; fail "install.sh"; }
|
||||
grep -q '#signin=isc_' "$WORK/install.log" || { cat "$WORK/install.log"; fail "no sign-in link printed"; }
|
||||
ok "installed $version; both units active: $(docker exec $C systemctl is-active ianitor-control ianitor-edge | tr '\n' ' ')"
|
||||
|
||||
as_ianitor() { docker exec $C runuser -u ianitor -- "$@"; }
|
||||
ADMIN=$(as_ianitor ianitor-control token create --name smoke --config /etc/ianitor/control.toml 2>/dev/null | tail -n1)
|
||||
FABRICA=$(as_ianitor ianitor-control token create --name fabrica --scope previews --config /etc/ianitor/control.toml 2>/dev/null | tail -n1)
|
||||
api() { docker exec $C curl -s -H "Authorization: Bearer $1" "${@:2}"; }
|
||||
|
||||
step "the intermediate, signed offline"
|
||||
rid=$(api "$ADMIN" -X POST http://127.0.0.1:7878/api/v1/certs/intermediate/renewal | jq -r .request_id)
|
||||
api "$ADMIN" "http://127.0.0.1:7878/api/v1/pki-requests/$rid/csr" > "$WORK/int.csr"
|
||||
"$CTL" ca sign --root "$WORK/root" --csr "$WORK/int.csr" --out "$WORK/int.crt" --yes --passphrase-file "$WORK/pass" >/dev/null 2>&1 || fail "ca sign"
|
||||
docker cp "$WORK/int.crt" $C:/tmp/int.crt
|
||||
docker exec $C chmod 0644 /tmp/int.crt
|
||||
as_ianitor ianitor-control pki install /tmp/int.crt --config /etc/ianitor/control.toml >/dev/null 2>&1 || fail "pki install"
|
||||
docker exec $C systemctl restart ianitor-control
|
||||
for i in $(seq 60); do api "$ADMIN" http://127.0.0.1:7878/api/v1/hosts 2>/dev/null | grep -q ianitor.smoke.test && break; sleep 2; done
|
||||
ok "intermediate installed; admin host added"
|
||||
|
||||
step "a branch build on 127.0.0.1:23456"
|
||||
docker exec -d $C sh -c 'mkdir -p /srv/app && echo "hello from fix-42" > /srv/app/index.html && python3 -m http.server 23456 --bind 127.0.0.1 --directory /srv/app'
|
||||
sleep 2
|
||||
|
||||
step "Fabrica opens the preview (scripts/preview.sh, previews-only token)"
|
||||
docker cp "$REPO/scripts/preview.sh" $C:/tmp/preview.sh
|
||||
url=$(docker exec -e IANITOR_URL=http://127.0.0.1:7878 -e IANITOR_PREVIEW_TOKEN="$FABRICA" $C sh /tmp/preview.sh open shop fix-42 http://127.0.0.1:23456 3600)
|
||||
[ "$url" = "https://fix-42--shop.pv.smoke.test/" ] || fail "preview URL: $url"
|
||||
ok "preview URL $url"
|
||||
body=$(curl -sS --cacert "$WORK/root/domi-root.crt" --resolve fix-42--shop.pv.smoke.test:38443:127.0.0.1 https://fix-42--shop.pv.smoke.test:38443/ || true)
|
||||
[ "$body" = "hello from fix-42" ] || fail "the preview through edge: $body"
|
||||
ok "the preview answers through edge (Pingora under systemd), with a Domi certificate"
|
||||
code=$(api "$FABRICA" -o /dev/null -w '%{http_code}' http://127.0.0.1:7878/api/v1/hosts)
|
||||
[ "$code" = 403 ] || fail "preview token on hosts: $code"
|
||||
ok "the preview token cannot read the hosts (403)"
|
||||
|
||||
step "closed on merge"
|
||||
docker exec -e IANITOR_URL=http://127.0.0.1:7878 -e IANITOR_PREVIEW_TOKEN="$FABRICA" $C sh /tmp/preview.sh close shop fix-42 >/dev/null
|
||||
for i in $(seq 45); do
|
||||
code=$(curl -s -o /dev/null -w '%{http_code}' --cacert "$WORK/root/domi-root.crt" --resolve fix-42--shop.pv.smoke.test:38443:127.0.0.1 https://fix-42--shop.pv.smoke.test:38443/ || true)
|
||||
[ "$code" != 200 ] && break
|
||||
sleep 2
|
||||
done
|
||||
[ "$code" != 200 ] || fail "still served after close"
|
||||
ok "gone after close ($code)"
|
||||
echo "SMOKE PASSED"
|
||||
Reference in New Issue
Block a user