From 262f82aa640c90f33084a3cd8f84c7af3b1efeb2 Mon Sep 17 00:00:00 2001 From: Kyle Isom Date: Wed, 12 Apr 2023 05:15:34 +0000 Subject: [PATCH] Move source to packer, add board spec. --- .../ubuntu-board-gen => packer}/BUILD.bazel | 10 ++-- packer/boards/cm4-cluster-ubuntu-22.04.2.json | 54 +++++++++++++++++++ packer/build-image.sh | 2 +- {src/packer => packer/packerlib}/BUILD.bazel | 4 +- {src/packer => packer/packerlib}/board.go | 2 +- {src/packer => packer/packerlib}/builder.go | 2 +- packer/packerlib/packer.go | 3 ++ .../packerlib}/provisioner.go | 2 +- {src/packer => packer/packerlib}/ubuntu.go | 4 +- packer/scripts/install-base.sh | 1 + .../main.go => packer/ubuntu-board-gen.go | 2 +- src/packer/packer.go | 3 -- 12 files changed, 72 insertions(+), 17 deletions(-) rename {src/cmd/ubuntu-board-gen => packer}/BUILD.bazel (57%) create mode 100644 packer/boards/cm4-cluster-ubuntu-22.04.2.json rename {src/packer => packer/packerlib}/BUILD.bazel (74%) rename {src/packer => packer/packerlib}/board.go (93%) rename {src/packer => packer/packerlib}/builder.go (99%) create mode 100644 packer/packerlib/packer.go rename {src/packer => packer/packerlib}/provisioner.go (99%) rename {src/packer => packer/packerlib}/ubuntu.go (98%) rename src/cmd/ubuntu-board-gen/main.go => packer/ubuntu-board-gen.go (87%) delete mode 100644 src/packer/packer.go diff --git a/src/cmd/ubuntu-board-gen/BUILD.bazel b/packer/BUILD.bazel similarity index 57% rename from src/cmd/ubuntu-board-gen/BUILD.bazel rename to packer/BUILD.bazel index 0e84234..54dcdb3 100644 --- a/src/cmd/ubuntu-board-gen/BUILD.bazel +++ b/packer/BUILD.bazel @@ -1,18 +1,18 @@ load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library") go_library( - name = "ubuntu-board-gen_lib", - srcs = ["main.go"], - importpath = "git.wntrmute.dev/kyle/bladerunner/src/cmd/ubuntu-board-gen", + name = "packer_lib", + srcs = ["ubuntu-board-gen.go"], + importpath = "git.wntrmute.dev/kyle/bladerunner/packer", visibility = ["//visibility:private"], deps = [ - "//src/packer", + "//packer/packerlib", "@ht_sr_git_kisom_goutils//die", ], ) go_binary( name = "ubuntu-board-gen", - embed = [":ubuntu-board-gen_lib"], + embed = [":packer_lib"], visibility = ["//visibility:public"], ) diff --git a/packer/boards/cm4-cluster-ubuntu-22.04.2.json b/packer/boards/cm4-cluster-ubuntu-22.04.2.json new file mode 100644 index 0000000..72a52de --- /dev/null +++ b/packer/boards/cm4-cluster-ubuntu-22.04.2.json @@ -0,0 +1,54 @@ +{ + "variables": {}, + "builders": [ + { + "type": "arm", + "file_urls": [ + "build/ubuntu-22.04.2-preinstalled-server-arm64+raspi.img.xz", + "https://cdimage.ubuntu.com/releases/22.04.2/release/ubuntu-22.04.2-preinstalled-server-arm64+raspi.img.xz" + ], + "file_checksum_url": "http://cdimage.ubuntu.com/releases/22.04.2/release/SHA256SUMS", + "file_checksum_type": "sha256", + "file_target_extension": "xz", + "file_unarchive_cmd": [ + "xz", + "--decompress", + "$ARCHIVE_PATH" + ], + "image_build_method": "reuse", + "image_path": "build/cm4-cluster-ubuntu-22.04.2.img", + "image_size": "32G", + "image_type": "dos", + "image_partitions": [ + { + "name": "boot", + "type": "c", + "start_sector": 2048, + "size": "256M", + "mountpoint": "/boot/firmware" + }, + { + "name": "root", + "type": "83", + "start_sector": 526336, + "size": "31.7G", + "mountpoint": "/" + } + ], + "image_chroot_env": [ + "PATH=/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin" + ], + "qemu_binary_source_path": "/usr/bin/qemu-aarch64-static", + "qemu_binary_destination_path": "/usr/bin/qemu-aarch64-static" + } + ], + "provisioners": [ + { + "scripts": [ + "scripts/install-base.sh" + ], + "type": "shell" + } + ], + "post-processors": null +} \ No newline at end of file diff --git a/packer/build-image.sh b/packer/build-image.sh index 6dd0cd2..6d0aff2 100755 --- a/packer/build-image.sh +++ b/packer/build-image.sh @@ -11,7 +11,7 @@ errmsg () { preflight () { case "${IMAGE_TYPE}" in - ubuntu) PACKER_BUILD_FILE="boards/pi-cm4-ubuntu-22.04.2.json" ;; + ubuntu) PACKER_BUILD_FILE="boards/cm4-cluster-ubuntu-22.04.2.json" ;; raspbian) PACKER_BUILD_FILE="boards/raspberry-pi/raspios-lite-arm.json" ;; custom) if [ -z "${PACKER_BUILD_FILE}" ] diff --git a/src/packer/BUILD.bazel b/packer/packerlib/BUILD.bazel similarity index 74% rename from src/packer/BUILD.bazel rename to packer/packerlib/BUILD.bazel index 65b4649..e0df3b9 100644 --- a/src/packer/BUILD.bazel +++ b/packer/packerlib/BUILD.bazel @@ -1,7 +1,7 @@ load("@io_bazel_rules_go//go:def.bzl", "go_library") go_library( - name = "packer", + name = "packerlib", srcs = [ "board.go", "builder.go", @@ -9,7 +9,7 @@ go_library( "provisioner.go", "ubuntu.go", ], - importpath = "git.wntrmute.dev/kyle/bladerunner/src/packer", + importpath = "git.wntrmute.dev/kyle/bladerunner/packer/packerlib", visibility = ["//visibility:public"], deps = ["@in_gopkg_yaml_v2//:yaml_v2"], ) diff --git a/src/packer/board.go b/packer/packerlib/board.go similarity index 93% rename from src/packer/board.go rename to packer/packerlib/board.go index a2e03a9..6bdcfab 100644 --- a/src/packer/board.go +++ b/packer/packerlib/board.go @@ -1,4 +1,4 @@ -package packer +package packerlib type Board struct { Variables map[string]string `json:"variables"` diff --git a/src/packer/builder.go b/packer/packerlib/builder.go similarity index 99% rename from src/packer/builder.go rename to packer/packerlib/builder.go index 61d32ed..18ebc77 100644 --- a/src/packer/builder.go +++ b/packer/packerlib/builder.go @@ -1,4 +1,4 @@ -package packer +package packerlib // RootPartitionSizes describes how big a single root partition should // be given a standard 256M boot partition. This should cover standard diff --git a/packer/packerlib/packer.go b/packer/packerlib/packer.go new file mode 100644 index 0000000..114b2ba --- /dev/null +++ b/packer/packerlib/packer.go @@ -0,0 +1,3 @@ +// Package packerlib contains utilities for interacting with Packer +// in the context of building images for the computeblade cluster. +package packerlib diff --git a/src/packer/provisioner.go b/packer/packerlib/provisioner.go similarity index 99% rename from src/packer/provisioner.go rename to packer/packerlib/provisioner.go index e15b095..58ad251 100644 --- a/src/packer/provisioner.go +++ b/packer/packerlib/provisioner.go @@ -1,4 +1,4 @@ -package packer +package packerlib type Provisioner map[string]interface{} diff --git a/src/packer/ubuntu.go b/packer/packerlib/ubuntu.go similarity index 98% rename from src/packer/ubuntu.go rename to packer/packerlib/ubuntu.go index 67f0ee4..4facbdd 100644 --- a/src/packer/ubuntu.go +++ b/packer/packerlib/ubuntu.go @@ -1,4 +1,4 @@ -package packer +package packerlib import ( "bytes" @@ -96,7 +96,7 @@ func (spec UbuntuBoardSpec) Board() Board { } func LoadUbuntuSpecs(path string) (specFile UbuntuBoardSpecFile, err error) { - log.Println("loading from", specFile) + log.Println("loading from", path) data, err := ioutil.ReadFile(path) if err != nil { return diff --git a/packer/scripts/install-base.sh b/packer/scripts/install-base.sh index 407c673..08e4534 100755 --- a/packer/scripts/install-base.sh +++ b/packer/scripts/install-base.sh @@ -3,6 +3,7 @@ set -euxo pipefail echo "==> Setting nameserver" +rm /etc/resolv.conf echo 'nameserver 8.8.8.8' > /etc/resolv.conf echo "==> installing base updates" diff --git a/src/cmd/ubuntu-board-gen/main.go b/packer/ubuntu-board-gen.go similarity index 87% rename from src/cmd/ubuntu-board-gen/main.go rename to packer/ubuntu-board-gen.go index 8ae4cd4..a664723 100644 --- a/src/cmd/ubuntu-board-gen/main.go +++ b/packer/ubuntu-board-gen.go @@ -4,7 +4,7 @@ import ( "flag" "git.sr.ht/~kisom/goutils/die" - "git.wntrmute.dev/kyle/bladerunner/src/packer" + packer "git.wntrmute.dev/kyle/bladerunner/packer/packerlib" ) func main() { diff --git a/src/packer/packer.go b/src/packer/packer.go deleted file mode 100644 index eca0443..0000000 --- a/src/packer/packer.go +++ /dev/null @@ -1,3 +0,0 @@ -// Package packer contains utilities for interacting with Packer -// in the context of building images for the computeblade cluster. -package packer