Some checks failed
Deploy to Phoenix / deploy (push) Has been cancelled
Co-authored-by: Cursor <cursoragent@cursor.com>
90 lines
3.4 KiB
Bash
90 lines
3.4 KiB
Bash
#!/usr/bin/env bash
|
|
# Create LXC 5700 (dev-vm): shared development environment for four users, Cursor Remote SSH,
|
|
# and private GitOps (Gitea). Large disk for all projects from /home/intlc/projects.
|
|
#
|
|
# Usage: ./scripts/create-dev-vm-5700.sh [--dry-run]
|
|
# --dry-run Print commands only, do not create.
|
|
#
|
|
# Overrides (env): PROXMOX_HOST, STORAGE, DEV_VM_DISK_GB, TEMPLATE
|
|
# See: docs/04-configuration/DEV_VM_GITOPS_PLAN.md
|
|
|
|
set -euo pipefail
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
|
|
source "${PROJECT_ROOT}/config/ip-addresses.conf" 2>/dev/null || true
|
|
|
|
VMID=5700
|
|
HOST="${PROXMOX_HOST:-${PROXMOX_R630_01:-192.168.11.11}}"
|
|
IP="${IP_DEV_VM:-192.168.11.59}"
|
|
GATEWAY="${NETWORK_GATEWAY:-192.168.11.1}"
|
|
NETWORK="${NETWORK:-vmbr0}"
|
|
STORAGE="${STORAGE:-local-lvm}"
|
|
# Prefer Ubuntu 22.04 for dev (better tooling); fallback Debian 12
|
|
TEMPLATE="${TEMPLATE:-local:vztmpl/ubuntu-22.04-standard_22.04-1_amd64.tar.zst}"
|
|
DEV_VM_DISK_GB="${DEV_VM_DISK_GB:-400}"
|
|
MEMORY_MB=16384
|
|
CORES=4
|
|
SSH_OPTS="-o ConnectTimeout=15 -o StrictHostKeyChecking=accept-new"
|
|
|
|
DRY_RUN=false
|
|
[[ "${1:-}" == "--dry-run" ]] && DRY_RUN=true
|
|
|
|
echo "=== Dev VM (5700) — Create ==="
|
|
echo "Host: $HOST | IP: $IP | Disk: ${DEV_VM_DISK_GB}G | RAM: ${MEMORY_MB}MB | Cores: $CORES"
|
|
echo "Storage: $STORAGE | Template: $TEMPLATE"
|
|
echo ""
|
|
|
|
# Check template exists on host (try Ubuntu first, then Debian)
|
|
resolve_template() {
|
|
local node
|
|
node=$(ssh $SSH_OPTS root@$HOST "hostname" 2>/dev/null || true)
|
|
if ssh $SSH_OPTS root@$HOST "pveam list local 2>/dev/null | grep -q 'ubuntu-22.04-standard'" 2>/dev/null; then
|
|
echo "local:vztmpl/ubuntu-22.04-standard_22.04-1_amd64.tar.zst"
|
|
elif ssh $SSH_OPTS root@$HOST "pveam list local 2>/dev/null | grep -q 'debian-12-standard'" 2>/dev/null; then
|
|
echo "local:vztmpl/debian-12-standard_12.12-1_amd64.tar.zst"
|
|
else
|
|
echo "$TEMPLATE"
|
|
fi
|
|
}
|
|
|
|
if $DRY_RUN; then
|
|
echo "[DRY-RUN] Would create LXC $VMID on $HOST with:"
|
|
echo " hostname=dev-vm, memory=${MEMORY_MB}, cores=$CORES, rootfs=$STORAGE:${DEV_VM_DISK_GB}, ip=$IP/24, gw=$GATEWAY"
|
|
echo " Run without --dry-run to create."
|
|
exit 0
|
|
fi
|
|
|
|
if ssh $SSH_OPTS root@$HOST "pct list 2>/dev/null" | grep -q " $VMID "; then
|
|
echo "Container $VMID already exists on $HOST."
|
|
read -p "Stop and destroy it, then recreate? [yN] " r
|
|
[[ "${r,,}" != "y" ]] && exit 0
|
|
ssh $SSH_OPTS root@$HOST "pct stop $VMID 2>/dev/null || true; pct destroy $VMID --purge 1" 2>/dev/null || true
|
|
sleep 2
|
|
fi
|
|
|
|
RESOLVED_TEMPLATE=$(resolve_template)
|
|
echo "Using template: $RESOLVED_TEMPLATE"
|
|
echo "Creating CT $VMID (dev-vm)..."
|
|
ssh $SSH_OPTS root@$HOST "pct create $VMID $RESOLVED_TEMPLATE \
|
|
--hostname dev-vm \
|
|
--memory $MEMORY_MB \
|
|
--cores $CORES \
|
|
--rootfs $STORAGE:${DEV_VM_DISK_GB} \
|
|
--net0 name=eth0,bridge=$NETWORK,ip=$IP/24,gw=$GATEWAY \
|
|
--nameserver $DNS_PRIMARY \
|
|
--description 'Shared dev VM: 4 users, Cursor, private Gitea (GitOps). See docs/04-configuration/DEV_VM_GITOPS_PLAN.md' \
|
|
--start 1 \
|
|
--onboot 1 \
|
|
--unprivileged 0"
|
|
|
|
echo "Waiting for container to boot..."
|
|
sleep 15
|
|
echo "Container 5700 (dev-vm) is running at $IP."
|
|
echo ""
|
|
echo "Next steps:"
|
|
echo " 1. Run setup script for users + Gitea: bash scripts/setup-dev-vm-users-and-gitea.sh"
|
|
echo " 2. Rsync projects: rsync -avz /home/intlc/projects/ dev1@$IP:/srv/projects/"
|
|
echo " 3. In Cursor: Remote-SSH → dev1@$IP (after adding SSH keys)"
|
|
echo "See: docs/04-configuration/DEV_VM_GITOPS_PLAN.md"
|