feat(server): sync live archrepo, add retention pruning and Caddy config

Bring the deployed server into the repo: prune.sh + archrepo-prune.timer for
version retention, refreshed README/install.sh, and the live Caddyfile used
by /admin and /api. Keeps the admin UI and its Caddy config in one place.
This commit is contained in:
BlackAngelTV committed 2026-11-20 11:51:39 +00:00
1 parent c903e28254
commit 108e4e6e63
4 files changed
+320 -12

No files matched your search

+54 -3
View File
@@ -6,7 +6,7 @@
#
# Variables reconnues : ARCHREPO_ROOT, ARCHREPO_STATE_DIR, ARCHREPO_NAME,
# ARCHREPO_ARCH, ARCHREPO_BIND, ARCHREPO_MAX_UPLOAD, ARCHREPO_USER,
# ARCHREPO_TOKEN_FILE, ARCHREPO_UNIT.
# ARCHREPO_TOKEN_FILE, ARCHREPO_UNIT, ARCHREPO_KEEP (versions gardées, 3).
set -euo pipefail
@@ -21,13 +21,18 @@ SERVICE_USER="${ARCHREPO_USER:-archrepo}"
TOKEN_FILE="${ARCHREPO_TOKEN_FILE:-/etc/archrepo/token}"
UNIT_FILE="${ARCHREPO_UNIT:-/etc/systemd/system/archrepo.service}"
SERVICE_NAME="$(basename "$UNIT_FILE" .service)"
KEEP="${ARCHREPO_KEEP:-3}"
SERVICE_DIR="$(dirname "$UNIT_FILE")"
PRUNE_UNIT="$SERVICE_DIR/$SERVICE_NAME-prune.service"
PRUNE_NAME="$(basename "$PRUNE_UNIT" .service)"
PRUNE_TIMER="${PRUNE_UNIT%.service}.timer"
if [[ $EUID -ne 0 ]]; then
exec sudo --preserve-env=ARCHREPO_ROOT,ARCHREPO_STATE_DIR,ARCHREPO_NAME,ARCHREPO_ARCH,ARCHREPO_BIND,ARCHREPO_MAX_UPLOAD,ARCHREPO_USER,ARCHREPO_TOKEN_FILE,ARCHREPO_UNIT \
exec sudo --preserve-env=ARCHREPO_ROOT,ARCHREPO_STATE_DIR,ARCHREPO_NAME,ARCHREPO_ARCH,ARCHREPO_BIND,ARCHREPO_MAX_UPLOAD,ARCHREPO_USER,ARCHREPO_TOKEN_FILE,ARCHREPO_UNIT,ARCHREPO_KEEP \
bash "$0" "$@"
fi
for dependency in python3 tar; do
for dependency in python3 tar curl perl; do
command -v "$dependency" >/dev/null || { echo "dépendance manquante : $dependency" >&2; exit 1; }
done
PYTHON="$(command -v python3)"
@@ -104,8 +109,52 @@ EOF
chmod 0644 "$UNIT_FILE"
echo "✓ unité systemd écrite dans $UNIT_FILE"
# --- rétention des anciennes versions ---------------------------------------
cat >"$PRUNE_UNIT" <<EOF
[Unit]
Description=archrepo — rétention (garde $KEEP versions par paquet)
Documentation=file://$APP_DIR/README.md
After=$SERVICE_NAME.service
[Service]
Type=oneshot
User=$SERVICE_USER
Group=$SERVICE_USER
Environment=REPO_URL=http://$BIND
Environment=ARCHREPO_TOKEN_FILE=$TOKEN_FILE
Environment=ARCHREPO_KEEP=$KEEP
ExecStart=$APP_DIR/prune.sh
Restart=on-failure
RestartSec=30
Nice=10
IOSchedulingClass=idle
NoNewPrivileges=yes
PrivateTmp=yes
ProtectSystem=strict
ProtectHome=read-only
ReadWritePaths=$STATE_DIR
EOF
chmod 0644 "$PRUNE_UNIT"
cat >"$PRUNE_TIMER" <<EOF
[Unit]
Description=archrepo — purge périodique des anciennes versions
[Timer]
OnBootSec=5min
OnUnitActiveSec=1h
AccuracySec=1min
Unit=$PRUNE_NAME.service
[Install]
WantedBy=timers.target
EOF
chmod 0644 "$PRUNE_TIMER"
echo "✓ rétention : $PRUNE_NAME.timer (garde $KEEP versions par paquet)"
systemctl daemon-reload
systemctl enable "$SERVICE_NAME" >/dev/null
systemctl enable --now "$PRUNE_NAME.timer" >/dev/null
systemctl restart "$SERVICE_NAME"
# --- vérification -----------------------------------------------------------
@@ -136,3 +185,5 @@ echo " Caddy : ajoutez le bloc de Caddyfile.snippet dans /etc/caddy/Caddyfile p
echo " sudo caddy validate --config /etc/caddy/Caddyfile && sudo systemctl reload caddy"
echo
echo " publication : ./push.sh mon-paquet-1.0-1-x86_64.pkg.tar.zst"
echo " rétention : $KEEP versions par paquet ($PRUNE_NAME.timer, purge horaire)"
echo " à la main : ./prune.sh --dry-run puis ./prune.sh"