Create Vagrant box from base image
This commit is contained in:
parent
509b6af145
commit
4b49404a0c
@ -4,8 +4,13 @@ HEADLESS ?= true
|
||||
|
||||
default: install
|
||||
|
||||
install:
|
||||
PKR_VAR_headless="$(HEADLESS)" packer build .
|
||||
install: base
|
||||
|
||||
base:
|
||||
PKR_VAR_headless="$(HEADLESS)" packer build x86_64-qemu-base.pkr.hcl
|
||||
|
||||
vagrant:
|
||||
PKR_VAR_headless="$(HEADLESS)" packer build x86_64-qemu-vagrant.pkr.hcl
|
||||
|
||||
clean:
|
||||
rm -rf ./builds
|
||||
|
20
debian-13/scripts/vagrant.sh
Normal file
20
debian-13/scripts/vagrant.sh
Normal file
@ -0,0 +1,20 @@
|
||||
#!/usr/bin/env bash
|
||||
set -eu
|
||||
|
||||
export DEBIAN_FRONTEND=noninteractive
|
||||
apt-get update
|
||||
apt-get install -y openssl curl sudo
|
||||
|
||||
useradd -m -p "$(openssl passwd -1 vagrant)" vagrant
|
||||
|
||||
echo "vagrant ALL=(ALL) NOPASSWD:ALL" >/etc/sudoers.d/vagrant
|
||||
chmod 440 /etc/sudoers.d/vagrant
|
||||
|
||||
install -d -m 0700 -o vagrant -g vagrant /home/vagrant/.ssh
|
||||
BASE_GH_URL="https://raw.githubusercontent.com/hashicorp/vagrant/refs/heads"
|
||||
curl -fsSL "${BASE_GH_URL}/main/keys/vagrant.pub" \
|
||||
-o /home/vagrant/.ssh/authorized_keys
|
||||
chmod 600 /home/vagrant/.ssh/authorized_keys
|
||||
|
||||
sed -i 's/PermitRootLogin.*/PermitRootLogin no/' /etc/ssh/sshd_config
|
||||
passwd -d root
|
56
debian-13/x86_64-qemu-vagrant.pkr.hcl
Normal file
56
debian-13/x86_64-qemu-vagrant.pkr.hcl
Normal file
@ -0,0 +1,56 @@
|
||||
packer {
|
||||
required_plugins {
|
||||
qemu = {
|
||||
version = ">= 1.1.3"
|
||||
source = "github.com/hashicorp/qemu"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
variable "memory" {
|
||||
default = 2048
|
||||
}
|
||||
|
||||
variable "ssh_password" {
|
||||
default = "debian"
|
||||
}
|
||||
|
||||
variable "headless" {
|
||||
default = true
|
||||
}
|
||||
|
||||
variable "disk_size" {
|
||||
default = 102400
|
||||
}
|
||||
|
||||
source "qemu" "debian-13-64-vagrant" {
|
||||
iso_url = "builds/qemu/debian-13-64-base/debian-13-64-base"
|
||||
disk_image = true
|
||||
iso_checksum = "none"
|
||||
output_directory = "builds/qemu/debian-13-64-vagrant"
|
||||
shutdown_command = "/usr/bin/systemctl poweroff"
|
||||
disk_interface = "virtio"
|
||||
disk_size = var.disk_size
|
||||
memory = var.memory
|
||||
headless = var.headless
|
||||
format = "qcow2"
|
||||
accelerator = "kvm"
|
||||
http_directory = "http"
|
||||
ssh_username = "root"
|
||||
ssh_password = var.ssh_password
|
||||
ssh_timeout = "60m"
|
||||
vm_name = "debian-13-64-base"
|
||||
net_device = "virtio-net"
|
||||
boot_wait = "5s"
|
||||
}
|
||||
|
||||
build {
|
||||
name = "debian-base"
|
||||
sources = ["source.qemu.debian-13-64-vagrant"]
|
||||
|
||||
provisioner "shell" {
|
||||
scripts = [
|
||||
"scripts/vagrant.sh"
|
||||
]
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user