From 239c52fd13917998ec7f259f43d89512a9248c29 Mon Sep 17 00:00:00 2001 From: Li Qing Qiao Date: Wed, 11 Nov 2020 15:17:12 +0800 Subject: [PATCH] feat(tools): Add docker compilation environment for esp8266. --- tools/docker/Dockerfile | 70 ++++++++++++++++++++++++++++++++++++++ tools/docker/entrypoint.sh | 6 ++++ tools/docker/hooks/build | 14 ++++++++ 3 files changed, 90 insertions(+) create mode 100644 tools/docker/Dockerfile create mode 100755 tools/docker/entrypoint.sh create mode 100755 tools/docker/hooks/build diff --git a/tools/docker/Dockerfile b/tools/docker/Dockerfile new file mode 100644 index 00000000..c5db05e7 --- /dev/null +++ b/tools/docker/Dockerfile @@ -0,0 +1,70 @@ +FROM ubuntu:18.04 + +ARG DEBIAN_FRONTEND=noninteractive + +RUN apt-get update && apt-get install -y \ + vim \ + apt-utils \ + bison \ + ca-certificates \ + ccache \ + check \ + curl \ + flex \ + git \ + gperf \ + lcov \ + libncurses-dev \ + libusb-1.0-0-dev \ + make \ + ninja-build \ + python3 \ + python3-pip \ + unzip \ + wget \ + xz-utils \ + zip \ + && apt-get autoremove -y \ + && rm -rf /var/lib/apt/lists/* \ + && update-alternatives --install /usr/bin/python python /usr/bin/python3 10 + +RUN python -m pip install --upgrade pip virtualenv + +# To build the image for a branch or a tag of IDF, pass --build-arg IDF_CLONE_BRANCH_OR_TAG=name. +# To build the image with a specific commit ID of IDF, pass --build-arg IDF_CHECKOUT_REF=commit-id. +# It is possibe to combine both, e.g.: +# IDF_CLONE_BRANCH_OR_TAG=release/vX.Y +# IDF_CHECKOUT_REF=. + +ARG IDF_CLONE_URL=https://github.com/espressif/ESP8266_RTOS_SDK.git +ARG IDF_CLONE_BRANCH_OR_TAG=master +ARG IDF_CHECKOUT_REF= + +ENV IDF_PATH=/opt/esp/ESP8266_RTOS_SDK +ENV IDF_TOOLS_PATH=/opt/esp + +RUN echo IDF_CHECKOUT_REF=$IDF_CHECKOUT_REF IDF_CLONE_BRANCH_OR_TAG=$IDF_CLONE_BRANCH_OR_TAG && \ + git clone --recursive \ + ${IDF_CLONE_BRANCH_OR_TAG:+-b $IDF_CLONE_BRANCH_OR_TAG} \ + $IDF_CLONE_URL $IDF_PATH && \ + if [ -n "$IDF_CHECKOUT_REF" ]; then \ + cd $IDF_PATH && \ + git checkout $IDF_CHECKOUT_REF && \ + git submodule update --init --recursive; \ + fi + +# Install all the required tools, plus CMake +RUN $IDF_PATH/tools/idf_tools.py --non-interactive install cmake \ + && $IDF_PATH/tools/idf_tools.py --non-interactive install xtensa-lx106-elf \ + && $IDF_PATH/tools/idf_tools.py --non-interactive install-python-env \ + && rm -rf $IDF_TOOLS_PATH/dist \ + && pip install -r $IDF_PATH/requirements.txt + +# Ccache is installed, enable it by default +ENV IDF_CCACHE_ENABLE=1 + +COPY entrypoint.sh /opt/esp/entrypoint.sh + +ENTRYPOINT [ "/opt/esp/entrypoint.sh" ] + +CMD [ "/bin/bash" ] \ No newline at end of file diff --git a/tools/docker/entrypoint.sh b/tools/docker/entrypoint.sh new file mode 100755 index 00000000..7cf15f19 --- /dev/null +++ b/tools/docker/entrypoint.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env bash +set -e + +. $IDF_PATH/export.sh + +exec "$@" diff --git a/tools/docker/hooks/build b/tools/docker/hooks/build new file mode 100755 index 00000000..f9829511 --- /dev/null +++ b/tools/docker/hooks/build @@ -0,0 +1,14 @@ +#!/bin/bash + +# This file gets executed to build the image on the Docker Hub. +# See https://docs.docker.com/docker-hub/builds/advanced/#build-hook-examples for details. + +set -euo pipefail + +echo "Building for branch ${SOURCE_BRANCH}, commit ${SOURCE_COMMIT}" + +docker build \ + --build-arg IDF_CLONE_BRANCH_OR_TAG=${SOURCE_BRANCH} \ + --build-arg IDF_CHECKOUT_REF=${SOURCE_COMMIT} \ + -f $DOCKERFILE_PATH \ + -t $IMAGE_NAME .