Skip to content

Commit

Permalink
Add local Docker build option
Browse files Browse the repository at this point in the history
  • Loading branch information
calebdw committed Oct 3, 2023
1 parent 9a67b25 commit 44589f3
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 0 deletions.
24 changes: 24 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
21 changes: 21 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
40 changes: 40 additions & 0 deletions bin/build.sh
Original file line number Diff line number Diff line change
@@ -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)
2 changes: 2 additions & 0 deletions firmware/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*
!.gitignore

0 comments on commit 44589f3

Please sign in to comment.