From 44589f3466116165cb6ff1a1067d8bb0f77a8bed Mon Sep 17 00:00:00 2001 From: Caleb White Date: Tue, 3 Oct 2023 09:20:57 -0500 Subject: [PATCH] Add local Docker build option --- Dockerfile | 24 ++++++++++++++++++++++++ Makefile | 21 +++++++++++++++++++++ bin/build.sh | 40 ++++++++++++++++++++++++++++++++++++++++ firmware/.gitignore | 2 ++ 4 files changed, 87 insertions(+) create mode 100644 Dockerfile create mode 100644 Makefile create mode 100755 bin/build.sh create mode 100644 firmware/.gitignore diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..e4d48b6 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,24 @@ +FROM docker.io/zmkfirmware/zmk-build-arm:stable + +RUN apt-get update \ + && apt-get install -y wget \ + && wget https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64 -O /usr/bin/yq \ + && chmod +x /usr/bin/yq + +ARG USER_ID=1000 + +RUN adduser --disabled-password --gecos '' --uid ${USER_ID} zmk + +USER zmk + +WORKDIR /app + +COPY config/west.yml config/west.yml + +RUN west init -l config \ + && west update \ + && west zephyr-export + +COPY bin/build.sh ./ + +CMD ["./build.sh"] diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..24a8415 --- /dev/null +++ b/Makefile @@ -0,0 +1,21 @@ +DOCKER := $(shell { command -v podman || command -v docker; }) + +.PHONY: all clean distclean + +all: + $(DOCKER) build --tag zmk --build-arg USER_ID=$(shell id -u) . + $(DOCKER) volume create build + $(DOCKER) run --rm -it --name zmk \ + -v build:/app \ + -v $(PWD)/build.yaml:/app/build.yaml:ro \ + -v $(PWD)/config:/app/config:ro \ + -v $(PWD)/firmware:/app/firmware \ + -e OUTPUT_ZMK_CONFIG=$(OUTPUT_ZMK_CONFIG) \ + zmk + +clean: + rm -rf firmware/[^.]* + -$(DOCKER) volume rm build config firmware + +distclean: clean + -$(DOCKER) image rm zmk diff --git a/bin/build.sh b/bin/build.sh new file mode 100755 index 0000000..fb0bc9c --- /dev/null +++ b/bin/build.sh @@ -0,0 +1,40 @@ +#!/usr/bin/env bash + +config_dir="${PWD}/config" +timestamp=$(date -u +"%Y%m%d%H%M%S") + +while IFS=$',' read -r board shield; do + extra_cmake_args=${shield:+-DSHIELD="$shield"} + artifact_name=${shield:+${shield// /-}-}${board}-zmk + filename="firmware/${timestamp}-${artifact_name}" + build_dir="build/${artifact_name}" + + echo "" + echo "-----------------" + echo "BUILDING FIRMWARE" + echo "-----------------" + echo "Zephyr: ${ZEPHYR_VERSION}" + echo "Board: ${board}" + echo "Shield: ${shield}" + echo "" + + if [[ ! -d "$build_dir" ]]; then + west build -s zmk/app -b "$board" -d ${build_dir} -- \ + -DZMK_CONFIG="$config_dir" "${extra_cmake_args}" + else + west build -d ${build_dir} -- -DZMK_CONFIG="$config_dir" + fi + + if [[ ! -z $OUTPUT_ZMK_CONFIG ]]; then + grep -v -e "^#" -e "^$" ${build_dir}/zephyr/.config \ + | sort > "${filename}.config" + fi + + cp ${build_dir}/zephyr/zmk.uf2 "${filename}.uf2" +done < <(yq ' + [{"board": .board[], "shield": .shield[] // ""}] + .include + | filter(.board) + | unique_by(.board + .shield).[] + | [.board, .shield // ""] + | @csv +' build.yaml) diff --git a/firmware/.gitignore b/firmware/.gitignore new file mode 100644 index 0000000..d6b7ef3 --- /dev/null +++ b/firmware/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore