Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor images for old Mbed CLI 1 and Mbed CLI 2 #6

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
# docker-hub
This repository contains the Dockerfile for building docker hub images
# mbed-os-docker-images
This repository contains the Dockerfile for building docker hub images of Mbed OS and additional tools required for embedded development in Mbed.

### Docker-hub address: https://hub.docker.com/u/mbedos
## Prerequisites

[Docker](https://www.docker.com/)

## Docker Hub address: https://hub.docker.com/u/mbedos

## mbed-os-env
Docker image with old Mbed tools (mbed-cli).

## mbed-os-env-cmake
Docker image with new Mbed tools (mbed-tools).
54 changes: 3 additions & 51 deletions mbed-os-env-cmake/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,54 +7,6 @@ FROM ubuntu:20.04
ARG WORKDIR=/root

# ------------------------------------------------------------------------------
# Install tools via apt
ENV DEBIAN_FRONTEND=noninteractive
RUN apt -y update && \
apt -y install git \
wget \
python3 \
python3-dev \
python3-setuptools \
python3-usb \
python3-pip \
software-properties-common \
build-essential \
cmake \
astyle \
mercurial \
ninja-build \
libssl-dev \
&& apt clean && rm -rf /var/lib/apt/lists


# ------------------------------------------------------------------------------
# Install Python modules (which are not included in requirements.txt)
RUN pip3 install -U \
mbed-cli \
cmake \
mbed-tools

# Set up mbed environment
WORKDIR /root/
RUN wget https://github.com/ARMmbed/mbed-os/raw/master/requirements.txt && \
pip3 install -r requirements.txt

# ------------------------------------------------------------------------------
# Install arm-none-eabi-gcc
WORKDIR /root/
RUN wget -q 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
ENV PATH="/root/gcc-arm-none-eabi-9-2019-q4-major/bin:${PATH}"


# ------------------------------------------------------------------------------
# Display and save environment settings
RUN python3 --version | tee env_settings && \
arm-none-eabi-gcc --version | tee -a env_settings && \
(echo -n 'mbed-cli ' && mbed --version) | tee -a env_settings && \
(echo -n 'mbed-greentea ' && mbedgt --version) | tee -a env_settings && \
(echo -n 'mbed-host-tests ' && mbedhtrun --version) | tee -a env_settings


WORKDIR /root
# Bootstrap
ADD bootstrap.sh /root
RUN sh /root/bootstrap.sh
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really dislike the change to a single command, a change to bootstrap.sh triggers a full rebuild and it is slow with multiarch. Whereas, with various RUN, actions made before the modification are cached.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am agree with @pan- here, change it to a single command makes the huge docker image (1.4GB I think) into a single layer, every change will triggers a full rebuilding of whole layer. And this impair the benefit of the layer caching, and make the upload/download a slower process

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another point is if this bootstrap scripts calling other scripts make changes to the docker image contents, the it would be unclear what it is in the docker image.
One of major benefit of Dockerfile is : It is self-descriptive, by reading the Dockerfile, you know what it is inside image

Copy link
Collaborator

@LDong-Arm LDong-Arm Mar 3, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The initial idea was to share one script for Docker and others (e.g. Vagrant), but I agree that performance (caching) should be prioritised.

It would be good to have this part reverted, while having other improvements (e.g. installing CMake via PPA) merged soon, so our CI (mainly Travis) can benefit from that.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some Travis scripts currently still fetch the raw Ubuntu image and install stuff manually at the moment

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(By "reverted" I mean a separate PR - no need to abandon any work we've done here)

38 changes: 38 additions & 0 deletions mbed-os-env-cmake/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# mbed-OS development environment docker image

This docker image is the official Mbed OS development environment which includes latest Mbed CLI 2.
* It is based on ubuntu 20.04
* Python 3 is installed
* arm-none-eabi-gcc toolchain is installed
* pyOCD is installed
* Cmake is installed
* Latest released version of mbed-tools and GreenTea are installed

# How to use docker image:

## Pull docker images
```bash
docker pull mbedos/mbed-os-env-cmake

```

## Run Mbed OS environment without HW support (build mbed images only)
launch docker by
```bash
docker run -it mbedos/mbed-os-env:<lable>
```
Then you will have the container with mbed OS development environment.
you should be able to compile mbed commands/examples as recommenced in mbed documentations
e.g.
```bash
mbed-tools import --no-requirements mbed-os-example-blinky
cd mbed-os-example-blinky
mbed-tools compile -m <TARGET> -t GCC_ARM
```

## Run Mbed OS environment with HW support (USB pass-through)
If you want to use this docker container connect and flash your targets. you need some extra command line option to pass-through your USB devices.
```bash
sudo docker run -it --privileged -v /dev/disk/by-id:/dev/disk/by-id -v /dev/serial/by-id:/dev/serial/by-id mbed-os-env:<label>
```
Then you will have the container with mbed OS development environment.
69 changes: 69 additions & 0 deletions mbed-os-env-cmake/bootstrap.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#!/usr/bin/env sh

# ------------------------------------------------------------------------------
# Install tools via apt-get
export DEBIAN_FRONTEND=noninteractive
apt-get -y update
apt-get -y install git \
wget \
python3 \
python3-dev \
python3-setuptools \
python3-usb \
python3-pip \
software-properties-common \
build-essential \
astyle \
mercurial \
ninja-build \
libssl-dev \
srecord

wget -O - https://apt.kitware.com/keys/kitware-archive-latest.asc 2>/dev/null | gpg --dearmor - | tee /etc/apt/trusted.gpg.d/kitware.gpg >/dev/null
add-apt-repository 'deb https://apt.kitware.com/ubuntu/ focal main'
apt-get -y update
apt-get -y install cmake
apt-get clean
rm -rf /var/lib/apt/lists

# ------------------------------------------------------------------------------
# Set up mbed environment
cd /root
wget https://github.com/ARMmbed/mbed-os/raw/latest/tools/cmake/requirements.txt
pip3 install -r requirements.txt

# ------------------------------------------------------------------------------
# Install Python modules (which are not included in requirements.txt)
pip3 install \
mbed-tools \
pyocd \
mbed-greentea \
mbed-host-tests


# ------------------------------------------------------------------------------
# Install arm-none-eabi-gcc
TARBALL=""
ARCH="$(uname -m)"
if [ "$ARCH" = "aarch64" ]
then
TARBALL="gcc-arm-none-eabi-9-2019-q4-major-aarch64-linux.tar.bz2"
else
TARBALL="gcc-arm-none-eabi-9-2019-q4-major-x86_64-linux.tar.bz2"
fi

wget -q https://developer.arm.com/-/media/Files/downloads/gnu-rm/9-2019q4/$TARBALL
tar -xjf $TARBALL
rm $TARBALL
PATH="/root/gcc-arm-none-eabi-9-2019-q4-major/bin:${PATH}"
echo 'PATH="/root/gcc-arm-none-eabi-9-2019-q4-major/bin:${PATH}"' >> ~/.bashrc


# ------------------------------------------------------------------------------
# Display and save environment settings
python3 --version | tee env_settings
arm-none-eabi-gcc --version | tee -a env_settings
(echo -n 'mbed-tools ' && mbed-tools --version) | tee -a env_settings
(echo -n 'mbed-greentea ' && mbedgt --version) | tee -a env_settings
(echo -n 'mbed-host-tests ' && mbedhtrun --version) | tee -a env_settings
(echo -n 'pyocd ' && pyocd --version) | tee -a env_settings
5 changes: 5 additions & 0 deletions mbed-os-env-cmake/docker-build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env sh

set -e

docker build "$@" -t mbed/mbed-os-env-cmake .
14 changes: 14 additions & 0 deletions mbed-os-env-cmake/docker-run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env sh

set -e

PORT="8080"
WORKSPACE=${@:-$HOME}
PROJECT_DIR="/work/$(basename $WORKSPACE)"

PARAMS="$PARAMS -it --rm"
PARAMS="$PARAMS -v $WORKSPACE:$PROJECT_DIR"
PARAMS="$PARAMS -p $PORT:8080"
PARAMS="$PARAMS -w $PROJECT_DIR"

docker run $PARAMS mbed/mbed-os-env-cmake
57 changes: 3 additions & 54 deletions mbed-os-env/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,57 +7,6 @@ FROM ubuntu:20.04
ARG WORKDIR=/root

# ------------------------------------------------------------------------------
# Install tools via apt
ENV DEBIAN_FRONTEND=noninteractive
RUN apt -y update && \
apt -y install git \
wget \
python3 \
python3-dev \
python3-setuptools \
python3-usb \
python3-pip \
software-properties-common \
build-essential \
astyle \
mercurial \
ninja-build \
libssl-dev \
&& apt clean && rm -rf /var/lib/apt/lists


# ------------------------------------------------------------------------------
# Install Python modules (which are not included in requirements.txt)
RUN pip3 install -U \
mbed-cli \
mbed-tools

# Set up mbed environment
WORKDIR /root/
RUN wget https://github.com/ARMmbed/mbed-os/raw/master/requirements.txt && \
pip3 install -r requirements.txt

# ------------------------------------------------------------------------------
# Install updated cmake - refer https://cmake.org/install/
COPY cmake-3.19.0-rc3-Linux-x86_64.sh /tmp
RUN sh /tmp/cmake-3.19.0-rc3-Linux-x86_64.sh --exclude-subdir --prefix=/usr/local

# ------------------------------------------------------------------------------
# Install arm-none-eabi-gcc
WORKDIR /root/
RUN wget -q 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
ENV PATH="/root/gcc-arm-none-eabi-9-2019-q4-major/bin:${PATH}"


# ------------------------------------------------------------------------------
# Display and save environment settings
RUN python3 --version | tee env_settings && \
arm-none-eabi-gcc --version | tee -a env_settings && \
(echo -n 'mbed-cli ' && mbed --version) | tee -a env_settings && \
(echo -n 'mbed-greentea ' && mbedgt --version) | tee -a env_settings && \
(echo -n 'mbed-host-tests ' && mbedhtrun --version) | tee -a env_settings

WORKDIR /root

# Bootstrap
ADD bootstrap.sh /root
RUN sh /root/bootstrap.sh
93 changes: 86 additions & 7 deletions mbed-os-env/README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
# mbed-OS development environment docker image

This docker image is the official mbed-OS development environment.
This docker image is the official Mbed OS development environment.
* It is based on ubuntu 20.04
* Python and cmake are installed
* Python 3 is installed
* arm-none-eabi-gcc toolchain is installed
* Latest released version of mbed-cli and GreenTea are installed
* All other mbed-OS dependency tools are installed.
* pyOCD is installed
* Latest released version of Mbed CLI and GreenTea are installed
* All other Mbed OS dependency tools are installed

# How to use docker image:

Expand All @@ -15,7 +16,7 @@ docker pull mbedos/mbed-os-env

```

## Run mbed OS environment without HW support (build mbed images only)
## Run Mbed OS environment without HW support (build mbed images only)
launch docker by
```bash
docker run -it mbedos/mbed-os-env:<lable>
Expand All @@ -24,12 +25,12 @@ Then you will have the container with mbed OS development environment.
you should be able to compile mbed commands/examples as recommenced in mbed documentations
e.g.
```bash
mbed import mbed-os-example-blinky
mbed import --no-requirements mbed-os-example-blinky
cd mbed-os-example-blinky
mbed compile -m <TARGET> -t GCC_ARM
```

## Run mbed OS environment with HW support (USB pass-through)
## Run Mbed OS environment with HW support (USB pass-through)
If you want to use this docker container connect and flash your targets. you need some extra command line option to pass-through your USB devices.
```bash
sudo docker run -it --privileged -v /dev/disk/by-id:/dev/disk/by-id -v /dev/serial/by-id:/dev/serial/by-id mbed-os-env:<label>
Expand All @@ -46,4 +47,82 @@ mbed clone https://github.com/ARMmbed/mbed-os.git
cd mbed-os
mbed test -t GCC_ARM -m <target>
```
To make sure your mbed targets been detected, you might want to manually run the mount command and `mbedls` to check
```bash
mount /dev/sdb /mnt
mbedls
```
if `mbedls` detected your connected target, then you should be able to run mbed tests/examples as recommenced in mbed documentations
``` bash
mbed clone https://github.com/ARMmbed/mbed-os.git
cd mbed-os
mbed test -t GCC_ARM -m <target>
```
To make sure your mbed targets been detected, you might want to manually run the mount command and `mbedls` to check
```bash
mount /dev/sdb /mnt
mbedls
```
if `mbedls` detected your connected target, then you should be able to run mbed tests/examples as recommenced in mbed documentations
``` bash
mbed clone https://github.com/ARMmbed/mbed-os.git
cd mbed-os
mbed test -t GCC_ARM -m <target>
```
To make sure your mbed targets been detected, you might want to manually run the mount command and `mbedls` to check
```bash
mount /dev/sdb /mnt
mbedls
```
if `mbedls` detected your connected target, then you should be able to run mbed tests/examples as recommenced in mbed documentations
``` bash
mbed clone https://github.com/ARMmbed/mbed-os.git
cd mbed-os
mbed test -t GCC_ARM -m <target>
```
To make sure your mbed targets been detected, you might want to manually run the mount command and `mbedls` to check
```bash
mount /dev/sdb /mnt
mbedls
```
if `mbedls` detected your connected target, then you should be able to run mbed tests/examples as recommenced in mbed documentations
``` bash
mbed clone https://github.com/ARMmbed/mbed-os.git
cd mbed-os
mbed test -t GCC_ARM -m <target>
```
To make sure your mbed targets been detected, you might want to manually run the mount command and `mbedls` to check
```bash
mount /dev/sdb /mnt
mbedls
```
if `mbedls` detected your connected target, then you should be able to run mbed tests/examples as recommenced in mbed documentations
``` bash
mbed clone https://github.com/ARMmbed/mbed-os.git
cd mbed-os
mbed test -t GCC_ARM -m <target>
```
To make sure your mbed targets been detected, you might want to manually run the mount command and `mbedls` to check
```bash
mount /dev/sdb /mnt
mbedls
```
if `mbedls` detected your connected target, then you should be able to run mbed tests/examples as recommenced in mbed documentations
``` bash
mbed clone https://github.com/ARMmbed/mbed-os.git
cd mbed-os
mbed test -t GCC_ARM -m <target>
```

# Development

## Build docker image locally

```bash
./docker-build.sh
```

## Run docker image locally
```bash
./docker-run.sh
```
Loading