diff --git a/Vagrantfile.in b/Vagrantfile.in index ee91113..5b0d697 100644 --- a/Vagrantfile.in +++ b/Vagrantfile.in @@ -6,7 +6,8 @@ # backwards compatibility). Please don't change it unless you know what # you're doing. Vagrant.configure("2") do |config| - config.vm.box = "@@BOX@@" + config.vm.box = "@@BOX_NAME@@" + config.vm.box_url = "@@BOX@@" # Create a private network, which allows host-only access to the machine # using a specific IP. diff --git a/ansible/roles/vagrant/tasks/main.yml b/ansible/roles/vagrant/tasks/main.yml index 31435c5..c524140 100644 --- a/ansible/roles/vagrant/tasks/main.yml +++ b/ansible/roles/vagrant/tasks/main.yml @@ -33,6 +33,9 @@ mode: "0600" dest: "{{ ansible_user_dir }}/.ssh/authorized_keys" url: https://raw.githubusercontent.com/hashicorp/vagrant/master/keys/vagrant.pub + register: _fetch_authorized_keys + retries: 3 + until: _fetch_authorized_keys is success - name: Sudo commands block: diff --git a/attic/debian-9-x86_64.pkrvars.hcl b/attic/debian-9-x86_64.pkrvars.hcl deleted file mode 100644 index 290c717..0000000 --- a/attic/debian-9-x86_64.pkrvars.hcl +++ /dev/null @@ -1,16 +0,0 @@ -distro = "debian" -version = "9" -iso = { - url = "https://cdimage.debian.org/cdimage/archive/9.13.0/amd64/iso-cd/debian-9.13.0-amd64-netinst.iso" - checksum = "71c7e9eb292acc880f84605b1ca2b997f25737fe0a43fc9586f61d35cd2eb43b" -} -boot_command = [ - "", - "auto ", - "DEBIAN_FRONTEND=text ", - "net.ifnames=0 ", - "biosdevnames=0 ", - "preseed/url=http://{{.HTTPIP}}:{{ .HTTPPort }}/debian/9-preseed.cfg ", - "console=ttyS0 ", - "" -] diff --git a/build_all.xsh b/build_all.xsh new file mode 100755 index 0000000..8d4fd44 --- /dev/null +++ b/build_all.xsh @@ -0,0 +1,12 @@ +#!/usr/bin/env xonsh +import argparse +source ./test.xsh + + +parser = argparse.ArgumentParser("Build all") +parser.add_argument("--provider", choices=get_providers(), default="qemu.x86_64") +args = parser.parse_args() + + +for f in g`distros/**/build.xsh`: + ./@(f) --provider @(args.provider) diff --git a/distros/centos-8stream-x86_64.pkrvars.hcl.sh b/distros/centos-8stream-x86_64.pkrvars.hcl.sh deleted file mode 100755 index 282c2a3..0000000 --- a/distros/centos-8stream-x86_64.pkrvars.hcl.sh +++ /dev/null @@ -1,24 +0,0 @@ -#!/usr/bin/env bash - -# Name of the file to write out -name="${0%.sh}" - -checksums="$(mktemp)" -until curl -f -L -o "${checksums}" "http://mirror.centos.org/centos/8-stream/isos/x86_64/CHECKSUM"; do - sleep 1 -done -sha="$(cat "${checksums}" | grep latest-boot | grep SHA256 | cut -d' ' -f 4)" - -cat << EOF > "${name}" -distro = "centos" -version = "8stream" -iso = { - url = "http://mirror.centos.org/centos/8-stream/isos/x86_64/CentOS-Stream-8-x86_64-latest-boot.iso" - checksum = "${sha}" -} -boot_command = [ - "", - "inst.text inst.ks=cdrom:/http/centos/8stream/x86_64.ks console=ttyS0", - "" -] -EOF diff --git a/distros/centos-9stream-x86_64.pkrvars.hcl.sh b/distros/centos-9stream-x86_64.pkrvars.hcl.sh deleted file mode 100755 index d711016..0000000 --- a/distros/centos-9stream-x86_64.pkrvars.hcl.sh +++ /dev/null @@ -1,28 +0,0 @@ -#!/usr/bin/env bash - -set -ex - -# Name of the file to write out -name="${0%.sh}" - -baseurl="https://mirror.stream.centos.org/9-stream/BaseOS/x86_64/iso/CentOS-Stream-9-latest-x86_64-boot.iso" -checksums="$(mktemp)" -until curl -f -L -o "${checksums}" "${baseurl}.SHA256SUM"; do - sleep 1 -done -sha="$(cat "${checksums}" | awk '/SHA256/ {print $4}')" -rm "${checksums}" - -cat << EOF > "${name}" -distro = "centos" -version = "9stream" -iso = { - url = "${baseurl}" - checksum = "${sha}" -} -boot_command = [ - "", - "inst.text inst.ks=cdrom:/http/centos/9stream-x86_64.ks console=tty0", - "" -] -EOF diff --git a/distros/centos-stream/8/build.xsh b/distros/centos-stream/8/build.xsh new file mode 100755 index 0000000..c4058ed --- /dev/null +++ b/distros/centos-stream/8/build.xsh @@ -0,0 +1,14 @@ +#!/usr/bin/env xonsh +$RAISE_SUBPROC_ERROR = True +from pathlib import Path +import sys +self = Path(__file__).absolute() +base = self.parent.parent.parent.parent +source @(base / "test.xsh") + + +opts = get_parser(sys.argv[1:]) + +cd @(str(base)) +for provider in opts["providers"]: + packer build -var=@(opts["headless"]) -var-file=@(self.parent / "x86_64.pkrvars.hcl") @(opts["upload"]) -only=@(provider) @(base / "sources") diff --git a/distros/centos-stream/8/x86_64.pkrvars.hcl b/distros/centos-stream/8/x86_64.pkrvars.hcl new file mode 100644 index 0000000..b507b7f --- /dev/null +++ b/distros/centos-stream/8/x86_64.pkrvars.hcl @@ -0,0 +1,169 @@ +distro = "centos" +version = "8stream" +iso = { + url = "http://mirror.centos.org/centos/8-stream/isos/x86_64/CentOS-Stream-8-x86_64-latest-boot.iso" + checksum = "029ead89f720becd5ee2a8cf9935aad12fda7494d61674710174b4674b357530" +} +boot_command = [ + "", + "inst.text inst.ks=cdrom:/ks.cfg console=tty0", + "" +] +cd_files = { + "ks.cfg" = <> /etc/fstab + +# sudo +echo "%vagrant ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/vagrant +chmod 0440 /etc/sudoers.d/vagrant + +# Fix for https://github.com/CentOS/sig-cloud-instance-build/issues/38 +cat > /etc/sysconfig/network-scripts/ifcfg-eth0 << EOF +DEVICE="eth0" +BOOTPROTO="dhcp" +ONBOOT="yes" +TYPE="Ethernet" +PERSISTENT_DHCLIENT="yes" +EOF + +# sshd: disable password authentication and DNS checks +ex -s /etc/ssh/sshd_config <>/etc/sysconfig/sshd <> /home/vagrant/.ssh/authorized_keys +chmod 600 /home/vagrant/.ssh/authorized_keys +chown -R vagrant:vagrant /home/vagrant/.ssh + +# Fix for issue #76, regular users can gain admin privileges via su +ex -s /etc/pam.d/su <<'EOF' +# allow vagrant to use su, but prevent others from becoming root or vagrant +/^account\s\+sufficient\s\+pam_succeed_if.so uid = 0 use_uid quiet$/ +:append +account [success=1 default=ignore] \\ + pam_succeed_if.so user = vagrant use_uid quiet +account required pam_succeed_if.so user notin root:vagrant +. +:update +:quit +EOF + +# systemd should generate a new machine id during the first boot, to +# avoid having multiple Vagrant instances with the same id in the local +# network. /etc/machine-id should be empty, but it must exist to prevent +# boot errors (e.g. systemd-journald failing to start). +:>/etc/machine-id + +echo 'vag' > /etc/yum/vars/infra + +# Blacklist the floppy module to avoid probing timeouts +echo blacklist floppy > /etc/modprobe.d/nofloppy.conf +chcon -u system_u -r object_r -t modules_conf_t /etc/modprobe.d/nofloppy.conf + +# Customize the initramfs +pushd /etc/dracut.conf.d +# Enable VMware PVSCSI support for VMware Fusion guests. +echo 'add_drivers+=" vmw_pvscsi "' > vmware-fusion-drivers.conf +echo 'add_drivers+=" hv_netvsc hv_storvsc hv_utils hv_vmbus hid-hyperv "' > hyperv-drivers.conf +# There's no floppy controller, but probing for it generates timeouts +echo 'omit_drivers+=" floppy "' > nofloppy.conf +popd +# Fix the SELinux context of the new files +restorecon -f - < "${name}" +distro = "centos" +version = "8stream" +iso = { + url = "http://mirror.centos.org/centos/8-stream/isos/x86_64/CentOS-Stream-8-x86_64-latest-boot.iso" + checksum = "${sha}" +} +boot_command = [ + "", + "inst.text inst.ks=cdrom:/ks.cfg console=tty0", + "" +] +cd_files = { + "ks.cfg" = <> /etc/fstab + +# sudo +echo "%vagrant ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/vagrant +chmod 0440 /etc/sudoers.d/vagrant + +# Fix for https://github.com/CentOS/sig-cloud-instance-build/issues/38 +cat > /etc/sysconfig/network-scripts/ifcfg-eth0 << EOF +DEVICE="eth0" +BOOTPROTO="dhcp" +ONBOOT="yes" +TYPE="Ethernet" +PERSISTENT_DHCLIENT="yes" +EOF + +# sshd: disable password authentication and DNS checks +ex -s /etc/ssh/sshd_config <>/etc/sysconfig/sshd <> /home/vagrant/.ssh/authorized_keys +chmod 600 /home/vagrant/.ssh/authorized_keys +chown -R vagrant:vagrant /home/vagrant/.ssh + +# Fix for issue #76, regular users can gain admin privileges via su +ex -s /etc/pam.d/su <<'EOF' +# allow vagrant to use su, but prevent others from becoming root or vagrant +/^account\s\+sufficient\s\+pam_succeed_if.so uid = 0 use_uid quiet\$/ +:append +account [success=1 default=ignore] \\ + pam_succeed_if.so user = vagrant use_uid quiet +account required pam_succeed_if.so user notin root:vagrant +. +:update +:quit +EOF + +# systemd should generate a new machine id during the first boot, to +# avoid having multiple Vagrant instances with the same id in the local +# network. /etc/machine-id should be empty, but it must exist to prevent +# boot errors (e.g. systemd-journald failing to start). +:>/etc/machine-id + +echo 'vag' > /etc/yum/vars/infra + +# Blacklist the floppy module to avoid probing timeouts +echo blacklist floppy > /etc/modprobe.d/nofloppy.conf +chcon -u system_u -r object_r -t modules_conf_t /etc/modprobe.d/nofloppy.conf + +# Customize the initramfs +pushd /etc/dracut.conf.d +# Enable VMware PVSCSI support for VMware Fusion guests. +echo 'add_drivers+=" vmw_pvscsi "' > vmware-fusion-drivers.conf +echo 'add_drivers+=" hv_netvsc hv_storvsc hv_utils hv_vmbus hid-hyperv "' > hyperv-drivers.conf +# There's no floppy controller, but probing for it generates timeouts +echo 'omit_drivers+=" floppy "' > nofloppy.conf +popd +# Fix the SELinux context of the new files +restorecon -f - <", + "inst.text inst.ks=cdrom:/ks.cfg console=tty0", + "" +] +cd_files = { + "ks.cfg" = < /tmp/disks.ks +echo "part / --fstype=ext4 --asprimary --size=1024 --grow --ondisk=$disk" >> /tmp/disks.ks +%end + +user --name=vagrant --plaintext --password=vagrant + +%packages --inst-langs=en +bash-completion +man-pages +bzip2 +rsync +nfs-utils +cifs-utils +chrony +yum-utils +hyperv-daemons +open-vm-tools +# Vagrant boxes aren't normally visible, no need for Plymouth +-plymouth +# Microcode updates cannot work in a VM +-microcode_ctl +# Firmware packages are not needed in a VM +-iwl100-firmware +-iwl1000-firmware +-iwl105-firmware +-iwl135-firmware +-iwl2000-firmware +-iwl2030-firmware +-iwl3160-firmware +-iwl3945-firmware +-iwl4965-firmware +-iwl5000-firmware +-iwl5150-firmware +-iwl6000-firmware +-iwl6000g2a-firmware +-iwl6050-firmware +-iwl7260-firmware +# Don't build rescue initramfs +-dracut-config-rescue +%end + +# kdump needs to reserve 160MB + 2bits/4kB RAM, and automatic allocation only +# works on systems with at least 2GB RAM (which excludes most Vagrant boxes) +# CBS doesn't support %addon yet https://bugs.centos.org/view.php?id=12169 +%addon com_redhat_kdump --disable +%end + +%post +# configure swap to a file +fallocate -l 2G /swapfile +chmod 600 /swapfile +mkswap /swapfile +echo "/swapfile none swap defaults 0 0" >> /etc/fstab + +# sudo +echo "%vagrant ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/vagrant +chmod 0440 /etc/sudoers.d/vagrant + +# Fix for https://github.com/CentOS/sig-cloud-instance-build/issues/38 +cat > /etc/sysconfig/network-scripts/ifcfg-eth0 << EOF +DEVICE="eth0" +BOOTPROTO="dhcp" +ONBOOT="yes" +TYPE="Ethernet" +PERSISTENT_DHCLIENT="yes" +EOF + +# sshd: disable password authentication and DNS checks +ex -s /etc/ssh/sshd_config <>/etc/sysconfig/sshd <> /home/vagrant/.ssh/authorized_keys +chmod 600 /home/vagrant/.ssh/authorized_keys +chown -R vagrant:vagrant /home/vagrant/.ssh + +# Fix for issue #76, regular users can gain admin privileges via su +ex -s /etc/pam.d/su <<'EOF' +# allow vagrant to use su, but prevent others from becoming root or vagrant +/^account\s\+sufficient\s\+pam_succeed_if.so uid = 0 use_uid quiet$/ +:append +account [success=1 default=ignore] \ + pam_succeed_if.so user = vagrant use_uid quiet +account required pam_succeed_if.so user notin root:vagrant +. +:update +:quit +EOF + +# systemd should generate a new machine id during the first boot, to +# avoid having multiple Vagrant instances with the same id in the local +# network. /etc/machine-id should be empty, but it must exist to prevent +# boot errors (e.g. systemd-journald failing to start). +:>/etc/machine-id + +echo 'vag' > /etc/yum/vars/infra + +# Blacklist the floppy module to avoid probing timeouts +echo blacklist floppy > /etc/modprobe.d/nofloppy.conf +chcon -u system_u -r object_r -t modules_conf_t /etc/modprobe.d/nofloppy.conf + +# Customize the initramfs +pushd /etc/dracut.conf.d +# Enable VMware PVSCSI support for VMware Fusion guests. +echo 'add_drivers+=" vmw_pvscsi "' > vmware-fusion-drivers.conf +echo 'add_drivers+=" hv_netvsc hv_storvsc hv_utils hv_vmbus hid-hyperv "' > hyperv-drivers.conf +# There's no floppy controller, but probing for it generates timeouts +echo 'omit_drivers+=" floppy "' > nofloppy.conf +popd +# Fix the SELinux context of the new files +restorecon -f - < "${name}" +distro = "centos" +version = "9stream" +iso = { + url = "${baseurl}" + checksum = "${sha}" +} +boot_command = [ + "", + "inst.text inst.ks=cdrom:/ks.cfg console=tty0", + "" +] +cd_files = { + "ks.cfg" = < /tmp/disks.ks +echo "part / --fstype=ext4 --asprimary --size=1024 --grow --ondisk=\$disk" >> /tmp/disks.ks +%end + +user --name=vagrant --plaintext --password=vagrant + +%packages --inst-langs=en +bash-completion +man-pages +bzip2 +rsync +nfs-utils +cifs-utils +chrony +yum-utils +hyperv-daemons +open-vm-tools +# Vagrant boxes aren't normally visible, no need for Plymouth +-plymouth +# Microcode updates cannot work in a VM +-microcode_ctl +# Firmware packages are not needed in a VM +-iwl100-firmware +-iwl1000-firmware +-iwl105-firmware +-iwl135-firmware +-iwl2000-firmware +-iwl2030-firmware +-iwl3160-firmware +-iwl3945-firmware +-iwl4965-firmware +-iwl5000-firmware +-iwl5150-firmware +-iwl6000-firmware +-iwl6000g2a-firmware +-iwl6050-firmware +-iwl7260-firmware +# Don't build rescue initramfs +-dracut-config-rescue +%end + +# kdump needs to reserve 160MB + 2bits/4kB RAM, and automatic allocation only +# works on systems with at least 2GB RAM (which excludes most Vagrant boxes) +# CBS doesn't support %addon yet https://bugs.centos.org/view.php?id=12169 +%addon com_redhat_kdump --disable +%end + +%post +# configure swap to a file +fallocate -l 2G /swapfile +chmod 600 /swapfile +mkswap /swapfile +echo "/swapfile none swap defaults 0 0" >> /etc/fstab + +# sudo +echo "%vagrant ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/vagrant +chmod 0440 /etc/sudoers.d/vagrant + +# Fix for https://github.com/CentOS/sig-cloud-instance-build/issues/38 +cat > /etc/sysconfig/network-scripts/ifcfg-eth0 << EOF +DEVICE="eth0" +BOOTPROTO="dhcp" +ONBOOT="yes" +TYPE="Ethernet" +PERSISTENT_DHCLIENT="yes" +EOF + +# sshd: disable password authentication and DNS checks +ex -s /etc/ssh/sshd_config <>/etc/sysconfig/sshd <> /home/vagrant/.ssh/authorized_keys +chmod 600 /home/vagrant/.ssh/authorized_keys +chown -R vagrant:vagrant /home/vagrant/.ssh + +# Fix for issue #76, regular users can gain admin privileges via su +ex -s /etc/pam.d/su <<'EOF' +# allow vagrant to use su, but prevent others from becoming root or vagrant +/^account\s\+sufficient\s\+pam_succeed_if.so uid = 0 use_uid quiet\$/ +:append +account [success=1 default=ignore] \\ + pam_succeed_if.so user = vagrant use_uid quiet +account required pam_succeed_if.so user notin root:vagrant +. +:update +:quit +EOF + +# systemd should generate a new machine id during the first boot, to +# avoid having multiple Vagrant instances with the same id in the local +# network. /etc/machine-id should be empty, but it must exist to prevent +# boot errors (e.g. systemd-journald failing to start). +:>/etc/machine-id + +echo 'vag' > /etc/yum/vars/infra + +# Blacklist the floppy module to avoid probing timeouts +echo blacklist floppy > /etc/modprobe.d/nofloppy.conf +chcon -u system_u -r object_r -t modules_conf_t /etc/modprobe.d/nofloppy.conf + +# Customize the initramfs +pushd /etc/dracut.conf.d +# Enable VMware PVSCSI support for VMware Fusion guests. +echo 'add_drivers+=" vmw_pvscsi "' > vmware-fusion-drivers.conf +echo 'add_drivers+=" hv_netvsc hv_storvsc hv_utils hv_vmbus hid-hyperv "' > hyperv-drivers.conf +# There's no floppy controller, but probing for it generates timeouts +echo 'omit_drivers+=" floppy "' > nofloppy.conf +popd +# Fix the SELinux context of the new files +restorecon -f - <", - "linux inst.ks=cdrom:/ks.cfg console=tty0", + "", + " inst.ks=cdrom:/ks.cfg console=tty0", "" ] cd_files = { diff --git a/distros/debian-10-x86_64.pkrvars.hcl b/distros/debian-10-x86_64.pkrvars.hcl deleted file mode 100644 index f716dd1..0000000 --- a/distros/debian-10-x86_64.pkrvars.hcl +++ /dev/null @@ -1,17 +0,0 @@ -distro = "debian" -version = "10" -iso = { - url = "https://cdimage.debian.org/cdimage/archive/10.13.0/amd64/iso-cd/debian-10.13.0-amd64-netinst.iso" - checksum = "75aa64071060402a594dcf1e14afd669ca0f8bf757b56d4c9c1a31b8f7c8f931" -} -boot_command = [ - "", - "auto ", - "DEBIAN_FRONTEND=text ", - "net.ifnames=0 ", - "biosdevnames=0 ", - "preseed/url=http://{{.HTTPIP}}:{{ .HTTPPort }}/debian/10-preseed.cfg ", - "console=ttyS0 ", - "console=tty0 ", - "" -] diff --git a/distros/debian-11-x86_64.pkrvars.hcl b/distros/debian-11-x86_64.pkrvars.hcl deleted file mode 100644 index 1136a02..0000000 --- a/distros/debian-11-x86_64.pkrvars.hcl +++ /dev/null @@ -1,16 +0,0 @@ -distro = "debian" -version = "11" -iso = { - url = "https://cdimage.debian.org/cdimage/archive/11.7.0/amd64/iso-cd/debian-11.7.0-amd64-netinst.iso" - checksum = "eb3f96fd607e4b67e80f4fc15670feb7d9db5be50f4ca8d0bf07008cb025766b" -} -boot_command = [ - "", - "auto ", - "DEBIAN_FRONTEND=text ", - "net.ifnames=0 ", - "biosdevnames=0 ", - "preseed/url=http://{{.HTTPIP}}:{{ .HTTPPort }}/debian/11-preseed.cfg ", - "console=ttyS0 ", - "" -] diff --git a/distros/debian-12-x86_64.pkrvars.hcl b/distros/debian-12-x86_64.pkrvars.hcl deleted file mode 100644 index aaf7445..0000000 --- a/distros/debian-12-x86_64.pkrvars.hcl +++ /dev/null @@ -1,16 +0,0 @@ -distro = "debian" -version = "12" -iso = { - url = "https://cdimage.debian.org/cdimage/archive/12.0.0/amd64/iso-cd/debian-12.0.0-amd64-netinst.iso" - checksum = "3b0e9718e3653435f20d8c2124de6d363a51a1fd7f911b9ca0c6db6b3d30d53e" -} -boot_command = [ - "", - "auto ", - "DEBIAN_FRONTEND=text ", - "net.ifnames=0 ", - "biosdevnames=0 ", - "preseed/url=http://{{.HTTPIP}}:{{ .HTTPPort }}/debian/12-preseed.cfg ", - "console=ttyS0 ", - "" -] diff --git a/distros/debian/10/build.xsh b/distros/debian/10/build.xsh new file mode 100755 index 0000000..b4da09c --- /dev/null +++ b/distros/debian/10/build.xsh @@ -0,0 +1,17 @@ +#!/usr/bin/env xonsh +$RAISE_SUBPROC_ERROR = True +from pathlib import Path +import sys +self = Path(__file__).absolute() +base = self.parent.parent.parent.parent +source @(base / "test.xsh") + + +unsupported = set({ +}) + +opts = get_parser(sys.argv[1:], unsupported) + +cd @(str(base)) +for provider in opts["providers"]: + packer build -var=@(opts["headless"]) -var-file=@(self.parent / "x86_64.pkrvars.hcl") @(opts["upload"]) -only=@(provider) @(base / "sources") diff --git a/http/debian/11-preseed.cfg b/distros/debian/10/x86_64.pkrvars.hcl similarity index 85% rename from http/debian/11-preseed.cfg rename to distros/debian/10/x86_64.pkrvars.hcl index 8878035..993a118 100644 --- a/http/debian/11-preseed.cfg +++ b/distros/debian/10/x86_64.pkrvars.hcl @@ -1,3 +1,19 @@ +distro = "debian" +version = "10" +iso = { + url = "https://cdimage.debian.org/cdimage/archive/10.13.0/amd64/iso-cd/debian-10.13.0-amd64-netinst.iso" + checksum = "75aa64071060402a594dcf1e14afd669ca0f8bf757b56d4c9c1a31b8f7c8f931" +} +boot_command = [ + "", + "auto ", + "DEBIAN_FRONTEND=text ", + "preseed/url=http://{{.HTTPIP}}:{{ .HTTPPort }}/preseed.cfg ", + "console=tty0 ", + "" +] +http_files = { + "/preseed.cfg" = < /target/etc/sudoers.d/vagrant; \ echo 'vagrant ALL=(ALL) NOPASSWD: ALL' >> /target/etc/sudoers.d/vagrant; \ chmod 440 /target/etc/sudoers.d/vagrant +KICKSTART +} diff --git a/distros/debian/11/build.xsh b/distros/debian/11/build.xsh new file mode 100755 index 0000000..b4da09c --- /dev/null +++ b/distros/debian/11/build.xsh @@ -0,0 +1,17 @@ +#!/usr/bin/env xonsh +$RAISE_SUBPROC_ERROR = True +from pathlib import Path +import sys +self = Path(__file__).absolute() +base = self.parent.parent.parent.parent +source @(base / "test.xsh") + + +unsupported = set({ +}) + +opts = get_parser(sys.argv[1:], unsupported) + +cd @(str(base)) +for provider in opts["providers"]: + packer build -var=@(opts["headless"]) -var-file=@(self.parent / "x86_64.pkrvars.hcl") @(opts["upload"]) -only=@(provider) @(base / "sources") diff --git a/http/debian/10-preseed.cfg b/distros/debian/11/x86_64.pkrvars.hcl similarity index 85% rename from http/debian/10-preseed.cfg rename to distros/debian/11/x86_64.pkrvars.hcl index 8878035..f241269 100644 --- a/http/debian/10-preseed.cfg +++ b/distros/debian/11/x86_64.pkrvars.hcl @@ -1,3 +1,19 @@ +distro = "debian" +version = "11" +iso = { + url = "https://cdimage.debian.org/cdimage/archive/11.7.0/amd64/iso-cd/debian-11.7.0-amd64-netinst.iso" + checksum = "eb3f96fd607e4b67e80f4fc15670feb7d9db5be50f4ca8d0bf07008cb025766b" +} +boot_command = [ + "", + "auto ", + "DEBIAN_FRONTEND=text ", + "preseed/url=http://{{.HTTPIP}}:{{ .HTTPPort }}/preseed.cfg ", + "console=tty0 ", + "" +] +http_files = { + "/preseed.cfg" = < /target/etc/sudoers.d/vagrant; \ echo 'vagrant ALL=(ALL) NOPASSWD: ALL' >> /target/etc/sudoers.d/vagrant; \ chmod 440 /target/etc/sudoers.d/vagrant +KICKSTART +} diff --git a/distros/debian/12/build.xsh b/distros/debian/12/build.xsh new file mode 100755 index 0000000..b4da09c --- /dev/null +++ b/distros/debian/12/build.xsh @@ -0,0 +1,17 @@ +#!/usr/bin/env xonsh +$RAISE_SUBPROC_ERROR = True +from pathlib import Path +import sys +self = Path(__file__).absolute() +base = self.parent.parent.parent.parent +source @(base / "test.xsh") + + +unsupported = set({ +}) + +opts = get_parser(sys.argv[1:], unsupported) + +cd @(str(base)) +for provider in opts["providers"]: + packer build -var=@(opts["headless"]) -var-file=@(self.parent / "x86_64.pkrvars.hcl") @(opts["upload"]) -only=@(provider) @(base / "sources") diff --git a/http/debian/12-preseed.cfg b/distros/debian/12/x86_64.pkrvars.hcl similarity index 84% rename from http/debian/12-preseed.cfg rename to distros/debian/12/x86_64.pkrvars.hcl index 8878035..27bfdb2 100644 --- a/http/debian/12-preseed.cfg +++ b/distros/debian/12/x86_64.pkrvars.hcl @@ -1,3 +1,20 @@ +distro = "debian" +version = "12" +iso = { + url = "https://cdimage.debian.org/cdimage/archive/12.0.0/amd64/iso-cd/debian-12.0.0-amd64-netinst.iso" + checksum = "3b0e9718e3653435f20d8c2124de6d363a51a1fd7f911b9ca0c6db6b3d30d53e" +} +boot_command = [ + "", + "auto ", + "DEBIAN_FRONTEND=text ", + "preseed/url=http://{{.HTTPIP}}:{{ .HTTPPort }}/preseed.cfg ", + "console=tty0 ", + "" +] +http_files = { + "/preseed.cfg" = < /target/etc/sudoers.d/vagrant; \ echo 'vagrant ALL=(ALL) NOPASSWD: ALL' >> /target/etc/sudoers.d/vagrant; \ chmod 440 /target/etc/sudoers.d/vagrant +KICKSTART +} diff --git a/distros/debian/9/build.xsh b/distros/debian/9/build.xsh new file mode 100755 index 0000000..b4da09c --- /dev/null +++ b/distros/debian/9/build.xsh @@ -0,0 +1,17 @@ +#!/usr/bin/env xonsh +$RAISE_SUBPROC_ERROR = True +from pathlib import Path +import sys +self = Path(__file__).absolute() +base = self.parent.parent.parent.parent +source @(base / "test.xsh") + + +unsupported = set({ +}) + +opts = get_parser(sys.argv[1:], unsupported) + +cd @(str(base)) +for provider in opts["providers"]: + packer build -var=@(opts["headless"]) -var-file=@(self.parent / "x86_64.pkrvars.hcl") @(opts["upload"]) -only=@(provider) @(base / "sources") diff --git a/http/debian/9-preseed.cfg b/distros/debian/9/x86_64.pkrvars.hcl similarity index 76% rename from http/debian/9-preseed.cfg rename to distros/debian/9/x86_64.pkrvars.hcl index 8878035..9941ac0 100644 --- a/http/debian/9-preseed.cfg +++ b/distros/debian/9/x86_64.pkrvars.hcl @@ -1,3 +1,30 @@ +distro = "debian" +version = "9" +iso = { + url = "https://cdimage.debian.org/cdimage/archive/9.13.0/amd64/iso-cd/debian-9.13.0-amd64-netinst.iso" + checksum = "71c7e9eb292acc880f84605b1ca2b997f25737fe0a43fc9586f61d35cd2eb43b" +} +boot_command = [ + "", + "auto ", + "DEBIAN_FRONTEND=text ", + "preseed/url=http://{{.HTTPIP}}:{{ .HTTPPort }}/preseed.cfg ", + "console=tty0 ", + "--- ", # Lines after this are copied to the resulting system?! + "biosdevnames=0 ", + "net.ifnames=0 ", + "" +] +http_files = { + "/preseed.cfg" = < /target/etc/sudoers.d/vagrant; \ echo 'vagrant ALL=(ALL) NOPASSWD: ALL' >> /target/etc/sudoers.d/vagrant; \ chmod 440 /target/etc/sudoers.d/vagrant + +KICKSTART +} diff --git a/sources/virtualbox-iso.pkr.hcl b/sources/virtualbox-iso.pkr.hcl index f353169..f578c86 100644 --- a/sources/virtualbox-iso.pkr.hcl +++ b/sources/virtualbox-iso.pkr.hcl @@ -18,8 +18,7 @@ source "virtualbox-iso" "x86_64" { cpus = local.cpus memory = local.memory headless = var.headless - nic_type = "virtio" - guest_os_type = "RedHat_64" + guest_os_type = "Linux_64" guest_additions_url = "http://download.virtualbox.org/virtualbox/7.0.10/VBoxGuestAdditions_7.0.10.iso" guest_additions_sha256 = "bbabd89b8fff38a257bab039a278f0c4dc4426eff6e4238c1db01edb7284186a" vboxmanage = [ diff --git a/test.xsh b/test.xsh index e46b4ac..da891fb 100755 --- a/test.xsh +++ b/test.xsh @@ -3,6 +3,7 @@ import argparse import pathlib import re +import sys import time @@ -16,10 +17,10 @@ def get_vagrant_provider(provider): def get_providers(): "List of providers as defined in sources/" - providers: list[str] = [ + providers: set[str] = { "virtualbox-iso.x86_64", "qemu.x86_64" - ] + } return providers @@ -31,46 +32,40 @@ def get_builds(): return builds -def get_parser(args): +def get_parser(args, unsupported=set()): parser = argparse.ArgumentParser("Builder") parser.add_argument("--headless", action="store_true") parser.add_argument("--upload", action="store_true") + parser.add_argument("--provider", action="append") parsed = parser.parse_args(args) opts = {} if parsed.headless: - opts["headless"] = "hadless=true" + opts["headless"] = "headless=true" else: opts["headless"] = "headless=false" if parsed.upload: opts["upload"] = "" else: opts["upload"] = "-except=upload" + if parsed.provider: + opts["providers"] = set(parsed.provider) + else: + opts["providers"] = get_providers() + # Filter providers + opts["providers"] -= unsupported return opts def main(): # Equivalent of `set -e` in Bash - $RAISE_SUBPROC_ERROR = True - - # Parse user arguments - parser = argparse.ArgumentParser("Test script") - parser.add_argument("--build", "-b", required=True, choices=get_builds()) - parser.add_argument("--provider", "-p", default="virtualbox-iso.x86_64", choices=get_providers()) - parser.add_argument("--headless", action="store_true") - args = parser.parse_args() - - if args.headless: - headless = "headless=true" - else: - headless = "headless=false" - - packer build -var @(headless) -var-file distros/@(args.build).pkrvars.hcl -except=upload -only=@(args.provider) sources/ - vagrant box add --force --name @(args.build) @(args.build).box - sed -e f's/@@BOX@@/{args.build}/' Vagrantfile.in > Vagrantfile - vagrant up --provider @(get_vagrant_provider(args.provider)) --provision - vagrant ssh -c "ls -la ~/" - vagrant destroy -f - rm -r .vagrant + #$RAISE_SUBPROC_ERROR = True + for box in g`*.box`: + sed -e f's#@@BOX@@#file:///home/greg/src/vms/vms/{box}#' -e f's/@@BOX_NAME@@/{box}/' Vagrantfile.in > Vagrantfile + #vagrant box add --force --name @(args.build) @(args.build).box + #vagrant up --provider @(get_vagrant_provider(args.provider)) --provision + vagrant up --provider libvirt + vagrant destroy -f + rm -rf .vagrant if __name__ == '__main__':