diff --git a/WORKSPACE b/WORKSPACE index 37d4609..fe1531c 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -7,31 +7,3 @@ http_archive( sha256 = "94c634d499558a76fa649edb13721dce6e98fb1e7018dfaeba3cd7a083945e91", build_file = "@//:gtest.BUILD", ) - -## OCI -# see https://github.com/bazel-contrib/rules_oci/releases/tag/v0.3.9 -http_archive( - name = "rules_oci", - sha256 = "f6125c9a123a2ac58fb6b13b4b8d4631827db9cfac025f434bbbefbd97953f7c", - strip_prefix = "rules_oci-0.3.9", - url = "https://github.com/bazel-contrib/rules_oci/releases/download/v0.3.9/rules_oci-v0.3.9.tar.gz", -) - -load("@rules_oci//oci:dependencies.bzl", "rules_oci_dependencies") - -rules_oci_dependencies() - -load("@rules_oci//oci:repositories.bzl", "LATEST_CRANE_VERSION", "LATEST_ZOT_VERSION", "oci_register_toolchains") - -oci_register_toolchains( - name = "oci", - crane_version = LATEST_CRANE_VERSION, - # Uncommenting the zot toolchain will cause it to be used instead of crane for some tasks. - # Note that it does not support docker-format images. - # zot_version = LATEST_ZOT_VERSION, -) - -# Optional, for oci_tarball rule -load("@rules_pkg//:deps.bzl", "rules_pkg_dependencies") - -rules_pkg_dependencies() \ No newline at end of file diff --git a/packer/README.md b/packer/README.md index b6d8cfc..84210db 100644 --- a/packer/README.md +++ b/packer/README.md @@ -3,6 +3,12 @@ This directory contains the tooling to build raspberry pi images using packer. +- `install-packer.sh` will set up packer and packer-builder-arm. It will + also install additional dependencies assuming a Debian-ish system. This + is mostly intended for use in containers, as my Ansible config should + cover this for hardware. +- `run-docker.sh` runs the builder in Docker. + ### Resources diff --git a/packer/build-image.sh b/packer/build-image.sh new file mode 100644 index 0000000..ff029a8 --- /dev/null +++ b/packer/build-image.sh @@ -0,0 +1,37 @@ +#!/usr/bin/env bash + +set -euxo pipefail + +IMAGE_TYPE="${1:-ubuntu}" +PACKER_BUILD_FILE= + +errmsg () { + echo "$@" > /dev/stderr +} + +preflight () { + case "${IMAGE_TYPE}" in + ubuntu) PACKER_BUILD_FILE="boards/raspberry-pi-4/ubuntu_server_20.04_arm64.json" ;; + raspbian) PACKER_BUILD_FILE="boards/raspberry-pi/raspios-lite-arm.json" ;; + custom) + PACKER_BUILD_FILE="${2:-}" + if [ -z "${PACKER_BUILD_FILE}" ] + then + errmsg "[!] custom board requires a board file path" + exit 1 + fi + ;; + *) + errmsg "[!] invalid image type ${IMAGE_TYPE}." + errmsg "[!] valid image types are" + errmsg " - raspbian" + errmsg " - ubuntu" + errmsg " - custom path/to/board/file" + exit 1 + ;; + esac +} + +build_image () { + packer build ${PACKER_BUILD_FILE} +} \ No newline at end of file diff --git a/packer/run-docker.sh b/packer/run-docker.sh index b85f442..9438c48 100755 --- a/packer/run-docker.sh +++ b/packer/run-docker.sh @@ -2,46 +2,18 @@ set -euxo pipefail -IMAGE_TYPE="${1:-ubuntu}" PACKER_IMAGE_NAME="bladerunner/packer:latest" -PACKER_BUILD_FILE= - -errmsg () { - echo "$@" > /dev/stderr -} preflight () { - case "${IMAGE_TYPE}" in - ubuntu) PACKER_BUILD_FILE="boards/raspberry-pi-4/ubuntu_server_20.04_arm64.json" ;; - raspbian) PACKER_BUILD_FILE="boards/raspberry-pi/raspios-lite-arm.json" ;; - custom) - PACKER_BUILD_FILE="${2:-}" - if [ -z "${PACKER_BUILD_FILE}" ] - then - errmsg "[!] custom board requires a board file path" - exit 1 - fi - ;; - *) - errmsg "[!] invalid image type ${IMAGE_TYPE}." - errmsg "[!] valid image types are" - errmsg " - raspbian" - errmsg " - ubuntu" - errmsg " - custom path/to/board/file" - exit 1 - ;; - esac - if [ -z "$(docker image ls -q ${PACKER_IMAGE_NAME})" ] then docker image build -t "${PACKER_IMAGE_NAME}" . fi - } run_image () { # privileged is required for loopback devices - docker run --privileged=true -i -t -v build:/packer/build -v /dev:/dev ${PACKER_IMAGE_NAME} -c "packer build ${PACKER_BUILD_FILE}" + docker run --privileged=true -i -t -v build:/packer/build -v /dev:/dev ${PACKER_IMAGE_NAME} -c "./build-image.sh" } preflight