Skip to content

Commit

Permalink
Implement Docker best practices on mbed os image
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 <[email protected]>
  • Loading branch information
electrocucaracha committed Oct 6, 2021
1 parent 6453262 commit 6cd1474
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 36 deletions.
63 changes: 28 additions & 35 deletions integrations/docker/images/chip-build-mbed-os/Dockerfile
Original file line number Diff line number Diff line change
@@ -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

# ------------------------------------------------------------------------------
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.11
0.5.12

0 comments on commit 6cd1474

Please sign in to comment.