add gateway automatic template and fefan vm

This commit is contained in:
2026-01-19 17:05:38 +01:00
parent d98c7b8bdb
commit f851ead7cd
56 changed files with 1243 additions and 82 deletions

View File

@@ -0,0 +1,9 @@
GITEA_HOME="/var/lib/gitea"
GITEA_CONF="/var/lib/gitea/app.ini"
GITEA_USER="git"
GITEA_VERSION="1.25.3"
GITEA_BINARY="/usr/local/bin/gitea"
GITEA_SERVICE="/etc/systemd/system/gitea.service"
DB_NAME="giteadb"
DB_USER="gitea"
GITEA_BACKUPS_DIR="/backups/gitea"

View File

@@ -31,11 +31,14 @@ packages:
- postgresql
- postgresql-client
mounts:
- [ "192.168.1.12:/main/backups", "/backups", "nfs", "defaults,_netdev,x-systemd.requires=network-online.target", "0", "0" ]
write_files:
- path: /etc/fstab
- path: /opt/gitea/gitea.env
permissions: "0644"
content: |
${proxmox_host_ip}:/main/backups /backups nfs defaults,_netdev 0 0
${env-file-content}
- path: /opt/gitea/env.sh
permissions: "0644"
content: |
@@ -52,11 +55,11 @@ write_files:
permissions: "0755"
content: |
${create-backup-script}
- path: /etc/systemd/system/weekly-backup.timer
- path: /etc/systemd/system/create-backup.timer
permissions: "0644"
content: |
${create-backup-timer}
- path: /etc/systemd/system/weekly-backup.service
- path: /etc/systemd/system/create-backup.service
permissions: "0644"
content: |
${create-backup-service}
@@ -73,7 +76,7 @@ runcmd:
# Backup setup
- mkdir -p /backups
- mount -t nfs ${proxmox_host_ip}:/main/backups /backups
- systemctl enable --now weekly-backup.timer
- systemctl enable --now create-backup.timer
# Docker setup
- systemctl enable docker
- systemctl start docker

View File

@@ -5,6 +5,6 @@ source /opt/gitea/env.sh
TIMESTAMP=$(date +'%Y-%m-%d_%H%M%S')
sudo -u "$GITEA_USER" gitea dump -c "$GITEA_HOME/app.ini" -f $GITEA_BACKUPS_DIR/gitea-dump-\$TIMESTAMP.zip
sudo -u "$GITEA_USER" gitea dump -c "$GITEA_HOME/app.ini" -f $GITEA_BACKUPS_DIR/gitea-dump-$TIMESTAMP.zip
ls -1dt $GITEA_BACKUPS_DIR/gitea-dump-*.zip | tail -n +5 | xargs -r rm -f

View File

@@ -1,12 +1,4 @@
#!/bin/bash
set -euo pipefail
GITEA_HOME="/var/lib/gitea"
GITEA_CONF="$GITEA_HOME/app.ini"
GITEA_USER="git"
GITEA_VERSION="1.25.3"
GITEA_BINARY="/usr/local/bin/gitea"
GITEA_SERVICE="/etc/systemd/system/gitea.service"
DB_NAME="giteadb"
DB_USER="gitea"
GITEA_BACKUPS_DIR="/backups/gitea"
set -a
[ -f /opt/gitea/gitea.env ] && source /opt/gitea/gitea.env
set +a

View File

