From 6cd1474decba361ff1cfd2db3cc86a754e06bd30 Mon Sep 17 00:00:00 2001 From: Victor Morales Date: Wed, 6 Oct 2021 16:00:30 -0700 Subject: [PATCH] Implement Docker best practices on mbed os 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-mbed-os/Dockerfile | 63 +++++++++---------- integrations/docker/images/chip-build/version | 2 +- 2 files changed, 29 insertions(+), 36 deletions(-) diff --git a/integrations/docker/images/chip-build-mbed-os/Dockerfile b/integrations/docker/images/chip-build-mbed-os/Dockerfile index b8270f6852114c..37dcfaf9beb5d6 100644 --- a/integrations/docker/images/chip-build-mbed-os/Dockerfile +++ b/integrations/docker/images/chip-build-mbed-os/Dockerfile @@ -1,62 +1,55 @@ ARG VERSION=latest -FROM connectedhomeip/chip-build:${VERSION} +FROM connectedhomeip/chip-build:${VERSION} as build -# ------------------------------------------------------------------------------ -# Install system tools via apt RUN set -x \ && apt-get update \ - && DEBIAN_FRONTEND=noninteractive apt-get install -fy \ - python3-setuptools \ - python3-usb \ - software-properties-common \ - build-essential \ - astyle \ - mercurial \ - && rm -rf /var/lib/apt/lists \ + && DEBIAN_FRONTEND=noninteractive apt-get install -fy --no-install-recommends \ + wget=1.20.3-1ubuntu1 \ + && apt-get clean \ + && rm -rf /var/lib/apt/lists/ \ && : # last line +SHELL ["/bin/bash", "-o", "pipefail", "-c"] # ------------------------------------------------------------------------------ # Install Mbed-OS sources RUN set -x \ - && (mkdir -p /opt/mbed-os \ - && cd /opt/mbed-os \ - && wget --progress=dot:giga https://github.com/ARMmbed/mbed-os/archive/mbed-os-6.7.0.tar.gz \ - && tar --strip-components=1 -xzf mbed-os-6.7.0.tar.gz \ - && rm mbed-os-6.7.0.tar.gz) \ + && mkdir -p /opt/mbed-os \ + && wget -O - --progress=dot:giga https://github.com/ARMmbed/mbed-os/archive/mbed-os-6.7.0.tar.gz | tar --strip-components=1 -xz -C /opt/mbed-os \ && : # last line # ------------------------------------------------------------------------------ -# Install Python modules +# Install ARM Toolchain (gcc-arm-none-eabi-9-2019-q4) RUN set -x \ - && pip3 install --no-cache-dir -U mbed-cli mbed-tools \ - && pip3 install --no-cache-dir --ignore-installed -r /opt/mbed-os/requirements.txt \ + && mkdir -p /opt/mbed-os-toolchain \ + && wget -O - --progress=dot:giga https://developer.arm.com/-/media/Files/downloads/gnu-rm/9-2019q4/RC2.1/gcc-arm-none-eabi-9-2019-q4-major-x86_64-linux.tar.bz2 | tar -xj -C /opt/mbed-os-toolchain \ && : # last line # ------------------------------------------------------------------------------ -# Install ARM Toolchain (gcc-arm-none-eabi-9-2019-q4) +# Install openocd RUN set -x \ - && (mkdir -p /opt/mbed-os-toolchain \ - && cd /opt/mbed-os-toolchain \ - && wget --progress=dot:giga https://developer.arm.com/-/media/Files/downloads/gnu-rm/9-2019q4/RC2.1/gcc-arm-none-eabi-9-2019-q4-major-x86_64-linux.tar.bz2 \ - && tar -xjf gcc-arm-none-eabi-9-2019-q4-major-x86_64-linux.tar.bz2 \ - && rm gcc-arm-none-eabi-9-2019-q4-major-x86_64-linux.tar.bz2 \ - && : ) # last line + && mkdir -p /opt/openocd \ + && wget -O - --progress=dot:giga https://github.com/cypresssemiconductorco/openocd/releases/download/release-v4.2.0/openocd-4.2.0.1430-linux.tar.gz | tar --strip-components=1 -xz -C /opt/openocd \ + && : # last line + +ARG VERSION=latest +FROM connectedhomeip/chip-build:${VERSION} + +COPY --from=build /opt/mbed-os/requirements.txt /opt/mbed-os/requirements.txt +COPY --from=build /opt/mbed-os-toolchain/ /opt/mbed-os-toolchain/ +COPY --from=build /opt/openocd/ /opt/openocd/ # ------------------------------------------------------------------------------ -# Configure mbed build system +# Install Python modules RUN set -x \ - && mbed config -G GCC_ARM_PATH /opt/mbed-os-toolchain/gcc-arm-none-eabi-9-2019-q4-major/bin/ \ - && mbed toolchain -G -s GCC_ARM \ + && pip3 install --no-cache-dir -U mbed-cli==1.10.5 mbed-tools==7.33.0 \ + && pip3 install --no-cache-dir --ignore-installed -r /opt/mbed-os/requirements.txt \ && : # last line # ------------------------------------------------------------------------------ -# Install openocd +# Configure mbed build system RUN set -x \ - && (mkdir -p /opt/openocd \ - && cd /opt/openocd \ - && wget --progress=dot:giga https://github.com/cypresssemiconductorco/openocd/releases/download/release-v4.2.0/openocd-4.2.0.1430-linux.tar.gz \ - && tar --strip-components=1 -xzf openocd-4.2.0.1430-linux.tar.gz \ - && rm openocd-4.2.0.1430-linux.tar.gz) \ + && mbed config -G GCC_ARM_PATH /opt/mbed-os-toolchain/gcc-arm-none-eabi-9-2019-q4-major/bin/ \ + && mbed toolchain -G -s GCC_ARM \ && : # last line # ------------------------------------------------------------------------------ diff --git a/integrations/docker/images/chip-build/version b/integrations/docker/images/chip-build/version index 69626fb9299734..9d6c1754eb69ad 100644 --- a/integrations/docker/images/chip-build/version +++ b/integrations/docker/images/chip-build/version @@ -1 +1 @@ -0.5.11 +0.5.12