diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index 78ee985dd6..4d06230f80 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker-image.yml @@ -57,3 +57,6 @@ jobs: push: true tags: ${{ env.DOCKERHUB_REPO }}:${{ env.TAG_NAME }} platforms: ${{ env.BUILD_PLATFORMS }} + build-args: | + ESP_MATTER_CLONE_URL=${{ github.server_url }}/${{ github.repository }}.git + ESP_MATTER_CLONE_SHALLOW=1 diff --git a/tools/docker/README.md b/tools/docker/README.md new file mode 100644 index 0000000000..20e8d7fbbe --- /dev/null +++ b/tools/docker/README.md @@ -0,0 +1,22 @@ +# Espressif's SDK for Matter Docker Image + +This is a Docker image for the [Espressif's SDK for Matter (ESP-MATTER)](https://github.com/espressif/esp-matter). It is intended for building applications of ESP-IDF that uses Espressif's SDK for Matter, when doing automated builds. + +This image contains a copy of the Espressif's SDK for Matter, a copy of ESP-IDF and the required tools for Matter to build ESP-IDF projects that use Espressif's SDK for Matter. + +## Basic Usage + +Build a project located in the current directory using `idf.py build` command: + +```bash +docker run --rm -v $PWD:/project -w /project espressif/esp-matter:latest idf.py build +``` +## Building custom images + +The Dockerfile in Espressif's SDK for Matter repository provides several build arguments which can be used to customize the Docker image: + +These are the different build arguments that can be used: +- ``ESP_MATTER_CLONE_URL``: URL of the repository to clone Espressif's SDK for Matter. Can be set to a custom URL when working with a fork of Espressif's SDK for Matter. Default is ``https://github.com/espressif/esp-matter.git``. +- ``ESP_MATTER_CLONE_BRANCH_OR_TAG``: Name of a git branch or tag use when cloning Espressif's SDK for Matter. This value is passed to ``git clone`` command using the ``--branch`` argument. Default is ``main``. +- ``ESP_MATTER_CHECKOUT_REF``: If this argument is set to a non-empty value, ``git checkout $ESP_MATTER_CHECKOUT_REF`` command will be performed after cloning. This argument can be set to the SHA of the specific commit to check out, for example if some specific commit on a release branch is desired. +- ``ESP_MATTER_CLONE_SHALLOW``: If this argument is set to a non-empty value, ``--depth=1`` argument will be used when performing ``git clone`` and it will download only the required submodules by Matter for ESP32 platform only using [``checkout_submodules.py``](https://github.com/project-chip/connectedhomeip/blob/master/scripts/checkout_submodules.py). If it is empty will clone recursively all the submodules from Matter repository. diff --git a/tools/docker/entrypoint.sh b/tools/docker/entrypoint.sh new file mode 100755 index 0000000000..3954472ba1 --- /dev/null +++ b/tools/docker/entrypoint.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env bash +set -e + +. $IDF_PATH/export.sh +. $ESP_MATTER_PATH/export.sh + +exec "$@" diff --git a/tools/docker/matter-builds b/tools/docker/matter-builds index 96d29019e9..13a7a3c52a 100644 --- a/tools/docker/matter-builds +++ b/tools/docker/matter-builds @@ -1,16 +1,48 @@ ARG VERSION=latest FROM connectedhomeip/chip-build-esp32:${VERSION} as build +# To build the image for a branch or a tag of ESP-MATTER, pass --build-arg ESP_MATTER_CLONE_BRANCH_OR_TAG=name. +# To build the image with a specific commit ID of ESP-MATTER, pass --build-arg ESP_MATTER_CHECKOUT_REF=commit-id. +# It is possibe to combine both, e.g.: +# ESP_MATTER_CLONE_BRANCH_OR_TAG=release/vX.Y +# ESP_MATTER_CHECKOUT_REF=. +# Use ESP_MATTER_CLONE_SHALLOW=1 to peform shallow clone (i.e. --depth=1 --shallow-submodules) + +ARG ESP_MATTER_CLONE_URL=https://github.com/espressif/esp-matter.git +ARG ESP_MATTER_CLONE_BRANCH_OR_TAG=main +ARG ESP_MATTER_CHECKOUT_REF= +ARG ESP_MATTER_CLONE_SHALLOW= + WORKDIR /opt/espressif ENV ESP_MATTER_PATH=/opt/espressif/esp-matter RUN set -x \ - && git clone --depth 1 https://github.com/espressif/esp-matter.git \ - && cd esp-matter \ - && git submodule update --init --depth 1 \ - && ./connectedhomeip/connectedhomeip/scripts/checkout_submodules.py --platform esp32 --shallow \ + && if [ -n "$ESP_MATTER_CLONE_SHALLOW" ]; then \ + git clone \ + ${ESP_MATTER_CLONE_BRANCH_OR_TAG:+-b $ESP_MATTER_CLONE_BRANCH_OR_TAG} \ + $ESP_MATTER_CLONE_URL $ESP_MATTER_PATH; \ + else \ + git clone --recursive \ + ${ESP_MATTER_CLONE_BRANCH_OR_TAG:+-b $ESP_MATTER_CLONE_BRANCH_OR_TAG} \ + $ESP_MATTER_CLONE_URL $ESP_MATTER_PATH; \ + fi \ + && cd $ESP_MATTER_PATH \ + && if [ -n "$ESP_MATTER_CHECKOUT_REF" ]; then \ + git checkout $ESP_MATTER_CHECKOUT_REF \ + && if [ -n "$ESP_MATTER_CLONE_SHALLOW" ]; then \ + git fetch origin --depth=1 --recurse-submodules ${ESP_MATTER_CHECKOUT_REF}; \ + fi; \ + fi \ + && if [ -n "$ESP_MATTER_CLONE_SHALLOW" ]; then \ + git submodule update --init --depth=1 \ + && ./connectedhomeip/connectedhomeip/scripts/checkout_submodules.py --platform esp32 --shallow; \ + fi \ && . $IDF_PATH/export.sh \ && ./install.sh \ && : # last line +COPY entrypoint.sh /opt/esp/entrypoint.sh +ENTRYPOINT [ "/opt/esp/entrypoint.sh" ] +CMD [ "/bin/bash" ] + WORKDIR /opt/espressif/esp-matter