feature: Update forge script for alerting and backup testing, add docs for other toolchain scripts

This commit is contained in:
Keith Solomon
2025-12-05 09:57:10 -06:00
parent 5e993d9dd9
commit 97572196f9
5 changed files with 104 additions and 15 deletions

View File

@@ -0,0 +1,25 @@
#!/usr/bin/env bash
set -euo pipefail
level="${1:-INFO}" # e.g., INFO, WARN, ERROR
event="${2:-general}" # e.g., backup, restore-test
message="${3:-}"
# Telegram config via environment
BOT_TOKEN="${TELEGRAM_BOT_TOKEN:-}"
CHAT_ID="${TELEGRAM_CHAT_ID:-}"
# Log to syslog
logger -t soloforge "[$level][$event] $message"
# Send to Telegram if configured
if [[ -n "$BOT_TOKEN" && -n "$CHAT_ID" ]]; then
# Keep the message simple to avoid escaping headaches
safe_msg=$(echo "$message" | tr '"' "'" )
curl -sS -X POST \
"https://api.telegram.org/bot${BOT_TOKEN}/sendMessage" \
-d "chat_id=${CHAT_ID}" \
--data-urlencode "text=[SoloForge][$level][$event] $safe_msg" \
>/dev/null 2>&1 || true
fi

View File

@@ -23,8 +23,8 @@ mv "$GITEA_DIR/$dump_file" "$BACKUP_DIR/$dump_file"
echo "[backup] Dump created at $BACKUP_DIR/$dump_file"
# Optional: Upload to Backblaze B2 via rclone
# Make sure you configured a remote named 'b2'
rclone copy "$BACKUP_DIR/$dump_file" b2:soloforge-backups
# Make sure you configured a remote named 'B2'
rclone copy "$BACKUP_DIR/$dump_file" B2:soloforge-backups
echo "[backup] Uploaded $dump_file to Backblaze B2"
echo "[backup] All done."

View File

@@ -0,0 +1,45 @@
#!/usr/bin/env bash
set -euo pipefail
BACKUP_DIR="/gitea/backups"
TMP_BASE="/tmp/soloforge-restore-test"
CONTAINER_IMAGE="gitea/gitea:latest" # for future deeper tests if desired
mkdir -p "$TMP_BASE"
latest="$(ls -1t "$BACKUP_DIR"/gitea-dump-*.zip 2>/dev/null | head -n1 || true)"
if [[ -z "$latest" ]]; then
echo "[restore-test] No backup files found in $BACKUP_DIR"
forge-alert.sh "ERROR" "restore-test" "No backup files found in $BACKUP_DIR"
exit 1
fi
echo "[restore-test] Using latest backup: $latest"
# Basic ZIP integrity test
echo "[restore-test] Running unzip -t ..."
if ! unzip -t "$latest" >/dev/null 2>&1; then
echo "[restore-test] unzip -t failed for $latest"
forge-alert.sh "ERROR" "restore-test" "Backup failed unzip test: $(basename "$latest")"
exit 1
fi
# Optional: extraction smoke test
tmpdir="$(mktemp -d "$TMP_BASE/restore-test-XXXXXX")"
echo "[restore-test] Extracting into $tmpdir ..."
if ! unzip -qq "$latest" -d "$tmpdir"; then
echo "[restore-test] unzip extract failed for $latest"
forge-alert.sh "ERROR" "restore-test" "Backup failed extraction: $(basename "$latest")"
rm -rf "$tmpdir"
exit 1
fi
# Clean up
rm -rf "$tmpdir"
echo "[restore-test] Backup passed unzip + extraction checks."
forge-alert.sh "INFO" "restore-test" "Backup $(basename "$latest") passed restore tests."

View File

@@ -48,6 +48,7 @@ Usage:
forge gitea-logs Tail logs from Gitea container
forge runner-logs Tail logs from Actions runner container
forge backup Run a Gitea dump and move it into BACKUP_DIR
forge restore-test Run backup restore sanity checks (unzip + extract)
forge restart-gitea Restart Gitea stack
forge restart-runner Restart Actions runner stack
forge runner-reset Re-register runner with current labels (destroys .runner)
@@ -95,26 +96,26 @@ cmd_backup() {
dest="$BACKUP_DIR/gitea-dump-$ts.zip"
echo "Running Gitea dump inside container: $GITEA_CONTAINER_NAME"
# Gitea dump will write gitea-dump-*.zip under /data which is mounted to $GITEA_DIR/gitea
docker exec -u 1000 "$GITEA_CONTAINER_NAME" gitea dump -c /data/gitea/conf/app.ini --file /data/gitea-dump-$ts.zip
if ! docker exec -u 1000 "$GITEA_CONTAINER_NAME" sh -lc \
"gitea dump -c /data/gitea/conf/app.ini --file /data/gitea-dump-$ts.zip"; then
echo "Error: gitea dump failed" >&2
forge-alert.sh "ERROR" "backup" "gitea dump failed"
echo "Locating latest dump..."
local dump
dump=$(ls -1t "$GITEA_DIR"/gitea/gitea-dump-*.zip 2>/dev/null | head -n1 || true)
if [[ -z "$dump" ]]; then
echo "Error: no gitea-dump-*.zip found under $GITEA_DIR/gitea" >&2
exit 1
fi
local base
base=$(basename "$dump")
local dest="$BACKUP_DIR/$base"
if [[ ! -f "$dump" ]]; then
echo "Error: expected dump file not found: $dump" >&2
forge-alert.sh "ERROR" "backup" "dump file missing: $dump"
exit 1
fi
echo "Moving $dump -> $dest"
mv "$dump" "$dest"
echo "Backup complete: $dest"
forge-alert.sh "INFO" "backup" "Backup complete: $(basename "$dest")"
}
cmd_restart_gitea() {
@@ -205,6 +206,9 @@ case "$cmd" in
backup)
cmd_backup
;;
restore-test)
/usr/local/bin/forge-restore-test.sh
;;
restart-gitea)
cmd_restart_gitea
;;