Add common module managing common services and scripts (act_runner, create/restore backups)

Fix script environment variables
Add Fefan configuration
Fix gateway services file provisionning through ssh
This commit is contained in:
2026-01-20 15:42:17 +01:00
parent 152f09ac50
commit 1de2fe9ab4
53 changed files with 285 additions and 442 deletions

View File

@@ -1,8 +1,11 @@
# Environment files
ENV_FILE_LOCATION=/opt/environment/.env
# Application Specifics
#openssl rand -hex 20
WEBHOOK_SECRET=xxx
TRAEFIK_VERSION=v3.6.7
TRAEFIK_BINARY=/usr/local/bin/traefik
TRAEFIK_USER=traefik
TRAEFIK_CONF=/home/traefik/traefik.yml
GATEWAY_REPOSITORY=/Mop/gateway
GATEWAY_REPOSITORY_LOCATION=/home/traefik/gateway
DYNAMIC_CONFIG_LOCATION=/home/gateway/services.yaml

View File

@@ -26,11 +26,7 @@ packages:
- gunicorn
write_files:
- path: /opt/gateway/env.sh
permissions: "0644"
content: |
${environment-setup-script}
- path: /opt/gateway/gateway.env
- path: /opt/environment/.env
permissions: "0644"
content: |
${env-file-content}
@@ -38,14 +34,6 @@ write_files:
permissions: "0755"
content: |
${install-traefik-script}
- path: /usr/local/bin/pull-webhook.py
permissions: "0755"
content: |
${pull-webhook-script}
- path: /etc/systemd/system/pull-webhook.service
permissions: "0755"
content: |
${pull-webhook-service}
- path: /etc/systemd/system/traefik.service
permissions: "0755"
content: |
@@ -53,8 +41,6 @@ write_files:
runcmd:
- /opt/gateway/install-traefik.sh
- systemctl enable pull-webhook.service
- systemctl start pull-webhook.service
final_message: |
Base system ready for ${hostname}

View File

@@ -1,4 +0,0 @@
#!/bin/bash
set -a
[ -f /opt/gateway/gateway.env ] && source /opt/gateway/gateway.env
set +a

View File

@@ -1,13 +1,13 @@
#!/bin/bash
# GATEWAY_REPOSITORY_LOCATION (path on vm)
# DYNAMIC_CONFIG_LOCATION (path on vm)
# GATEWAY_REPOSITORY (path on gitea)
# TRAEFIK_USER
# TRAEFIK_BINARY
# TRAEFIK_VERSION
# TRAEFIK_CONF
source /opt/gateway/env.sh
source /opt/environment/.env
if ! id -u $TRAEFIK_USER >/dev/null 2>&1; then
adduser \
@@ -32,8 +32,6 @@ chown $TRAEFIK_USER:$TRAEFIK_USER /etc/traefik/acme.json
chmod 600 /etc/traefik/acme.json
setcap 'cap_net_bind_service=+ep' /usr/local/bin/traefik
git clone https://gitea.aldon.fr/$GATEWAY_REPOSITORY.git $GATEWAY_REPOSITORY_LOCATION
cat > "$TRAEFIK_CONF" <<EOF
entryPoints:
web:
@@ -42,7 +40,7 @@ entryPoints:
address: ":443"
providers:
file:
directory: $GATEWAY_REPOSITORY_LOCATION
filename: $DYNAMIC_CONFIG_LOCATION
watch: true
api:
dashboard: false

View File

@@ -1,23 +0,0 @@
from flask import Flask, request, abort
import subprocess
import os
SECRET = os.environ.get("WEBHOOK_SECRET")
REPOSITORY = os.environ.get("GATEWAY_REPOSITORY_LOCATION")
app = Flask(__name__)
@app.route("/reload", methods=["POST"])
def reload():
token = request.headers.get("X-Webhook-Token")
if token != SECRET:
abort(403)
subprocess.run(
["git", "-C", REPOSITORY, "pull"],
check=True
)
return "ok\n"
if __name__ == "__main__":
app.run()

View File

@@ -1,13 +0,0 @@
[Unit]
Description=Traefik config webhook
After=network.target
[Service]
WorkingDirectory=/usr/local/bin
ExecStart=/usr/bin/gunicorn --bind 0.0.0.0:5555 pull-webhook:app
EnvironmentFile=/opt/gateway/gateway.env
Restart=always
User=root
[Install]
WantedBy=multi-user.target

View File

@@ -15,19 +15,18 @@ module "vm" {
ssh_public_key = var.ssh_public_key
proxmox_host_ip = var.proxmox_host_ip
cloudinit_config = templatefile(
"${path.module}/cloud-init/service.yaml",
{
hostname = var.hostname
domain = var.domain
ssh_key = var.ssh_public_key
proxmox_host_ip = var.proxmox_host_ip
environment-setup-script = indent(6, file("${path.module}/lib/scripts/env.sh"))
env-file-content = indent(6, file("${path.module}/.env"))
pull-webhook-service = indent(6, file("${path.module}/lib/services/pull-webhook.service"))
pull-webhook-script = indent(6, file("${path.module}/lib/scripts/pull-webhook.py"))
proxmox_host_ip = var.proxmox_host_ip
traefik-service = indent(6, file("${path.module}/lib/services/traefik.service"))
install-traefik-script = indent(6, file("${path.module}/lib/scripts/install-traefik.sh"))
env-file-content = indent(6, file("${path.module}/.env"))
}
)
}

View File

@@ -0,0 +1,3 @@
output "vm_ip_address" {
value = var.vm_ip_address
}

View File

@@ -1,22 +1,27 @@
variable "name" {
description = "Virtual Machine name"
type = string
}
variable "vm_id" {
description = "Virtual Machine id"
type = number
}
variable "node_name" {
description = "Proxmox node name"
type = string
default = "mop"
}
variable "cores" {
description = "Number of CPU cores for this virtual machine"
type = number
default = 2
}
variable "memory" {
description = "Memory RAM for this virtual machine"
type = number
default = 2048
}
@@ -28,35 +33,39 @@ variable "balloon" {
}
variable "template_id" {
description = "Virtual machine template ID"
type = number
}
variable "ssh_public_key" {
type = string
description = "Public SSH key for cloud-init user"
type = string
}
variable "hostname" {
description = "VM hostname"
description = "Virtual Machine hostname (<service-name>)"
type = string
default = "test"
}
variable "domain" {
description = "VM domain"
description = "Virtual Machine domain (example.fr)"
type = string
default = ""
}
variable "disk_size" {
description = "Disk size for the virtual machine"
type = number
default = 10
}
variable "proxmox_host_ip" {
description = "Proxmox host base ip"
type = string
}
variable "vm_ip_address" {
description = "Virtual machine ip"
type = string
}