feat: Add Packer build automation scripts
Some checks are pending
Build and Release / build-sign-package (push) Waiting to run

- Added packer/variables.pkr.hcl with configurable variables
- Added build-template.sh with interactive build script
- Added .env.example for environment configuration
- Updated windows.pkr.hcl to use variables
- Supports environment variables and command line arguments
This commit is contained in:
root 2026-02-06 16:01:52 +00:00
parent e4f03427b7
commit 61ae0d0a07
4 changed files with 315 additions and 17 deletions

199
build-template.sh Executable file
View file

@ -0,0 +1,199 @@
#!/bin/bash
# Windows Packer Build Script
# This script builds the Windows 11 LTSC template on Proxmox
set -e
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m'
echo -e "${BLUE}╔════════════════════════════════════════════════════════════╗${NC}"
echo -e "${BLUE}${NC} ${GREEN}Windows 11 LTSC Packer Build${NC} ${BLUE}${NC}"
echo -e "${BLUE}${NC} ${GREEN}Proxmox Virtual Environment${NC} ${BLUE}${NC}"
echo -e "${BLUE}╚════════════════════════════════════════════════════════════╝${NC}"
echo ""
# Default values
PROXMOX_NODE="la-vmh-07"
PROXMOX_URL="https://${PROXMOX_NODE}:8006/api2/json"
PROXMOX_USERNAME="root@pam"
# Check for .env file
if [ -f ".env" ]; then
echo -e "${GREEN}Loading configuration from .env file...${NC}"
source .env
fi
# Parse command line arguments
while [[ $# -gt 0 ]]; do
case $1 in
--node)
PROXMOX_NODE="$2"
PROXMOX_URL="https://${PROXMOX_NODE}:8006/api2/json"
shift 2
;;
--url)
PROXMOX_URL="$2"
shift 2
;;
--user)
PROXMOX_USERNAME="$2"
shift 2
;;
--password)
export PKR_VAR_proxmox_password="$2"
shift 2
;;
--check)
echo "Running validation only..."
CHECK_MODE=true
shift
;;
--help|-h)
echo "Usage: $0 [OPTIONS]"
echo ""
echo "Options:"
echo " --node HOSTNAME Proxmox node name (default: la-vmh-07)"
echo " --url URL Proxmox API URL"
echo " --user USERNAME Proxmox username (default: root@pam)"
echo " --password PASS Proxmox password"
echo " --check Validate only, don't build"
echo ""
echo "Environment variables:"
echo " PKR_VAR_proxmox_password Proxmox password"
echo " PKR_VAR_proxmox_url Proxmox API URL"
echo " PKR_VAR_proxmox_node Proxmox node name"
exit 0
;;
*)
echo -e "${RED}Unknown option: $1${NC}"
exit 1
;;
esac
done
# Determine script directory
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$SCRIPT_DIR"
echo -e "${YELLOW}Configuration:${NC}"
echo " Proxmox URL: $PROXMOX_URL"
echo " Proxmox User: $PROXMOX_USERNAME"
echo " Proxmox Node: $PROXMOX_NODE"
echo ""
# Check if running on Proxmox host
echo -e "${YELLOW}Checking environment...${NC}"
if hostname | grep -q "pve\|proxmox"; then
echo -e "${GREEN}✓ Running on Proxmox host${NC}"
ON_PROXMOX=true
else
echo -e "${YELLOW}⚠ Running on remote host${NC}"
echo -e "${YELLOW} Make sure Proxmox API is accessible from this machine${NC}"
ON_PROXMOX=false
fi
# Check for Packer
echo ""
echo -e "${YELLOW}Checking for Packer...${NC}"
if ! command -v packer &> /dev/null; then
echo -e "${RED}Packer not found!${NC}"
echo ""
echo "To install Packer:"
echo ""
if [ "$ON_PROXMOX" = true ]; then
echo " # On Proxmox:"
echo " wget https://apt.releases.hashicorp.com/pool/main/h/hashicorp_*_amd64.deb"
echo " apt install -y ./hashicorp_*.deb"
echo " rm hashicorp_*.deb"
else
echo " # Download from:"
echo " https://www.packer.io/downloads"
echo ""
echo " # Or via Homebrew (macOS):"
echo " brew install packer"
echo ""
echo " # Or via Chocolatey (Windows):"
echo " choco install packer"
fi
exit 1
fi
echo -e "${GREEN}✓ Packer version: $(packer --version)${NC}"
# Initialize Packer
echo ""
echo -e "${YELLOW}Initializing Packer plugins...${NC}"
packer init packer/
# Validate configuration
echo ""
echo -e "${YELLOW}Validating Packer configuration...${NC}"
export PKR_VAR_proxmox_url="$PROXMOX_URL"
export PKR_VAR_proxmox_node="$PROXMOX_NODE"
export PKR_VAR_proxmox_username="$PROXMOX_USERNAME"
if ! packer validate packer/windows.pkr.hcl; then
echo -e "${RED}❌ Packer validation failed!${NC}"
exit 1
fi
echo -e "${GREEN}✓ Configuration validated${NC}"
# Check mode - just validate and exit
if [ "$CHECK_MODE" = true ]; then
echo ""
echo -e "${GREEN}Validation complete. No build performed.${NC}"
exit 0
fi
# Build the template
echo ""
echo -e "${BLUE}╔════════════════════════════════════════════════════════════╗${NC}"
echo -e "${BLUE}${NC} ${GREEN}Starting Build${NC} ${BLUE}${NC}"
echo -e "${BLUE}╚════════════════════════════════════════════════════════════╝${NC}"
echo ""
echo -e "${YELLOW}⏱ Estimated time: 15-25 minutes${NC}"
echo -e "${YELLOW}📝 Build logs will be shown in real-time${NC}"
echo ""
# Set environment variables
export PKR_VAR_proxmox_url="$PROXMOX_URL"
export PKR_VAR_proxmox_node="$PROXMOX_NODE"
# Run Packer build
if packer build -timestamp-ui packer/windows.pkr.hcl; then
echo ""
echo -e "${GREEN}╔════════════════════════════════════════════════════════════╗${NC}"
echo -e "${GREEN}${NC} ${GREEN}✅ BUILD SUCCESSFUL!${NC} ${GREEN}${NC}"
echo -e "${GREEN}╚════════════════════════════════════════════════════════════╝${NC}"
echo ""
echo -e "${GREEN}Template created successfully!${NC}"
echo ""
echo "Next steps:"
echo " 1. Verify in Proxmox: ${YELLOW}qm list | grep win11-ltsc${NC}"
echo " 2. Note the VM ID (e.g., 9000)"
echo " 3. Update terraform/variables.tf with the VM ID"
echo " 4. Test provisioning: ${YELLOW}cd terraform && tofu init && tofu apply${NC}"
echo ""
else
echo ""
echo -e "${RED}╔══════════════════════════════════════════════════════╗${NC}"
echo -e "${RED}${NC} ${RED}❌ BUILD FAILED${NC} ${RED}${NC}"
echo -e "${RED}╚══════════════════════════════════════════════════════╝${NC}"
echo ""
echo -e "${YELLOW}Troubleshooting steps:${NC}"
echo " 1. Verify Proxmox is running and accessible"
echo " 2. Check ISO files exist in /mnt/pve-07-iso-nvme/template/iso/"
echo " 3. Verify credentials are correct"
echo " 4. Check network connectivity"
echo ""
echo -e "${YELLOW}Common issues:${NC}"
echo " - ISO not found: Verify path in variables.pkr.hcl"
echo " - WinRM timeout: Check Autounattend.xml configuration"
echo " - Permission denied: Verify Proxmox user permissions"
exit 1
fi