2020-08-19 16:01:01 +02:00
# Build the project using Docker
2020-12-18 18:58:34 +01:00
2022-12-06 10:51:40 +01:00
A [Docker image (Dockerfile) ](../docker ) containing all the build environment is available for X86_64 and ARM64 architectures.
2022-05-25 15:12:16 +02:00
These images make the build of the firmware and the generation of the DFU file for OTA quite easy, as well as preventing clashes with any other toolchains or development environments you may have installed.
2020-08-19 16:01:01 +02:00
2022-05-23 19:39:10 +02:00
Based on Ubuntu 22.04 with the following build dependencies:
2020-12-13 00:50:20 +01:00
2022-08-21 13:50:09 +02:00
- ARM GCC Toolchain
- nRF SDK
- MCUBoot
- adafruit-nrfutil
- lv_font_conv
2020-12-13 00:50:20 +01:00
2020-12-18 18:58:34 +01:00
## Run a container to build the project
2022-08-21 13:50:09 +02:00
The `infinitime-build` image contains all the dependencies you need.
2022-05-25 15:12:16 +02:00
The default `CMD` will compile sources found in `/sources` , so you need only mount your code.
2021-10-17 00:10:36 +02:00
Before continuing, make sure you first build the image as indicated in the [Build the image ](#build-the-image ) section, or check the [Using the image from Docker Hub ](#using-the-image-from-docker-hub ) section if you prefer to use a pre-made image.
2020-12-13 00:50:20 +01:00
2022-08-21 13:50:09 +02:00
This example will build the firmware, generate the MCUBoot image and generate the DFU file.
2022-05-25 15:12:16 +02:00
For cloning the repo, see [these instructions ](../doc/buildAndProgram.md#clone-the-repo ). Outputs will be written to ** < project_root > /build/output**:
2020-12-13 00:50:20 +01:00
2020-12-17 14:12:06 +01:00
```bash
2020-12-18 18:58:34 +01:00
cd < project_root > # e.g. cd ./work/Pinetime
2022-05-25 15:12:16 +02:00
docker run --rm -it -v ${PWD}:/sources --user $(id -u):$(id -g) infinitime-build
2020-08-19 16:01:01 +02:00
```
2022-08-21 13:50:09 +02:00
By default, the container runs as `root` , which is not convenient as all the files generated by the build will also belong to `root` .
The parameter `--user` overrides that default behavior.
The command above will run as your current user.
2022-05-23 19:39:10 +02:00
2022-08-21 13:50:09 +02:00
If you only want to build a single CMake target, you can pass it in as the first parameter to the build script.
This means calling the script explicitly as it will override the `CMD` .
2022-05-25 15:12:16 +02:00
Here's an example for `pinetime-app` :
2020-08-19 16:01:01 +02:00
2020-12-17 14:12:06 +01:00
```bash
2022-05-25 15:12:16 +02:00
docker run --rm -it -v ${PWD}:/sources --user $(id -u):$(id -g) infinitime-build /opt/build.sh pinetime-app
2020-12-17 14:12:06 +01:00
```
2020-08-19 16:01:01 +02:00
2020-12-18 18:58:34 +01:00
## Using the image from Docker Hub
2022-05-18 21:52:07 +02:00
The image is available via Docker Hub for both the amd64 and arm64v8 architectures at [infinitime/infinitime-build ](https://hub.docker.com/repository/docker/infinitime/infinitime-build ).
2020-12-18 18:58:34 +01:00
2022-05-25 15:12:16 +02:00
You can run it using the following command:
2020-12-13 00:50:20 +01:00
2020-12-17 14:12:06 +01:00
```bash
2022-05-25 15:12:16 +02:00
docker run --rm -it -v ${PWD}:/sources --user $(id -u):$(id -g) infinitime/infinitime-build
2022-05-23 19:39:10 +02:00
```
2020-12-18 18:58:34 +01:00
The default `latest` tag *should* automatically identify the correct image architecture, but if for some reason Docker does not, you can specify it manually:
2022-08-21 13:50:09 +02:00
- For AMD64 (x86_64) systems: `docker pull --platform linux/amd64 infinitime/infinitime-build`
2020-12-18 18:58:34 +01:00
2022-08-21 13:50:09 +02:00
- For ARM64v8 (ARM64/aarch64) systems: `docker pull --platform linux/arm64 infinitime/infinitime-build`
2020-12-18 18:58:34 +01:00
## Build the image
You can build the image yourself if you like!
The following commands must be run from the root of the project. This operation will take some time but, when done, a new image named *infinitime-build* is available.
```bash
2022-05-25 15:12:16 +02:00
docker build -t infinitime-build ./docker
2022-08-21 13:50:09 +02:00
```