chore(scripts): add compose, k3s, backup, and media helpers
Automate image load, Helm install, database backup, and sample video regeneration.
This commit is contained in:
Executable
+21
@@ -0,0 +1,21 @@
|
||||
#!/usr/bin/env bash
|
||||
# Backup Postgres + RustFS volume data for pargar.
|
||||
# Usage: ./scripts/backup.sh [output-dir]
|
||||
set -euo pipefail
|
||||
|
||||
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
|
||||
OUT="${1:-$ROOT/backups/$(date -u +%Y%m%dT%H%M%SZ)}"
|
||||
mkdir -p "$OUT"
|
||||
|
||||
echo "Backing up Postgres to $OUT/postgres.sql.gz"
|
||||
docker compose -f "$ROOT/docker-compose.yml" exec -T postgres \
|
||||
pg_dump -U "${POSTGRES_USER:-pargar}" "${POSTGRES_DB:-pargar}" | gzip > "$OUT/postgres.sql.gz"
|
||||
|
||||
echo "Backing up RustFS volume snapshot marker to $OUT"
|
||||
docker compose -f "$ROOT/docker-compose.yml" exec -T rustfs \
|
||||
sh -c 'tar -C /data -czf - .' > "$OUT/rustfs-data.tar.gz" || {
|
||||
echo "Note: if rustfs tar failed, copy volume rustfs_data manually" >&2
|
||||
}
|
||||
|
||||
echo "Done: $OUT"
|
||||
ls -lh "$OUT"
|
||||
Executable
+16
@@ -0,0 +1,16 @@
|
||||
#!/usr/bin/env bash
|
||||
# Dev / laptop stack (Traefik + localhost TLS + published DB ports).
|
||||
set -euo pipefail
|
||||
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
|
||||
cd "$ROOT"
|
||||
|
||||
if [[ ! -f .env ]]; then
|
||||
echo "Missing .env — copy .env.example and fill secrets." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
exec docker compose \
|
||||
-f deploy/compose/compose.yaml \
|
||||
-f deploy/compose/compose.dev.yaml \
|
||||
--env-file .env \
|
||||
"$@"
|
||||
Executable
+27
@@ -0,0 +1,27 @@
|
||||
#!/usr/bin/env bash
|
||||
# Production compose stack (Traefik + Let's Encrypt). Never use DEV_MODE=true here.
|
||||
set -euo pipefail
|
||||
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
|
||||
cd "$ROOT"
|
||||
|
||||
ENV_FILE="${ENV_FILE:-.env.prod}"
|
||||
if [[ ! -f "$ENV_FILE" ]]; then
|
||||
echo "Missing $ENV_FILE — copy .env.prod.example and fill production secrets/DNS." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Guardrails
|
||||
if grep -Eq '^[[:space:]]*DEV_MODE[[:space:]]*=[[:space:]]*true' "$ENV_FILE"; then
|
||||
echo "Refusing to start: DEV_MODE=true in $ENV_FILE" >&2
|
||||
exit 1
|
||||
fi
|
||||
if ! grep -Eq '^[[:space:]]*ACME_EMAIL[[:space:]]*=' "$ENV_FILE"; then
|
||||
echo "Refusing to start: ACME_EMAIL must be set in $ENV_FILE" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
exec docker compose \
|
||||
-f deploy/compose/compose.yaml \
|
||||
-f deploy/compose/compose.prod.yaml \
|
||||
--env-file "$ENV_FILE" \
|
||||
"$@"
|
||||
Executable
+18
@@ -0,0 +1,18 @@
|
||||
#!/usr/bin/env bash
|
||||
# Install / upgrade Pargar on local k3s with the k3s values profile.
|
||||
set -euo pipefail
|
||||
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
|
||||
cd "$ROOT"
|
||||
|
||||
NS="${NS:-pargar}"
|
||||
RELEASE="${RELEASE:-pargar}"
|
||||
|
||||
helm upgrade --install "$RELEASE" ./deploy/helm/pargar \
|
||||
--namespace "$NS" \
|
||||
--create-namespace \
|
||||
-f ./deploy/helm/pargar/values-k3s.yaml \
|
||||
"$@"
|
||||
|
||||
echo
|
||||
echo "Add hosts entry if needed: <node-ip> pargar.local"
|
||||
echo "Health: curl -k https://pargar.local/api/health"
|
||||
Executable
+16
@@ -0,0 +1,16 @@
|
||||
#!/usr/bin/env bash
|
||||
# Build compose images and import them into local k3s containerd.
|
||||
set -euo pipefail
|
||||
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
|
||||
cd "$ROOT"
|
||||
|
||||
if ! command -v k3s >/dev/null 2>&1; then
|
||||
echo "k3s not found. Install: https://docs.k3s.io/quick-start" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
./scripts/compose-dev.sh build backend frontend
|
||||
|
||||
echo "Importing images into k3s..."
|
||||
docker save pargar-backend:local pargar-frontend:local | sudo k3s ctr images import -
|
||||
echo "Done. Images: pargar-backend:local pargar-frontend:local"
|
||||
Executable
+15
@@ -0,0 +1,15 @@
|
||||
#!/usr/bin/env bash
|
||||
# Regenerate backend/media/sample.mp4 (SMPTE color bars, 45s, 1280x720 H.264).
|
||||
# Recovery only — runtime does not depend on ffmpeg.
|
||||
set -euo pipefail
|
||||
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
|
||||
OUT="$ROOT/backend/media/sample.mp4"
|
||||
mkdir -p "$(dirname "$OUT")"
|
||||
if ! command -v ffmpeg >/dev/null 2>&1; then
|
||||
echo "ffmpeg not found" >&2
|
||||
exit 1
|
||||
fi
|
||||
ffmpeg -y -f lavfi -i smptebars=size=1280x720:rate=24 \
|
||||
-f lavfi -i "sine=frequency=1000:sample_rate=44100" \
|
||||
-t 45 -c:v libx264 -pix_fmt yuv420p -c:a aac -shortest "$OUT"
|
||||
echo "Wrote $OUT"
|
||||
Reference in New Issue
Block a user