101 lines
6.0 KiB
Bash
101 lines
6.0 KiB
Bash
#!/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"
|