- Forgejo + Redis Docker stack (wetgit-forgejo role) - FastAPI + Celery systemd services (wetgit-app role) - Nginx vhosts voor git.wetgit.nl en api.wetgit.nl (wetgit-nginx role) - SSL via Let's Encrypt (certbot webroot) - Backup script (forgejo dump, geen downtime) - Codeberg mirror script - Cron jobs voor backup/mirror/log cleanup - Ansible vault voor secrets (encrypted) Geïsoleerd van dt-platform: eigen poorten, users, directories.
55 lines
1.6 KiB
Django/Jinja
55 lines
1.6 KiB
Django/Jinja
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
# Mirror WetGit repos from self-hosted Forgejo to Codeberg
|
|
# Managed by Ansible — runs daily at 04:00
|
|
|
|
CODEBERG_USER="coornhert"
|
|
CODEBERG_TOKEN_FILE="{{ app_dir }}/.codeberg-token"
|
|
MIRROR_DIR="{{ app_dir }}/mirrors"
|
|
LOG_PREFIX="[$(date '+%Y-%m-%d %H:%M:%S')]"
|
|
|
|
REPOS=(
|
|
"wetgit/meta"
|
|
"wetgit/rijk"
|
|
# Add more as they are created:
|
|
# "wetgit/cvdr-noord-holland"
|
|
# "wetgit/eu"
|
|
)
|
|
|
|
if [ ! -f "$CODEBERG_TOKEN_FILE" ]; then
|
|
echo "$LOG_PREFIX ERROR: Codeberg token not found at $CODEBERG_TOKEN_FILE"
|
|
exit 1
|
|
fi
|
|
|
|
CODEBERG_TOKEN=$(cat "$CODEBERG_TOKEN_FILE")
|
|
mkdir -p "$MIRROR_DIR"
|
|
|
|
for REPO in "${REPOS[@]}"; do
|
|
REPO_NAME=$(basename "$REPO")
|
|
REPO_MIRROR_DIR="$MIRROR_DIR/$REPO_NAME.git"
|
|
FORGEJO_URL="https://{{ forgejo_domain }}/${REPO}.git"
|
|
CODEBERG_URL="https://${CODEBERG_USER}:${CODEBERG_TOKEN}@codeberg.org/${REPO}.git"
|
|
|
|
echo "$LOG_PREFIX Mirroring $REPO..."
|
|
|
|
if [ ! -d "$REPO_MIRROR_DIR" ]; then
|
|
echo "$LOG_PREFIX Initial clone from Forgejo..."
|
|
git clone --bare "$FORGEJO_URL" "$REPO_MIRROR_DIR"
|
|
cd "$REPO_MIRROR_DIR"
|
|
git remote add codeberg "$CODEBERG_URL"
|
|
else
|
|
cd "$REPO_MIRROR_DIR"
|
|
echo "$LOG_PREFIX Fetching from Forgejo..."
|
|
git fetch origin --prune '+refs/heads/*:refs/heads/*' '+refs/tags/*:refs/tags/*'
|
|
fi
|
|
|
|
echo "$LOG_PREFIX Pushing to Codeberg..."
|
|
git push codeberg --mirror --force 2>&1 || {
|
|
echo "$LOG_PREFIX WARNING: Push to Codeberg failed for $REPO (non-fatal)"
|
|
}
|
|
|
|
echo "$LOG_PREFIX Done: $REPO"
|
|
done
|
|
|
|
echo "$LOG_PREFIX Mirror complete."
|