diff --git a/cableos/Makefile b/cableos/Makefile index a5014ed..66dd690 100644 --- a/cableos/Makefile +++ b/cableos/Makefile @@ -1,29 +1,33 @@ +#!/usr/bin/make -f include ../scripts/check.mk PACKER ?= packer PACKER_LOG ?= 0 -TIMEOUT ?= 1h -RM ?= RM -SERIES ?= jammy +export PACKER_LOG +BOOT ?= uefi ARCH ?= amd64 -URL ?= http://releases.ubuntu.com -SUMS ?= SHA256SUMS TIMEOUT ?= 1h -export PACKER_LOG +ISO= ?= boot-images/debirf-live_bullseye_amd64.iso + .PHONY: all clean -all: cableos-installer.qcow2 -$(eval $(call check_packages_deps)) +all: cableos-installer.tar.gz +$(eval $(call check_packages_deps,cloud-image-utils ovmf libnbd0 nbdfuse nbdkit fuse2fs debirf,cloud-image-utils ovmf libnbd0 nbdfuse nbdkit fuse2fs debirf)) + +lint: + packer validate . + packer fmt -check -diff . -cableos-installer.qcow2: check-deps clean - # ${PACKER} build template.json - ${PACKER} init . build.pkr.hcl && ${PACKER} build -var timeout=${TIMEOUT} build.pkr.hcl +format: + packer fmt . -# cableos-installer.tar.gz: check-deps clean -# # ${PACKER} build template.json -# ${PACKER} init . build.pkr.hcl && ${PACKER} build -var timeout=${TIMEOUT} build.pkr.hcl +cableos-installer.tar.gz: check-deps clean + ${PACKER} init cableos-installer.pkr.hcl && ${PACKER} build \ + -var architecture=${ARCH} \ + -var boot_mode=${BOOT} \ + -var timeout=${TIMEOUT} cableos-installer.pkr.hcl clean: - ${RM} -rf output-images/cableos-installer.qcow2 cableos-installer.tar.gz + ${RM} -rf output-cableos-installer/* cableos-installer-*.gz diff --git a/cableos/build.pkr.hcl b/cableos/build.pkr.hcl deleted file mode 100644 index 50914ec..0000000 --- a/cableos/build.pkr.hcl +++ /dev/null @@ -1,62 +0,0 @@ -// Define Packer Source for QEMU -source "qemu" "debirf-live" { - iso_url = "/boot-images/debirf-live_bullseye_amd64.iso" - iso_checksum = "none" - disk_size = 10240 - output_directory = "output-images" - vm_name = "debirf-live" - format = "qcow2" - accelerator = "kvm" - http_directory = "http" - boot_command = [ - "", - "linux /boot-images/vmlinuz-6.0.0-0.deb11.6-amd64 auto hostname=debirf-live ", - "initrd /boot-images/debirf-live_bullseye_6.0.0-0.deb11.6-amd64.cgz ", - "boot" - ] - ssh_username = "root" - ssh_password = "install" - ssh_port = 22 - ssh_wait_timeout = "10000s" - headless = false -} - -// Define Build -build { - sources = [ - "source.qemu.debirf-live" - ] - - // Provisioners for installation and file extraction - provisioner "file" { - source = "/buildfiles/APOLLO_PLATFORM-release-3.21.3.0-7+auto15.iso" - destination = "/opt/APOLLO_PLATFORM-release-3.21.3.0-7+auto15.iso" - } - - provisioner "file" { - source = "/buildfiles/startup.sh" - destination = "/etc/init.d/startup.sh" - - } - provisioner "shell" { - inline = [ - "echo 'Files copied successfully..'" - ] - } - - // Post-processors to create new images and prepare for MAAS - - post-processor "qemu" { - only = ["qemu"] - output = "output-images/cableos-installer.qcow" - format = "qcow2" - disk_interface = "virtio" - } - - post-processor "shell-local" { - inline = [ - "qemu-img convert -f qcow2 -O raw cableos-installer.qcow cableos-installer.img", - "maas admin boot-resources create name=custom/cableos-installer name_title='CableOS Installation Image' architecture=amd64/generic content@=cableos-installer.img" - ] - } -} diff --git a/cableos/cableos-installer.pkr.hcl b/cableos/cableos-installer.pkr.hcl new file mode 100644 index 0000000..862583f --- /dev/null +++ b/cableos/cableos-installer.pkr.hcl @@ -0,0 +1,191 @@ +packer { + required_version = ">= 1.7.0" + required_plugins { + qemu = { + version = "~> 1.0" + source = "github.com/hashicorp/qemu" + } + } +} +variable "boot_mode" { + type = string + default = "uefi" + description = "The default boot mode support baked into the image." +} +variable "customize_script" { + type = string + default = "/dev/null" + description = "The filename of the script that will run in the VM to customize the image." +} + +variable "headless" { + type = bool + default = true + description = "Whether VNC viewer should not be launched." +} + +variable "http_directory" { + type = string + default = "http" +} + +variable "http_proxy" { + type = string + default = "${env("http_proxy")}" +} + +variable "apollo_iso" { + type = string + default = "APOLLO_PLATFORM-release-3.21.3.0-7+auto15.iso" +} +variable "live_iso" { + type = string + default = "debirf-live_bullseye_amd64.iso" +} + +variable "base_filename" { + type = string + default = "cableos-installer" + description = "The base filename for outputs" +} +variable "https_proxy" { + type = string + default = "${env("https_proxy")}" +} + +variable "no_proxy" { + type = string + default = "${env("no_proxy")}" +} + +variable "ssh_password" { + type = string + default = "install" +} + +variable "ssh_username" { + type = string + default = "root" +} + +variable "timeout" { + type = string + default = "1h" + description = "Timeout for building the image" +} + + +locals { + qemu_arch = { + "amd64" = "x86_64" + "arm64" = "aarch64" + } + uefi_imp = { + "amd64" = "OVMF" + "arm64" = "AAVMF" + } + qemu_machine = { + "amd64" = "accel=kvm" + "arm64" = "virt" + } + qemu_cpu = { + "amd64" = "host" + "arm64" = "cortex-a57" + } + + proxy_env = [ + "http_proxy=${var.http_proxy}", + "https_proxy=${var.https_proxy}", + "no_proxy=${var.https_proxy}", + ] +} +// Define Packer Source for QEMU + + +source "qemu" "cableos" { + boot_wait = "2s" + cpus = 2 + disk_image = true + disk_size = "4G" + format = "qcow2" + headless = var.headless + http_directory = var.http_directory + iso_checksum = "none" + iso_url = "build_images/${var.live_iso}" + memory = 2048 + qemu_binary = "qemu-system-${lookup(local.qemu_arch, var.architecture, "")}" + qemu_img_args { + create = ["-F", "qcow2"] + } + qemuargs = [ + ["-machine", "${lookup(local.qemu_machine, var.architecture, "")}"], + ["-cpu", "${lookup(local.qemu_cpu, var.architecture, "")}"], + ["-device", "virtio-gpu-pci"], + ["-drive", "file=output-cableos-installer/${var.base_filename},format=qcow2"], + ] + shutdown_command = "sudo -S shutdown -P now" + ssh_handshake_attempts = 50 + ssh_password = var.ssh_password + ssh_timeout = var.timeout + ssh_username = var.ssh_username + ssh_wait_timeout = var.timeout + use_backing_file = true +} + +// Define Build +build { + name = "cableos-installer" + sources = [ + "source.qemu.cableos" + ] + + // Provisioners for installation and file extraction + provisioner "file" { + source = "/buildfiles/${var.apollo_iso}" + destination = "/opt/${var.apollo_iso}" + } + + provisioner "file" { + source = "/buildfiles/startup.sh" + destination = "/etc/init.d/startup.sh" + + } + provisioner "shell" { + inline = [ + "echo 'Files copied successfully..'" + ] + } + +// Post-processors to create new images and prepare for MAAS + + // Create tar.gz file + + post-processor "shell-local" { + inline = [ + "IMG_FMT=qcow2", + "SOURCE=cableos", + "ROOT_PARTITION=3", + "DETECT_BLS_BOOT=1", + "OUTPUT=${var.base_filename}.tar.gz", + "source ../scripts/fuse-nbd", + "source ../scripts/fuse-tar-root" + ] + inline_shebang = "/bin/bash -e" + } + + // Create .qcow and .iso images + post-processor "qemu" { + only = ["qemu"] + output = "output-cableos-installer/${base_filename}.qcow" + format = "qcow2" + disk_interface = "virtio" + } + post-processor "shell-local" { + inline = [ + "qemu-img convert -f qcow2 -O raw output-cableos-installer/${base_filename}.qcow output-cableos-installer/${base-filename}.img", + "maas admin boot-resources create name=custom/new name_title='New Image' architecture=amd64/generic content@=new.img", + "echo 'Packer Provisioning Complete'" + + ] + } +} diff --git a/cableos/http/curtin-userdata-cableos-installer b/cableos/http/curtin-userdata-cableos-installer new file mode 100644 index 0000000..c9fb58f --- /dev/null +++ b/cableos/http/curtin-userdata-cableos-installer @@ -0,0 +1,24 @@ +#cloud-config +kernel: + fallback-package: linux-image-amd64 + package: linux-image-amd64 + +apt: + preserve_sources_list: true + +debconf_selections: + maas: | + {{for line in str(curtin_preseed).splitlines()}} + {{line}} + {{endfor}} + +late_commands: + maas: [wget, '--no-proxy', '{{node_disable_pxe_url}}', '--post-data', '{{node_disable_pxe_data}}', '-O', '/dev/null'] + late_1: mount --bind $TARGET_MOUNT_POINT /mnt + late_2: grep -A2 datasource /etc/cloud/cloud.cfg.d/91_kernel_cmdline_url.cfg | sed 's/curtin//' | tee /mnt/etc/cloud/cloud.cfg.d/debian.cfg + late_3: sed -i 's@ubuntu.com/ubuntu@debian.org/debian@g;s@archive@deb@g;s@ubuntu@debian@g;s@Ubuntu@Debian@g;s@security.debian.org/debian@security.debian.org@g' /mnt/etc/cloud/cloud.cfg + late_5: debver=$(cat /mnt/etc/debian_version | awk -F. '{print $1}'); if [ ${debver} -eq 10 ]; then rel="buster"; elif [ ${debver} -eq 11 ]; then rel="bullseye"; elif [ ${debver} -eq 12 ]; then rel="bookworm"; fi; sed -i s/stable/${rel}/g /mnt/etc/apt/sources.list; + late_6: sed -i '/^set -e/{n;N;d}' /mnt/etc/kernel/postinst.d/zz-update-grub + late_7: rm -f /usr/local/bin/dpkg-query + late_8: rm -f /usr/local/bin/netplan + diff --git a/cableos/http/scratch/user-data-cloudimg b/cableos/http/scratch/user-data-cloudimg new file mode 100644 index 0000000..dc0e262 --- /dev/null +++ b/cableos/http/scratch/user-data-cloudimg @@ -0,0 +1,19 @@ +#cloud-config +users: + - name: root + lock_passwd: false + plain_text_passwd: "debian" + ssh_redirect_user: false +ssh_pwauth: True +disable_root: false +preserve_hostname: true +runcmd: + - sed -i -e '/^[#]*PermitRootLogin/s/^.*$/PermitRootLogin yes/' /etc/ssh/sshd_config + - systemctl restart ssh +bootcmd: + - mkdir /run/packer_backup + - mkdir /run/packer_backup/etc + - mkdir /run/packer_backup/etc/apt + - mkdir /run/packer_backup/etc/ssh + - cp --preserve /etc/apt/sources.list /run/packer_backup/etc/apt/ + - cp --preserve /etc/ssh/sshd_config /run/packer_backup/etc/ssh/ diff --git a/cableos/http/user-data-cableos-installer b/cableos/http/user-data-cableos-installer new file mode 100644 index 0000000..dc0e262 --- /dev/null +++ b/cableos/http/user-data-cableos-installer @@ -0,0 +1,19 @@ +#cloud-config +users: + - name: root + lock_passwd: false + plain_text_passwd: "debian" + ssh_redirect_user: false +ssh_pwauth: True +disable_root: false +preserve_hostname: true +runcmd: + - sed -i -e '/^[#]*PermitRootLogin/s/^.*$/PermitRootLogin yes/' /etc/ssh/sshd_config + - systemctl restart ssh +bootcmd: + - mkdir /run/packer_backup + - mkdir /run/packer_backup/etc + - mkdir /run/packer_backup/etc/apt + - mkdir /run/packer_backup/etc/ssh + - cp --preserve /etc/apt/sources.list /run/packer_backup/etc/apt/ + - cp --preserve /etc/ssh/sshd_config /run/packer_backup/etc/ssh/ diff --git a/cableos/build.sh b/cableos/scratch/build.sh similarity index 100% rename from cableos/build.sh rename to cableos/scratch/build.sh diff --git a/cableos/scratch/build2.pkr.hcl b/cableos/scratch/build2.pkr.hcl new file mode 100644 index 0000000..dfa26ed --- /dev/null +++ b/cableos/scratch/build2.pkr.hcl @@ -0,0 +1,173 @@ +packer { + required_version = ">= 1.7.0" + required_plugins { + qemu = { + version = "~> 1.0" + source = "github.com/hashicorp/qemu" + } + } +} +variable "boot_mode" { + type = string + default = "uefi" + description = "The default boot mode support baked into the image." +} +variable "customize_script" { + type = string + default = "/dev/null" + description = "The filename of the script that will run in the VM to customize the image." +} + +variable "headless" { + type = bool + default = true + description = "Whether VNC viewer should not be launched." +} + +variable "http_directory" { + type = string + default = "http" +} + +variable "http_proxy" { + type = string + default = "${env("http_proxy")}" +} + +variable "apollo_iso" { + type = string + default = "APOLLO_PLATFORM-release-3.21.3.0-7+auto15.iso" +} +variable "live_iso" { + type = string + default = "debirf-live_bullseye_amd64.iso" +} + +variable "base_filename" { + type = string + default = "cableos-installer" + description = "The base filename for outputs" +} +variable "https_proxy" { + type = string + default = "${env("https_proxy")}" +} + +variable "no_proxy" { + type = string + default = "${env("no_proxy")}" +} + +variable "ssh_password" { + type = string + default = "install" +} + +variable "ssh_username" { + type = string + default = "root" +} + +variable "timeout" { + type = string + default = "1h" + description = "Timeout for building the image" +} + + +locals { + qemu_arch = { + "amd64" = "x86_64" + "arm64" = "aarch64" + } + uefi_imp = { + "amd64" = "OVMF" + "arm64" = "AAVMF" + } + qemu_machine = { + "amd64" = "accel=kvm" + "arm64" = "virt" + } + qemu_cpu = { + "amd64" = "host" + "arm64" = "cortex-a57" + } + + proxy_env = [ + "http_proxy=${var.http_proxy}", + "https_proxy=${var.https_proxy}", + "no_proxy=${var.https_proxy}", + ] +} +// Define Packer Source for QEMU + + +source "qemu" "debirf-live" { + boot_wait = "2s" + cpus = 2 + disk_image = true + disk_size = "4G" + format = "qcow2" + headless = var.headless + http_directory = var.http_directory + iso_checksum = "none" + iso_url = "build_images/${var.live_iso}" + iso_target_path = "tempfiles/${var.base_filename}.iso" + memory = 2048 + qemu_binary = "qemu-system-${lookup(local.qemu_arch, var.architecture, "")}" + qemu_img_args { + create = ["-F", "qcow2"] + } + qemuargs = [ + ["-machine", "${lookup(local.qemu_machine, var.architecture, "")}"], + ["-cpu", "${lookup(local.qemu_cpu, var.architecture, "")}"], + ["-device", "virtio-gpu-pci"], + ["-drive", "file=output-images/${var.base_filename},format=qcow2"], + ] + shutdown_command = "sudo -S shutdown -P now" + ssh_handshake_attempts = 50 + ssh_password = var.ssh_password + ssh_timeout = var.timeout + ssh_username = var.ssh_username + ssh_wait_timeout = var.timeout + use_backing_file = true +} + +// Define Build +build { + name = "cableos-installer" + sources = [ + "source.qemu.debirf-live" + ] + + // Provisioners for installation and file extraction + provisioner "file" { + source = "/buildfiles/${var.apollo_iso}" + destination = "/opt/${var.apollo_iso}" + } + + provisioner "file" { + source = "/buildfiles/startup.sh" + destination = "/etc/init.d/startup.sh" + + } + provisioner "shell" { + inline = [ + "echo 'Files copied successfully..'" + ] + } + + // Post-processors to create new images and prepare for MAAS + post-processor "shell-local" { + inline = [ + "IMG_FMT=qcow2", + "SOURCE=debirf-live", + "ROOT_PARTITION=3", + "DETECT_BLS_BOOT=1", + "OUTPUT=output-images/${var.filename}.tar.gz", + "source ../scripts/fuse-nbd", + "source ../scripts/fuse-tar-root" + ] + inline_shebang = "/bin/bash -e" + } +} diff --git a/cableos/debirf.json b/cableos/scratch/debirf.json similarity index 100% rename from cableos/debirf.json rename to cableos/scratch/debirf.json diff --git a/cableos/tempfiles/.gitkeep b/cableos/tempfiles/.gitkeep new file mode 100644 index 0000000..57c53d5 --- /dev/null +++ b/cableos/tempfiles/.gitkeep @@ -0,0 +1 @@ +./*