diff --git a/.github/workflows/docker_management.publish.yml b/.github/workflows/docker_management.publish.yml new file mode 100644 index 0000000000..8a043b05f6 --- /dev/null +++ b/.github/workflows/docker_management.publish.yml @@ -0,0 +1,121 @@ + +name: Publish or Update docker image for mbed-os-5.15 + +on: + push: + branches: + - mbed-os-5.15 + + paths: + - requirements.txt + - docker_images/mbed-os-env/** + - .github/workflows/docker_management.publish.yml + + # manual trigger when needed + workflow_dispatch: + +jobs: + prepare-tags: + runs-on: ubuntu-latest + steps: + - + name: Extract branch name + shell: bash + run: echo "##[set-output name=branch;]$(echo ${GITHUB_REF#refs/heads/})" + id: extract_branch + + - + name: Checkout + uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - + name: Set UUID + id: generate-uuid + uses: filipstefansson/uuid-action@v1 + +# set docker tags we are building, and intending to publish +# dev-tag is temporary for testing purpose. This should be considered as unstable. +# dated-tag is created for versioning purpose +# prod-tag-latest could be used by customers, CI etc for keeping up to date + - + name: Get build information + shell: bash + run: | + mkdir -p build_info + date=$(date +"%Y.%m.%dT%H.%M.%S") + echo dev-${{ steps.extract_branch.outputs.branch }}-${date}-${{ steps.generate-uuid.outputs.uuid }} > build_info/dev_tag + echo ${{ steps.extract_branch.outputs.branch }}-${date} > build_info/prod_tag_dated + echo ${{ steps.extract_branch.outputs.branch }}-latest > build_info/prod_tag_latest + echo ${{ steps.extract_branch.outputs.branch }} > build_info/mbed_os_version + echo ${{ github.repository_owner }} | tr '[:upper:]' '[:lower:]' > build_info/repository_owner + + - + name: Archive information + uses: actions/upload-artifact@v2 + with: + name: build-info + path: build_info + + + build-container: + runs-on: ubuntu-latest + needs: prepare-tags + + steps: + - + name: unarchive artefacts + uses: actions/download-artifact@v2 + with: + name: build-info + + - + name: Get build info from archive + shell: bash + id: build_info + run: | + value=`cat dev_tag` + echo "DEV TAG is $value" + echo "::set-output name=DOCKER_DEV_TAG::$value" + value=`cat prod_tag_dated` + echo "PROD TAG DATED is $value" + echo "::set-output name=DOCKER_PROD_TAG_DATED::$value" + value=`cat prod_tag_latest` + echo "::set-output name=DOCKER_PROD_TAG_LATEST::$value" + echo "PROD TAG is $value" + value=`cat repository_owner` + echo "::set-output name=REPO_OWNER::$value" + - + name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + + - + name: Login to ghcr.io + uses: docker/login-action@v1 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + + - + name: Checkout + uses: actions/checkout@v2 + + - + name: Build docker containers + uses: docker/build-push-action@v2 + id: docker_build_dev + with: + context: . + platforms: linux/amd64 + push: true + file: ./docker_images/mbed-os-env/Dockerfile + tags: ghcr.io/${{ steps.build_info.outputs.REPO_OWNER }}/mbed-os-env:${{ steps.build_info.outputs.DOCKER_PROD_TAG_LATEST }} + + # as docker tags are reused, copy also to a "fixed tag" + # for troubleshooting purpose if needed + - + name: copy tag to fixed tag + run: | + 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 }} diff --git a/.github/workflows/docker_management.test.yml b/.github/workflows/docker_management.test.yml new file mode 100644 index 0000000000..c15877c4bc --- /dev/null +++ b/.github/workflows/docker_management.test.yml @@ -0,0 +1,72 @@ +name: Build and test docker image + +# This workflow is triggered when Dockerfile related or github action itself changes are made in a PR +# The workflow is quite simple - builds and test the image. Release of newer version is done only when PR is merged. + +on: + pull_request: + branches: [ mbed-os-5.15 ] + paths: + - docker_images/mbed-os-env/** + - .github/workflows/docker_management.* + - requirements.txt + +jobs: + + build-container: + runs-on: ubuntu-latest + + strategy: + matrix: + platform: [linux/amd64] + + steps: + - + name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + + # use mbed-os-5.15 branch of blinky + - + name: Checkout + uses: actions/checkout@v2 + with: + repository: ARMmbed/mbed-os-example-blinky + path: mbed-os-example-blinky + ref: mbed-os-5.15 + + - + name: Remove mbed-os from example-application + shell: bash + run: | + cd mbed-os-example-blinky + rm -rf mbed-os + - + name: Checkout + uses: actions/checkout@v2 + with: + path: mbed-os-example-blinky/mbed-os + + - + name: Build container + uses: docker/build-push-action@v2 + id: docker_build_dev + with: + context: ./mbed-os-example-blinky/mbed-os + platforms: ${{ matrix.platform }} + file: ./mbed-os-example-blinky/mbed-os/docker_images/mbed-os-env/Dockerfile + load: true + tags: mbed-os-env:a_pr_test + + - + name: test the container + id: test + uses: addnab/docker-run-action@v2 + with: + options: -v ${{ github.workspace }}:/work -w=/work + image: mbed-os-env:a_pr_test + shell: bash + run: | + uname -m + cd mbed-os-example-blinky + # build using CLI1 + mbed compile -m K64F -t GCC_ARM \ No newline at end of file diff --git a/docker_images/mbed-os-env/Dockerfile b/docker_images/mbed-os-env/Dockerfile new file mode 100644 index 0000000000..cbac5430b4 --- /dev/null +++ b/docker_images/mbed-os-env/Dockerfile @@ -0,0 +1,89 @@ +# ------------------------------------------------------------------------------ +# Pull base image +FROM ubuntu:20.04 + +# ------------------------------------------------------------------------------ +# Arguments +ARG WORKDIR=/root + +# ------------------------------------------------------------------------------ +# Install tools via apt +ENV DEBIAN_FRONTEND=noninteractive +RUN set -x \ + && apt -y update \ + && apt -y install \ + git \ + wget \ + python3 \ + python3-dev \ + python3-setuptools \ + python3-pip \ + build-essential \ + astyle \ + mercurial \ + ninja-build \ + libssl-dev \ + cargo \ + flex \ + bison \ + doxygen \ + aspell \ + ccache \ + gcovr \ + && apt clean && rm -rf /var/lib/apt/lists \ + && update-alternatives --install /usr/bin/python python /usr/bin/python3.8 1 \ + && : # last line + +# Set up Mbed environment +WORKDIR /tmp/ +COPY requirements.txt . +RUN set -x \ + && pip3 install -r requirements.txt \ + && : # last line + +# ------------------------------------------------------------------------------ +# Install Python modules (which are not included in requirements.txt) +RUN set -x \ + && pip3 install -U \ + mbed-cli \ + && : # last line + +# ------------------------------------------------------------------------------ +# install scancode-toolkit, which is available only in x86_64 +RUN set -x \ + && [ "$(uname -m)" = "x86_64" ] && \ + pip install scancode-toolkit + +# ------------------------------------------------------------------------------ +# Install arm-none-eabi-gcc +WORKDIR /opt/mbed-os-toolchain + +RUN set -x \ + && [ "$(uname -m)" = "aarch64" ] && \ + TARBALL="gcc-arm-none-eabi-9-2019-q4-major-aarch64-linux.tar.bz2" || \ + TARBALL="gcc-arm-none-eabi-9-2019-q4-major-x86_64-linux.tar.bz2" \ + && wget -q https://developer.arm.com/-/media/Files/downloads/gnu-rm/9-2019q4/${TARBALL} \ + && tar -xjf ${TARBALL} \ + && rm ${TARBALL} \ + && : # last line + +# ------------------------------------------------------------------------------ + +# Configure environment variables +ENV MBED_GCC_ARM_PATH=/opt/mbed-os-toolchain/gcc-arm-none-eabi-9-2019-q4-major/bin/ +ENV PATH="${PATH}:${MBED_GCC_ARM_PATH}" + +# ------------------------------------------------------------------------------ +# Display, check and save environment settings +# NOTE: using bash instead of Ubuntu default bash due to unsupport for pipefail +# Pipefail is crucial here, if the tools didn't install properly, docker build should not pass because of piping +RUN /bin/bash -c \ + "set -x -o pipefail \ + && arm-none-eabi-gcc --version | grep arm-none-eabi-gcc | tee env_settings \ + && python --version 2>&1 | tee -a env_settings \ + && (echo -n 'mbed-cli ' && mbed --version) | tee -a env_settings \ + && (echo -n 'mbed-greentea ' && mbedgt --version | grep ^[0-9]) | tee -a env_settings \ + && (echo -n 'mbed-host-tests ' && mbedhtrun --version) | tee -a env_settings \ + && : # LAST LINE" + +WORKDIR /root diff --git a/docker_images/mbed-os-env/README.md b/docker_images/mbed-os-env/README.md new file mode 100644 index 0000000000..e1ccabf975 --- /dev/null +++ b/docker_images/mbed-os-env/README.md @@ -0,0 +1,49 @@ +# Mbed OS development environment Docker image + +This Docker image is the official Mbed OS development environment. + +* It is based on Ubuntu 20.04 +* Arm-none-eabi-gcc toolchain is installed +* Latest released version of mbed-cli and mbed-greentea are installed +* All other Mbed OS dependency tools are installed. + +# How to use the Docker image: + +## Pull the Docker image +```bash +docker pull ghcr.io/armmbed/mbed-os-env: