From 3534b1274fad64157c75b4aeb275c01e1cfda0a7 Mon Sep 17 00:00:00 2001 From: Kyle Isom Date: Mon, 10 Apr 2023 23:02:14 -0700 Subject: [PATCH] ansible skeleton, tweaking packer Docker build. --- ansible/cluster.yml | 6 ++++ ansible/inventory | 34 +++++++++++++++++++++ ansible/roles/base/README.md | 4 +++ ansible/roles/base/tasks/main.yml | 0 ansible/roles/coral/README.md | 4 +++ ansible/roles/coral/tasks/main.yml | 0 packer/Dockerfile | 4 ++- packer/install-packer.sh | 5 ++-- packer/run-docker.sh | 48 ++++++++++++++++++++++++++++++ 9 files changed, 102 insertions(+), 3 deletions(-) create mode 100644 ansible/cluster.yml create mode 100644 ansible/inventory create mode 100644 ansible/roles/base/README.md create mode 100644 ansible/roles/base/tasks/main.yml create mode 100644 ansible/roles/coral/README.md create mode 100644 ansible/roles/coral/tasks/main.yml create mode 100755 packer/run-docker.sh diff --git a/ansible/cluster.yml b/ansible/cluster.yml new file mode 100644 index 0000000..43e8c12 --- /dev/null +++ b/ansible/cluster.yml @@ -0,0 +1,6 @@ +- hosts: cluster + roles: + - base +- hosts: blade-coral + roles: + - coral \ No newline at end of file diff --git a/ansible/inventory b/ansible/inventory new file mode 100644 index 0000000..98b1bdc --- /dev/null +++ b/ansible/inventory @@ -0,0 +1,34 @@ +[blades] +cluster-dev-01 +cluster-dev-02 +cluster-dev-03 +cluster-dev-04 +cluster-dev-05 +cluster-tpm-01 +cluster-tpm-02 +cluster-tpm-03 +cluster-tpm-04 +cluster-tpm-05 + +[blade-dev] +cluster-dev-01 +cluster-dev-02 +cluster-dev-03 +cluster-dev-04 +cluster-dev-05 + +[blade-tpm] +cluster-tpm-01 +cluster-tpm-02 +cluster-tpm-03 +cluster-tpm-04 +cluster-tpm-05 + +# which boards have the Coral TPUs enabled? +[blade-coral] +cluster-dev-04 +cluster-tpm-04 +cluster-tpm-05 + +[cluster-main] +cluster-00 \ No newline at end of file diff --git a/ansible/roles/base/README.md b/ansible/roles/base/README.md new file mode 100644 index 0000000..0b36d40 --- /dev/null +++ b/ansible/roles/base/README.md @@ -0,0 +1,4 @@ +# Role: Base + +The baseline for each board is the bare-minimum tooling that a blade needs to +start up. \ No newline at end of file diff --git a/ansible/roles/base/tasks/main.yml b/ansible/roles/base/tasks/main.yml new file mode 100644 index 0000000..e69de29 diff --git a/ansible/roles/coral/README.md b/ansible/roles/coral/README.md new file mode 100644 index 0000000..6794334 --- /dev/null +++ b/ansible/roles/coral/README.md @@ -0,0 +1,4 @@ +# Role: Coral + +The `coral` blades have a pair of Coral TPUs on them, and need to be setup +appropriately. \ No newline at end of file diff --git a/ansible/roles/coral/tasks/main.yml b/ansible/roles/coral/tasks/main.yml new file mode 100644 index 0000000..e69de29 diff --git a/packer/Dockerfile b/packer/Dockerfile index bc80bd8..7db54c8 100644 --- a/packer/Dockerfile +++ b/packer/Dockerfile @@ -2,12 +2,14 @@ FROM ubuntu:22.04 LABEL org.opencontainers.image.authors=kyle@imap.cc -RUN apt-get update && apt-get -y install git curl sudo +RUN apt-get update && apt-get -y install git curl sudo xz-utils RUN git clone https://git.wntrmute.dev/kyle/bladerunner RUN bladerunner/tools/install-go.sh ADD . packer WORKDIR packer +VOLUME build RUN ./install-packer.sh +WORKDIR build/packer-builder-arm ENTRYPOINT ["/usr/bin/env", "bash"] diff --git a/packer/install-packer.sh b/packer/install-packer.sh index 9492f8c..128971d 100755 --- a/packer/install-packer.sh +++ b/packer/install-packer.sh @@ -8,11 +8,12 @@ ARCH=amd64 PACKER_FILE=packer_${PACKER_VERSION}_linux_${ARCH} UPSTREAM="https://github.com/mkaczanowski/packer-builder-arm" UPGRADE="false" +BUILD_DIR="$(pwd)/build" prep () { sudo apt-get update && sudo apt-get -y install git unzip qemu-user-static e2fsprogs dosfstools 'bsdtar|libarchive-tools' - mkdir -p build - pushd build + mkdir -p ${BUILD_DIR} + pushd ${BUILD_DIR} } install_packer () { diff --git a/packer/run-docker.sh b/packer/run-docker.sh new file mode 100755 index 0000000..b85f442 --- /dev/null +++ b/packer/run-docker.sh @@ -0,0 +1,48 @@ +#!/usr/bin/env bash + +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}" +} + +preflight +run_image