Add deploy-instance.sh: spin up isolated lchat instances from one config
Templates a throwaway per-instance app.toml (unique app name + disk name) in a temp dir and deploys via 'miren deploy -d'. No per-instance config in git; no secrets in the script (admin token is generated or passed at runtime).
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 file changed,
+40
−0
deploy-instance.sh+40 −0
diff --git a/deploy-instance.sh b/deploy-instance.sh| new file mode 100755 |
| index 0000000..f2509c9 |
| --- /dev/null |
| +++ b/deploy-instance.sh |
| @@ -0,0 +1,40 @@ |
| +#!/usr/bin/env bash |
| +# Spin up an additional, fully-isolated lchat instance from the single committed |
| +# app.toml — its own Miren app, disk, admin token, and route. Keeps git clean: |
| +# no per-instance config files. |
| +# |
| +# Usage: ./deploy-instance.sh <instance> <hostname> [admin-token] |
| +# ./deploy-instance.sh paja paja.luan.chat |
| +# |
| +# Miren's app.toml has no variable interpolation, so we template a throwaway copy |
| +# in a temp dir (unique app name + unique disk name) and deploy from there. |
| +set -euo pipefail |
| + |
| +INSTANCE="${1:?usage: deploy-instance.sh <instance> <hostname> [admin-token]}" |
| +HOST="${2:?usage: deploy-instance.sh <instance> <hostname> [admin-token]}" |
| +TOKEN="${3:-$(openssl rand -base64 32 | tr -d '\n' | tr '+/' '-_' | tr -d '=')}" |
| +CLUSTER="${MIREN_CLUSTER:-luanchat}" |
| + |
| +REPO="$(cd "$(dirname "$0")" && pwd)" |
| +TMP="$(mktemp -d)" |
| +trap 'rm -rf "$TMP"' EXIT |
| + |
| +# Build context = the source, with instance-specific app name + disk name. |
| +cp -R "$REPO"/. "$TMP"/ |
| +rm -rf "$TMP/.git" |
| +sed -e "s/^name = \"lchat\"\$/name = \"$INSTANCE\"/" \ |
| + -e "s/^name = \"lchat-data\"\$/name = \"${INSTANCE}-data\"/" \ |
| + "$REPO/.miren/app.toml" > "$TMP/.miren/app.toml" |
| + |
| +echo "Deploying '$INSTANCE' (disk: ${INSTANCE}-data, host: $HOST, cluster: $CLUSTER)" |
| +miren deploy -d "$TMP" -C "$CLUSTER" -f \ |
| + -e LCHAT_DB=/data/lchat.db -e "LCHAT_ADMIN_TOKEN=$TOKEN" |
| +miren route set "$HOST" "$INSTANCE" -C "$CLUSTER" |
| + |
| +URL="https://$HOST/admin#token=$TOKEN" |
| +command -v pbcopy >/dev/null 2>&1 && printf '%s' "$URL" | pbcopy && COPIED=" (copied to clipboard)" || COPIED="" |
| +echo |
| +echo "✅ '$INSTANCE' deployed and routed to $HOST" |
| +echo " Admin URL is https://$HOST/admin#token=…${COPIED}" |
| +echo " Recover the token anytime: miren env get LCHAT_ADMIN_TOKEN -u -a $INSTANCE -C $CLUSTER" |
| +echo " Last step: add DNS $HOST A -> <server IP> (TLS auto-provisions after)." |