diff --git a/docs/packer.rst b/docs/packer.rst index 85db862..20b9820 100644 --- a/docs/packer.rst +++ b/docs/packer.rst @@ -14,7 +14,7 @@ The first time, make sure dependencies are installed and run ``./install-packer. .. code-block:: shell - bazel run //packer:ubuntu-board-gen -f $(pwd)/ubuntu-boards.yml -o $(pwd)/boards + bazel run -- //packer:ubuntu-board-gen -f $(pwd)/ubuntu-boards.yml -o $(pwd)/boards This will place the board with a default name in the ``boards`` directory. diff --git a/packer/BUILD.bazel b/packer/BUILD.bazel index 2139a7e..db9d093 100644 --- a/packer/BUILD.bazel +++ b/packer/BUILD.bazel @@ -1,4 +1,4 @@ -load("@io_bazel_rules_go//go:def.bzl", "go_binary") +load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library") #go_library( # name = "packer_lib", @@ -13,9 +13,16 @@ load("@io_bazel_rules_go//go:def.bzl", "go_binary") go_binary( name = "ubuntu-board-gen", - srcs = ["ubuntu-board-gen.go"], + embed = [":packer_lib"], importpath = "git.wntrmute.dev/kyle/bladerunner/packer", visibility = ["//visibility:public"], +) + +go_library( + name = "packer_lib", + srcs = ["ubuntu-board-gen.go"], + importpath = "git.wntrmute.dev/kyle/bladerunner/packer", + visibility = ["//visibility:private"], deps = [ "//packer/packerlib", "@ht_sr_git_kisom_goutils//die", diff --git a/packer/boards/cm4-cluster-ubuntu-22.04.2.img.json b/packer/boards/cm4-cluster-ubuntu-22.04.2.img.json deleted file mode 100644 index 72a52de..0000000 --- a/packer/boards/cm4-cluster-ubuntu-22.04.2.img.json +++ /dev/null @@ -1,54 +0,0 @@ -{ - "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/boards/cm4-cluster-ubuntu-22.04.2.json b/packer/boards/cm4-cluster-ubuntu-22.04.2.json deleted file mode 100644 index 72a52de..0000000 --- a/packer/boards/cm4-cluster-ubuntu-22.04.2.json +++ /dev/null @@ -1,54 +0,0 @@ -{ - "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 8307042..4bdc6d5 100755 --- a/packer/build-image.sh +++ b/packer/build-image.sh @@ -15,17 +15,17 @@ IMAGE_TYPE="${1:-ubuntu}" preflight () { case "${IMAGE_TYPE}" in ubuntu) - PACKER_BUILD_FILE="boards/pi-cm4-ubuntu-22.04.2.json" ;; + PACKER_BUILD_FILE="boards/cm4-cluster-ubuntu-22.04.2.json" if [ "${SKIP_LOCAL_CACHE}" != "yes" ] then - REMOTE_IMAGE_URL="$(jq '.builders[0].file_urls' boards/pi-cm4-ubuntu-22.04.2.json | grep https | tr -d ' \"')" + REMOTE_IMAGE_URL="$(jq '.builders[0].file_urls' ${PACKER_BUILD_FILE} | grep https | tr -d ' \",')" fi - + ;; custom) PACKER_BUILD_FILE="${2:-}" if [ "${SKIP_LOCAL_CACHE}" != "yes" ] then - REMOTE_IMAGE_URL="$(jq '.builders[0].file_urls' ${PACKER_BUILD_FILE} | grep https | tr -d ' \"')" + REMOTE_IMAGE_URL="$(jq '.builders[0].file_urls' ${PACKER_BUILD_FILE} | grep https | tr -d ' \",')" fi if [ -z "${PACKER_BUILD_FILE}" ] @@ -45,20 +45,20 @@ preflight () { } cache_remote_url () { - if [ "${SKIP_LOCAL_CACHE}" != "yes" ] + if [ "${SKIP_LOCAL_CACHE}" = "yes" ] then echo "[+] skipping fetch of remote file: SKIP_LOCAL_CACHE=yes" return 0 fi - local CACHED_FILE="$(jq '.builders[0].file_urls' boards/pi-cm4-ubuntu-22.04.2.json | grep -v https | tr -d ' \"')" + local CACHED_FILE="$(jq '.builders[0].file_urls' ${PACKER_BUILD_FILE} | grep -v https | grep \" | tr -d ' \",')" if [ -z "${CACHED_FILE}" ] then echo "[+] skipping fetch of remote file: no local file provided" return 0 fi - if [ -z "${REMOTE_URL}" ] + if [ -z "${REMOTE_IMAGE_URL}" ] then echo "[+] skipping fetch of remote file: no remote file provided" return 0 @@ -73,7 +73,7 @@ cache_remote_url () { return 0 fi - curl -fsSL -o "${CACHED_FILE}" "${REMOTE_URL}" + curl -fsSL -o "${CACHED_FILE}" "${REMOTE_IMAGE_URL}" } build_image () { diff --git a/packer/install-packer.sh b/packer/install-packer.sh index be989e3..8296415 100755 --- a/packer/install-packer.sh +++ b/packer/install-packer.sh @@ -35,10 +35,14 @@ install_packer () { install_packer_builder_arm () { if [ -x "${INSTALL_DIR}/packer-builder-arm" -a -z "${UPGRADE}" ] then - return 0 + return 0 + fi + + if [ ! -d "${UPSTREAM##*/}" ] + then + git clone "${UPSTREAM}" fi - git clone "${UPSTREAM}" pushd "${UPSTREAM##*/}" go mod download go build diff --git a/packer/packerlib/BUILD.bazel b/packer/packerlib/BUILD.bazel index e0df3b9..bfdefcf 100644 --- a/packer/packerlib/BUILD.bazel +++ b/packer/packerlib/BUILD.bazel @@ -1,4 +1,4 @@ -load("@io_bazel_rules_go//go:def.bzl", "go_library") +load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test") go_library( name = "packerlib", @@ -13,3 +13,9 @@ go_library( visibility = ["//visibility:public"], deps = ["@in_gopkg_yaml_v2//:yaml_v2"], ) + +go_test( + name = "packerlib_test", + srcs = ["ubuntu_test.go"], + embed = [":packerlib"], +) diff --git a/packer/packerlib/ubuntu.go b/packer/packerlib/ubuntu.go index 4facbdd..dee5eb7 100644 --- a/packer/packerlib/ubuntu.go +++ b/packer/packerlib/ubuntu.go @@ -61,7 +61,6 @@ func (spec UbuntuBoardSpec) JSONPath(base string) string { dest := spec.ImageName ext := filepath.Ext(dest) if ext != "" { - ext = "." + ext dest = strings.TrimSuffix(dest, ext) }