nkbmusic/admin/deploy-admin.sh
metatroncubeswdev cf645071aa Add NK Admin dashboard (Flutter web) for admin.nkbmusic.com
Email-code sign-in for admins only; Overview with a needs-attention list;
Songs with search, playback, editing, approve/hide and bulk edit; Albums
and Singers with merge; creator applications queue. Adds the admin views,
functions and creator_applications table, a deploy-admin script and a
how-to guide. The admin nginx config no longer caches unhashed JS and
sends its security headers again.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-30 11:35:44 -04:00

59 lines
2.6 KiB
Bash

#!/bin/sh
# Builds NK Admin and publishes it to the nk-admin container (admin.nkbmusic.com).
# Run on your own computer (needs Flutter, ssh and tar; Git Bash works on Windows):
#
# sh admin/deploy-admin.sh
#
# Optional environment:
# NK_SSH ssh target (default dev@72.62.169.43)
# NK_PROJECT Supabase project dir (default APPS/nk-backend/supabase-project, under the ssh home)
# NK_ENV env.json to build with (default ../env.json, the app's file)
# NK_SKIP_BUILD=1 publish the existing build/web without building again
set -eu
HERE="$(cd "$(dirname "$0")" && pwd)"
SSH_TARGET="${NK_SSH:-dev@72.62.169.43}"
PROJECT="${NK_PROJECT:-APPS/nk-backend/supabase-project}"
ENV_FILE="${NK_ENV:-$HERE/../env.json}"
say() { printf '\n==> %s\n' "$*"; }
die() { printf 'Error: %s\n' "$*" >&2; exit 1; }
cd "$HERE"
if [ "${NK_SKIP_BUILD:-}" != 1 ]; then
[ -f "$ENV_FILE" ] || die "missing $ENV_FILE (copy env.example.json and fill it in)"
say "Building NK Admin"
flutter pub get >/dev/null
flutter build web --release --dart-define-from-file="$ENV_FILE"
fi
[ -f build/web/index.html ] || die "no build found in admin/build/web"
say "Uploading to $SSH_TARGET:$PROJECT/nk/admin"
# The folder is bind-mounted into the container, so its contents are replaced in place
# (unpacked next to it first, then swapped in) rather than the folder itself.
tar -C build/web -czf - . | ssh "$SSH_TARGET" "set -e
cd '$PROJECT'
rm -rf nk/admin.new && mkdir -p nk/admin.new nk/admin nk/nginx
tar -xzf - -C nk/admin.new
find nk/admin -mindepth 1 -delete
cp -a nk/admin.new/. nk/admin/
rm -rf nk/admin.new"
say "Updating the web server config"
ssh "$SSH_TARGET" "cat > '$PROJECT/nk/nginx/admin.conf'" < "$HERE/../server/nginx/admin.conf"
ssh "$SSH_TARGET" "set -e
cd '$PROJECT'
docker compose up -d nk-admin >/dev/null
docker compose exec -T nk-admin nginx -s reload >/dev/null 2>&1 || docker compose restart nk-admin >/dev/null
if curl -fsS http://127.0.0.1:\${NK_ADMIN_PORT:-18080}/ | grep -q flutter_bootstrap; then
echo 'NK Admin is being served on 127.0.0.1:18080.'
else
echo 'Warning: the admin container did not return the new page (docker compose logs nk-admin).'
fi
PGPASSWORD=\$(grep -E '^POSTGRES_PASSWORD=' .env | cut -d= -f2-)
applied=\$(docker compose exec -T -e PGPASSWORD=\"\$PGPASSWORD\" db psql -h localhost -U postgres -d postgres -tA \
-c \"select 1 from public.nk_schema_migrations where name = '20261031000000_admin.sql'\" 2>/dev/null || true)
[ \"\$applied\" = 1 ] || echo 'Warning: the admin database migration is not applied yet. Push to git, then run: sh ~/APPS/nanga_kathai/server/update.sh'"
say "Done: https://admin.nkbmusic.com"