Files
proxdeploy/deploy/install-lxc.sh
T
florian.wildeandClaude Opus 5.5 533a821087 feat(betrieb): Docker Compose und LXC-Installer
Ein Laufzeit-Paket (scripts/paket-bauen.sh) für beide Wege: Next standalone, worker als Bundle mit nur den nötigen Paketen, Migrationen ohne Prisma-CLI. Compose lokal komplett hochgefahren; der Installer auf pve-demo in einem echten Debian-13-LXC durchgelaufen.

Closes #019

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-12 17:35:41 +02:00

122 lines
5.5 KiB
Bash
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env bash
# ProxDeploy in einem Debian-13-LXC einrichten – auf dem Proxmox-Host als root ausführen.
#
# ./install-lxc.sh --paket proxdeploy-0.6.0.tar.gz [Optionen]
# ./install-lxc.sh --aktualisieren <ctid> --paket proxdeploy-0.6.1.tar.gz
#
# Optionen (alle optional außer --paket):
# --ctid N Container-ID (Standard: nächste freie)
# --hostname NAME Hostname (Standard: proxdeploy)
# --storage NAME Storage für die Disk (Standard: local-lvm)
# --disk GB Disk in GB (Standard: 8)
# --cores N CPU-Kerne (Standard: 2)
# --memory MB RAM (Standard: 2048)
# --bridge NAME Bridge (Standard: vmbr0)
# --vlan TAG VLAN-Tag
# --ip CIDR feste Adresse, z. B. 10.0.10.50/24 (Standard: DHCP); dazu --gw
# --gw ADRESSE Gateway bei fester Adresse
# --url URL öffentliche Adresse (APP_URL), z. B. https://proxdeploy.example
# (Standard: http://<IP des Containers>:3000)
# --tags LISTE zusätzliche Proxmox-Tags, z. B. proxdeploy-test
#
# Das Paket baut `scripts/paket-bauen.sh <version> --tar` im Repository.
set -euo pipefail
fehler() { echo "✗ $*" >&2; exit 1; }
schritt() { echo "◐ $*"; }
fertig() { echo "✓ $*"; }
[ "$(id -u)" = 0 ] || fehler "Bitte als root auf dem Proxmox-Host ausführen."
command -v pct >/dev/null || fehler "pct fehlt – läuft das auf einem Proxmox-VE-Host?"
ctid="" hostname="proxdeploy" storage="local-lvm" disk=8 cores=2 memory=2048 bridge="vmbr0"
vlan="" ip="dhcp" gw="" url="" paket="" aktualisieren="" tags=""
while [ $# -gt 0 ]; do
case "$1" in
--ctid) ctid="$2"; shift 2 ;;
--hostname) hostname="$2"; shift 2 ;;
--storage) storage="$2"; shift 2 ;;
--disk) disk="$2"; shift 2 ;;
--cores) cores="$2"; shift 2 ;;
--memory) memory="$2"; shift 2 ;;
--bridge) bridge="$2"; shift 2 ;;
--vlan) vlan="$2"; shift 2 ;;
--ip) ip="$2"; shift 2 ;;
--gw) gw="$2"; shift 2 ;;
--url) url="$2"; shift 2 ;;
--tags) tags="$2"; shift 2 ;;
--paket) paket="$2"; shift 2 ;;
--aktualisieren) aktualisieren="$2"; shift 2 ;;
-h|--help) sed -n '2,25p' "$0"; exit 0 ;;
*) fehler "Unbekannte Option $1 (siehe --help)" ;;
esac
done
[ -n "$paket" ] || fehler "--paket fehlt (proxdeploy-<version>.tar.gz)."
[ -f "$paket" ] || fehler "$paket gibt es nicht."
tar -tzf "$paket" ./VERSION >/dev/null 2>&1 || fehler "$paket ist kein ProxDeploy-Paket (VERSION fehlt)."
version="$(tar -xzOf "$paket" ./VERSION)"
innen="$(dirname "$0")/im-container.sh"
[ -f "$innen" ] || fehler "im-container.sh fehlt neben diesem Skript."
pushen() {
pct push "$1" "$paket" /root/proxdeploy-paket.tar.gz
pct push "$1" "$innen" /root/proxdeploy-im-container.sh --perms 0700
}
# ── Aktualisieren ───────────────────────────────────────────────────────────────────────────────
if [ -n "$aktualisieren" ]; then
pct status "$aktualisieren" | grep -q running || fehler "Container $aktualisieren läuft nicht."
schritt "Aktualisiere Container $aktualisieren auf $version"
pushen "$aktualisieren"
pct exec "$aktualisieren" -- bash /root/proxdeploy-im-container.sh aktualisieren
exit 0
fi
# ── Neu einrichten ──────────────────────────────────────────────────────────────────────────────
[ -n "$ctid" ] || ctid="$(pvesh get /cluster/nextid)"
pct status "$ctid" >/dev/null 2>&1 && fehler "Container $ctid gibt es schon."
if [ "$ip" != dhcp ]; then
[[ "$ip" =~ ^[0-9.]+/[0-9]+$ ]] || fehler "--ip: Format 10.0.10.50/24"
[ -n "$gw" ] || fehler "Bei fester Adresse fehlt --gw."
fi
schritt "LXC-Template Debian 13"
pveam update >/dev/null
vorlage="$(pveam available --section system | awk '/debian-13-standard_.*_amd64\.tar\.zst/ {print $2}' | sort -V | tail -1)"
[ -n "$vorlage" ] || fehler "Kein Debian-13-Template in pveam gefunden."
template_storage="$(pvesm status --content vztmpl | awk 'NR>1 {print $1; exit}')"
[ -n "$template_storage" ] || fehler "Kein Storage für Container-Templates (Inhalt vztmpl)."
if ! pveam list "$template_storage" | grep -q "$vorlage"; then
pveam download "$template_storage" "$vorlage" >/dev/null
fi
fertig "$vorlage auf $template_storage"
netz="name=eth0,bridge=$bridge,firewall=1"
[ -n "$vlan" ] && netz="$netz,tag=$vlan"
if [ "$ip" = dhcp ]; then netz="$netz,ip=dhcp"; else netz="$netz,ip=$ip,gw=$gw"; fi
schritt "Container $ctid anlegen"
pct create "$ctid" "$template_storage:vztmpl/$vorlage" \
--hostname "$hostname" --cores "$cores" --memory "$memory" --swap 512 \
--rootfs "$storage:$disk" --net0 "$netz" \
--unprivileged 1 --features nesting=1 --onboot 1 \
--tags "proxdeploy${tags:+;$tags}" \
--description "ProxDeploy $version – eingerichtet mit install-lxc.sh" >/dev/null
pct start "$ctid"
fertig "Container $ctid ($hostname) läuft"
schritt "Netzwerk"
adresse=""
for _ in $(seq 1 60); do
adresse="$(pct exec "$ctid" -- ip -4 -o addr show dev eth0 2>/dev/null | awk '{print $4}' | cut -d/ -f1 | head -1)"
[ -n "$adresse" ] && pct exec "$ctid" -- getent hosts deb.debian.org >/dev/null 2>&1 && break
adresse=""
sleep 2
done
[ -n "$adresse" ] || fehler "Container $ctid bekommt keine Adresse oder kein DNS."
fertig "IP $adresse"
[ -n "$url" ] || url="http://$adresse:3000"
pushen "$ctid"
pct exec "$ctid" -- bash /root/proxdeploy-im-container.sh installieren --url "$url"