Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reusable Docker image #29

Merged
merged 8 commits into from
Oct 23, 2022
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
FROM zmkfirmware/zmk-build-arm:2.4
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to apply #25 for v2 branch

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same, i just omitted it here since there's an open PR for it.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pr has since been merged btw


RUN mkdir -p /app/firmware

WORKDIR /app

COPY config/west.yml config/west.yml
Expand All @@ -13,7 +11,6 @@ RUN west update
# West Zephyr export
RUN west zephyr-export
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be out-of-scope, and I'm not familiar with west, but might it make sense to not have these as multiple layers1? Only bringing up since this is about improving the image building process.

Footnotes

  1. Hadolint DL3059

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, interesting. I combined these RUN lines but it did not make a difference in the image size; apparently it isn't doing too much in the way of transient files? I also don't know enough about west to say which of those commands are likely to bust the layer cache, so I'm inclined to keep them individually cache-able.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ha, my very next run demonstrated this in action:

 => CACHED [4/7] RUN west init -l config
 => [5/7] RUN west update

The rule you linked to makes the tradeoff clear and I'm ok optimizing for speed in this case.

Putting easy cacheable and non-cacheable commands in the same layer (by using one RUN command) might have negative performance issues.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

O sorry, it shouldn't do anything for the size/speed, should just effect the layers that Docker generates. I was thinking it may be a case similar to https://docs.docker.com/develop/develop-images/dockerfile_best-practices/#apt-get (with subcommands like init and update).
Can avoid issues where earlier stages succeed & cached, resulting in later stages to have a(n) inconsistent/un-reproducible/non-updating state. I.e. they're actually coupled stages and should be apart of the same RUN


COPY config config
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 @@
.PHONY: clean timestamp setup

all: setup build

build: timestamp firmware/$$(TIMESTAMP)-left.uf2 firmware/$$(TIMESTAMP)-right.uf2

clean:
rm ./firmware/*.uf2

firmware/%-left.uf2 firmware/%-right.uf2: config/adv360.keymap timestamp
docker run --rm -it --name zmk \
-v $(PWD)/firmware:/app/firmware \
-v $(PWD)/config:/app/config:ro \
-e TIMESTAMP=$(TIMESTAMP) \
zmk

setup:
docker build --tag zmk .
joshfrench marked this conversation as resolved.
Show resolved Hide resolved

timestamp:
$(eval TIMESTAMP:=$(shell date -u +"%Y%m%d%H%M%S"))
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,16 @@

## To build Firmware locally using Docker

### Setup
### First run

1. Execute `setup.sh`.
1. Execute `make all`.
2. Check the `firmware` directory for the latest firmware build.

### Build firmware
### Subsequent runs

1. Execute `run.sh`
2. Check the `firmware` directory for the latest firmware build.
If the only file you have changed is `config/adv360.keymap`, execute `make build` and check the `firmware` directory for the latest firmware build.

If you have changed other files in the `config` directory (such as `config/west.yml`) you will need to execute `make all` to rebuild the Docker image as well as the firmware.

### Flash firmware

Expand Down
4 changes: 2 additions & 2 deletions bin/build.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#!/usr/bin/env bash

set -e
set -eu

PWD=$(pwd)
TIMESTAMP=$(date -u +"%Y%m%d%H%M%S")
TIMESTAMP="${TIMESTAMP:-$(date -u +"%Y%m%d%H%M%S")}"

# West Build (left)
west build -s zmk/app -d build/left -b adv360_left -- -DZMK_CONFIG="${PWD}/config"
Expand Down
8 changes: 0 additions & 8 deletions run.sh

This file was deleted.

5 changes: 0 additions & 5 deletions setup.sh

This file was deleted.