packer: fix build scripts, packerlib update.

There were some hardcoded values left in there, and the remote caching
wasn't working right.

The ubuntu-board-gen tool now produces the right output file
name.
This commit is contained in:
Kyle Isom 2023-04-12 12:50:11 -07:00
parent 91a631ef4f
commit be216aefe5
8 changed files with 31 additions and 123 deletions

View File

@ -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.

View File

@ -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",

View File

@ -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
}

View File

@ -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
}

View File

@ -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 () {

View File

@ -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

View File

@ -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"],
)

View File

@ -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)
}