@@ -21,6 +21,12 @@ mkdir -p $GITEA_HOME/{custom,data,log}
chown -R $GITEA_USER:$GITEA_USER $GITEA_HOME
chmod -R 750 $GITEA_HOME
mkdir -p /home/$GITEA_USER/.ssh
touch /home/$GITEA_USER/.ssh/authorized_keys
chown -R $GITEA_USER:$GITEA_USER /home/$GITEA_USER/.ssh
chmod 700 /home/$GITEA_USER/.ssh
chmod 600 /home/$GITEA_USER/.ssh/authorized_keys
if [ ! -f $GITEA_BINARY ]; then
wget -O /tmp/gitea "https://dl.gitea.com/gitea/$GITEA_VERSION/gitea-$GITEA_VERSION-linux-amd64"
chmod +x /tmp/gitea
@@ -67,6 +73,7 @@ INTERNAL_TOKEN = $GITEA_INTERNAL_TOKEN
[server]
DOMAIN = gitea.aldon.fr
SSH_AUTHORIZED_KEYS = /home/git/.ssh/authorized_keys
HTTP_PORT = 3000
ROOT_URL = https://gitea.aldon.fr
DISABLE_SSH = false
@@ -89,5 +96,9 @@ chmod 640 $GITEA_CONF
systemctl daemon-reload
systemctl enable gitea
sudo -u git gitea --config $GITEA_CONF admin regenerate keys
systemctl is-active --quiet gitea || systemctl start gitea
echo "---- Gitea installation completed ----"

View File

@@ -0,0 +1,9 @@
[Unit]
Description=Backup Service
Wants=network.target
After=network.target gitea.service
[Service]
Type=oneshot
User=root
ExecStart=/usr/local/bin/backup.sh

View File

@@ -1,5 +1,5 @@
[Unit]
Description=Run Gitea backup weekly
Description=Run backup weekly
[Timer]
OnCalendar=Sun *-*-* 01:00:00

View File

@@ -1,11 +1,9 @@
[Unit]
Description=Restore latest Gitea backup
Description=Restore latest backup
After=network.target postgresql.service gitea.service
Requires=postgresql.service gitea.service
[Service]
Type=oneshot
User=root
ExecStart=/usr/local/bin/restore-backup.sh
WorkingDirectory=/var/lib/gitea
TimeoutStartSec=600
ExecStart=/usr/local/bin/restore-backup.sh

View File

@@ -1,10 +0,0 @@
[Unit]
Description=Weekly Gitea Backup
Wants=network.target
After=network.target gitea.service
Before=shutdown.target reboot.target halt.target
[Service]
Type=oneshot
User=root
ExecStart=/usr/local/bin/backup.sh

View File

@@ -5,7 +5,7 @@ module "vm" {
domain = var.domain
vm_id = var.vm_id
node_name = var.node_name
vm_ip_address = "192.168.1.90"
vm_ip_address = var.vm_ip_address
template_id = var.template_id
@@ -26,10 +26,12 @@ module "vm" {
restore-backup-script = indent(6, file("${path.module}/lib/scripts/restore-backup.sh"))
restore-backup-service = indent(6, file("${path.module}/lib/services/restore-backup.service"))
create-backup-script = indent(6, file("${path.module}/lib/scripts/create-backup.sh"))
create-backup-service = indent(6, file("${path.module}/lib/services/weekly-backup.service"))
create-backup-timer = indent(6, file("${path.module}/lib/services/weekly-backup.timer"))
create-backup-service = indent(6, file("${path.module}/lib/services/create-backup.service"))
create-backup-timer = indent(6, file("${path.module}/lib/services/create-backup.timer"))
install-gitea-script = indent(6, file("${path.module}/lib/scripts/install-gitea.sh"))
gitea-service = indent(6, file("${path.module}/lib/services/gitea.service"))
env-file-content = indent(6, file("${path.module}/.env"))
}
)
}

View File

@@ -0,0 +1,9 @@
output "traefik_service" {
value = [{
domain = var.domain
name = var.name
host = "${var.hostname}"
ip = var.vm_ip_address
port = 3000
}]
}

View File

@@ -21,6 +21,12 @@ variable "memory" {
default = 2048
}
variable "balloon" {
description = "Minimum vm memory, using ballooning devide to reach Proxmox node memory target."
type = number
default = 1024
}
variable "template_id" {
type = number
}
@@ -49,4 +55,8 @@ variable "disk_size" {
variable "proxmox_host_ip" {
type = string
}
variable "vm_ip_address" {
type = string
}