vienalatina/scripts/deploy-board.sh
Claude 5ea6b1ac98
One dashboard, five sections, and a moderation queue
The members area had grown one navigation entry per phase, and three of the
five were inside an admin-only block in base.html — so an ordinary member
signed in to a wall and a member list, with their own profile, their own
private messages and the content editor all invisible. Everything worked and
nothing was reachable. That is the bug this starts from.

The navigation is now Inicio · Muro · Privados · Publicaciones, plus Gestión
for admins, and the account items (Mi perfil, Descargar mis datos, Salir) moved
to a menu under the member's own name — a <details> element, because the CSP has
no 'unsafe-inline' and a menu needing onclick="" silently never opens. Inicio is
a new dashboard; the wall moved from /comunidad/ to /comunidad/muro and kept its
thread URLs. test_navigation.py asserts the navigation per role from the
rendered page, so this cannot come back quietly.

Public posts are now curated. A member proposes one and it waits in a new
`submissions` table; a moderator or admin approves it — which commits it
through content.publish, the same function the editor uses, with the author
named per commit so git history says who wrote it, not who approved it — or
returns it with a reason the author reads. Moderators and admins do not queue.
Nothing a member writes reaches the repository before approval, because a
commit to it *is* publication: the webhook starts the pipeline. A proposal's
picture stays private in /data/uploads until then, and the private copy goes
when the public one is committed. There is deliberately no way to promote a wall
thread into a proposal.

The moderator role needed the role CHECK widened, and SQLite has no DROP
CONSTRAINT, so migration 4 rebuilds `members` — eight tables reference it, the
one-owner index has to be recreated by hand, and PRAGMA foreign_key_check runs
before the commit. One trap worth recording: the allowed roles can only be read
back out of sqlite_master's verbatim CREATE TABLE text, comments included, so
schema.sql's own comment explaining the rebuild made the step decide it had
already run. The start-up test caught it; comments are stripped now.

A moderator curates content and has no power over people: no creating,
suspending, promoting or erasing anybody. set_role moved from owner-only to
admin-level so moderators can be appointed routinely, and checks may_create on
the new role as well, so admins still cannot mint admins. content.py splits per
collection — posts need a moderator, the site's static pages need an admin.

Also: erasure deletes a member's submissions and their pictures and clears
reviewed_by, which the existing foreign-key guard forced; deploy-board.sh takes
a backup before restarting, since two migrations now rebuild a table in place
and one of them holds your own account; README and docs/server-setup.md updated
for the roles, the sections and migration 4.

370 tests pass.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NizVpJ2dwzCbjCrTLCjeHn
2026-09-30 11:09:55 +00:00

102 lines
4.2 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)"
if [ -n "$missing" ]; then
echo
echo "!! These settings exist in .env.example but not in your .env:"
echo "$missing" | sed 's/^/ /'
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
case "$name" in
GITEA_ADMIN_TOKEN) note="no se pueden crear cuentas ni cambiar contraseñas" ;;
MAIL_HOST|MAIL_PASSWORD) note="no se envían invitaciones ni recuperaciones" ;;
BOARD_SECRET_KEY) note="LA APP NO ARRANCA" ;;
*) note="" ;;
esac
printf ' %-20s %s\n' "$name" "$note"
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
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