server_init/packer/build.sh
Nelis Volschenk 06580f9db6 Add Packer template for building Ubuntu 24.04 server image
Build a QCOW2 image locally with QEMU/KVM + autoinstall, then provision
with the existing Ansible playbook. Allows testing changes locally before
deploying to production. Outputs a ready-to-upload image for hosting providers.

Usage: cp server.pkrvars.hcl.example server.pkrvars.hcl, fill in values,
then run ./build.sh

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-05-04 07:28:30 +00:00

36 lines
1.1 KiB
Bash
Executable file

#!/bin/bash
set -e
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$SCRIPT_DIR"
if [ ! -f server.pkrvars.hcl ]; then
echo "Error: server.pkrvars.hcl not found."
echo "Copy server.pkrvars.hcl.example to server.pkrvars.hcl and fill in your values."
exit 1
fi
echo "=== Initializing Packer plugins ==="
packer init ubuntu-server.pkr.hcl
echo ""
echo "=== Building image ==="
echo "This will take 15-30 minutes depending on your machine."
echo ""
packer build -var-file=server.pkrvars.hcl ubuntu-server.pkr.hcl
echo ""
echo "==========================================="
echo " Image built successfully!"
echo "==========================================="
echo " Output: $SCRIPT_DIR/output/packer-ubuntu-server"
echo ""
echo " To test locally:"
echo " qemu-system-x86_64 -m 4096 -hda output/packer-ubuntu-server -enable-kvm"
echo ""
echo " To convert for other formats:"
echo " qemu-img convert -f qcow2 -O raw output/packer-ubuntu-server output/server.raw"
echo " qemu-img convert -f qcow2 -O vmdk output/packer-ubuntu-server output/server.vmdk"
echo "==========================================="