From 3cf4fbf664baa63784c20ba4d80d6405891aa8fa Mon Sep 17 00:00:00 2001 From: Victor Morales Date: Mon, 25 Oct 2021 15:16:40 -0700 Subject: [PATCH] Implement Docker best practices on nRF Connect image 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 --- .../images/chip-build-nrf-platform/Dockerfile | 62 +++++++++++++------ integrations/docker/images/chip-build/version | 2 +- 2 files changed, 44 insertions(+), 20 deletions(-) diff --git a/integrations/docker/images/chip-build-nrf-platform/Dockerfile b/integrations/docker/images/chip-build-nrf-platform/Dockerfile index 351ea2c465082c..fffe75bd2b0996 100644 --- a/integrations/docker/images/chip-build-nrf-platform/Dockerfile +++ b/integrations/docker/images/chip-build-nrf-platform/Dockerfile @@ -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 diff --git a/integrations/docker/images/chip-build/version b/integrations/docker/images/chip-build/version index 0e3066329c6192..4552b9c1ef9dc0 100644 --- a/integrations/docker/images/chip-build/version +++ b/integrations/docker/images/chip-build/version @@ -1 +1 @@ -0.5.24 Version bump reason: [Cirque] Bump version for virtual android chip-tool test +0.5.25 Version bump reason: [nRF Connect] Implement Docker best practices