From d57eccbe7c6eb4b15aeac06590c9bc719fc1fe56 Mon Sep 17 00:00:00 2001 From: Codex Date: Fri, 19 Jun 2026 11:55:56 +0200 Subject: [PATCH] Add Proxmox deployment script --- deploy-kostenverdeler-pve.md | 53 +++++++++++ deploy-kostenverdeler-pve.sh | 166 +++++++++++++++++++++++++++++++++++ 2 files changed, 219 insertions(+) create mode 100644 deploy-kostenverdeler-pve.md create mode 100644 deploy-kostenverdeler-pve.sh diff --git a/deploy-kostenverdeler-pve.md b/deploy-kostenverdeler-pve.md new file mode 100644 index 0000000..386faa3 --- /dev/null +++ b/deploy-kostenverdeler-pve.md @@ -0,0 +1,53 @@ +# Kostenverdeler deployen op Proxmox VE + +Gebruik `deploy-kostenverdeler-pve.sh` in de shell van je Proxmox host. + +## Snel starten met DHCP + +```bash +bash deploy-kostenverdeler-pve.sh +``` + +Dit maakt standaard container `120` aan en serveert de app op poort `8080`. + +## Met statisch IP + +```bash +CTID=120 \ +NET0_IP="192.168.1.50/24" \ +GATEWAY="192.168.1.1" \ +bash deploy-kostenverdeler-pve.sh +``` + +## Met domeinnaam via Caddy + +Zorg eerst dat DNS naar de container wijst. Daarna: + +```bash +CTID=120 \ +NET0_IP="192.168.1.50/24" \ +GATEWAY="192.168.1.1" \ +DOMAIN="kosten.henrystuifzand.nl" \ +bash deploy-kostenverdeler-pve.sh +``` + +## Veelgebruikte variabelen + +```bash +CTID=120 +HOSTNAME=kostenverdeler +STORAGE=local-lvm +TEMPLATE_STORAGE=local +DISK_SIZE=4 +MEMORY=256 +CORES=1 +BRIDGE=vmbr0 +DOMAIN= +REPO_URL=https://git.henrystuifzand.nl/henry/kostenverdeler.git +``` + +## Updaten na een nieuwe commit + +```bash +pct exec 120 -- bash -lc 'cd /var/www/kostenverdeler && git pull && systemctl reload caddy' +``` diff --git a/deploy-kostenverdeler-pve.sh b/deploy-kostenverdeler-pve.sh new file mode 100644 index 0000000..9df1e45 --- /dev/null +++ b/deploy-kostenverdeler-pve.sh @@ -0,0 +1,166 @@ +#!/usr/bin/env bash +set -Eeuo pipefail + +# Kostenverdeler deployment script for a Proxmox VE host. +# Run this from the PVE shell as root: +# bash deploy-kostenverdeler-pve.sh +# +# Adjust the variables below before running. + +CTID="${CTID:-120}" +HOSTNAME="${HOSTNAME:-kostenverdeler}" +STORAGE="${STORAGE:-local-lvm}" +TEMPLATE_STORAGE="${TEMPLATE_STORAGE:-local}" +DISK_SIZE="${DISK_SIZE:-4}" +MEMORY="${MEMORY:-256}" +CORES="${CORES:-1}" +BRIDGE="${BRIDGE:-vmbr0}" + +# DHCP by default. For static IP, use for example: +# NET0_IP="192.168.1.50/24" +# GATEWAY="192.168.1.1" +NET0_IP="${NET0_IP:-dhcp}" +GATEWAY="${GATEWAY:-}" + +# Leave DOMAIN empty to serve on port 8080. +# Set DOMAIN="kosten.henrystuifzand.nl" if DNS points to this container/reverse proxy. +DOMAIN="${DOMAIN:-}" + +REPO_URL="${REPO_URL:-https://git.henrystuifzand.nl/henry/kostenverdeler.git}" +APP_DIR="${APP_DIR:-/var/www/kostenverdeler}" +TEMPLATE="${TEMPLATE:-debian-12-standard_12.7-1_amd64.tar.zst}" + +log() { + printf '\n\033[1;32m==>\033[0m %s\n' "$*" +} + +die() { + printf '\n\033[1;31mERROR:\033[0m %s\n' "$*" >&2 + exit 1 +} + +require_root() { + [[ "${EUID}" -eq 0 ]] || die "Run dit script als root op de Proxmox host." +} + +require_pve() { + command -v pct >/dev/null 2>&1 || die "pct niet gevonden. Run dit script in de Proxmox VE shell." + command -v pveam >/dev/null 2>&1 || die "pveam niet gevonden. Run dit script in de Proxmox VE shell." +} + +template_path() { + printf '/var/lib/vz/template/cache/%s' "${TEMPLATE}" +} + +ensure_template() { + if [[ -f "$(template_path)" ]]; then + log "Debian template bestaat al: ${TEMPLATE}" + return + fi + + log "Template-lijst bijwerken" + pveam update + + log "Debian template downloaden: ${TEMPLATE}" + pveam download "${TEMPLATE_STORAGE}" "${TEMPLATE}" +} + +create_container() { + pct status "${CTID}" >/dev/null 2>&1 && die "Container ${CTID} bestaat al. Kies een andere CTID of verwijder de bestaande container." + + local net0="name=eth0,bridge=${BRIDGE},ip=${NET0_IP}" + if [[ -n "${GATEWAY}" && "${NET0_IP}" != "dhcp" ]]; then + net0="${net0},gw=${GATEWAY}" + fi + + log "LXC container ${CTID} aanmaken" + pct create "${CTID}" "$(template_path)" \ + --hostname "${HOSTNAME}" \ + --ostype debian \ + --storage "${STORAGE}" \ + --rootfs "${STORAGE}:${DISK_SIZE}" \ + --memory "${MEMORY}" \ + --cores "${CORES}" \ + --net0 "${net0}" \ + --unprivileged 1 \ + --features nesting=1 \ + --start 1 +} + +wait_for_network() { + log "Wachten tot de container netwerk heeft" + for _ in {1..60}; do + if pct exec "${CTID}" -- bash -lc 'getent hosts deb.debian.org >/dev/null 2>&1'; then + return + fi + sleep 2 + done + die "Container kreeg geen werkende netwerkverbinding." +} + +install_app() { + log "Pakketten installeren in container" + pct exec "${CTID}" -- bash -lc 'apt-get update && apt-get install -y --no-install-recommends ca-certificates curl git caddy' + + log "Applicatie clonen" + pct exec "${CTID}" -- bash -lc "rm -rf '${APP_DIR}' && mkdir -p '$(dirname "${APP_DIR}")' && git clone '${REPO_URL}' '${APP_DIR}'" + + log "Caddy configureren" + if [[ -n "${DOMAIN}" ]]; then + pct exec "${CTID}" -- bash -lc "cat > /etc/caddy/Caddyfile <<'CADDY' +${DOMAIN} { + root * ${APP_DIR} + file_server +} +CADDY" + else + pct exec "${CTID}" -- bash -lc "cat > /etc/caddy/Caddyfile <<'CADDY' +:8080 { + root * ${APP_DIR} + file_server +} +CADDY" + fi + + pct exec "${CTID}" -- bash -lc 'systemctl enable --now caddy && systemctl reload caddy' +} + +container_ip() { + pct exec "${CTID}" -- bash -lc "hostname -I | awk '{print \$1}'" 2>/dev/null || true +} + +print_result() { + local ip + ip="$(container_ip)" + + log "Klaar" + if [[ -n "${DOMAIN}" ]]; then + printf 'App URL: https://%s\n' "${DOMAIN}" + elif [[ -n "${ip}" ]]; then + printf 'App URL: http://%s:8080\n' "${ip}" + else + printf 'App URL: http://:8080\n' + fi + + cat <