Skip to content

Commit faac0ed

Browse files
committed
GitHub Action workflow for mbed-os-env docker image test and publish
1 parent f3f55c8 commit faac0ed

File tree

4 files changed

+331
-0
lines changed

4 files changed

+331
-0
lines changed
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
2+
name: Publish or Update docker image for mbed-os-5.15
3+
4+
on:
5+
push:
6+
branches:
7+
- mbed-os-5.15
8+
9+
paths:
10+
- requirements.txt
11+
- docker_images/mbed-os-env/**
12+
- .github/workflows/docker_management.publish.yml
13+
14+
# manual trigger when needed
15+
workflow_dispatch:
16+
17+
jobs:
18+
prepare-tags:
19+
runs-on: ubuntu-latest
20+
steps:
21+
-
22+
name: Extract branch name
23+
shell: bash
24+
run: echo "##[set-output name=branch;]$(echo ${GITHUB_REF#refs/heads/})"
25+
id: extract_branch
26+
27+
-
28+
name: Checkout
29+
uses: actions/checkout@v2
30+
with:
31+
fetch-depth: 0
32+
33+
-
34+
name: Set UUID
35+
id: generate-uuid
36+
uses: filipstefansson/uuid-action@v1
37+
38+
# set docker tags we are building, and intending to publish
39+
# dev-tag is temporary for testing purpose. This should be considered as unstable.
40+
# dated-tag is created for versioning purpose
41+
# prod-tag-latest could be used by customers, CI etc for keeping up to date
42+
-
43+
name: Get build information
44+
shell: bash
45+
run: |
46+
mkdir -p build_info
47+
date=$(date +"%Y.%m.%dT%H.%M.%S")
48+
echo dev-${{ steps.extract_branch.outputs.branch }}-${date}-${{ steps.generate-uuid.outputs.uuid }} > build_info/dev_tag
49+
echo ${{ steps.extract_branch.outputs.branch }}-${date} > build_info/prod_tag_dated
50+
echo ${{ steps.extract_branch.outputs.branch }}-latest > build_info/prod_tag_latest
51+
echo ${{ steps.extract_branch.outputs.branch }} > build_info/mbed_os_version
52+
echo ${{ github.repository_owner }} | tr '[:upper:]' '[:lower:]' > build_info/repository_owner
53+
54+
-
55+
name: Archive information
56+
uses: actions/upload-artifact@v2
57+
with:
58+
name: build-info
59+
path: build_info
60+
61+
62+
build-container:
63+
runs-on: ubuntu-latest
64+
needs: prepare-tags
65+
66+
steps:
67+
-
68+
name: unarchive artefacts
69+
uses: actions/download-artifact@v2
70+
with:
71+
name: build-info
72+
73+
-
74+
name: Get build info from archive
75+
shell: bash
76+
id: build_info
77+
run: |
78+
value=`cat dev_tag`
79+
echo "DEV TAG is $value"
80+
echo "::set-output name=DOCKER_DEV_TAG::$value"
81+
value=`cat prod_tag_dated`
82+
echo "PROD TAG DATED is $value"
83+
echo "::set-output name=DOCKER_PROD_TAG_DATED::$value"
84+
value=`cat prod_tag_latest`
85+
echo "::set-output name=DOCKER_PROD_TAG_LATEST::$value"
86+
echo "PROD TAG is $value"
87+
value=`cat repository_owner`
88+
echo "::set-output name=REPO_OWNER::$value"
89+
-
90+
name: Set up Docker Buildx
91+
uses: docker/setup-buildx-action@v1
92+
93+
-
94+
name: Login to ghcr.io
95+
uses: docker/login-action@v1
96+
with:
97+
registry: ghcr.io
98+
username: ${{ github.repository_owner }}
99+
password: ${{ secrets.GITHUB_TOKEN }}
100+
101+
-
102+
name: Checkout
103+
uses: actions/checkout@v2
104+
105+
-
106+
name: Build docker containers
107+
uses: docker/build-push-action@v2
108+
id: docker_build_dev
109+
with:
110+
context: .
111+
platforms: linux/amd64
112+
push: true
113+
file: ./docker_images/mbed-os-env/Dockerfile
114+
tags: ghcr.io/${{ steps.build_info.outputs.REPO_OWNER }}/mbed-os-env:${{ steps.build_info.outputs.DOCKER_PROD_TAG_LATEST }}
115+
116+
# as docker tags are reused, copy also to a "fixed tag"
117+
# for troubleshooting purpose if needed
118+
-
119+
name: copy tag to fixed tag
120+
run: |
121+
docker run quay.io/skopeo/stable --src-creds=${{ github.repository_owner }}:${{ secrets.GITHUB_TOKEN }} --dest-creds=${{ github.repository_owner }}:${{ secrets.GITHUB_TOKEN }} copy --all docker://ghcr.io/${{ steps.build_info.outputs.REPO_OWNER }}/mbed-os-env:${{ steps.build_info.outputs.DOCKER_PROD_TAG_LATEST }} docker://ghcr.io/${{ steps.build_info.outputs.REPO_OWNER }}/mbed-os-env:${{ steps.build_info.outputs.DOCKER_PROD_TAG_DATED }}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
name: Build and test docker image
2+
3+
# This workflow is triggered when Dockerfile related or github action itself changes are made in a PR
4+
# The workflow is quite simple - builds and test the image. Release of newer version is done only when PR is merged.
5+
6+
on:
7+
pull_request:
8+
branches: [ mbed-os-5.15 ]
9+
paths:
10+
- docker_images/mbed-os-env/**
11+
- .github/workflows/docker_management.*
12+
- requirements.txt
13+
14+
jobs:
15+
16+
build-container:
17+
runs-on: ubuntu-latest
18+
19+
strategy:
20+
matrix:
21+
platform: [linux/amd64]
22+
23+
steps:
24+
-
25+
name: Set up Docker Buildx
26+
uses: docker/setup-buildx-action@v1
27+
28+
# use mbed-os-5.15 branch of blinky
29+
-
30+
name: Checkout
31+
uses: actions/checkout@v2
32+
with:
33+
repository: ARMmbed/mbed-os-example-blinky
34+
path: mbed-os-example-blinky
35+
ref: mbed-os-5.15
36+
37+
-
38+
name: Remove mbed-os from example-application
39+
shell: bash
40+
run: |
41+
cd mbed-os-example-blinky
42+
rm -rf mbed-os
43+
-
44+
name: Checkout
45+
uses: actions/checkout@v2
46+
with:
47+
path: mbed-os-example-blinky/mbed-os
48+
49+
-
50+
name: Build container
51+
uses: docker/build-push-action@v2
52+
id: docker_build_dev
53+
with:
54+
context: ./mbed-os-example-blinky/mbed-os
55+
platforms: ${{ matrix.platform }}
56+
file: ./mbed-os-example-blinky/mbed-os/docker_images/mbed-os-env/Dockerfile
57+
load: true
58+
tags: mbed-os-env:a_pr_test
59+
60+
-
61+
name: test the container
62+
id: test
63+
uses: addnab/docker-run-action@v2
64+
with:
65+
options: -v ${{ github.workspace }}:/work -w=/work
66+
image: mbed-os-env:a_pr_test
67+
shell: bash
68+
run: |
69+
uname -m
70+
cd mbed-os-example-blinky
71+
# build using CLI1
72+
mbed compile -m K64F -t GCC_ARM

docker_images/mbed-os-env/Dockerfile

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
# ------------------------------------------------------------------------------
2+
# Pull base image
3+
FROM ubuntu:20.04
4+
5+
# ------------------------------------------------------------------------------
6+
# Arguments
7+
ARG WORKDIR=/root
8+
9+
# ------------------------------------------------------------------------------
10+
# Install tools via apt
11+
ENV DEBIAN_FRONTEND=noninteractive
12+
RUN set -x \
13+
&& apt -y update \
14+
&& apt -y install \
15+
git \
16+
wget \
17+
python3 \
18+
python3-dev \
19+
python3-setuptools \
20+
python3-pip \
21+
build-essential \
22+
astyle \
23+
mercurial \
24+
ninja-build \
25+
libssl-dev \
26+
cargo \
27+
flex \
28+
bison \
29+
doxygen \
30+
aspell \
31+
ccache \
32+
gcovr \
33+
&& apt clean && rm -rf /var/lib/apt/lists \
34+
&& update-alternatives --install /usr/bin/python python /usr/bin/python3.8 1 \
35+
&& : # last line
36+
37+
# Set up Mbed environment
38+
WORKDIR /tmp/
39+
COPY requirements.txt .
40+
RUN set -x \
41+
&& pip3 install -r requirements.txt \
42+
&& : # last line
43+
44+
# ------------------------------------------------------------------------------
45+
# Install Python modules (which are not included in requirements.txt)
46+
RUN set -x \
47+
&& pip3 install -U \
48+
mbed-cli \
49+
&& : # last line
50+
51+
# ------------------------------------------------------------------------------
52+
# install scancode-toolkit, which is available only in x86_64
53+
RUN set -x \
54+
&& [ "$(uname -m)" = "x86_64" ] && \
55+
pip install scancode-toolkit
56+
57+
# ------------------------------------------------------------------------------
58+
# Install arm-none-eabi-gcc
59+
WORKDIR /opt/mbed-os-toolchain
60+
61+
RUN set -x \
62+
&& [ "$(uname -m)" = "aarch64" ] && \
63+
TARBALL="gcc-arm-none-eabi-9-2019-q4-major-aarch64-linux.tar.bz2" || \
64+
TARBALL="gcc-arm-none-eabi-9-2019-q4-major-x86_64-linux.tar.bz2" \
65+
&& wget -q https://developer.arm.com/-/media/Files/downloads/gnu-rm/9-2019q4/${TARBALL} \
66+
&& tar -xjf ${TARBALL} \
67+
&& rm ${TARBALL} \
68+
&& : # last line
69+
70+
# ------------------------------------------------------------------------------
71+
72+
# Configure environment variables
73+
ENV MBED_GCC_ARM_PATH=/opt/mbed-os-toolchain/gcc-arm-none-eabi-9-2019-q4-major/bin/
74+
ENV PATH="${PATH}:${MBED_GCC_ARM_PATH}"
75+
76+
# ------------------------------------------------------------------------------
77+
# Display, check and save environment settings
78+
# NOTE: using bash instead of Ubuntu default bash due to unsupport for pipefail
79+
# Pipefail is crucial here, if the tools didn't install properly, docker build should not pass because of piping
80+
RUN /bin/bash -c \
81+
"set -x -o pipefail \
82+
&& arm-none-eabi-gcc --version | grep arm-none-eabi-gcc | tee env_settings \
83+
&& python --version 2>&1 | tee -a env_settings \
84+
&& (echo -n 'mbed-cli ' && mbed --version) | tee -a env_settings \
85+
&& (echo -n 'mbed-greentea ' && mbedgt --version | grep ^[0-9]) | tee -a env_settings \
86+
&& (echo -n 'mbed-host-tests ' && mbedhtrun --version) | tee -a env_settings \
87+
&& : # LAST LINE"
88+
89+
WORKDIR /root

docker_images/mbed-os-env/README.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Mbed OS development environment Docker image
2+
3+
This Docker image is the official Mbed OS development environment.
4+
5+
* It is based on Ubuntu 20.04
6+
* Arm-none-eabi-gcc toolchain is installed
7+
* Latest released version of mbed-cli and mbed-greentea are installed
8+
* All other Mbed OS dependency tools are installed.
9+
10+
# How to use the Docker image:
11+
12+
## Pull the Docker image
13+
```bash
14+
docker pull ghcr.io/armmbed/mbed-os-env:<label>
15+
```
16+
17+
## Run Mbed OS environment without HW support (build Mbed images only)
18+
Launch the Docker image by
19+
```bash
20+
docker run -it ghcr.io/armmbed/mbed-os-env:<label>
21+
```
22+
Then you will have a container with an Mbed OS development environment.
23+
You should be able to compile Mbed commands/examples as recommended in the documentation
24+
e.g.
25+
```bash
26+
mbed-tools import mbed-os-example-blinky
27+
cd mbed-os-example-blinky
28+
mbed-tools compile -m <TARGET> -t GCC_ARM
29+
```
30+
31+
## Run Mbed OS environment with HW support (USB pass-through)
32+
:warning: This currently works only on Linux host machines with [Mbed CLI 1](https://os.mbed.com/docs/mbed-os/v6.13/build-tools/mbed-cli-1.html).
33+
34+
If you want to use this Docker image to connect and flash your targets, you will need some extra command line option to pass-through your USB devices.
35+
```bash
36+
sudo docker run -it --privileged -v /dev/disk/by-id:/dev/disk/by-id -v /dev/serial/by-id:/dev/serial/by-id ghcr.io/armmbed/mbed-os-env:<label>
37+
```
38+
Then you will have a container with an Mbed OS development environment.
39+
To make sure your Mbed targets have been detected, you might want to manually run the mount command and `mbedls` to check
40+
```bash
41+
mount /dev/sdb /mnt
42+
mbedls
43+
```
44+
If `mbedls` detected your connected target, then you should be able to run Mbed tests/examples as recommended in the Mbed documentation.
45+
``` bash
46+
mbed import mbed-os
47+
cd mbed-os
48+
mbed test -t GCC_ARM -m <target>
49+
```

0 commit comments

Comments
 (0)