Note: keep up to date to the latest improvements and contribute to this project on GitHub.
Getting all dependencies in place to build the sample applications in our SDK can be a challenge, and it requires to install certain version globally in the system, which might not be preferable for everyone.
We can leverage Docker, a containerization tool, to contain the dependencies in a way that they do not affect to local system. The dependencies will be installed inside an image, which only uses disk space and we then can build the firmware inside this image.
Here is an example Dockerfile for use with the current fw-nrfconnect-nrf tree.
Clone the repo:
git clone https://github.com/NordicPlayground/fw-nrfconnect-nrf
Copy the Dockerfile to e.g. /tmp/Dockerfile:
/tmp/Dockerfile
wget https://raw.githubusercontent.com/coderbyheart/fw-nrfconnect-nrf-docker/saga/Dockerfile
Build the Docker image (this will take some time, but is only needed once):
cd fw-nrfconnect-nrf docker build -t ncs -f /tmp/Dockerfile .
Now you can build the sample, and if you change the source code, you can just execute this command again.
docker run --name ncs --rm -v ${PWD}:/workdir/ncs/fw-nrfconnect-nrf ncs /bin/bash -c 'cd ncs/fw-nrfconnect-nrf/applications/asset_tracker; west build -p always -b nrf9160_pca20035ns'
The firmware file will be in applications/asset_tracker/build/zephyr/merged.hex.
applications/asset_tracker/build/zephyr/merged.hex
cd /tmp git clone https://github.com/NordicPlayground/fw-nrfconnect-nrf wget https://raw.githubusercontent.com/coderbyheart/fw-nrfconnect-nrf-docker/saga/Dockerfile cd fw-nrfconnect-nrf docker build -t ncs -f /tmp/Dockerfile . docker run --name ncs --rm -v /tmp/fw-nrfconnect-nrf:/workdir/ncs/fw-nrfconnect-nrf ncs /bin/bash -c 'cd ncs/fw-nrfconnect-nrf/applications/asset_tracker; west build -p always -b nrf9160_pca20035ns' ls -la applications/asset_tracker/build/zephyr/merged.hex
Note: Using a pre-build image is a convenient way to quickly build your firmware but using images from untrusted third-parties poses the risk of exposing your source code.
When using the pre-build docker image, you can skip the `docker build` step and directly run this command in your source folder to build the asset_tracker application:
docker run --name fw-nrfconnect-nrf-docker --rm -v /tmp/fw-nrfconnect-nrf:/workdir/ncs/fw-nrfconnect-nrf coderbyheart/fw-nrfconnect-nrf-docker:latest \ /bin/bash -c 'cd ncs/fw-nrfconnect-nrf/applications/asset_tracker; west build -p always -b nrf9160_pca20035ns'
If you maintain your application outside of the fw-nrfconnect-nrf tree (like we do with the Cat Tracker example in Bifravst), the solution works exactly the same, since west will fetch the dependencies in the same way.
add DFU docker here, https://gitlab.com/ehirdoy/nrfc-api
Thank you Hiroshi, I have merged your PR that adds this feature.
Slightly advanced with 'west flash' called from Docker. No need SDK at all on your local machine ;)$ cat Dockerfile # github.com/.../fw-nrfconnect-nrf-dockerFROM coderbyheart/fw-nrfconnect-nrf-docker:latestRUN cd /tmp && \ wget www.nordicsemi.com/.../nRFCommandLineTools1070Linuxamd64tar.gz && tar xvzf nRFCommandLineTools1070Linuxamd64tar.gz && dpkg -i *.deb$ docker build --network host -t doyu/ncs . && docker push doyu/ncs$ docker run --rm -v ${PWD}:/workdir/ncs/fw-nrfconnect-nrf doyu/ncs /bin/bash -c 'cd ncs/fw-nrfconnect-nrf/applications/asset_tracker; west build -p always -b nrf9160_pca10090ns'$ docker run --privileged --rm --device=/dev/ttyACM0 -v $(pwd):/workdir/ncs/fw-nrfconnect-nrf doyu/ncs /bin/bash -c 'cd ncs/fw-nrfconnect-nrf/applications/asset_tracker; west flash'https://hub.docker.com/repository/docker/doyu/ncs
scaggsp I got this request from another person, so I added an image: https://github.com/coderbyheart/fw-nrfconnect-nrf-docker#using-prebuild-image-from-dockerhub ... or see above.
Thank you for the feedback! Can you tell me how this would improve your workflow? Don't you think this is risky, loading a precompiled image from an untrusted location to compile your firmware?