From 888d2ab4fce8c8f61a37db36ce6060cb07f6dad1 Mon Sep 17 00:00:00 2001 From: Nicolas Date: Sat, 16 May 2026 20:04:31 +0200 Subject: [PATCH] feat: initial commit of robust gitea configuration --- .gitignore | 12 ++++++++++ README.md | 55 ++++++++++++++++++++++++++++++++++++++++++++++ backup_gitea.sh | 22 +++++++++++++++++++ docker-compose.yml | 45 +++++++++++++++++++++++++++++++++++++ 4 files changed, 134 insertions(+) create mode 100644 .gitignore create mode 100644 README.md create mode 100755 backup_gitea.sh create mode 100644 docker-compose.yml diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8b7f65b --- /dev/null +++ b/.gitignore @@ -0,0 +1,12 @@ +# Secrets +.env + +# Docker Persistence +data/ +db_data/ +config/ + +# Backups & Logs +*.zip +*.log +docker-compose.yml.bak diff --git a/README.md b/README.md new file mode 100644 index 0000000..50708b8 --- /dev/null +++ b/README.md @@ -0,0 +1,55 @@ +# Gitea - Git with a cup of tea + +Instance Gitea auto-hébergée, robuste et performante, utilisant PostgreSQL. + +## Architecture + +- **Gitea** : Image Rootless (`gitea/gitea:1.21-rootless`) +- **Base de données** : PostgreSQL 16 (Alpine) +- **Réseaux** : + - `proxy_network` : Accès via Nginx Proxy Manager. + - `gitea_internal` : Communication privée entre Gitea et PostgreSQL. + +## Configuration + +- **URL Web** : `http://localhost:3001` (ou via ton domaine configuré dans NPM) +- **SSH** : Port `2222` +- **Utilisateur Système** : `nb` (UID 1001) + +## Persistence + +Les données sont stockées localement sur le SSD pour des performances optimales : +- `./data` : Données applicatives et dépôts Git. +- `./config` : Configuration Gitea (`app.ini`). +- `./db_data` : Fichiers de la base de données PostgreSQL. + +## Sauvegardes (Backups) + +Un script de sauvegarde automatisé est en place : +- **Script** : `./backup_gitea.sh` +- **Destination** : `/mnt/nas_freebox/backup/gitea/` +- **Fréquence** : Quotidienne à 03h00 via Cron. +- **Rétention** : 7 jours sur le NAS. + +## Commandes utiles + +```bash +# Lancer les services +docker compose up -d + +# Arrêter les services +docker compose down + +# Voir les logs +docker compose logs -f + +# Lancer un backup manuel +./backup_gitea.sh +``` + +## Dépannage (Troubleshooting) + +### Erreur réseau NPM (16/05/2026) +- **Problème** : Impossible d'accéder à Gitea via l'URL locale ou le domaine. NPM était arrêté avec l'erreur `network not found`. +- **Cause** : Désynchronisation de l'ID du réseau `proxy_network` après des modifications d'infrastructure. +- **Résolution** : Redémarrage complet de NPM via `docker compose down && docker compose up -d` pour forcer la reconnexion au réseau externe. diff --git a/backup_gitea.sh b/backup_gitea.sh new file mode 100755 index 0000000..99cf1c2 --- /dev/null +++ b/backup_gitea.sh @@ -0,0 +1,22 @@ +#!/bin/bash +BACKUP_DIR="/home/nb/docker/gitea/data" +NAS_DIR="/mnt/nas_freebox/backup/gitea" +DATE=$(date +%Y%m%d_%H%M%S) + +echo "Starting Gitea backup: $DATE" + +# Generate dump using new paths +docker exec -u 1001 gitea /usr/local/bin/gitea dump -c /etc/gitea/app.ini -f /var/lib/gitea/gitea-dump.zip + +# Move to NAS +if [ -f "$BACKUP_DIR/gitea-dump.zip" ]; then + cp "$BACKUP_DIR/gitea-dump.zip" "$NAS_DIR/gitea_backup_$DATE.zip" + rm "$BACKUP_DIR/gitea-dump.zip" + echo "Backup successful: $NAS_DIR/gitea_backup_$DATE.zip" +else + echo "Backup failed: Dump file not found" + exit 1 +fi + +# Retention: keep 7 days +find "$NAS_DIR" -name "gitea_backup_*.zip" -mtime +7 -delete diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..c2aa1fb --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,45 @@ +services: + server: + image: gitea/gitea:1.21-rootless + container_name: gitea + user: "1001:1001" + restart: unless-stopped + environment: + - GITEA__database__DB_TYPE=postgres + - GITEA__database__HOST=db-gitea:5432 + - GITEA__database__NAME=gitea + - GITEA__database__USER=gitea + - GITEA__database__PASSWD=${DB_PASSWORD} + - INSTALL_LOCK=true + networks: + - proxy_network + - gitea_internal + volumes: + - ./data:/var/lib/gitea + - ./config:/etc/gitea + - /etc/timezone:/etc/timezone:ro + - /etc/localtime:/etc/localtime:ro + ports: + - "3001:3000" + - "2222:2222" + depends_on: + - db-gitea + + db-gitea: + image: postgres:16-alpine + container_name: gitea-db + restart: unless-stopped + environment: + - POSTGRES_USER=gitea + - POSTGRES_PASSWORD=${DB_PASSWORD} + - POSTGRES_DB=gitea + networks: + - gitea_internal + volumes: + - ./db_data:/var/lib/postgresql/data + +networks: + proxy_network: + external: true + gitea_internal: + driver: bridge