-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rename files and directory names to work with MAAS script vars, updat…
…es / additions to makefile and packer scripts
- Loading branch information
Showing
10 changed files
with
446 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'" | ||
|
||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 '[email protected]/[email protected]/debian@g;s@archive@deb@g;s@ubuntu@debian@g;s@Ubuntu@Debian@g;[email protected]/[email protected]@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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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/ |
File renamed without changes.
Oops, something went wrong.