Skip to content

Commit d546061

Browse files
committed
chore(ci): split Dockerfile into dev/builder/runtime stages
Rebuilding the full image on every code change is slow. A reusable dev stage lets you iterate on build/test/develop without repeating setup. The project is not supported on Debian Trixie, therefore the dev container is useful to use Debian Bookworm. Relate-to: UIC-3673
1 parent 0063214 commit d546061

2 files changed

Lines changed: 53 additions & 25 deletions

File tree

Dockerfile

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
# SPDX-License-Identifier: Zlib
22
# SPDX-FileCopyrightText: Silicon Laboratories Inc. https://www.silabs.com
33

4-
FROM debian:bookworm AS builder
4+
FROM debian:bookworm AS dev
55

6-
ARG UNIFYSDK_GIT_REPOSITORY https://github.com/SiliconLabs/UnifySDK
7-
ARG UNIFYSDK_GIT_TAG main
6+
ARG UNIFYSDK_GIT_REPOSITORY=https://github.com/SiliconLabs/UnifySDK
7+
ARG UNIFYSDK_GIT_TAG=main
8+
ENV UNIFYSDK_GIT_REPOSITORY=${UNIFYSDK_GIT_REPOSITORY} \
9+
UNIFYSDK_GIT_TAG=${UNIFYSDK_GIT_TAG}
810

911
ENV project z-wave-protocol-controller
1012
ENV workdir /usr/local/opt/${project}
@@ -13,6 +15,8 @@ ADD . ${workdir}
1315
ARG HELPER="./helper.mk"
1416
ARG HELPER_SETUP_RULES=setup
1517
ARG HELPER_DEFAULT_RULES=default
18+
ENV HELPER=${HELPER} \
19+
HELPER_DEFAULT_RULES=${HELPER_DEFAULT_RULES}
1620

1721
WORKDIR ${workdir}
1822

@@ -23,7 +27,10 @@ RUN echo "# log: Setup system" \
2327
&& apt-get install -y --no-install-recommends -- make sudo \
2428
&& ${HELPER} help ${HELPER_SETUP_RULES} \
2529
&& date -u
30+
ENTRYPOINT [ "/usr/bin/bash" ]
31+
CMD []
2632

33+
FROM dev AS builder
2734
RUN echo "# log: Build" \
2835
&& set -x \
2936
&& ${HELPER} ${HELPER_DEFAULT_RULES} \
@@ -36,7 +43,7 @@ RUN echo "# log: Build" \
3643
&& ${HELPER} distclean \
3744
&& date -u
3845

39-
FROM debian:bookworm
46+
FROM debian:bookworm AS runtime
4047
ENV project=z-wave-protocol-controller
4148
ARG workdir=/usr/local/opt/${project}
4249
COPY --from=builder ${workdir}/dist/ ${workdir}/dist/

README.md

Lines changed: 42 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,47 @@ Or relevant sources pages, to get started head to:
2323

2424
## Quickstart
2525

26+
### Docker build
27+
28+
The fastest (less than 20min) way to build z-wave-protocol-controller from scratch
29+
is to delegate all tasks to docker. The final image will contain the binaries that
30+
you can use.
31+
32+
```sh
33+
docker build https://github.com/SiliconLabsSoftware/z-wave-protocol-controller.git#ver_1.7.0
34+
```
35+
36+
This one-liner will do download latest release, setup environment, build, test, package...
37+
38+
Also a docker-compose file is provided to start ZPC and use it along a MQTT client
39+
(eg:
40+
[mosquitto-clients](https://github.com/eclipse-mosquitto/mosquitto/)
41+
).
42+
43+
### Docker development
44+
45+
The project Dockerfile has three stages: `dev` (setup only, for interactive
46+
use), `builder` (full build and package), and `runtime` (minimal runnable
47+
image). To work iteratively in a container with your host source bind-mounted
48+
(e.g., build and run ctest without rebuilding the image each time):
49+
50+
```sh
51+
# Build the dev stage
52+
docker build --target dev -t z-wave-protocol-controller:dev .
53+
54+
# Run a shell with your source mounted
55+
docker run -it --rm -v "$PWD:/usr/local/opt/z-wave-protocol-controller" -w /usr/local/opt/z-wave-protocol-controller z-wave-protocol-controller:dev
56+
57+
# Inside the container: build and run unit tests
58+
./helper.mk default
59+
60+
# Run unit tests
61+
ctest --test-dir build/applications --output-on-failure
62+
```
63+
64+
Power users might prefer to work in sources tree in a native GNU/Linux
65+
environment as explained below.
66+
2667
### Native (Linux) build
2768

2869
The project is CMake based, to prepare the environment,
@@ -136,7 +177,7 @@ You can use this [script](./scripts/wslusb.ps1).
136177
Start by installing the usbipd service as described at: https://learn.microsoft.com/en-us/windows/wsl/connect-usb
137178

138179
```sh
139-
# You can list devices using:
180+
# You can list devices using:
140181

141182
(Powershell)$ ./wslusb.ps1 -List
142183

@@ -157,26 +198,6 @@ Start by installing the usbipd service as described at: https://learn.microsoft.
157198

158199
Refer to [./doc](doc) for more (using shell, MQTT, WebApp etc).
159200

160-
161-
### Docker build
162-
163-
The fastest (less than 20min) way to build z-wave-protocol-controller from scratch
164-
is to delegate all tasks to docker.
165-
166-
```sh
167-
docker build https://github.com/SiliconLabsSoftware/z-wave-protocol-controller.git#ver_1.7.0
168-
```
169-
170-
This one-liner will do download latest release, setup environment, build, test, package...
171-
172-
Also a docker-compose file is provided to start ZPC and use it along a MQTT client
173-
(eg:
174-
[mosquitto-clients](https://github.com/eclipse-mosquitto/mosquitto/)
175-
).
176-
177-
Power users might prefer to work in sources tree in a native GNU/Linux
178-
environment as explained above.
179-
180201
## Contributing
181202

182203
- [CONTRIBUTING.md](CONTRIBUTING.md)

0 commit comments

Comments
 (0)