Skip to content

Commit

Permalink
Implement Docker best practices on nRF Connect image (#10937)
Browse files Browse the repository at this point in the history
Some of these best practices are:
* Multi-stage builds
* Pin versions
* Avoid additional packages installation
* Clean all missing after apt command

Signed-off-by: Victor Morales <v.morales@samsung.com>

Co-authored-by: Justin Wood <woody@apple.com>
  • Loading branch information
2 people authored and pull[bot] committed Jun 23, 2023
1 parent 25b1c76 commit 1714612
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 20 deletions.
62 changes: 43 additions & 19 deletions integrations/docker/images/chip-build-nrf-platform/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,44 +1,68 @@
ARG VERSION=latest
FROM connectedhomeip/chip-build:${VERSION}
FROM connectedhomeip/chip-build:${VERSION} as build

# Compatible Nordic Connect SDK revision.
ARG NCS_REVISION=ffcf07fe4586634a6793a48e5444a7196e7ebac6

RUN set -x \
&& apt-get update \
&& apt-get install --no-install-recommends -fy \
curl=7.68.0-1ubuntu2.7 \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/ \
&& : # last line

# ==================================================
# nRF Connect SDK dependencies
# ==================================================

# Tools for building, flashing and accessing device logs
WORKDIR /opt/NordicSemiconductor/nRF5_tools/install
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
RUN set -x \
&& apt-get update \
&& apt-get install --no-install-recommends -fy device-tree-compiler ccache \
&& mkdir -p /opt/NordicSemiconductor/nRF5_tools/ \
&& curl https://www.nordicsemi.com/-/media/Software-and-other-downloads/Desktop-software/nRF-command-line-tools/sw/Versions-10-x-x/10-12-1/nRFCommandLineTools10121Linuxamd64.tar.gz \
| tar zxvf - \
&& cd .. \
&& tar xvf install/JLink_Linux_V688a_x86_64.tgz \
&& tar xvf install/nRF-Command-Line-Tools_10_12_1.tar \
&& rm -rf ./install /var/lib/apt/lists/ \
&& tar xvf JLink_Linux_V688a_x86_64.tgz -C /opt/NordicSemiconductor/nRF5_tools/ \
&& tar xvf nRF-Command-Line-Tools_10_12_1.tar -C /opt/NordicSemiconductor/nRF5_tools/ \
&& : # last line

# ==================================================
# nRF Connect SDK
# ==================================================

WORKDIR /opt/NordicSemiconductor/nrfconnect
RUN set -x \
# python3-yaml package conflicts with nRF Python requirements
&& (apt remove -fy python3-yaml && apt autoremove || exit 0) \
&& python3 -m pip install -U --no-cache-dir pip setuptools wheel cmake west \
&& python3 -m pip install -U --no-cache-dir \
cmake==3.21.2 \
west==0.11.1 \
&& west init -m https://github.com/nrfconnect/sdk-nrf \
&& git -C nrf fetch origin "$NCS_REVISION" \
&& git -C nrf checkout FETCH_HEAD \
&& west config update.narrow true \
&& west config update.fetch smart \
&& west update -o=--depth=1 -n -f smart \
&& python3 -m pip install --no-cache-dir -r zephyr/scripts/requirements.txt \
&& python3 -m pip install --no-cache-dir -r nrf/scripts/requirements.txt \
&& python3 -m pip install --no-cache-dir -r bootloader/mcuboot/scripts/requirements.txt \
&& : # last line

FROM connectedhomeip/chip-build:${VERSION}

# Tools for building, flashing and accessing device logs
RUN set -x \
&& apt-get update \
&& apt-get install --no-install-recommends -fy \
device-tree-compiler=1.5.1-1 \
ccache=3.7.7-1 \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/ \
&& : # last line

COPY --from=build /opt/NordicSemiconductor/nRF5_tools/ /opt/NordicSemiconductor/nRF5_tools/
COPY --from=build /opt/NordicSemiconductor/nrfconnect/ /opt/NordicSemiconductor/nrfconnect/

# ==================================================
# nRF Connect SDK
# ==================================================

RUN set -x \
# python3-yaml package conflicts with nRF Python requirements
&& (apt-get remove -fy python3-yaml && apt-get autoremove || exit 0) \
&& python3 -m pip install --no-cache-dir -r /opt/NordicSemiconductor/nrfconnect/zephyr/scripts/requirements.txt \
&& python3 -m pip install --no-cache-dir -r /opt/NordicSemiconductor/nrfconnect/nrf/scripts/requirements.txt \
&& python3 -m pip install --no-cache-dir -r /opt/NordicSemiconductor/nrfconnect/bootloader/mcuboot/scripts/requirements.txt \
&& : # last line

ENV NRF5_TOOLS_ROOT=/opt/NordicSemiconductor/nRF5_tools
Expand Down
2 changes: 1 addition & 1 deletion integrations/docker/images/chip-build/version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.5.25 Version bump reason: [Telink] Implement Docker best practices
0.5.26 Version bump reason: [nRF Connect] Implement Docker best practices

0 comments on commit 1714612

Please sign in to comment.