A screenshot of /srv/board/.env showed the whole diagnosis at once: no CONTENT_TOKEN line, so the app falls back to the admin token and Gitea answers 403 — and two live OAuth credentials for a login flow deleted two phases ago, sitting there because the deploy never touches .env and never will. So it names them. The check is the mirror of the one already there: settings in .env that .env.example no longer documents, found with `comm -13` over the same two sorted lists. A commented-out line in the example counts as undocumented, which is how a setting is retired — comment it there, and the next deploy says it is still on the server. Nothing is rewritten; deleting a line from a file holding secrets is a decision, not a cleanup. The "missing" warning also grew consequences. It has been listing CONTENT_TOKEN as one bare name among several since it was added, which is easy to scroll past; it now reads "CONTENT_TOKEN — el editor no puede publicar nada en el sitio", sharing one note_for helper with the empty-value warning below it so the two cannot drift. And .env.example stops describing a job GITEA_ADMIN_TOKEN no longer has. It says what is true now: members have no accounts on the git server, nothing in the members area calls it, and it CANNOT publish, because Gitea's scopes are per category and `admin` does not contain `repository`. That sentence is the one that was missing while the editor sat unable to commit and looking configured. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NizVpJ2dwzCbjCrTLCjeHn
129 lines
5.4 KiB
Bash
Executable File
129 lines
5.4 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Put the current checkout of the members area onto the server.
|
|
#
|
|
# The app's code is baked into the image by docker/board/Dockerfile (`COPY apps
|
|
# /srv/apps`), so pulling new commits changes nothing on its own — the container
|
|
# keeps running the code that was in the image when it was built. `docker
|
|
# compose up -d --force-recreate` does not help either: same tag, same layers,
|
|
# same old code. That is a quiet failure, because everything reports success and
|
|
# the site behaves exactly as it did before.
|
|
#
|
|
# This script is the whole update, in the order that matters:
|
|
#
|
|
# git pull # done by you, first
|
|
# sudo bash scripts/deploy-board.sh # backs up, builds, restarts
|
|
#
|
|
# It never touches /srv/board/.env. That file holds the secrets and exists only
|
|
# on the server; the repository has .env.example instead, and the two drifting
|
|
# apart is expected — new settings appear in the example and have to be copied
|
|
# across by hand.
|
|
|
|
set -euo pipefail
|
|
|
|
REPO="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
|
TARGET="${BOARD_DIR:-/srv/board}"
|
|
IMAGE="vienalatina/board:1"
|
|
|
|
cd "$REPO"
|
|
|
|
echo "==> Building $IMAGE from $(git rev-parse --short HEAD)"
|
|
docker build -t "$IMAGE" -f docker/board/Dockerfile .
|
|
|
|
echo "==> Syncing compose files into $TARGET (never .env)"
|
|
mkdir -p "$TARGET"
|
|
cp "$REPO/infra/board/docker-compose.yml" "$TARGET/docker-compose.yml"
|
|
cp "$REPO/infra/board/.env.example" "$TARGET/.env.example"
|
|
|
|
if [ ! -f "$TARGET/.env" ]; then
|
|
echo "No $TARGET/.env — copy .env.example to .env and fill it in first." >&2
|
|
exit 1
|
|
fi
|
|
|
|
# Settings that appear in the example and not in the live file. Nothing is
|
|
# copied automatically: some of them are secrets, and a blank line silently
|
|
# added to .env is worse than a line missing loudly.
|
|
missing="$(comm -23 \
|
|
<(grep -oE '^[A-Z][A-Z0-9_]*=' "$TARGET/.env.example" | sort -u) \
|
|
<(grep -oE '^[A-Z][A-Z0-9_]*=' "$TARGET/.env" | sort -u) || true)"
|
|
note_for() {
|
|
case "${1%=}" in
|
|
CONTENT_TOKEN) echo "el editor no puede publicar nada en el sitio" ;;
|
|
GITEA_ADMIN_TOKEN) echo "sólo para cuentas del servidor de git; NO publica" ;;
|
|
MAIL_HOST|MAIL_PASSWORD) echo "no se envían invitaciones ni recuperaciones" ;;
|
|
BOARD_SECRET_KEY) echo "LA APP NO ARRANCA" ;;
|
|
*) echo "" ;;
|
|
esac
|
|
}
|
|
|
|
if [ -n "$missing" ]; then
|
|
echo
|
|
echo "!! These settings exist in .env.example but not in your .env:"
|
|
while read -r name; do
|
|
printf ' %-20s %s\n' "$name" "$(note_for "$name")"
|
|
done <<< "$missing"
|
|
echo " Add them to $TARGET/.env and run this again if the feature needs them."
|
|
echo
|
|
fi
|
|
|
|
# Present but empty, which the check above cannot see: `NAME=` has the name.
|
|
# Worth its own warning, because an empty value is how a feature ends up
|
|
# switched off while looking configured — GITEA_ADMIN_TOKEN= reads as a settled
|
|
# decision and behaves as a missing one. Each of these disables something whole.
|
|
blank="$(grep -oE '^[A-Z][A-Z0-9_]*=[[:space:]]*$' "$TARGET/.env" | sed 's/=.*//' || true)"
|
|
if [ -n "$blank" ]; then
|
|
echo
|
|
echo "!! These are set to nothing in your .env, so their feature is off:"
|
|
while read -r name; do
|
|
printf ' %-20s %s\n' "$name" "$(note_for "$name")"
|
|
done <<< "$blank"
|
|
echo
|
|
fi
|
|
|
|
# A backup before every restart, not only before the ones known to migrate.
|
|
#
|
|
# The app applies numbered migrations at start-up (apps/board/migrations.py), and
|
|
# two of them rebuild a table in place: `attachments`, and `members` — the table
|
|
# your own account is in. Neither can be undone once it has run. Remembering to
|
|
# back up by hand works right up until the deploy that mattered, so it happens
|
|
# here. Skipped with BOARD_SKIP_BACKUP=1 if there is no database yet.
|
|
if [ -z "${BOARD_SKIP_BACKUP:-}" ] && [ -f "${BOARD_DB:-$TARGET/data/board.db}" ]; then
|
|
echo "==> Backing up first (migrations are irreversible in place)"
|
|
bash "$REPO/scripts/backup-board.sh"
|
|
fi
|
|
|
|
# The mirror image of the check above: settings your .env holds that
|
|
# .env.example no longer documents. Those are what a feature looks like after it
|
|
# is removed — the OAuth client id and secret outlived the login they belonged
|
|
# to by two phases, sitting in a file as live credentials for a flow nothing
|
|
# calls. A commented-out line in the example counts as undocumented, which is
|
|
# how a setting is retired: comment it there, and this names it here.
|
|
#
|
|
# Named, never touched: this script has never written to .env and does not start
|
|
# now. Deleting a line is a decision, and the file may hold something deliberate
|
|
# that the repository does not know about.
|
|
stale="$(comm -13 \
|
|
<(grep -oE '^[A-Z][A-Z0-9_]*=' "$TARGET/.env.example" | sort -u) \
|
|
<(grep -oE '^[A-Z][A-Z0-9_]*=' "$TARGET/.env" | sort -u) || true)"
|
|
if [ -n "$stale" ]; then
|
|
echo
|
|
echo "!! Your .env has settings the repository no longer documents:"
|
|
echo "$stale" | sed 's/^/ /'
|
|
echo " Nothing reads them. If one holds a secret, revoke it and delete the line."
|
|
echo
|
|
fi
|
|
|
|
echo "==> Restarting"
|
|
cd "$TARGET"
|
|
docker compose up -d --force-recreate
|
|
|
|
# The schema is applied at start-up with CREATE TABLE IF NOT EXISTS and then the
|
|
# numbered migrations run, so a new table and a changed one both arrive with the
|
|
# new code. If the container is not up a few seconds later it died during that,
|
|
# and the log says why — the log line naming each migration applied is the one
|
|
# to read.
|
|
sleep 3
|
|
docker compose ps
|
|
echo
|
|
echo "Recent log:"
|
|
docker compose logs --tail 20 board
|