fix(docker): validate and atomically save first-boot configuration
This commit is contained in:
1 parent
ef2cd0c8c7
commit
e20737a509
8 files changed
+314
-168
No files matched your search
+10
-31
@@ -1,43 +1,22 @@
|
||||
#!/bin/sh
|
||||
dir="$HOME/.nanobot"
|
||||
|
||||
# Container config bootstrap. Two deploy paths share the init-once logic:
|
||||
# - Render (RENDER=true): template wires secrets via ${VAR} env vars, resolved
|
||||
# at startup by the config loader.
|
||||
# - Local Docker (NANOBOT_DOCKER_BOOTSTRAP=1, set by docker-compose.yml): a
|
||||
# template with binds that work across the container boundary, and secrets
|
||||
# baked in at first boot (env value if provided, otherwise generated) so a
|
||||
# missing env var can never crash-loop the containers.
|
||||
# Initializes the on-disk config only when it does not already exist, so
|
||||
# WebUI/provider settings edited at runtime survive restarts.
|
||||
# Logs each decision so a failed start is diagnosable in the container logs.
|
||||
# Privilege dropping is handled below, for every root start (not just here).
|
||||
if [ "$RENDER" = "true" ] || [ "$NANOBOT_DOCKER_BOOTSTRAP" = "1" ]; then
|
||||
echo "[entrypoint] container deploy — starting as $(id)"
|
||||
mkdir -p "$dir" || echo "[entrypoint] warning: mkdir $dir failed"
|
||||
# Render keeps environment references in its deployment template. Local
|
||||
# Compose generates and validates its initial config through Python instead.
|
||||
if [ "$RENDER" = "true" ]; then
|
||||
config="$dir/config.json"
|
||||
mkdir -p "$dir" || exit 1
|
||||
if [ ! -f "$config" ]; then
|
||||
if [ "$RENDER" = "true" ]; then
|
||||
echo "[entrypoint] initializing $config from render-config.json"
|
||||
cp /app/render-config.json "$config" || echo "[entrypoint] warning: cp config failed"
|
||||
else
|
||||
web_token="${NANOBOT_WEB_TOKEN:-$(od -An -N16 -tx1 /dev/urandom | tr -d ' \n')}"
|
||||
api_key="${NANOBOT_API_KEY:-$(od -An -N16 -tx1 /dev/urandom | tr -d ' \n')}"
|
||||
echo "[entrypoint] initializing $config from docker-config.json"
|
||||
sed -e "s|\${NANOBOT_WEB_TOKEN}|$web_token|" \
|
||||
-e "s|\${NANOBOT_API_KEY}|$api_key|" \
|
||||
/app/docker-config.json > "$config" \
|
||||
|| echo "[entrypoint] warning: config bootstrap failed"
|
||||
echo "[entrypoint] WebUI: http://localhost:8765 — password: $web_token"
|
||||
echo "[entrypoint] OpenAI-compatible API: http://127.0.0.1:8900/v1 — api key: $api_key"
|
||||
fi
|
||||
echo "[entrypoint] initializing $config from render-config.json"
|
||||
cp /app/render-config.json "$config" || exit 1
|
||||
else
|
||||
echo "[entrypoint] existing $config found — leaving it in place"
|
||||
if [ "$NANOBOT_DOCKER_BOOTSTRAP" = "1" ]; then
|
||||
echo "[entrypoint] WebUI password lives in $config (channels.websocket.tokenIssueSecret)"
|
||||
fi
|
||||
fi
|
||||
set -- "$@" --config "$config"
|
||||
elif [ "$NANOBOT_DOCKER_BOOTSTRAP" = "1" ]; then
|
||||
config="$dir/config.json"
|
||||
python -m nanobot.cli.docker_bootstrap "$config" || exit 1
|
||||
set -- "$@" --config "$config"
|
||||
fi
|
||||
|
||||
# Drop privileges whenever the container starts as root. Render mounts the
|
||||
|
||||
Reference in new issue
Block a user