mirror of
https://github.com/Dvorinka/Primora.git
synced 2026-10-28 07:41:23 +00:00
feat: phase 6 production hardening + DB-to-DB transfer
Security:
- Graceful shutdown: http.Server + signal.NotifyContext, 10s drain,
retention sweeper cancelled before pool close
- Scoped API keys (migration 00006): ingest/read/write/admin enforced in
auth middleware; scope picker + badges in Settings UI; scopeless legacy
keys act as admin. Read-only keys now get 403 on ingest (verified live)
- nginx: baseline security headers on all responses, CSP scoped to SPA;
fixed add_header inheritance shadowing
- better-auth rate limit enabled unconditionally (was gated on NODE_ENV,
which the shipped .env sets to development)
- Mailpit moved to docker-compose.dev.yml; prod compose cannot expose it
- setup.sh generates PRIMORA_ENCRYPTION_KEY
Reliability/ops:
- Retention: per-project retention_{events,audit,webhook}_days
(migration 00007, 0=off) + hourly RetentionSweeper; edit UI in Projects
- GET /api/v1/metrics Prometheus exposition
- compose: healthchecks + restart policies everywhere, dragonfly pinned
to v2.0.0, depends_on service_healthy
- backup.sh/restore.sh (pg_dump -Fc + storage volume); restore verified
against scratch postgres+volume
- .dockerignore: exclude target dirs (build context was 4.7GB)
Correctness/testing:
- DBX transfer endpoint: POST /db-connections/:id/transfer — SQL or Redis
target, 1000-row bound, server-side creds (verified live pg→dragonfly)
- Pagination audit: ListComponents capped at 500 (auto-registers)
- CI: goose up/reset/up job + compose e2e-smoke job (smoke-e2e.sh
verified locally: signup, bootstrap, scoped keys, ingest, metrics)
- k6 load sanity script: 6650 reqs, ~217/s, 0 real failures, p95 221ms
(429s = configured rate limiter working)
Docs: DEPLOYMENT_GUIDE.md, PRODUCTION_READINESS.md; verify script
repaired (stale refs + set -e arithmetic abort). ROADMAP: phase 2 +
phase 6 marked complete.
Authored By: TDvorak <[email protected]>
Generated with [Devin](https://devin.ai)
Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
1 parent
1b34dd43bb
commit
55edbf8b56
64 files changed
+2058
-165
No files matched your search
Executable
+47
@@ -0,0 +1,47 @@
|
||||
#!/usr/bin/env bash
|
||||
# Primora restore: rebuilds the database and storage volume from a backup
|
||||
# tarball produced by scripts/backup.sh.
|
||||
#
|
||||
# ./scripts/restore.sh backups/primora-20260101-120000.tar.gz
|
||||
#
|
||||
# DESTRUCTIVE: drops and recreates the target database's objects and
|
||||
# overwrites the storage volume. Stop the stack first:
|
||||
# docker compose stop backend auth
|
||||
# Then restore, then `docker compose up -d`.
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
ARCHIVE="${1:?usage: restore.sh <backup.tar.gz>}"
|
||||
POSTGRES_CONTAINER="${POSTGRES_CONTAINER:-primora-postgres-1}"
|
||||
POSTGRES_USER="${POSTGRES_USER:-primora}"
|
||||
POSTGRES_DB="${POSTGRES_DB:-primora}"
|
||||
STORAGE_VOLUME="${STORAGE_VOLUME:-primora_backend_storage}"
|
||||
|
||||
[ -f "$ARCHIVE" ] || { echo "no such archive: $ARCHIVE" >&2; exit 1; }
|
||||
docker exec "$POSTGRES_CONTAINER" true 2>/dev/null \
|
||||
|| { echo "postgres container $POSTGRES_CONTAINER is not running" >&2; exit 1; }
|
||||
|
||||
echo "This will overwrite database '$POSTGRES_DB' in $POSTGRES_CONTAINER"
|
||||
echo "and the contents of volume $STORAGE_VOLUME."
|
||||
read -r -p "Continue? [y/N] " confirm
|
||||
[ "$confirm" = "y" ] || [ "$confirm" = "Y" ] || { echo "aborted"; exit 1; }
|
||||
|
||||
# Workdir under cwd — /tmp is not bind-mountable on every docker setup.
|
||||
work="$(mktemp -d "$(pwd)/.restore-tmp.XXXXXX")"
|
||||
trap 'rm -rf "$work"' EXIT
|
||||
tar -xzf "$ARCHIVE" -C "$work"
|
||||
[ -f "$work/db.dump" ] || { echo "archive has no db.dump" >&2; exit 1; }
|
||||
|
||||
echo "==> restoring database"
|
||||
cat "$work/db.dump" | docker exec -i "$POSTGRES_CONTAINER" \
|
||||
pg_restore -U "$POSTGRES_USER" -d "$POSTGRES_DB" --clean --if-exists --no-owner
|
||||
|
||||
if [ -f "$work/storage.tar" ]; then
|
||||
echo "==> restoring storage volume $STORAGE_VOLUME"
|
||||
docker run --rm -v "$STORAGE_VOLUME:/data" -v "$work:/backup" \
|
||||
alpine:3 sh -c 'rm -rf /data/* /data/..?* /data/.[!.]* 2>/dev/null; tar -C /data -xf /backup/storage.tar'
|
||||
else
|
||||
echo "warning: archive has no storage.tar — skipping volume" >&2
|
||||
fi
|
||||
|
||||
echo "==> restore complete; restart the stack with: docker compose up -d"
|
||||
Reference in new issue
Block a user