Publish Neo Roundtable 0.6.0 (592b9cb9300330252653da69e8b58c4490f01fdc)

This commit is contained in:
GPT-6
2026-11-07 08:48:16 +01:00
commit d3adffdfaf
8 changed files with 1321 additions and 0 deletions
+41
View File
@@ -0,0 +1,41 @@
# Neo Roundtable
Self-hosted Neo Roundtable by Sky::NET.
## Requirements
- Debian (amd64) with Docker Engine and the Docker Compose plugin
- About 3 GB free disk for the images, plus room for your data
- 8 GB RAM recommended
- An access token from Sky::NET
## Install
```sh
curl -fsSL https://git.sn-s.net/neo/neo-roundtable/raw/branch/main/install | bash
```
The installer checks your system, then asks for your access token, an admin
name and password, and your two domains (Roundtable and Neo app). Nothing is
written before every question is answered.
It installs to `/opt/containers/neo-roundtable` and listens only on
`127.0.0.1:3060`. Put your own reverse proxy with TLS in front of it for both
domains. Settings live in `.env`.
## Everyday use
From the install folder:
- `./neo-admin status`: version, health, disk and last backup
- `./neo-admin update`: back up, then update to the latest release
- `./neo-admin rollback`: back to the previous release, if the database is unchanged
- `./neo-admin backup` and `./neo-admin restore <archive>`
- `./neo-admin reset-pwd <user>`
- `./neo-admin logs`
- `./neo-admin uninstall`: remove the containers, keep all data
- `./neo-admin uninstall --purge`: delete the installation and its data permanently
An existing installation from a source checkout: put `neo-admin` next to its
Compose file and run `./neo-admin adopt`.
## Good to know
- Backups cover the database, files, Neo originals and keys. Contacts Workshop
data is not included yet; back up its folder separately.
- Keep a copy of `.env`; it is not part of the backup.
- Neo Web and Contacts Workshop are off by default; switch them on in `.env`.
+140
View File
@@ -0,0 +1,140 @@
services:
postgres:
image: ${NEO_IMAGE_POSTGRES:?release image required}
restart: unless-stopped
labels:
roundtable.distribution: "1"
environment:
POSTGRES_DB: ${POSTGRES_DB:-roundtable}
POSTGRES_USER: ${POSTGRES_USER:-roundtable}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:?database password required}
volumes:
- ./data/psql/_data:/var/lib/postgresql
healthcheck:
test: ["CMD", "pg_isready", "-U", "${POSTGRES_USER:-roundtable}", "-d", "${POSTGRES_DB:-roundtable}"]
interval: 5s
timeout: 5s
retries: 5
roundtable:
image: ${NEO_IMAGE_ROUNDTABLE:?release image required}
restart: unless-stopped
labels:
roundtable.distribution: "1"
depends_on:
postgres:
condition: service_healthy
environment:
PGHOST: postgres
PGPORT: "5432"
PGUSER: ${POSTGRES_USER:-roundtable}
PGPASSWORD: ${POSTGRES_PASSWORD:?database password required}
PGDATABASE: ${POSTGRES_DB:-roundtable}
PGSSLMODE: disable
NEO_APP_ORIGIN: ${NEO_APP_ORIGIN:-}
ROUNDTABLE_PUBLIC_ORIGIN: ${ROUNDTABLE_PUBLIC_ORIGIN:-http://localhost:${ROUNDTABLE_PORT:-3060}}
ROUNDTABLE_OAUTH_SIGNING_KEY: ${ROUNDTABLE_OAUTH_SIGNING_KEY:-}
ROUNDTABLE_TRUSTED_PROXIES: ${ROUNDTABLE_TRUSTED_PROXIES:-${ROUNDTABLE_GATEWAY:-172.28.0.1}/32}
ROUNDTABLE_SUBNET: ${ROUNDTABLE_SUBNET:-172.28.0.0/16}
DUO_CLIENT_ID: ${DUO_CLIENT_ID:-}
DUO_CLIENT_SECRET: ${DUO_CLIENT_SECRET:-}
DUO_API_HOST: ${DUO_API_HOST:-}
DUO_FAIL_OPEN: ${DUO_FAIL_OPEN:-true}
ROUNDTABLE_DATA_DIR: ${ROUNDTABLE_DATA_DIR:-/data}
ROUNDTABLE_BACKUP_DIR: ${ROUNDTABLE_BACKUP_DIR:-/backups}
ROUNDTABLE_BACKUP_KEEP: ${ROUNDTABLE_BACKUP_KEEP:-5}
ROUNDTABLE_NEO_WEB: ${ROUNDTABLE_NEO_WEB:-}
ROUNDTABLE_CONTACTS_WORKSHOP: ${ROUNDTABLE_CONTACTS_WORKSHOP:-}
ROUNDTABLE_PHONE_REGION: ${ROUNDTABLE_PHONE_REGION:-DE}
ROUNDTABLE_OCR_URL: http://ocr:8090
ROUNDTABLE_TRANSCRIPTION_URL: http://transcription:8091
networks:
- default
- ocr-private
- transcription-private
- contacts-private
volumes:
- ./backups:/backups
- ./data:/data
- ./vault/neo-keys:/data/neo-keys
ports:
- "127.0.0.1:${ROUNDTABLE_PORT:-3060}:8080"
contacts-workshop:
profiles: [contacts]
image: ${NEO_IMAGE_CONTACTS:?release image required}
restart: unless-stopped
labels:
roundtable.distribution: "1"
depends_on:
- roundtable
environment:
ROUNDTABLE_PUBLIC_ORIGIN: ${ROUNDTABLE_PUBLIC_ORIGIN:-http://localhost:${ROUNDTABLE_PORT:-3060}}
ROUNDTABLE_PHONE_REGION: ${ROUNDTABLE_PHONE_REGION:-DE}
CONTACTS_WORKSHOP_DIR: /var/lib/contacts
read_only: true
tmpfs:
- /tmp:size=16m
cap_drop: [ALL]
security_opt: [no-new-privileges:true]
volumes:
- ./data/tools/contacts:/var/lib/contacts
networks:
- contacts-private
ocr:
image: ${NEO_IMAGE_OCR:?release image required}
restart: unless-stopped
labels:
roundtable.distribution: "1"
cpus: 2.0
mem_limit: 1536m
memswap_limit: 1536m
read_only: true
tmpfs:
- /tmp:size=64m
cap_drop: [ALL]
security_opt: [no-new-privileges:true]
healthcheck:
test: ["CMD", "python", "-c", "import urllib.request; urllib.request.urlopen('http://127.0.0.1:8090/healthz', timeout=2).close()"]
interval: 10s
timeout: 3s
start_period: 30s
retries: 3
networks:
- ocr-private
transcription:
image: ${NEO_IMAGE_TRANSCRIPTION:?release image required}
restart: unless-stopped
labels:
roundtable.distribution: "1"
cpus: 2.0
mem_limit: 2g
memswap_limit: 2g
read_only: true
tmpfs:
- /tmp:size=300m
cap_drop: [ALL]
security_opt: [no-new-privileges:true]
healthcheck:
test: ["CMD", "python", "-c", "import urllib.request; urllib.request.urlopen('http://127.0.0.1:8091/healthz', timeout=2).close()"]
interval: 10s
timeout: 3s
start_period: 30s
retries: 3
networks:
- transcription-private
networks:
contacts-private:
internal: true
transcription-private:
internal: true
ocr-private:
internal: true
default:
ipam:
config:
- subnet: ${ROUNDTABLE_SUBNET:-172.28.0.0/16}
gateway: ${ROUNDTABLE_GATEWAY:-172.28.0.1}
Executable
+12
View File
@@ -0,0 +1,12 @@
#!/usr/bin/env bash
set -euo pipefail
set +x
umask 077
if ! { : </dev/tty; } 2>/dev/null; then echo 'A terminal is required for installation.' >&2; exit 1; fi
command -v curl >/dev/null || { echo 'Install curl first.' >&2; exit 1; }
parent=${TMPDIR:-/tmp}
[[ ! -d /dev/shm || ! -w /dev/shm ]] || parent=/dev/shm
staging=$(mktemp -d "$parent/neo-bootstrap.XXXXXXXX")
trap 'rm -rf -- "$staging"' EXIT
curl --proto '=https' --proto-redir '=https' -fsSL https://git.sn-s.net/neo/neo-roundtable/raw/branch/main/neo-admin -o "$staging/neo-admin"
bash "$staging/neo-admin" install
Executable
+469
View File
@@ -0,0 +1,469 @@
#!/usr/bin/env bash
# Host-side Docker orchestration. Never source downloaded release metadata.
set -euo pipefail
set +x
umask 077
BASE=https://git.sn-s.net/neo/neo-roundtable/raw/branch/main
REGISTRY=git.sn-s.net
STAGING=
ROOT=/opt/containers/neo-roundtable
declare -A manifest=()
COMPOSE=()
RUN=(docker run --rm --network none)
helper_image=
error() { printf '%s\n' "$*" >&2; return 1; }
ok() { printf '✓ %s\n' "$*"; }
fetch() { curl --proto '=https' --proto-redir '=https' --connect-timeout 10 --max-time 120 -fsSL "$1" -o "$2"; }
staging() {
RUN=(docker run --rm --network none)
local parent=${TMPDIR:-/tmp}
[[ ! -d /dev/shm || ! -w /dev/shm ]] || parent=/dev/shm
STAGING=$(mktemp -d "$parent/neo-admin.XXXXXXXX")
trap 'unset token password; rm -rf -- "$STAGING"' EXIT
}
pin_docker() {
local endpoint=${DOCKER_HOST:-}
[[ -n $endpoint ]] || endpoint=$(docker context inspect --format '{{.Endpoints.docker.Host}}')
[[ $endpoint == unix://* ]] || { error 'Use a local Unix-socket Docker engine; remote contexts are not supported.'; return 1; }
export DOCKER_HOST=$endpoint
unset DOCKER_CONTEXT
}
terminal() { { : </dev/tty; } 2>/dev/null || error 'A terminal is required for installation.'; }
question() {
local name=$1 prompt=$2 hidden=${3:-0} value
if [[ $hidden == 1 ]]; then IFS= read -r -s -p "$prompt: " value </dev/tty; printf '\n' >/dev/tty
else IFS= read -r -p "$prompt: " value </dev/tty; fi
[[ -n $value && $value != *$'\r'* ]] || error 'An answer is required.'
printf -v "$name" '%s' "$value"
}
read_manifest() {
local file=$1 key value name
manifest=()
[[ $(wc -c < "$file") -le 16384 ]] || error 'Manifest is too large.'
while IFS='=' read -r key value || [[ -n $key ]]; do
[[ $key =~ ^[a-z][a-z0-9_]{0,63}$ && -n $value && ! -v manifest[$key] ]] || { error 'Invalid or duplicate manifest field.'; return 1; }
case "$key" in
format) [[ $value == 1 ]] ;;
platform) [[ $value == linux/amd64 ]] ;;
version) [[ $value =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]] ;;
revision|admin_sha256|compose_sha256) if [[ $key == revision ]]; then [[ $value =~ ^[0-9a-f]{40}$ ]]; else [[ $value =~ ^[0-9a-f]{64}$ ]]; fi ;;
schema) [[ $value =~ ^[1-9][0-9]{0,4}$ ]] ;;
postgres_major) [[ $value == 18 ]] ;;
admin_url|compose_url) [[ $value == "$BASE"/releases/* && $value != *[[:space:]\'\"\`\$\;\&\?\#]* && $value != *..* ]] ;;
image_roundtable|image_ocr|image_transcription|image_contacts)
name=${key#image_}; [[ $name != contacts ]] || name=contacts-workshop
[[ $value =~ ^git\.sn-s\.net/neo-distribution/$name@sha256:[0-9a-f]{64}$ ]] ;;
image_postgres) [[ $value =~ ^docker\.io/library/postgres@sha256:[0-9a-f]{64}$ ]] ;;
pull_bytes_roundtable|pull_bytes_ocr|pull_bytes_transcription|pull_bytes_contacts|pull_bytes_postgres|unpacked_bytes_roundtable|unpacked_bytes_ocr|unpacked_bytes_transcription|unpacked_bytes_contacts|unpacked_bytes_postgres)
[[ $value =~ ^[1-9][0-9]{0,14}$ ]] ;;
*) error 'Unknown manifest field.'; return 1 ;;
esac || { error "Invalid manifest field: $key"; return 1; }
manifest[$key]=$value
done < "$file"
for key in format platform version revision schema postgres_major admin_url admin_sha256 compose_url compose_sha256; do [[ -v manifest[$key] ]] || { error "Missing manifest field: $key"; return 1; }; done
for name in roundtable ocr transcription contacts postgres; do
for key in image_$name pull_bytes_$name unpacked_bytes_$name; do [[ -v manifest[$key] ]] || { error "Missing manifest field: $key"; return 1; }; done
done
[[ ${manifest[admin_url]} == "$BASE/releases/${manifest[version]}/neo-admin" && ${manifest[compose_url]} == "$BASE/releases/${manifest[version]}/compose.yml" ]] || error 'Release URLs must match the version.'
}
latest() { fetch "$BASE/stable.manifest" "$STAGING/release.manifest"; read_manifest "$STAGING/release.manifest"; helper_image=${manifest[image_roundtable]}; }
verify_file() { local actual; actual=$(sha256sum "$1"); [[ ${actual%% *} == "$2" ]] || error 'Release checksum mismatch.'; }
image_space() {
local name c=0 u=0 root available required
for name in roundtable ocr transcription contacts postgres; do
if ! docker image inspect "${manifest[image_$name]}" >/dev/null 2>&1; then
c=$((c+${manifest[pull_bytes_$name]})); u=$((u+${manifest[unpacked_bytes_$name]}))
fi
done
root=$(docker info --format '{{.DockerRootDir}}')
[[ -d $root ]] || { error 'Docker storage must be on this host so free disk can be checked.'; return 1; }
available=$(df -Pk "$root" | awk 'END {print $4*1024}')
required=$(((c+u)*12/10+1073741824))
awk -v a="$available" -v r="$required" 'BEGIN{exit !(a>=r)}' || { error "Docker disk needs $required additional bytes; free space first."; return 1; }
IMAGE_RESERVE_BYTES=$required; DOCKER_DEVICE=$(stat -c %d "$root")
ok "Docker disk reserve: $required bytes"
}
subnet_check() {
local subnet=172.28.0.0/16 network existing
# Compare the fixed production subnet as IPv4 ranges.
local a b c d prefix ip lo hi eip elo ehi eprefix
IFS='./' read -r a b c d prefix <<< "$subnet"
ip=$(((a<<24)+(b<<16)+(c<<8)+d)); lo=$((ip & (0xFFFFFFFF << (32-prefix)))); hi=$((lo + (1 << (32-prefix))-1))
while IFS= read -r network; do
[[ -n $network ]] || continue
while IFS= read -r existing; do
[[ $existing == *.*/* ]] || continue
IFS='./' read -r a b c d eprefix <<< "$existing"
eip=$(((a<<24)+(b<<16)+(c<<8)+d)); elo=$((eip & (0xFFFFFFFF << (32-eprefix)))); ehi=$((elo+(1 << (32-eprefix))-1))
((lo>ehi || elo>hi)) || { error "Docker subnet $subnet clashes with existing network $network ($existing); nothing changed."; return 1; }
done < <(docker network inspect --format '{{range .IPAM.Config}}{{println .Subnet}}{{end}}' "$network")
done < <(docker network ls -q)
}
host_checks() {
local mode=$1 os_id
[[ $(uname -m) == x86_64 && $(uname -s) == Linux ]] || { error 'Only Linux amd64 is supported.'; return 1; }; ok 'Linux amd64'
os_id=$(sed -n 's/^ID=//p' /etc/os-release | tr -d '"')
[[ $os_id == debian ]] || { error 'This installer currently supports Debian; use a supported Debian host.'; return 1; }; ok 'Debian'
command -v docker >/dev/null || { error 'Please install Docker properly https://docs.docker.com/engine/install/debian/'; return 1; }
pin_docker
if ! docker info >/dev/null 2>&1 || ! docker compose version >/dev/null 2>&1; then error 'Docker and its Compose plugin must be running and usable by this user.'; return 1; fi; ok 'Docker and Compose'
curl --proto '=https' --connect-timeout 10 --max-time 30 -sS -D "$STAGING/registry.headers" -o /dev/null "https://$REGISTRY/v2/"
grep -qi 'realm="https://git.sn-s.net/v2/token"' "$STAGING/registry.headers" || { error 'Registry must advertise its HTTPS token endpoint.'; return 1; }; ok 'Registry reachable over HTTPS'
if [[ $mode == install ]]; then
[[ ! -e $ROOT || ( -d $ROOT && -z $(ls -A -- "$ROOT") ) ]] || { error 'Install folder is not empty; use update or adopt.'; return 1; }
command -v ss >/dev/null || { error 'Install iproute2 so the listening port can be checked.'; return 1; }
[[ -z $(ss -H -ltn '( sport = :3060 )') ]] || { error '127.0.0.1:3060 is occupied; nothing changed.'; return 1; }
local project=neo-roundtable
[[ -z $(docker ps -aq --filter "label=com.docker.compose.project=$project") && -z $(docker volume ls -q --filter "label=com.docker.compose.project=$project") ]] || { error 'An existing Compose project or data volume was found; use adopt.'; return 1; }
if docker volume inspect "${project}_roundtable-postgres-data" >/dev/null 2>&1; then error 'An old database volume exists; use adopt.'; return 1; fi
local parent=$ROOT available
while [[ ! -d $parent ]]; do parent=$(dirname "$parent"); done
[[ -w $parent ]] || { error "Install folder parent $parent must be writable by this user."; return 1; }
available=$(df -Pk "$parent" | awk 'END {print $4*1024}')
awk -v a="$available" 'BEGIN{exit !(a>=1073741824)}' || { error 'Install filesystem needs at least 1 GiB free for initial data.'; return 1; }
subnet_check
ok 'Empty install folder, unused project, subnet and port 3060'
fi
image_space
}
login() { local directory=$1; mkdir -p "$directory"; chmod 700 "$directory"; printf '%s' "$token" | DOCKER_CONFIG="$directory" docker login "$REGISTRY" --username neo-pull --password-stdin >/dev/null; chmod 600 "$directory/config.json"; }
verify_token() {
export DOCKER_CONFIG=$STAGING/auth
login "$DOCKER_CONFIG"
local name
for name in roundtable ocr transcription contacts; do docker manifest inspect "${manifest[image_$name]}" > "$STAGING/$name.manifest" || { error "Token cannot read the $name image manifest."; return 1; }; done
ok 'Token reads all four image manifests'
}
pull_release() { local name; for name in roundtable ocr transcription contacts postgres; do docker pull --platform linux/amd64 "${manifest[image_$name]}"; done; }
export_images() {
export NEO_IMAGE_ROUNDTABLE=${manifest[image_roundtable]} NEO_IMAGE_OCR=${manifest[image_ocr]} NEO_IMAGE_TRANSCRIPTION=${manifest[image_transcription]} NEO_IMAGE_CONTACTS=${manifest[image_contacts]} NEO_IMAGE_POSTGRES=${manifest[image_postgres]}
}
helper() { "${COMPOSE[@]}" -f "$STAGING/helper.yml" run --rm -T --no-deps --entrypoint roundtable roundtable admin "$@"; }
make_override() {
local target=$1 name service services pgdata default_pgdata
services=$("${COMPOSE[@]}" config --services)
printf 'services:\n' > "$target"
for name in roundtable ocr transcription contacts postgres; do
service=$name; [[ $name != contacts ]] || service=contacts-workshop
# Adoption changes images only; it must not invent incomplete sidecars
# when an older source Compose does not declare them.
grep -Fxq "$service" <<< "$services" || continue
printf ' %s:\n image: %s\n pull_policy: never\n' "$service" "${manifest[image_$name]}" >> "$target"
if [[ $service == postgres && -f $STAGING/current.identity ]]; then
pgdata=$(helper identity-pgdata < "$STAGING/current.identity")
default_pgdata=$(docker image inspect --format '{{range .Config.Env}}{{println .}}{{end}}' "${manifest[image_postgres]}" | sed -n 's/^PGDATA=//p')
# Preserve custom image defaults explicitly, without needlessly
# changing the Compose hash when the new default already matches.
if [[ $pgdata != "\"$default_pgdata\"" ]]; then
printf ' environment:\n PGDATA: %s\n' "$pgdata" >> "$target"
fi
fi
done
}
setup_compose() {
export_images
cd "$ROOT"
local source_file
if [[ -f .neo-source ]]; then IFS= read -r source_file < .neo-source
elif [[ -f compose.yml ]]; then source_file=compose.yml
elif [[ -f docker-compose.yml ]]; then source_file=docker-compose.yml
else error 'No existing Compose configuration; use install.'; return 1; fi
[[ $source_file == compose.yml || $source_file == docker-compose.yml ]] || { error 'Invalid source Compose marker.'; return 1; }
COMPOSE=(docker compose -f "$ROOT/$source_file")
if [[ -f .neo-images.yml ]]; then COMPOSE+=(-f "$ROOT/.neo-images.yml"); fi
printf 'services:\n roundtable:\n image: %s\n pull_policy: never\n' "$helper_image" > "$STAGING/helper.yml"
}
identity() {
local mode=${1:-running} pg app major project id ids image replacement replacement_major pgdata
local -a observed
pg=$("${COMPOSE[@]}" ps -aq postgres); app=$("${COMPOSE[@]}" ps -aq roundtable)
[[ -n $pg && -n $app && $pg != *$'\n'* && $app != *$'\n'* ]] || { error 'Cannot prove data identity: retain the existing containers and repair the Compose project/mount configuration before retrying. Do not create a new database.'; return 1; }
if [[ $mode != recovery && $(docker inspect --format '{{.State.Running}}' "$pg") != true ]]; then
error 'Postgres is stopped; use restore or rollback for recovery.'; return 1
fi
image=$(docker inspect --format '{{.Image}}' "$pg")
[[ $image == sha256:* && $(docker image inspect --format '{{.Id}}' "$image") == "$image" ]] || { error 'Cannot verify the retained Postgres image; recover that exact local image before retrying. Do not recreate the database.'; return 1; }
major=$("${RUN[@]}" --entrypoint postgres "$image" --version); major=${major##* }; major=${major%%.*}
replacement=$("${COMPOSE[@]}" config --format json | "${RUN[@]}" -i --entrypoint roundtable "$helper_image" admin compose-postgres-image)
replacement=$(docker image inspect --format '{{.Id}}' "$replacement")
replacement_major=$("${RUN[@]}" --entrypoint postgres "$replacement" --version); replacement_major=${replacement_major##* }; replacement_major=${replacement_major%%.*}
[[ $major == 18 && $replacement_major == "$major" ]] || { error 'Verified Postgres image majors differ or are unsupported; repair the original image reference before retrying.'; return 1; }
pgdata=$(docker image inspect --format '{{range .Config.Env}}{{println .}}{{end}}' "$replacement" | sed -n 's/^PGDATA=//p')
observed=("$pg" "$app")
project=$(docker inspect --format '{{index .Config.Labels "com.docker.compose.project"}}' "$pg") || return 1
ids=$(docker ps -aq --no-trunc --filter "label=com.docker.compose.project=$project" --filter 'label=com.docker.compose.oneoff=False') || return 1
while IFS= read -r id; do
[[ -z $id || $id == "$pg" || $id == "$app" ]] || observed+=("$id")
done <<< "$ids"
{ docker inspect "${observed[@]}"; "${COMPOSE[@]}" config --format json; } | "${RUN[@]}" -i --entrypoint roundtable "$helper_image" admin adopt-check "$major" "$pgdata"
}
guard() {
local mode=${1:-running}
if [[ $mode == recovery && ! -f .neo-identity ]]; then error 'Cannot prove recovery identity: restore the recorded .neo-identity and original Compose configuration first. Do not recreate the database.'; return 1; fi
identity "$mode" > "$STAGING/current.identity" || { error 'Identity could not be proven. Repair the original Compose project, image and mounts, then retry; do not recreate the database.'; return 1; }
if [[ -f .neo-identity ]]; then cmp -s .neo-identity "$STAGING/current.identity" || { error 'Recorded data identity differs; nothing started or replaced. Repair the original Compose project/mounts before retrying.'; return 1; }; fi
local pg project legacy mounted state
pg=$("${COMPOSE[@]}" ps -aq postgres)
if [[ $mode == recovery ]]; then
if [[ $(docker inspect --format '{{.State.Running}}' "$pg") != true ]]; then
docker start "$pg" >/dev/null
fi
local deadline=$((SECONDS+60))
until docker exec "$pg" pg_isready -q; do
((SECONDS<deadline)) || { error 'Verified Postgres did not become ready. Repair its startup using docker logs; do not recreate it or change its mounts.'; return 1; }
sleep 1
done
fi
project=$(docker inspect --format '{{index .Config.Labels "com.docker.compose.project"}}' "$pg")
legacy=${project}_roundtable-postgres-data
mounted=$(docker inspect --format '{{range .Mounts}}{{if eq .Type "volume"}}{{println .Name}}{{end}}{{end}}' "$pg")
if ! grep -Fxq "$legacy" <<< "$mounted" && docker volume inspect "$legacy" >/dev/null 2>&1; then
# Do not start, traverse or copy an unused cluster to guess its contents.
# An empty current database plus a retained previous volume needs the
# operator's evidence before any service/data replacement.
state=$(helper data-state) || { error 'Cannot inspect the current database; nothing replaced.'; return 1; }
[[ $state == populated ]] || { error "Current database is empty and unused legacy volume $legacy exists; inspect it before continuing. Nothing replaced."; return 1; }
fi
}
locked() { exec 9>"$ROOT/.neo-lock"; flock -n 9 || error 'Another neo-admin operation is running.'; }
backup_now() {
helper capacity "${DOCKER_DEVICE:-0}" "${IMAGE_RESERVE_BYTES:-0}"
helper backup | tee "$STAGING/backup.log"
backup_file=$(sed -n 's/^Backup completed: //p' "$STAGING/backup.log" | tail -n 1)
[[ $backup_file == /backups/roundtable-*.tar.gz && $backup_file != *..* && $backup_file != *$'\n'* ]] || error 'Backup did not report a valid archive.'
}
recovery_guidance() {
local schema previous archive
echo 'Application failed to become healthy.' >&2
if [[ -f .neo-previous/schema && -f .neo-previous/backup ]]; then
IFS= read -r previous < .neo-previous/schema
IFS= read -r archive < .neo-previous/backup
if schema=$(helper schema) && [[ $schema == "$previous" ]]; then
echo 'Run: ./neo-admin rollback' >&2
else printf 'Run: ./neo-admin restore %q\n' "$archive" >&2; fi
else echo 'Run: ./neo-admin logs' >&2; fi
}
health() {
local mode=${1:-replace} service
local -a services=() options=()
if [[ $mode == recovery ]]; then
options+=(--no-deps)
while IFS= read -r service; do
if [[ $service != postgres && -n $("${COMPOSE[@]}" ps -aq "$service") ]]; then services+=("$service"); fi
done < <("${COMPOSE[@]}" config --services)
[[ ${#services[@]} -gt 0 ]] || { error 'No retained application containers; repair the original Compose configuration.'; return 1; }
fi
if ! "${COMPOSE[@]}" up -d --no-build --pull never --wait --wait-timeout 180 "${options[@]}" "${services[@]}"; then recovery_guidance; return 1; fi
# Healthz is served on both origins; no user data or credentials are sent.
local deadline=$((SECONDS+180))
until helper health http://roundtable:8080/healthz; do
((SECONDS<deadline)) || { recovery_guidance; return 1; }
sleep 2
done
helper status || { recovery_guidance; return 1; }
}
save_log() {
local app; app=$("${COMPOSE[@]}" ps -aq roundtable)
[[ -z $app ]] || docker logs --tail 5000 "$app" > "$ROOT/logs/previous-container.log" 2>&1
}
install_command() {
terminal
command -v docker >/dev/null || { error 'Please install Docker properly https://docs.docker.com/engine/install/debian/'; return 1; }
latest; host_checks install
local token password username rt_domain neo_domain
question token 'Access token' 1; verify_token
question username 'Admin user'; [[ $username =~ ^[a-zA-Z][a-zA-Z0-9_-]{1,63}$ ]] || error 'Invalid admin username.'
question password 'Admin password (at least 12 characters)' 1; [[ ${#password} -ge 12 ]] || error 'Password must be at least 12 characters.'
question rt_domain 'Neo Roundtable domain'; question neo_domain 'Neo app domain'
# Recheck immediately before the first persistent write.
host_checks install
fetch "${manifest[admin_url]}" "$STAGING/neo-admin"; verify_file "$STAGING/neo-admin" "${manifest[admin_sha256]}"
fetch "${manifest[compose_url]}" "$STAGING/compose.yml"; verify_file "$STAGING/compose.yml" "${manifest[compose_sha256]}"
# The first image supplies the Neo-specific validator/config writer. This
# bootstrap pull happens after all answers, using disposable auth only.
docker pull --platform linux/amd64 "$helper_image"
printf '%s\n%s\n' "$rt_domain" "$neo_domain" | "${RUN[@]}" -i --entrypoint roundtable "$helper_image" admin validate-domains
host_checks install
mkdir -p "$ROOT"; chmod 700 "$ROOT"
printf '%s\n%s\n' "$rt_domain" "$neo_domain" | "${RUN[@]}" -i -v "$ROOT:/target" --entrypoint roundtable "$helper_image" admin init /target "$(id -u)" "$(id -g)"
cp "$STAGING/compose.yml" "$ROOT/compose.yml"; cp "$STAGING/neo-admin" "$ROOT/neo-admin"; chmod 700 "$ROOT/neo-admin"
login "$ROOT/vault/docker-auth"; export DOCKER_CONFIG=$ROOT/vault/docker-auth; unset token
pull_release
cp "$STAGING/release.manifest" "$ROOT/release.manifest"
export_images; setup_compose
make_override "$ROOT/.neo-images.yml"; setup_compose; locked
"${COMPOSE[@]}" up -d --no-build --pull never --wait postgres
helper preflight
health
printf '%s\n%s\n' "$password" "$password" | "${COMPOSE[@]}" exec -T roundtable roundtable admin create-admin "$username"
unset password
identity > .neo-identity
printf 'The server runs on 127.0.0.1:3060; put your preferred reverse proxy in front of it.\n'
}
update_command() {
local operation=$1 backup_file old_schema
latest
if [[ $operation == update && -f $ROOT/release.manifest && ! -f $ROOT/.neo-rolled-back ]] && cmp -s "$ROOT/release.manifest" "$STAGING/release.manifest"; then echo 'Already current; nothing to update.'; return; fi
host_checks update
local token
if [[ $operation == adopt && ! -f $ROOT/vault/docker-auth/config.json ]]; then
terminal; question token 'Access token' 1; verify_token
else export DOCKER_CONFIG=$ROOT/vault/docker-auth; fi
fetch "${manifest[admin_url]}" "$STAGING/neo-admin"; verify_file "$STAGING/neo-admin" "${manifest[admin_sha256]}"
# Pull only the new helper before checks/backup. The old stack stays intact.
docker pull --platform linux/amd64 "$helper_image"
setup_compose; locked; guard
old_schema=$(helper schema); backup_now
image_space
pull_release
helper preflight
guard
if [[ -n ${token:-} ]]; then login "$ROOT/vault/docker-auth"; export DOCKER_CONFIG=$ROOT/vault/docker-auth; unset token; fi
mkdir -p logs .neo-previous
save_log
if [[ -f release.manifest ]]; then cp release.manifest .neo-previous/release.manifest; fi
if [[ -f .neo-images.yml ]]; then cp .neo-images.yml .neo-previous/images.yml; else
# Adopted source builds may have no registry digest: retain exact local IDs.
local service image
printf 'services:\n' > .neo-previous/images.yml
for service in postgres roundtable ocr transcription contacts-workshop; do
image=$(docker inspect --format '{{.Image}}' "$("${COMPOSE[@]}" ps -aq "$service")" 2>/dev/null || true)
[[ -z $image ]] || printf ' %s:\n image: %s\n pull_policy: never\n' "$service" "$image" >> .neo-previous/images.yml
done
fi
printf '%s\n' "$old_schema" > .neo-previous/schema
printf '%s\n' "$backup_file" > .neo-previous/backup
cp "$STAGING/current.identity" .neo-identity
# First adoption must retain an operable host launcher even if serve fails.
if [[ ! -f release.manifest ]]; then
cp "$STAGING/release.manifest" release.manifest
cp "$STAGING/neo-admin" neo-admin; chmod 700 neo-admin
touch .neo-rolled-back
fi
make_override "$STAGING/images.yml"; mv "$STAGING/images.yml" .neo-images.yml
# The original Compose file, .env and all mount sources remain intact.
setup_compose; guard; health
cp "$STAGING/release.manifest" release.manifest
cp "$STAGING/neo-admin" neo-admin.new; chmod 700 neo-admin.new; mv neo-admin.new neo-admin
rm -f .neo-rolled-back
echo 'Update complete.'
}
rollback_command() {
cd "$ROOT"
[[ -f .neo-previous/schema && -f .neo-previous/backup && -f .neo-previous/images.yml ]] || { error 'Nothing to roll back to.'; return 1; }
setup_compose; locked
COMPOSE+=(-f "$ROOT/.neo-previous/images.yml")
guard recovery
local schema previous backup_file
schema=$(helper schema); IFS= read -r previous < .neo-previous/schema; IFS= read -r backup_file < .neo-previous/backup
[[ $schema == "$previous" ]] || { printf 'Schema changed. Run: ./neo-admin restore %q\n' "$backup_file" >&2; return 1; }
cp .neo-previous/images.yml .neo-images.yml; setup_compose; health recovery
if [[ -f .neo-previous/release.manifest ]]; then cp .neo-previous/release.manifest release.manifest; else touch .neo-rolled-back; fi
}
validate_purge_plan() {
local project=$1 real_root type source resolved component owner owners id failed=0 covered i j
local -a types=() sources=()
real_root=$(realpath -e -- "$ROOT") || return 1
[[ $real_root != / ]] || { error 'Unsafe installation root; purge refused.'; return 1; }
while IFS=$'\t' read -r type source; do
if [[ $type == bind ]]; then
resolved=$(realpath -e -- "$source") || resolved=
component=$source
while [[ $component == */ && $component != / ]]; do component=${component%/}; done
while [[ $component != / && $component != . ]]; do
if [[ -L $component ]]; then resolved=; break; fi
component=$(dirname -- "$component") || return 1
done
if [[ $source != /* || ! -d $source || -z $resolved || $resolved != "$real_root/"* ]]; then
printf '%q: kept, delete by hand (external, symlinked or unresolved bind); purge refused.\n' "$source" >&2
failed=1; continue
fi
source=$resolved
elif [[ $type == volume ]]; then
owner=$(docker volume inspect --format '{{index .Labels "com.docker.compose.project"}}' "$source") || return 1
[[ $owner == "$project" ]] || { error "Volume $source is not project-owned; kept, delete by hand. Purge refused."; failed=1; continue; }
owners=$(docker ps -a --filter "volume=$source" --format '{{.ID}} {{.Label "com.docker.compose.project"}}') || return 1
while read -r id owner; do
[[ -z $id || $owner == "$project" ]] || { error "Volume $source is used outside this project; kept, delete by hand. Purge refused."; failed=1; }
done <<< "$owners"
else error 'Unknown purge mount type; purge refused.'; return 1; fi
types+=("$type"); sources+=("$source")
done < "$STAGING/purge.candidates"
[[ $failed == 0 ]] || return 1
# Only collapse nested bind paths after every source has passed validation.
: > "$STAGING/purge.plan"
for i in "${!sources[@]}"; do
covered=0
if [[ ${types[i]} == bind ]]; then
for j in "${!sources[@]}"; do
if [[ ${types[j]} == bind && ${sources[i]} == "${sources[j]}/"* ]]; then covered=1; break; fi
done
fi
[[ $covered == 1 ]] || printf '%s\t%s\n' "${types[i]}" "${sources[i]}" >> "$STAGING/purge.plan"
done
}
main() {
local operation=${1:-help}; shift || true
staging
case "$operation" in
install) [[ $# == 0 ]]; install_command ;;
check)
[[ $# == 0 ]]; latest
if [[ -f $ROOT/release.manifest || -f $ROOT/compose.yml || -f $ROOT/docker-compose.yml ]]; then host_checks update; else host_checks install; fi ;;
update|adopt) [[ $# == 0 ]]; update_command "$operation" ;;
help|--help|-h) echo 'neo-admin install|check|status|update|rollback|backup|restore <archive>|reset-pwd <user>|logs|uninstall [--purge]|adopt' ;;
status|backup|rollback|restore|reset-pwd|logs|uninstall)
[[ -f $ROOT/release.manifest ]] || { error 'No managed release; use adopt.'; return 1; }
pin_docker
read_manifest "$ROOT/release.manifest"; helper_image=${manifest[image_roundtable]}; export DOCKER_CONFIG=$ROOT/vault/docker-auth
setup_compose
case "$operation" in
status)
helper status
local app; app=$("${COMPOSE[@]}" ps -aq roundtable)
[[ -z $app ]] || { printf 'Running image '; docker inspect --format '{{.Image}}' "$app"; printf 'Running build metadata (version, revision):\n'; docker exec "$app" cat /usr/local/share/roundtable-build-info 2>/dev/null || echo unavailable; }
"${COMPOSE[@]}" ps ;;
logs) "${COMPOSE[@]}" logs --tail 200 ;;
rollback) rollback_command ;;
backup) locked; guard; backup_now ;;
reset-pwd) [[ $# == 1 ]]; locked; guard; "${COMPOSE[@]}" exec roundtable roundtable admin reset-pwd "$1" ;;
restore)
[[ $# == 1 && $1 == /backups/roundtable-*.tar.gz && $1 != *..* ]] || { error 'Use the /backups/roundtable-*.tar.gz path printed by backup.'; return 1; }
locked
# Restore with the image associated with the backup when reverting a migration.
if [[ -f .neo-previous/backup && $(cat .neo-previous/backup) == "$1" ]]; then
cp .neo-previous/images.yml "$STAGING/restore.yml"
else cp .neo-images.yml "$STAGING/restore.yml"; fi
COMPOSE+=(-f "$STAGING/restore.yml")
guard recovery; helper capacity
local -a writers=(roundtable)
if "${COMPOSE[@]}" config --services | grep -Fxq contacts-workshop; then writers+=(contacts-workshop); fi
"${COMPOSE[@]}" stop "${writers[@]}"
"${COMPOSE[@]}" -f "$STAGING/restore.yml" run --rm -T --no-deps --entrypoint roundtable roundtable restore --app-stopped "$1"
cp "$STAGING/restore.yml" .neo-images.yml
if [[ -f .neo-previous/release.manifest && $(cat .neo-previous/backup) == "$1" ]]; then cp .neo-previous/release.manifest release.manifest; fi
setup_compose; health recovery ;;
uninstall)
locked; guard
if [[ ${1:-} == --purge ]]; then
helper purge-plan < .neo-identity > "$STAGING/purge.candidates"
local type source project
project=$("${COMPOSE[@]}" config --format json | "${RUN[@]}" -i --entrypoint roundtable "$helper_image" admin compose-project)
validate_purge_plan "$project"
terminal; local answer; question answer 'Permanently delete this installation and its data? Type DELETE'
[[ $answer == DELETE ]] || { error 'Purge cancelled.'; return 1; }
"${COMPOSE[@]}" down
while IFS=$'\t' read -r type source; do
if [[ $type == volume ]]; then docker volume rm "$source"
else "${RUN[@]}" --mount "type=bind,src=$source,dst=/erase" --entrypoint roundtable "$helper_image" admin purge-mount /erase; fi
done < "$STAGING/purge.plan"
if [[ -f .neo-fresh ]]; then "${RUN[@]}" -v "$ROOT:/target" --entrypoint roundtable "$helper_image" admin purge /target; fi
echo 'Recorded installation data purged; source checkout (if any) kept.'
elif [[ $# == 0 ]]; then "${COMPOSE[@]}" down; echo 'Containers removed; data, keys and backups kept.'
else error 'Usage: neo-admin uninstall [--purge]'; fi ;;
esac ;;
*) error 'Unknown command; run neo-admin help.' ;;
esac
}
if [[ ${BASH_SOURCE[0]} == "$0" ]]; then main "$@"; fi
+140
View File
@@ -0,0 +1,140 @@
services:
postgres:
image: ${NEO_IMAGE_POSTGRES:?release image required}
restart: unless-stopped
labels:
roundtable.distribution: "1"
environment:
POSTGRES_DB: ${POSTGRES_DB:-roundtable}
POSTGRES_USER: ${POSTGRES_USER:-roundtable}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:?database password required}
volumes:
- ./data/psql/_data:/var/lib/postgresql
healthcheck:
test: ["CMD", "pg_isready", "-U", "${POSTGRES_USER:-roundtable}", "-d", "${POSTGRES_DB:-roundtable}"]
interval: 5s
timeout: 5s
retries: 5
roundtable:
image: ${NEO_IMAGE_ROUNDTABLE:?release image required}
restart: unless-stopped
labels:
roundtable.distribution: "1"
depends_on:
postgres:
condition: service_healthy
environment:
PGHOST: postgres
PGPORT: "5432"
PGUSER: ${POSTGRES_USER:-roundtable}
PGPASSWORD: ${POSTGRES_PASSWORD:?database password required}
PGDATABASE: ${POSTGRES_DB:-roundtable}
PGSSLMODE: disable
NEO_APP_ORIGIN: ${NEO_APP_ORIGIN:-}
ROUNDTABLE_PUBLIC_ORIGIN: ${ROUNDTABLE_PUBLIC_ORIGIN:-http://localhost:${ROUNDTABLE_PORT:-3060}}
ROUNDTABLE_OAUTH_SIGNING_KEY: ${ROUNDTABLE_OAUTH_SIGNING_KEY:-}
ROUNDTABLE_TRUSTED_PROXIES: ${ROUNDTABLE_TRUSTED_PROXIES:-${ROUNDTABLE_GATEWAY:-172.28.0.1}/32}
ROUNDTABLE_SUBNET: ${ROUNDTABLE_SUBNET:-172.28.0.0/16}
DUO_CLIENT_ID: ${DUO_CLIENT_ID:-}
DUO_CLIENT_SECRET: ${DUO_CLIENT_SECRET:-}
DUO_API_HOST: ${DUO_API_HOST:-}
DUO_FAIL_OPEN: ${DUO_FAIL_OPEN:-true}
ROUNDTABLE_DATA_DIR: ${ROUNDTABLE_DATA_DIR:-/data}
ROUNDTABLE_BACKUP_DIR: ${ROUNDTABLE_BACKUP_DIR:-/backups}
ROUNDTABLE_BACKUP_KEEP: ${ROUNDTABLE_BACKUP_KEEP:-5}
ROUNDTABLE_NEO_WEB: ${ROUNDTABLE_NEO_WEB:-}
ROUNDTABLE_CONTACTS_WORKSHOP: ${ROUNDTABLE_CONTACTS_WORKSHOP:-}
ROUNDTABLE_PHONE_REGION: ${ROUNDTABLE_PHONE_REGION:-DE}
ROUNDTABLE_OCR_URL: http://ocr:8090
ROUNDTABLE_TRANSCRIPTION_URL: http://transcription:8091
networks:
- default
- ocr-private
- transcription-private
- contacts-private
volumes:
- ./backups:/backups
- ./data:/data
- ./vault/neo-keys:/data/neo-keys
ports:
- "127.0.0.1:${ROUNDTABLE_PORT:-3060}:8080"
contacts-workshop:
profiles: [contacts]
image: ${NEO_IMAGE_CONTACTS:?release image required}
restart: unless-stopped
labels:
roundtable.distribution: "1"
depends_on:
- roundtable
environment:
ROUNDTABLE_PUBLIC_ORIGIN: ${ROUNDTABLE_PUBLIC_ORIGIN:-http://localhost:${ROUNDTABLE_PORT:-3060}}
ROUNDTABLE_PHONE_REGION: ${ROUNDTABLE_PHONE_REGION:-DE}
CONTACTS_WORKSHOP_DIR: /var/lib/contacts
read_only: true
tmpfs:
- /tmp:size=16m
cap_drop: [ALL]
security_opt: [no-new-privileges:true]
volumes:
- ./data/tools/contacts:/var/lib/contacts
networks:
- contacts-private
ocr:
image: ${NEO_IMAGE_OCR:?release image required}
restart: unless-stopped
labels:
roundtable.distribution: "1"
cpus: 2.0
mem_limit: 1536m
memswap_limit: 1536m
read_only: true
tmpfs:
- /tmp:size=64m
cap_drop: [ALL]
security_opt: [no-new-privileges:true]
healthcheck:
test: ["CMD", "python", "-c", "import urllib.request; urllib.request.urlopen('http://127.0.0.1:8090/healthz', timeout=2).close()"]
interval: 10s
timeout: 3s
start_period: 30s
retries: 3
networks:
- ocr-private
transcription:
image: ${NEO_IMAGE_TRANSCRIPTION:?release image required}
restart: unless-stopped
labels:
roundtable.distribution: "1"
cpus: 2.0
mem_limit: 2g
memswap_limit: 2g
read_only: true
tmpfs:
- /tmp:size=300m
cap_drop: [ALL]
security_opt: [no-new-privileges:true]
healthcheck:
test: ["CMD", "python", "-c", "import urllib.request; urllib.request.urlopen('http://127.0.0.1:8091/healthz', timeout=2).close()"]
interval: 10s
timeout: 3s
start_period: 30s
retries: 3
networks:
- transcription-private
networks:
contacts-private:
internal: true
transcription-private:
internal: true
ocr-private:
internal: true
default:
ipam:
config:
- subnet: ${ROUNDTABLE_SUBNET:-172.28.0.0/16}
gateway: ${ROUNDTABLE_GATEWAY:-172.28.0.1}
+469
View File
@@ -0,0 +1,469 @@
#!/usr/bin/env bash
# Host-side Docker orchestration. Never source downloaded release metadata.
set -euo pipefail
set +x
umask 077
BASE=https://git.sn-s.net/neo/neo-roundtable/raw/branch/main
REGISTRY=git.sn-s.net
STAGING=
ROOT=/opt/containers/neo-roundtable
declare -A manifest=()
COMPOSE=()
RUN=(docker run --rm --network none)
helper_image=
error() { printf '%s\n' "$*" >&2; return 1; }
ok() { printf '✓ %s\n' "$*"; }
fetch() { curl --proto '=https' --proto-redir '=https' --connect-timeout 10 --max-time 120 -fsSL "$1" -o "$2"; }
staging() {
RUN=(docker run --rm --network none)
local parent=${TMPDIR:-/tmp}
[[ ! -d /dev/shm || ! -w /dev/shm ]] || parent=/dev/shm
STAGING=$(mktemp -d "$parent/neo-admin.XXXXXXXX")
trap 'unset token password; rm -rf -- "$STAGING"' EXIT
}
pin_docker() {
local endpoint=${DOCKER_HOST:-}
[[ -n $endpoint ]] || endpoint=$(docker context inspect --format '{{.Endpoints.docker.Host}}')
[[ $endpoint == unix://* ]] || { error 'Use a local Unix-socket Docker engine; remote contexts are not supported.'; return 1; }
export DOCKER_HOST=$endpoint
unset DOCKER_CONTEXT
}
terminal() { { : </dev/tty; } 2>/dev/null || error 'A terminal is required for installation.'; }
question() {
local name=$1 prompt=$2 hidden=${3:-0} value
if [[ $hidden == 1 ]]; then IFS= read -r -s -p "$prompt: " value </dev/tty; printf '\n' >/dev/tty
else IFS= read -r -p "$prompt: " value </dev/tty; fi
[[ -n $value && $value != *$'\r'* ]] || error 'An answer is required.'
printf -v "$name" '%s' "$value"
}
read_manifest() {
local file=$1 key value name
manifest=()
[[ $(wc -c < "$file") -le 16384 ]] || error 'Manifest is too large.'
while IFS='=' read -r key value || [[ -n $key ]]; do
[[ $key =~ ^[a-z][a-z0-9_]{0,63}$ && -n $value && ! -v manifest[$key] ]] || { error 'Invalid or duplicate manifest field.'; return 1; }
case "$key" in
format) [[ $value == 1 ]] ;;
platform) [[ $value == linux/amd64 ]] ;;
version) [[ $value =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]] ;;
revision|admin_sha256|compose_sha256) if [[ $key == revision ]]; then [[ $value =~ ^[0-9a-f]{40}$ ]]; else [[ $value =~ ^[0-9a-f]{64}$ ]]; fi ;;
schema) [[ $value =~ ^[1-9][0-9]{0,4}$ ]] ;;
postgres_major) [[ $value == 18 ]] ;;
admin_url|compose_url) [[ $value == "$BASE"/releases/* && $value != *[[:space:]\'\"\`\$\;\&\?\#]* && $value != *..* ]] ;;
image_roundtable|image_ocr|image_transcription|image_contacts)
name=${key#image_}; [[ $name != contacts ]] || name=contacts-workshop
[[ $value =~ ^git\.sn-s\.net/neo-distribution/$name@sha256:[0-9a-f]{64}$ ]] ;;
image_postgres) [[ $value =~ ^docker\.io/library/postgres@sha256:[0-9a-f]{64}$ ]] ;;
pull_bytes_roundtable|pull_bytes_ocr|pull_bytes_transcription|pull_bytes_contacts|pull_bytes_postgres|unpacked_bytes_roundtable|unpacked_bytes_ocr|unpacked_bytes_transcription|unpacked_bytes_contacts|unpacked_bytes_postgres)
[[ $value =~ ^[1-9][0-9]{0,14}$ ]] ;;
*) error 'Unknown manifest field.'; return 1 ;;
esac || { error "Invalid manifest field: $key"; return 1; }
manifest[$key]=$value
done < "$file"
for key in format platform version revision schema postgres_major admin_url admin_sha256 compose_url compose_sha256; do [[ -v manifest[$key] ]] || { error "Missing manifest field: $key"; return 1; }; done
for name in roundtable ocr transcription contacts postgres; do
for key in image_$name pull_bytes_$name unpacked_bytes_$name; do [[ -v manifest[$key] ]] || { error "Missing manifest field: $key"; return 1; }; done
done
[[ ${manifest[admin_url]} == "$BASE/releases/${manifest[version]}/neo-admin" && ${manifest[compose_url]} == "$BASE/releases/${manifest[version]}/compose.yml" ]] || error 'Release URLs must match the version.'
}
latest() { fetch "$BASE/stable.manifest" "$STAGING/release.manifest"; read_manifest "$STAGING/release.manifest"; helper_image=${manifest[image_roundtable]}; }
verify_file() { local actual; actual=$(sha256sum "$1"); [[ ${actual%% *} == "$2" ]] || error 'Release checksum mismatch.'; }
image_space() {
local name c=0 u=0 root available required
for name in roundtable ocr transcription contacts postgres; do
if ! docker image inspect "${manifest[image_$name]}" >/dev/null 2>&1; then
c=$((c+${manifest[pull_bytes_$name]})); u=$((u+${manifest[unpacked_bytes_$name]}))
fi
done
root=$(docker info --format '{{.DockerRootDir}}')
[[ -d $root ]] || { error 'Docker storage must be on this host so free disk can be checked.'; return 1; }
available=$(df -Pk "$root" | awk 'END {print $4*1024}')
required=$(((c+u)*12/10+1073741824))
awk -v a="$available" -v r="$required" 'BEGIN{exit !(a>=r)}' || { error "Docker disk needs $required additional bytes; free space first."; return 1; }
IMAGE_RESERVE_BYTES=$required; DOCKER_DEVICE=$(stat -c %d "$root")
ok "Docker disk reserve: $required bytes"
}
subnet_check() {
local subnet=172.28.0.0/16 network existing
# Compare the fixed production subnet as IPv4 ranges.
local a b c d prefix ip lo hi eip elo ehi eprefix
IFS='./' read -r a b c d prefix <<< "$subnet"
ip=$(((a<<24)+(b<<16)+(c<<8)+d)); lo=$((ip & (0xFFFFFFFF << (32-prefix)))); hi=$((lo + (1 << (32-prefix))-1))
while IFS= read -r network; do
[[ -n $network ]] || continue
while IFS= read -r existing; do
[[ $existing == *.*/* ]] || continue
IFS='./' read -r a b c d eprefix <<< "$existing"
eip=$(((a<<24)+(b<<16)+(c<<8)+d)); elo=$((eip & (0xFFFFFFFF << (32-eprefix)))); ehi=$((elo+(1 << (32-eprefix))-1))
((lo>ehi || elo>hi)) || { error "Docker subnet $subnet clashes with existing network $network ($existing); nothing changed."; return 1; }
done < <(docker network inspect --format '{{range .IPAM.Config}}{{println .Subnet}}{{end}}' "$network")
done < <(docker network ls -q)
}
host_checks() {
local mode=$1 os_id
[[ $(uname -m) == x86_64 && $(uname -s) == Linux ]] || { error 'Only Linux amd64 is supported.'; return 1; }; ok 'Linux amd64'
os_id=$(sed -n 's/^ID=//p' /etc/os-release | tr -d '"')
[[ $os_id == debian ]] || { error 'This installer currently supports Debian; use a supported Debian host.'; return 1; }; ok 'Debian'
command -v docker >/dev/null || { error 'Please install Docker properly https://docs.docker.com/engine/install/debian/'; return 1; }
pin_docker
if ! docker info >/dev/null 2>&1 || ! docker compose version >/dev/null 2>&1; then error 'Docker and its Compose plugin must be running and usable by this user.'; return 1; fi; ok 'Docker and Compose'
curl --proto '=https' --connect-timeout 10 --max-time 30 -sS -D "$STAGING/registry.headers" -o /dev/null "https://$REGISTRY/v2/"
grep -qi 'realm="https://git.sn-s.net/v2/token"' "$STAGING/registry.headers" || { error 'Registry must advertise its HTTPS token endpoint.'; return 1; }; ok 'Registry reachable over HTTPS'
if [[ $mode == install ]]; then
[[ ! -e $ROOT || ( -d $ROOT && -z $(ls -A -- "$ROOT") ) ]] || { error 'Install folder is not empty; use update or adopt.'; return 1; }
command -v ss >/dev/null || { error 'Install iproute2 so the listening port can be checked.'; return 1; }
[[ -z $(ss -H -ltn '( sport = :3060 )') ]] || { error '127.0.0.1:3060 is occupied; nothing changed.'; return 1; }
local project=neo-roundtable
[[ -z $(docker ps -aq --filter "label=com.docker.compose.project=$project") && -z $(docker volume ls -q --filter "label=com.docker.compose.project=$project") ]] || { error 'An existing Compose project or data volume was found; use adopt.'; return 1; }
if docker volume inspect "${project}_roundtable-postgres-data" >/dev/null 2>&1; then error 'An old database volume exists; use adopt.'; return 1; fi
local parent=$ROOT available
while [[ ! -d $parent ]]; do parent=$(dirname "$parent"); done
[[ -w $parent ]] || { error "Install folder parent $parent must be writable by this user."; return 1; }
available=$(df -Pk "$parent" | awk 'END {print $4*1024}')
awk -v a="$available" 'BEGIN{exit !(a>=1073741824)}' || { error 'Install filesystem needs at least 1 GiB free for initial data.'; return 1; }
subnet_check
ok 'Empty install folder, unused project, subnet and port 3060'
fi
image_space
}
login() { local directory=$1; mkdir -p "$directory"; chmod 700 "$directory"; printf '%s' "$token" | DOCKER_CONFIG="$directory" docker login "$REGISTRY" --username neo-pull --password-stdin >/dev/null; chmod 600 "$directory/config.json"; }
verify_token() {
export DOCKER_CONFIG=$STAGING/auth
login "$DOCKER_CONFIG"
local name
for name in roundtable ocr transcription contacts; do docker manifest inspect "${manifest[image_$name]}" > "$STAGING/$name.manifest" || { error "Token cannot read the $name image manifest."; return 1; }; done
ok 'Token reads all four image manifests'
}
pull_release() { local name; for name in roundtable ocr transcription contacts postgres; do docker pull --platform linux/amd64 "${manifest[image_$name]}"; done; }
export_images() {
export NEO_IMAGE_ROUNDTABLE=${manifest[image_roundtable]} NEO_IMAGE_OCR=${manifest[image_ocr]} NEO_IMAGE_TRANSCRIPTION=${manifest[image_transcription]} NEO_IMAGE_CONTACTS=${manifest[image_contacts]} NEO_IMAGE_POSTGRES=${manifest[image_postgres]}
}
helper() { "${COMPOSE[@]}" -f "$STAGING/helper.yml" run --rm -T --no-deps --entrypoint roundtable roundtable admin "$@"; }
make_override() {
local target=$1 name service services pgdata default_pgdata
services=$("${COMPOSE[@]}" config --services)
printf 'services:\n' > "$target"
for name in roundtable ocr transcription contacts postgres; do
service=$name; [[ $name != contacts ]] || service=contacts-workshop
# Adoption changes images only; it must not invent incomplete sidecars
# when an older source Compose does not declare them.
grep -Fxq "$service" <<< "$services" || continue
printf ' %s:\n image: %s\n pull_policy: never\n' "$service" "${manifest[image_$name]}" >> "$target"
if [[ $service == postgres && -f $STAGING/current.identity ]]; then
pgdata=$(helper identity-pgdata < "$STAGING/current.identity")
default_pgdata=$(docker image inspect --format '{{range .Config.Env}}{{println .}}{{end}}' "${manifest[image_postgres]}" | sed -n 's/^PGDATA=//p')
# Preserve custom image defaults explicitly, without needlessly
# changing the Compose hash when the new default already matches.
if [[ $pgdata != "\"$default_pgdata\"" ]]; then
printf ' environment:\n PGDATA: %s\n' "$pgdata" >> "$target"
fi
fi
done
}
setup_compose() {
export_images
cd "$ROOT"
local source_file
if [[ -f .neo-source ]]; then IFS= read -r source_file < .neo-source
elif [[ -f compose.yml ]]; then source_file=compose.yml
elif [[ -f docker-compose.yml ]]; then source_file=docker-compose.yml
else error 'No existing Compose configuration; use install.'; return 1; fi
[[ $source_file == compose.yml || $source_file == docker-compose.yml ]] || { error 'Invalid source Compose marker.'; return 1; }
COMPOSE=(docker compose -f "$ROOT/$source_file")
if [[ -f .neo-images.yml ]]; then COMPOSE+=(-f "$ROOT/.neo-images.yml"); fi
printf 'services:\n roundtable:\n image: %s\n pull_policy: never\n' "$helper_image" > "$STAGING/helper.yml"
}
identity() {
local mode=${1:-running} pg app major project id ids image replacement replacement_major pgdata
local -a observed
pg=$("${COMPOSE[@]}" ps -aq postgres); app=$("${COMPOSE[@]}" ps -aq roundtable)
[[ -n $pg && -n $app && $pg != *$'\n'* && $app != *$'\n'* ]] || { error 'Cannot prove data identity: retain the existing containers and repair the Compose project/mount configuration before retrying. Do not create a new database.'; return 1; }
if [[ $mode != recovery && $(docker inspect --format '{{.State.Running}}' "$pg") != true ]]; then
error 'Postgres is stopped; use restore or rollback for recovery.'; return 1
fi
image=$(docker inspect --format '{{.Image}}' "$pg")
[[ $image == sha256:* && $(docker image inspect --format '{{.Id}}' "$image") == "$image" ]] || { error 'Cannot verify the retained Postgres image; recover that exact local image before retrying. Do not recreate the database.'; return 1; }
major=$("${RUN[@]}" --entrypoint postgres "$image" --version); major=${major##* }; major=${major%%.*}
replacement=$("${COMPOSE[@]}" config --format json | "${RUN[@]}" -i --entrypoint roundtable "$helper_image" admin compose-postgres-image)
replacement=$(docker image inspect --format '{{.Id}}' "$replacement")
replacement_major=$("${RUN[@]}" --entrypoint postgres "$replacement" --version); replacement_major=${replacement_major##* }; replacement_major=${replacement_major%%.*}
[[ $major == 18 && $replacement_major == "$major" ]] || { error 'Verified Postgres image majors differ or are unsupported; repair the original image reference before retrying.'; return 1; }
pgdata=$(docker image inspect --format '{{range .Config.Env}}{{println .}}{{end}}' "$replacement" | sed -n 's/^PGDATA=//p')
observed=("$pg" "$app")
project=$(docker inspect --format '{{index .Config.Labels "com.docker.compose.project"}}' "$pg") || return 1
ids=$(docker ps -aq --no-trunc --filter "label=com.docker.compose.project=$project" --filter 'label=com.docker.compose.oneoff=False') || return 1
while IFS= read -r id; do
[[ -z $id || $id == "$pg" || $id == "$app" ]] || observed+=("$id")
done <<< "$ids"
{ docker inspect "${observed[@]}"; "${COMPOSE[@]}" config --format json; } | "${RUN[@]}" -i --entrypoint roundtable "$helper_image" admin adopt-check "$major" "$pgdata"
}
guard() {
local mode=${1:-running}
if [[ $mode == recovery && ! -f .neo-identity ]]; then error 'Cannot prove recovery identity: restore the recorded .neo-identity and original Compose configuration first. Do not recreate the database.'; return 1; fi
identity "$mode" > "$STAGING/current.identity" || { error 'Identity could not be proven. Repair the original Compose project, image and mounts, then retry; do not recreate the database.'; return 1; }
if [[ -f .neo-identity ]]; then cmp -s .neo-identity "$STAGING/current.identity" || { error 'Recorded data identity differs; nothing started or replaced. Repair the original Compose project/mounts before retrying.'; return 1; }; fi
local pg project legacy mounted state
pg=$("${COMPOSE[@]}" ps -aq postgres)
if [[ $mode == recovery ]]; then
if [[ $(docker inspect --format '{{.State.Running}}' "$pg") != true ]]; then
docker start "$pg" >/dev/null
fi
local deadline=$((SECONDS+60))
until docker exec "$pg" pg_isready -q; do
((SECONDS<deadline)) || { error 'Verified Postgres did not become ready. Repair its startup using docker logs; do not recreate it or change its mounts.'; return 1; }
sleep 1
done
fi
project=$(docker inspect --format '{{index .Config.Labels "com.docker.compose.project"}}' "$pg")
legacy=${project}_roundtable-postgres-data
mounted=$(docker inspect --format '{{range .Mounts}}{{if eq .Type "volume"}}{{println .Name}}{{end}}{{end}}' "$pg")
if ! grep -Fxq "$legacy" <<< "$mounted" && docker volume inspect "$legacy" >/dev/null 2>&1; then
# Do not start, traverse or copy an unused cluster to guess its contents.
# An empty current database plus a retained previous volume needs the
# operator's evidence before any service/data replacement.
state=$(helper data-state) || { error 'Cannot inspect the current database; nothing replaced.'; return 1; }
[[ $state == populated ]] || { error "Current database is empty and unused legacy volume $legacy exists; inspect it before continuing. Nothing replaced."; return 1; }
fi
}
locked() { exec 9>"$ROOT/.neo-lock"; flock -n 9 || error 'Another neo-admin operation is running.'; }
backup_now() {
helper capacity "${DOCKER_DEVICE:-0}" "${IMAGE_RESERVE_BYTES:-0}"
helper backup | tee "$STAGING/backup.log"
backup_file=$(sed -n 's/^Backup completed: //p' "$STAGING/backup.log" | tail -n 1)
[[ $backup_file == /backups/roundtable-*.tar.gz && $backup_file != *..* && $backup_file != *$'\n'* ]] || error 'Backup did not report a valid archive.'
}
recovery_guidance() {
local schema previous archive
echo 'Application failed to become healthy.' >&2
if [[ -f .neo-previous/schema && -f .neo-previous/backup ]]; then
IFS= read -r previous < .neo-previous/schema
IFS= read -r archive < .neo-previous/backup
if schema=$(helper schema) && [[ $schema == "$previous" ]]; then
echo 'Run: ./neo-admin rollback' >&2
else printf 'Run: ./neo-admin restore %q\n' "$archive" >&2; fi
else echo 'Run: ./neo-admin logs' >&2; fi
}
health() {
local mode=${1:-replace} service
local -a services=() options=()
if [[ $mode == recovery ]]; then
options+=(--no-deps)
while IFS= read -r service; do
if [[ $service != postgres && -n $("${COMPOSE[@]}" ps -aq "$service") ]]; then services+=("$service"); fi
done < <("${COMPOSE[@]}" config --services)
[[ ${#services[@]} -gt 0 ]] || { error 'No retained application containers; repair the original Compose configuration.'; return 1; }
fi
if ! "${COMPOSE[@]}" up -d --no-build --pull never --wait --wait-timeout 180 "${options[@]}" "${services[@]}"; then recovery_guidance; return 1; fi
# Healthz is served on both origins; no user data or credentials are sent.
local deadline=$((SECONDS+180))
until helper health http://roundtable:8080/healthz; do
((SECONDS<deadline)) || { recovery_guidance; return 1; }
sleep 2
done
helper status || { recovery_guidance; return 1; }
}
save_log() {
local app; app=$("${COMPOSE[@]}" ps -aq roundtable)
[[ -z $app ]] || docker logs --tail 5000 "$app" > "$ROOT/logs/previous-container.log" 2>&1
}
install_command() {
terminal
command -v docker >/dev/null || { error 'Please install Docker properly https://docs.docker.com/engine/install/debian/'; return 1; }
latest; host_checks install
local token password username rt_domain neo_domain
question token 'Access token' 1; verify_token
question username 'Admin user'; [[ $username =~ ^[a-zA-Z][a-zA-Z0-9_-]{1,63}$ ]] || error 'Invalid admin username.'
question password 'Admin password (at least 12 characters)' 1; [[ ${#password} -ge 12 ]] || error 'Password must be at least 12 characters.'
question rt_domain 'Neo Roundtable domain'; question neo_domain 'Neo app domain'
# Recheck immediately before the first persistent write.
host_checks install
fetch "${manifest[admin_url]}" "$STAGING/neo-admin"; verify_file "$STAGING/neo-admin" "${manifest[admin_sha256]}"
fetch "${manifest[compose_url]}" "$STAGING/compose.yml"; verify_file "$STAGING/compose.yml" "${manifest[compose_sha256]}"
# The first image supplies the Neo-specific validator/config writer. This
# bootstrap pull happens after all answers, using disposable auth only.
docker pull --platform linux/amd64 "$helper_image"
printf '%s\n%s\n' "$rt_domain" "$neo_domain" | "${RUN[@]}" -i --entrypoint roundtable "$helper_image" admin validate-domains
host_checks install
mkdir -p "$ROOT"; chmod 700 "$ROOT"
printf '%s\n%s\n' "$rt_domain" "$neo_domain" | "${RUN[@]}" -i -v "$ROOT:/target" --entrypoint roundtable "$helper_image" admin init /target "$(id -u)" "$(id -g)"
cp "$STAGING/compose.yml" "$ROOT/compose.yml"; cp "$STAGING/neo-admin" "$ROOT/neo-admin"; chmod 700 "$ROOT/neo-admin"
login "$ROOT/vault/docker-auth"; export DOCKER_CONFIG=$ROOT/vault/docker-auth; unset token
pull_release
cp "$STAGING/release.manifest" "$ROOT/release.manifest"
export_images; setup_compose
make_override "$ROOT/.neo-images.yml"; setup_compose; locked
"${COMPOSE[@]}" up -d --no-build --pull never --wait postgres
helper preflight
health
printf '%s\n%s\n' "$password" "$password" | "${COMPOSE[@]}" exec -T roundtable roundtable admin create-admin "$username"
unset password
identity > .neo-identity
printf 'The server runs on 127.0.0.1:3060; put your preferred reverse proxy in front of it.\n'
}
update_command() {
local operation=$1 backup_file old_schema
latest
if [[ $operation == update && -f $ROOT/release.manifest && ! -f $ROOT/.neo-rolled-back ]] && cmp -s "$ROOT/release.manifest" "$STAGING/release.manifest"; then echo 'Already current; nothing to update.'; return; fi
host_checks update
local token
if [[ $operation == adopt && ! -f $ROOT/vault/docker-auth/config.json ]]; then
terminal; question token 'Access token' 1; verify_token
else export DOCKER_CONFIG=$ROOT/vault/docker-auth; fi
fetch "${manifest[admin_url]}" "$STAGING/neo-admin"; verify_file "$STAGING/neo-admin" "${manifest[admin_sha256]}"
# Pull only the new helper before checks/backup. The old stack stays intact.
docker pull --platform linux/amd64 "$helper_image"
setup_compose; locked; guard
old_schema=$(helper schema); backup_now
image_space
pull_release
helper preflight
guard
if [[ -n ${token:-} ]]; then login "$ROOT/vault/docker-auth"; export DOCKER_CONFIG=$ROOT/vault/docker-auth; unset token; fi
mkdir -p logs .neo-previous
save_log
if [[ -f release.manifest ]]; then cp release.manifest .neo-previous/release.manifest; fi
if [[ -f .neo-images.yml ]]; then cp .neo-images.yml .neo-previous/images.yml; else
# Adopted source builds may have no registry digest: retain exact local IDs.
local service image
printf 'services:\n' > .neo-previous/images.yml
for service in postgres roundtable ocr transcription contacts-workshop; do
image=$(docker inspect --format '{{.Image}}' "$("${COMPOSE[@]}" ps -aq "$service")" 2>/dev/null || true)
[[ -z $image ]] || printf ' %s:\n image: %s\n pull_policy: never\n' "$service" "$image" >> .neo-previous/images.yml
done
fi
printf '%s\n' "$old_schema" > .neo-previous/schema
printf '%s\n' "$backup_file" > .neo-previous/backup
cp "$STAGING/current.identity" .neo-identity
# First adoption must retain an operable host launcher even if serve fails.
if [[ ! -f release.manifest ]]; then
cp "$STAGING/release.manifest" release.manifest
cp "$STAGING/neo-admin" neo-admin; chmod 700 neo-admin
touch .neo-rolled-back
fi
make_override "$STAGING/images.yml"; mv "$STAGING/images.yml" .neo-images.yml
# The original Compose file, .env and all mount sources remain intact.
setup_compose; guard; health
cp "$STAGING/release.manifest" release.manifest
cp "$STAGING/neo-admin" neo-admin.new; chmod 700 neo-admin.new; mv neo-admin.new neo-admin
rm -f .neo-rolled-back
echo 'Update complete.'
}
rollback_command() {
cd "$ROOT"
[[ -f .neo-previous/schema && -f .neo-previous/backup && -f .neo-previous/images.yml ]] || { error 'Nothing to roll back to.'; return 1; }
setup_compose; locked
COMPOSE+=(-f "$ROOT/.neo-previous/images.yml")
guard recovery
local schema previous backup_file
schema=$(helper schema); IFS= read -r previous < .neo-previous/schema; IFS= read -r backup_file < .neo-previous/backup
[[ $schema == "$previous" ]] || { printf 'Schema changed. Run: ./neo-admin restore %q\n' "$backup_file" >&2; return 1; }
cp .neo-previous/images.yml .neo-images.yml; setup_compose; health recovery
if [[ -f .neo-previous/release.manifest ]]; then cp .neo-previous/release.manifest release.manifest; else touch .neo-rolled-back; fi
}
validate_purge_plan() {
local project=$1 real_root type source resolved component owner owners id failed=0 covered i j
local -a types=() sources=()
real_root=$(realpath -e -- "$ROOT") || return 1
[[ $real_root != / ]] || { error 'Unsafe installation root; purge refused.'; return 1; }
while IFS=$'\t' read -r type source; do
if [[ $type == bind ]]; then
resolved=$(realpath -e -- "$source") || resolved=
component=$source
while [[ $component == */ && $component != / ]]; do component=${component%/}; done
while [[ $component != / && $component != . ]]; do
if [[ -L $component ]]; then resolved=; break; fi
component=$(dirname -- "$component") || return 1
done
if [[ $source != /* || ! -d $source || -z $resolved || $resolved != "$real_root/"* ]]; then
printf '%q: kept, delete by hand (external, symlinked or unresolved bind); purge refused.\n' "$source" >&2
failed=1; continue
fi
source=$resolved
elif [[ $type == volume ]]; then
owner=$(docker volume inspect --format '{{index .Labels "com.docker.compose.project"}}' "$source") || return 1
[[ $owner == "$project" ]] || { error "Volume $source is not project-owned; kept, delete by hand. Purge refused."; failed=1; continue; }
owners=$(docker ps -a --filter "volume=$source" --format '{{.ID}} {{.Label "com.docker.compose.project"}}') || return 1
while read -r id owner; do
[[ -z $id || $owner == "$project" ]] || { error "Volume $source is used outside this project; kept, delete by hand. Purge refused."; failed=1; }
done <<< "$owners"
else error 'Unknown purge mount type; purge refused.'; return 1; fi
types+=("$type"); sources+=("$source")
done < "$STAGING/purge.candidates"
[[ $failed == 0 ]] || return 1
# Only collapse nested bind paths after every source has passed validation.
: > "$STAGING/purge.plan"
for i in "${!sources[@]}"; do
covered=0
if [[ ${types[i]} == bind ]]; then
for j in "${!sources[@]}"; do
if [[ ${types[j]} == bind && ${sources[i]} == "${sources[j]}/"* ]]; then covered=1; break; fi
done
fi
[[ $covered == 1 ]] || printf '%s\t%s\n' "${types[i]}" "${sources[i]}" >> "$STAGING/purge.plan"
done
}
main() {
local operation=${1:-help}; shift || true
staging
case "$operation" in
install) [[ $# == 0 ]]; install_command ;;
check)
[[ $# == 0 ]]; latest
if [[ -f $ROOT/release.manifest || -f $ROOT/compose.yml || -f $ROOT/docker-compose.yml ]]; then host_checks update; else host_checks install; fi ;;
update|adopt) [[ $# == 0 ]]; update_command "$operation" ;;
help|--help|-h) echo 'neo-admin install|check|status|update|rollback|backup|restore <archive>|reset-pwd <user>|logs|uninstall [--purge]|adopt' ;;
status|backup|rollback|restore|reset-pwd|logs|uninstall)
[[ -f $ROOT/release.manifest ]] || { error 'No managed release; use adopt.'; return 1; }
pin_docker
read_manifest "$ROOT/release.manifest"; helper_image=${manifest[image_roundtable]}; export DOCKER_CONFIG=$ROOT/vault/docker-auth
setup_compose
case "$operation" in
status)
helper status
local app; app=$("${COMPOSE[@]}" ps -aq roundtable)
[[ -z $app ]] || { printf 'Running image '; docker inspect --format '{{.Image}}' "$app"; printf 'Running build metadata (version, revision):\n'; docker exec "$app" cat /usr/local/share/roundtable-build-info 2>/dev/null || echo unavailable; }
"${COMPOSE[@]}" ps ;;
logs) "${COMPOSE[@]}" logs --tail 200 ;;
rollback) rollback_command ;;
backup) locked; guard; backup_now ;;
reset-pwd) [[ $# == 1 ]]; locked; guard; "${COMPOSE[@]}" exec roundtable roundtable admin reset-pwd "$1" ;;
restore)
[[ $# == 1 && $1 == /backups/roundtable-*.tar.gz && $1 != *..* ]] || { error 'Use the /backups/roundtable-*.tar.gz path printed by backup.'; return 1; }
locked
# Restore with the image associated with the backup when reverting a migration.
if [[ -f .neo-previous/backup && $(cat .neo-previous/backup) == "$1" ]]; then
cp .neo-previous/images.yml "$STAGING/restore.yml"
else cp .neo-images.yml "$STAGING/restore.yml"; fi
COMPOSE+=(-f "$STAGING/restore.yml")
guard recovery; helper capacity
local -a writers=(roundtable)
if "${COMPOSE[@]}" config --services | grep -Fxq contacts-workshop; then writers+=(contacts-workshop); fi
"${COMPOSE[@]}" stop "${writers[@]}"
"${COMPOSE[@]}" -f "$STAGING/restore.yml" run --rm -T --no-deps --entrypoint roundtable roundtable restore --app-stopped "$1"
cp "$STAGING/restore.yml" .neo-images.yml
if [[ -f .neo-previous/release.manifest && $(cat .neo-previous/backup) == "$1" ]]; then cp .neo-previous/release.manifest release.manifest; fi
setup_compose; health recovery ;;
uninstall)
locked; guard
if [[ ${1:-} == --purge ]]; then
helper purge-plan < .neo-identity > "$STAGING/purge.candidates"
local type source project
project=$("${COMPOSE[@]}" config --format json | "${RUN[@]}" -i --entrypoint roundtable "$helper_image" admin compose-project)
validate_purge_plan "$project"
terminal; local answer; question answer 'Permanently delete this installation and its data? Type DELETE'
[[ $answer == DELETE ]] || { error 'Purge cancelled.'; return 1; }
"${COMPOSE[@]}" down
while IFS=$'\t' read -r type source; do
if [[ $type == volume ]]; then docker volume rm "$source"
else "${RUN[@]}" --mount "type=bind,src=$source,dst=/erase" --entrypoint roundtable "$helper_image" admin purge-mount /erase; fi
done < "$STAGING/purge.plan"
if [[ -f .neo-fresh ]]; then "${RUN[@]}" -v "$ROOT:/target" --entrypoint roundtable "$helper_image" admin purge /target; fi
echo 'Recorded installation data purged; source checkout (if any) kept.'
elif [[ $# == 0 ]]; then "${COMPOSE[@]}" down; echo 'Containers removed; data, keys and backups kept.'
else error 'Usage: neo-admin uninstall [--purge]'; fi ;;
esac ;;
*) error 'Unknown command; run neo-admin help.' ;;
esac
}
if [[ ${BASH_SOURCE[0]} == "$0" ]]; then main "$@"; fi
+25
View File
@@ -0,0 +1,25 @@
format=1
platform=linux/amd64
version=0.6.0
revision=592b9cb9300330252653da69e8b58c4490f01fdc
schema=126
postgres_major=18
admin_url=https://git.sn-s.net/neo/neo-roundtable/raw/branch/main/releases/0.6.0/neo-admin
admin_sha256=1e85b1e624b27ba778d346d41782a690d50661ba4996670353dc08729fb817bf
compose_url=https://git.sn-s.net/neo/neo-roundtable/raw/branch/main/releases/0.6.0/compose.yml
compose_sha256=44c1dffd1ba1ec0290e4515defd65c346df84430fdaa4b04e1b8378d5deee6fa
image_roundtable=git.sn-s.net/neo-distribution/roundtable@sha256:88b885cfe5b619e63fd19befcde06164af0d486841da3bee2c462760a581eb45
pull_bytes_roundtable=32125055
unpacked_bytes_roundtable=64762883
image_ocr=git.sn-s.net/neo-distribution/ocr@sha256:cffdec8f6b6f4927870651460b993028c4ae7395a22acae1821faac0884cc5ff
pull_bytes_ocr=232859250
unpacked_bytes_ocr=554889172
image_transcription=git.sn-s.net/neo-distribution/transcription@sha256:eb40afedf2033d6b95ecff9b2143384f3eef9718623f9a4dcbc5e69908b9a18b
pull_bytes_transcription=706277822
unpacked_bytes_transcription=1066270843
image_contacts=git.sn-s.net/neo-distribution/contacts-workshop@sha256:37c965fcefbb1a8bdb1384f1021a56b2856ae03bc832b223849f6dd98482dd79
pull_bytes_contacts=17079895
unpacked_bytes_contacts=31930026
image_postgres=docker.io/library/postgres@sha256:300ebd02c6d4de9ee27ad7f6855d5d21b4d3a4a5117767c1197d284c635d9736
pull_bytes_postgres=120077966
unpacked_bytes_postgres=303748364
+25
View File
@@ -0,0 +1,25 @@
format=1
platform=linux/amd64
version=0.6.0
revision=592b9cb9300330252653da69e8b58c4490f01fdc
schema=126
postgres_major=18
admin_url=https://git.sn-s.net/neo/neo-roundtable/raw/branch/main/releases/0.6.0/neo-admin
admin_sha256=1e85b1e624b27ba778d346d41782a690d50661ba4996670353dc08729fb817bf
compose_url=https://git.sn-s.net/neo/neo-roundtable/raw/branch/main/releases/0.6.0/compose.yml
compose_sha256=44c1dffd1ba1ec0290e4515defd65c346df84430fdaa4b04e1b8378d5deee6fa
image_roundtable=git.sn-s.net/neo-distribution/roundtable@sha256:88b885cfe5b619e63fd19befcde06164af0d486841da3bee2c462760a581eb45
pull_bytes_roundtable=32125055
unpacked_bytes_roundtable=64762883
image_ocr=git.sn-s.net/neo-distribution/ocr@sha256:cffdec8f6b6f4927870651460b993028c4ae7395a22acae1821faac0884cc5ff
pull_bytes_ocr=232859250
unpacked_bytes_ocr=554889172
image_transcription=git.sn-s.net/neo-distribution/transcription@sha256:eb40afedf2033d6b95ecff9b2143384f3eef9718623f9a4dcbc5e69908b9a18b
pull_bytes_transcription=706277822
unpacked_bytes_transcription=1066270843
image_contacts=git.sn-s.net/neo-distribution/contacts-workshop@sha256:37c965fcefbb1a8bdb1384f1021a56b2856ae03bc832b223849f6dd98482dd79
pull_bytes_contacts=17079895
unpacked_bytes_contacts=31930026
image_postgres=docker.io/library/postgres@sha256:300ebd02c6d4de9ee27ad7f6855d5d21b4d3a4a5117767c1197d284c635d9736
pull_bytes_postgres=120077966
unpacked_bytes_postgres=303748364