From defe8c7ade7ad5cd7b37287f12f372d82da520dc Mon Sep 17 00:00:00 2001 From: Damien Date: Mon, 11 May 2026 20:08:02 +0200 Subject: [PATCH] feat(gitea-runner): add Prometheus metrics, logrotate and LXC tags --- gitea-runner/AGENT_PROMPT.md | 101 ----------------------------------- gitea-runner/install.sh | 25 ++++++++- 2 files changed, 24 insertions(+), 102 deletions(-) delete mode 100644 gitea-runner/AGENT_PROMPT.md diff --git a/gitea-runner/AGENT_PROMPT.md b/gitea-runner/AGENT_PROMPT.md deleted file mode 100644 index ea31264..0000000 --- a/gitea-runner/AGENT_PROMPT.md +++ /dev/null @@ -1,101 +0,0 @@ -# Agent Prompt — gitea-runner install.sh update - -## Objectif - -Modifier `gitea-runner/install.sh` pour ajouter : -1. Les tags LXC `infra-script` et `cicd` à la création du conteneur -2. La configuration automatique des métriques Prometheus de `act_runner` -3. La rotation des logs via `logrotate` - -## Fichier à modifier - -`gitea-runner/install.sh` sur la branche `feat/gitea-runner-metrics-logrotate` - -Lis d'abord le fichier actuel avant toute modification. - ---- - -## Changements attendus - -### 1. Tags LXC (dans `create_lxc()`) - -Dans la commande `pct create`, ajouter l'argument `--tags` : - -```bash -pct create "$CTID" "${TEMPLATE_STORAGE}:vztmpl/${TEMPLATE}" \ - --hostname "$HOSTNAME" \ - --cores "$CORES" \ - --memory "$RAM" \ - --rootfs "${STORAGE}:${DISK}" \ - --net0 "name=eth0,bridge=${BRIDGE},ip=dhcp" \ - --unprivileged 1 \ - --features nesting=1,keyctl=1 \ - --tags "infra-script,cicd" \ # ← AJOUTER CETTE LIGNE - --start 0 -``` - ---- - -### 2. Métriques Prometheus (dans `install_runner()`) - -Après le bloc de création de l'utilisateur `gitea-runner` et du répertoire `/var/lib/gitea-runner`, ajouter la génération et configuration du fichier `config.yaml` : - -```bash -log_info "Generating act_runner config with Prometheus metrics enabled..." -act_runner generate-config > /var/lib/gitea-runner/config.yaml -# Enable Prometheus metrics on port 9101 -sed -i '/^metrics:/,/enabled:/{s/enabled: false/enabled: true/}' /var/lib/gitea-runner/config.yaml -chown gitea-runner:docker /var/lib/gitea-runner/config.yaml -chmod 640 /var/lib/gitea-runner/config.yaml -``` - -Dans le service OpenRC généré, modifier `command_args` pour passer le fichier de config : - -```bash -# AVANT : -command_args="daemon" - -# APRÈS : -command_args="daemon --config /var/lib/gitea-runner/config.yaml" -``` - ---- - -### 3. Logrotate (dans `install_runner()`) - -Après la création du service OpenRC, ajouter l'installation et la configuration de logrotate : - -```bash -log_info "Configuring logrotate for gitea-runner..." -apk add --no-cache logrotate > /dev/null - -cat > /etc/logrotate.d/gitea-runner << 'LOGROTATE' -/var/log/gitea-runner.log { - daily - rotate 7 - compress - missingok - notifempty - copytruncate -} -LOGROTATE - -# S'assurer que logrotate est bien exécuté daily via le cron Alpine -ln -sf /usr/sbin/logrotate /etc/periodic/daily/logrotate 2>/dev/null || true -``` - ---- - -## Contraintes - -- Ne pas modifier la logique de détection de contexte (`main()`) -- Ne pas modifier `update_runner()` -- Conserver tous les `log_info` existants et leur style -- Le script doit rester compatible avec une réinstallation propre -- Utiliser le même style de code que le fichier existant (bash, `set -euo pipefail`, heredoc `<<'EOF'`) - -## Livrable - -Un seul commit sur `feat/gitea-runner-metrics-logrotate` modifiant `gitea-runner/install.sh`, puis ouvrir une PR vers `main` avec le titre : - -`feat(gitea-runner): add prometheus metrics, logrotate and LXC tags` diff --git a/gitea-runner/install.sh b/gitea-runner/install.sh index abe4727..54fcad1 100644 --- a/gitea-runner/install.sh +++ b/gitea-runner/install.sh @@ -94,6 +94,7 @@ create_lxc() { --net0 "name=eth0,bridge=${BRIDGE},ip=dhcp" \ --unprivileged 1 \ --features nesting=1,keyctl=1 \ + --tags "infra-script,cicd" \ --start 0 log_info "Configuring LXC for Docker and Tailscale..." @@ -163,6 +164,12 @@ install_runner() { mkdir -p /var/lib/gitea-runner chown -R gitea-runner:docker /var/lib/gitea-runner + log_info "Generating act_runner config with Prometheus metrics enabled..." + act_runner generate-config > /var/lib/gitea-runner/config.yaml + sed -i '/^metrics:/,/enabled:/{s/enabled: false/enabled: true/}' /var/lib/gitea-runner/config.yaml + chown gitea-runner:docker /var/lib/gitea-runner/config.yaml + chmod 640 /var/lib/gitea-runner/config.yaml + log_info "Creating OpenRC service..." cat <<'EOF' > /etc/init.d/gitea-runner #!/sbin/openrc-run @@ -170,7 +177,7 @@ install_runner() { name="Gitea Act Runner" description="Gitea Actions Runner Daemon" command="/usr/local/bin/act_runner" -command_args="daemon" +command_args="daemon --config /var/lib/gitea-runner/config.yaml" command_user="gitea-runner:docker" command_background=true pidfile="/run/${RC_SVCNAME}.pid" @@ -193,6 +200,22 @@ EOF chmod +x /etc/init.d/gitea-runner rc-update add gitea-runner default > /dev/null + log_info "Configuring logrotate for gitea-runner..." + apk add --no-cache logrotate > /dev/null + + cat > /etc/logrotate.d/gitea-runner << 'LOGROTATE' +/var/log/gitea-runner.log { + daily + rotate 7 + compress + missingok + notifempty + copytruncate +} +LOGROTATE + + ln -sf /usr/sbin/logrotate /etc/periodic/daily/logrotate 2>/dev/null || true + log_info "Enabling console auto-login..." mkdir -p /etc/conf.d cat <<'EOF' > /etc/conf.d/agetty