From cd6f3bddf77efcbcbd0ad7446db86c995fff4df2 Mon Sep 17 00:00:00 2001 From: Lucas Saavedra Vaz <32426024+lucasssvaz@users.noreply.github.com> Date: Thu, 8 Feb 2024 17:09:28 -0300 Subject: [PATCH 01/29] Test docker Image --- tools/docker/Dockerfile | 73 ++++++++++++++++++++++++++++++++++++++ tools/docker/entrypoint.sh | 18 ++++++++++ 2 files changed, 91 insertions(+) create mode 100644 tools/docker/Dockerfile create mode 100755 tools/docker/entrypoint.sh diff --git a/tools/docker/Dockerfile b/tools/docker/Dockerfile new file mode 100644 index 000000000..bad9436e2 --- /dev/null +++ b/tools/docker/Dockerfile @@ -0,0 +1,73 @@ +FROM ubuntu:22.04 + +ARG DEBIAN_FRONTEND=noninteractive + +RUN : \ + && apt-get update \ + && apt-get install -y --no-install-recommends \ + git \ + wget \ + curl \ + libssl-dev \ + libncurses-dev \ + flex \ + bison \ + gperf \ + python3 \ + python3-pip \ + python3-setuptools \ + python3-serial \ + python3-click \ + python3-cryptography \ + python3-future \ + python3-pyparsing \ + python3-pyelftools \ + cmake \ + ninja-build \ + ccache \ + jq \ + && pip install --upgrade pip \ + && apt-get autoremove -y \ + && rm -rf /var/lib/apt/lists/* \ + && : + +# To build the image for a branch or a tag of the lib-builder, pass --build-arg LIBBUILDER_CLONE_BRANCH_OR_TAG=name. +# To build the image with a specific commit ID of lib-builder, pass --build-arg LIBBUILDER_CHECKOUT_REF=commit-id. +# It is possibe to combine both, e.g.: +# LIBBUILDER_CLONE_BRANCH_OR_TAG=release/vX.Y +# LIBBUILDER_CHECKOUT_REF=. +# Use LIBBUILDER_CLONE_SHALLOW=1 to peform shallow clone (i.e. --depth=1 --shallow-submodules) +# Use LIBBUILDER_CLONE_SHALLOW_DEPTH=X to define the depth if LIBBUILDER_CLONE_SHALLOW is used (i.e. --depth=X) +# Use IDF_INSTALL_TARGETS to install tools only for selected chip targets (CSV) + +ARG LIBBUILDER_CLONE_URL=https://github.com/espressif/esp32-arduino-lib-builder +ARG LIBBUILDER_CLONE_BRANCH_OR_TAG=master +ARG LIBBUILDER_CHECKOUT_REF= +ARG LIBBUILDER_CLONE_SHALLOW= +ARG LIBBUILDER_CLONE_SHALLOW_DEPTH=1 +ARG LIBBUILDER_TARGETS=all + +ENV LIBBUILDER_PATH=/opt/esp/lib-builder + +RUN echo LIBBUILDER_CHECKOUT_REF=$LIBBUILDER_CHECKOUT_REF LIBBUILDER_CLONE_BRANCH_OR_TAG=$LIBBUILDER_CLONE_BRANCH_OR_TAG && \ + git clone --recursive \ + ${LIBBUILDER_CLONE_SHALLOW:+--depth=${LIBBUILDER_CLONE_SHALLOW_DEPTH} --shallow-submodules} \ + ${LIBBUILDER_CLONE_BRANCH_OR_TAG:+-b $LIBBUILDER_CLONE_BRANCH_OR_TAG} \ + $LIBBUILDER_CLONE_URL $LIBBUILDER_PATH && \ + git config --system --add safe.directory $LIBBUILDER_PATH && \ + if [ -n "$LIBBUILDER_CHECKOUT_REF" ]; then \ + cd $LIBBUILDER_PATH && \ + if [ -n "$LIBBUILDER_CLONE_SHALLOW" ]; then \ + git fetch origin --depth=${LIBBUILDER_CLONE_SHALLOW_DEPTH} --recurse-submodules ${LIBBUILDER_CHECKOUT_REF}; \ + fi && \ + git checkout $LIBBUILDER_CHECKOUT_REF && \ + git submodule update --init --recursive; \ + fi + +RUN cp $LIBBUILDER_PATH/tools/docker/entrypoint.sh $LIBBUILDER_PATH/entrypoint.sh + +# Ccache is installed, enable it by default +ENV IDF_CCACHE_ENABLE=1 + +WORKDIR $LIBBUILDER_PATH +ENTRYPOINT [ "$LIBBUILDER_PATH/entrypoint.sh" ] diff --git a/tools/docker/entrypoint.sh b/tools/docker/entrypoint.sh new file mode 100755 index 000000000..7234fe566 --- /dev/null +++ b/tools/docker/entrypoint.sh @@ -0,0 +1,18 @@ +#!/usr/bin/env bash +set -e + +# LIBBUILDER_GIT_SAFE_DIR has the same format as system PATH environment variable. +# All path specified in LIBBUILDER_GIT_SAFE_DIR will be added to user's +# global git config as safe.directory paths. For more information +# see git-config manual page. +if [ -n "${LIBBUILDER_GIT_SAFE_DIR+x}" ] +then + echo "Adding following directories into git's safe.directory" + echo "$LIBBUILDER_GIT_SAFE_DIR" | tr ':' '\n' | while read -r dir + do + git config --global --add safe.directory "$dir" + echo " $dir" + done +fi + +exec "$@" From a635979cad6aa5aedbb42469ab8548a4abda2c33 Mon Sep 17 00:00:00 2001 From: Lucas Saavedra Vaz <32426024+lucasssvaz@users.noreply.github.com> Date: Thu, 8 Feb 2024 19:14:53 -0300 Subject: [PATCH 02/29] Fix Dockerfile --- tools/docker/Dockerfile | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/tools/docker/Dockerfile b/tools/docker/Dockerfile index bad9436e2..61d4e4693 100644 --- a/tools/docker/Dockerfile +++ b/tools/docker/Dockerfile @@ -5,27 +5,30 @@ ARG DEBIAN_FRONTEND=noninteractive RUN : \ && apt-get update \ && apt-get install -y --no-install-recommends \ - git \ - wget \ + bison \ + ccache \ + cmake \ curl \ - libssl-dev \ - libncurses-dev \ flex \ - bison \ + git \ gperf \ + jq \ + libncurses-dev \ + libssl-dev \ + libusb-1.0 \ + ninja-build \ + patch \ python3 \ - python3-pip \ - python3-setuptools \ - python3-serial \ python3-click \ python3-cryptography \ python3-future \ - python3-pyparsing \ + python3-pip \ python3-pyelftools \ - cmake \ - ninja-build \ - ccache \ - jq \ + python3-pyparsing \ + python3-serial \ + python3-setuptools \ + python3-venv \ + wget \ && pip install --upgrade pip \ && apt-get autoremove -y \ && rm -rf /var/lib/apt/lists/* \ From 1768d26ddb5bad9170ab60150e07513f07e8b68a Mon Sep 17 00:00:00 2001 From: Lucas Saavedra Vaz <32426024+lucasssvaz@users.noreply.github.com> Date: Fri, 9 Feb 2024 19:52:47 -0300 Subject: [PATCH 03/29] Fix file permissions --- tools/docker/Dockerfile | 17 ++++++++++++++--- tools/docker/entrypoint.sh | 13 ++++++++++++- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/tools/docker/Dockerfile b/tools/docker/Dockerfile index 61d4e4693..6b7bd7ae3 100644 --- a/tools/docker/Dockerfile +++ b/tools/docker/Dockerfile @@ -1,5 +1,8 @@ FROM ubuntu:22.04 +# switch to root, let the entrypoint drop back to host user +USER root + ARG DEBIAN_FRONTEND=noninteractive RUN : \ @@ -34,6 +37,13 @@ RUN : \ && rm -rf /var/lib/apt/lists/* \ && : +# install gosu for a better su+exec command +ARG GOSU_VERSION=1.17 +RUN dpkgArch="$(dpkg --print-architecture | awk -F- '{ print $NF }')" \ + && wget -O /usr/local/bin/gosu "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$dpkgArch" \ + && chmod +x /usr/local/bin/gosu \ + && gosu nobody true + # To build the image for a branch or a tag of the lib-builder, pass --build-arg LIBBUILDER_CLONE_BRANCH_OR_TAG=name. # To build the image with a specific commit ID of lib-builder, pass --build-arg LIBBUILDER_CHECKOUT_REF=commit-id. # It is possibe to combine both, e.g.: @@ -51,6 +61,7 @@ ARG LIBBUILDER_CLONE_SHALLOW_DEPTH=1 ARG LIBBUILDER_TARGETS=all ENV LIBBUILDER_PATH=/opt/esp/lib-builder +ENV ARDUINO_PATH=/opt/esp/lib-builder/arduino-esp32 RUN echo LIBBUILDER_CHECKOUT_REF=$LIBBUILDER_CHECKOUT_REF LIBBUILDER_CLONE_BRANCH_OR_TAG=$LIBBUILDER_CLONE_BRANCH_OR_TAG && \ git clone --recursive \ @@ -67,10 +78,10 @@ RUN echo LIBBUILDER_CHECKOUT_REF=$LIBBUILDER_CHECKOUT_REF LIBBUILDER_CLONE_BRANC git submodule update --init --recursive; \ fi -RUN cp $LIBBUILDER_PATH/tools/docker/entrypoint.sh $LIBBUILDER_PATH/entrypoint.sh +COPY entrypoint.sh $LIBBUILDER_PATH/entrypoint.sh # Ccache is installed, enable it by default ENV IDF_CCACHE_ENABLE=1 -WORKDIR $LIBBUILDER_PATH -ENTRYPOINT [ "$LIBBUILDER_PATH/entrypoint.sh" ] +WORKDIR /opt/esp/lib-builder +ENTRYPOINT [ "/opt/esp/lib-builder/entrypoint.sh" ] diff --git a/tools/docker/entrypoint.sh b/tools/docker/entrypoint.sh index 7234fe566..36ef1b50b 100755 --- a/tools/docker/entrypoint.sh +++ b/tools/docker/entrypoint.sh @@ -15,4 +15,15 @@ then done fi -exec "$@" +if [ "$(id -u)" = "0" ]; then + groupadd -g ${HOST_UID} host_user + useradd -m -u ${HOST_UID} -g ${HOST_UID} host_user + chown -R ${HOST_UID}:${HOST_UID} /arduino-esp32 + chown -R ${HOST_UID}:${HOST_UID} /opt/esp + + # Add call to gosu to drop from root user to host_user + # when running original entrypoint + set -- gosu host_user "$@" -c /arduino-esp32 +fi + +exec "$@" -c /arduino-esp32 From 750c99112ce5fc0658e874a74d7b6e6a35d5ddc4 Mon Sep 17 00:00:00 2001 From: Lucas Saavedra Vaz <32426024+lucasssvaz@users.noreply.github.com> Date: Sat, 10 Feb 2024 00:20:29 -0300 Subject: [PATCH 04/29] Fix bugs and add run script --- tools/docker/Dockerfile | 1 + tools/docker/entrypoint.sh | 12 ++++++---- tools/docker/run.sh | 46 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 55 insertions(+), 4 deletions(-) create mode 100755 tools/docker/run.sh diff --git a/tools/docker/Dockerfile b/tools/docker/Dockerfile index 6b7bd7ae3..f8a5a6d8f 100644 --- a/tools/docker/Dockerfile +++ b/tools/docker/Dockerfile @@ -85,3 +85,4 @@ ENV IDF_CCACHE_ENABLE=1 WORKDIR /opt/esp/lib-builder ENTRYPOINT [ "/opt/esp/lib-builder/entrypoint.sh" ] +CMD [ "bash" ] diff --git a/tools/docker/entrypoint.sh b/tools/docker/entrypoint.sh index 36ef1b50b..12e715ff3 100755 --- a/tools/docker/entrypoint.sh +++ b/tools/docker/entrypoint.sh @@ -15,15 +15,19 @@ then done fi -if [ "$(id -u)" = "0" ]; then +if [ "$(id -u)" = "0" ] && [ -n "${HOST_UID}" ]; then groupadd -g ${HOST_UID} host_user useradd -m -u ${HOST_UID} -g ${HOST_UID} host_user - chown -R ${HOST_UID}:${HOST_UID} /arduino-esp32 + + if [ -d /arduino-esp32 ]; then + chown -R ${HOST_UID}:${HOST_UID} /arduino-esp32 + fi + chown -R ${HOST_UID}:${HOST_UID} /opt/esp # Add call to gosu to drop from root user to host_user # when running original entrypoint - set -- gosu host_user "$@" -c /arduino-esp32 + set -- gosu host_user "$@" fi -exec "$@" -c /arduino-esp32 +exec "$@" diff --git a/tools/docker/run.sh b/tools/docker/run.sh new file mode 100755 index 000000000..46ef4ad92 --- /dev/null +++ b/tools/docker/run.sh @@ -0,0 +1,46 @@ +#!/usr/bin/env bash + +i=0 +NEXT_ARG="false" +ARDUINO_DIR="" +DOCKER_ARGS=() +ORIGINAL_ARGS=("$@") +TRIMMED_ARGS=() + +while [ $i -lt ${#ORIGINAL_ARGS[@]} ]; do + arg=${ORIGINAL_ARGS[$i]} + if [ $arg == "-c" ]; then + NEXT_ARG="true" + elif [ $NEXT_ARG == "true" ]; then + ARDUINO_DIR=$arg + NEXT_ARG="false" + else + TRIMMED_ARGS+=($arg) + fi + i=$((i + 1)) +done + +if [ -n "$ARDUINO_DIR" ]; then + if [ ! -d "$ARDUINO_DIR" ]; then + echo "Arduino directory \"$ARDUINO_DIR\" does not exist" + exit 1 + fi + ARDUINO_DIR=$(echo $(cd $ARDUINO_DIR; pwd)) + DOCKER_ARGS+=(-v $ARDUINO_DIR:/arduino-esp32) + TRIMMED_ARGS+=(-c /arduino-esp32) +fi + +DOCKER_ARGS+=(-e HOST_UID=$UID) + +if [ -n "$LIBBUILDER_GIT_SAFE_DIR" ]; then + DOCKER_ARGS+=(-e LIBBUILDER_GIT_SAFE_DIR=$LIBBUILDER_GIT_SAFE_DIR) +fi + +if [ "$VERBOSE_OUTPUT" -eq 1 ]; then + echo "Arguments:" + echo "DOCKER_ARGS = ${DOCKER_ARGS[@]}" + echo "TRIMMED_ARGS = ${TRIMMED_ARGS[@]}" + echo "Running: docker run ${DOCKER_ARGS[@]} lucassvaz/esp32-arduino-lib-builder ./build.sh ${TRIMMED_ARGS[@]}" +fi + +docker run ${DOCKER_ARGS[@]} lucassvaz/esp32-arduino-lib-builder ./build.sh ${TRIMMED_ARGS[@]} From a4ee9275e4033828afec4519e639c7a0c9ad7903 Mon Sep 17 00:00:00 2001 From: Lucas Saavedra Vaz <32426024+lucasssvaz@users.noreply.github.com> Date: Mon, 19 Feb 2024 10:57:59 -0300 Subject: [PATCH 05/29] Update tools/docker/Dockerfile --- tools/docker/Dockerfile | 1 - 1 file changed, 1 deletion(-) diff --git a/tools/docker/Dockerfile b/tools/docker/Dockerfile index f8a5a6d8f..f09c804ff 100644 --- a/tools/docker/Dockerfile +++ b/tools/docker/Dockerfile @@ -51,7 +51,6 @@ RUN dpkgArch="$(dpkg --print-architecture | awk -F- '{ print $NF }')" \ # LIBBUILDER_CHECKOUT_REF=. # Use LIBBUILDER_CLONE_SHALLOW=1 to peform shallow clone (i.e. --depth=1 --shallow-submodules) # Use LIBBUILDER_CLONE_SHALLOW_DEPTH=X to define the depth if LIBBUILDER_CLONE_SHALLOW is used (i.e. --depth=X) -# Use IDF_INSTALL_TARGETS to install tools only for selected chip targets (CSV) ARG LIBBUILDER_CLONE_URL=https://github.com/espressif/esp32-arduino-lib-builder ARG LIBBUILDER_CLONE_BRANCH_OR_TAG=master From c93cfec519f2729f34226dcb46a8d7e2a8450618 Mon Sep 17 00:00:00 2001 From: Lucas Saavedra Vaz <32426024+lucasssvaz@users.noreply.github.com> Date: Wed, 21 Feb 2024 12:36:03 -0300 Subject: [PATCH 06/29] Add textual to docker image --- tools/docker/Dockerfile | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/docker/Dockerfile b/tools/docker/Dockerfile index f09c804ff..759a919ae 100644 --- a/tools/docker/Dockerfile +++ b/tools/docker/Dockerfile @@ -30,6 +30,7 @@ RUN : \ python3-pyparsing \ python3-serial \ python3-setuptools \ + python3-textual \ python3-venv \ wget \ && pip install --upgrade pip \ From f9e16c87a8e4fa92810ebbf8cf5a5f3a89bae005 Mon Sep 17 00:00:00 2001 From: Lucas Saavedra Vaz <32426024+lucasssvaz@users.noreply.github.com> Date: Thu, 22 Feb 2024 20:19:45 -0300 Subject: [PATCH 07/29] Reorder --- tools/docker/Dockerfile | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tools/docker/Dockerfile b/tools/docker/Dockerfile index 759a919ae..fc5ba3a03 100644 --- a/tools/docker/Dockerfile +++ b/tools/docker/Dockerfile @@ -62,6 +62,8 @@ ARG LIBBUILDER_TARGETS=all ENV LIBBUILDER_PATH=/opt/esp/lib-builder ENV ARDUINO_PATH=/opt/esp/lib-builder/arduino-esp32 +# Ccache is installed, enable it by default +ENV IDF_CCACHE_ENABLE=1 RUN echo LIBBUILDER_CHECKOUT_REF=$LIBBUILDER_CHECKOUT_REF LIBBUILDER_CLONE_BRANCH_OR_TAG=$LIBBUILDER_CLONE_BRANCH_OR_TAG && \ git clone --recursive \ @@ -80,9 +82,6 @@ RUN echo LIBBUILDER_CHECKOUT_REF=$LIBBUILDER_CHECKOUT_REF LIBBUILDER_CLONE_BRANC COPY entrypoint.sh $LIBBUILDER_PATH/entrypoint.sh -# Ccache is installed, enable it by default -ENV IDF_CCACHE_ENABLE=1 - WORKDIR /opt/esp/lib-builder ENTRYPOINT [ "/opt/esp/lib-builder/entrypoint.sh" ] CMD [ "bash" ] From ec816df1ac32e280b986816141be3e6d7ee4f63b Mon Sep 17 00:00:00 2001 From: Lucas Saavedra Vaz <32426024+lucasssvaz@users.noreply.github.com> Date: Wed, 28 Feb 2024 23:15:28 -0300 Subject: [PATCH 08/29] Fix --- tools/docker/Dockerfile | 3 +-- tools/docker/run.sh | 1 + 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/docker/Dockerfile b/tools/docker/Dockerfile index fc5ba3a03..2e543a2cd 100644 --- a/tools/docker/Dockerfile +++ b/tools/docker/Dockerfile @@ -30,10 +30,9 @@ RUN : \ python3-pyparsing \ python3-serial \ python3-setuptools \ - python3-textual \ python3-venv \ wget \ - && pip install --upgrade pip \ + && pip3 install --upgrade pip textual-dev \ && apt-get autoremove -y \ && rm -rf /var/lib/apt/lists/* \ && : diff --git a/tools/docker/run.sh b/tools/docker/run.sh index 46ef4ad92..2c7471174 100755 --- a/tools/docker/run.sh +++ b/tools/docker/run.sh @@ -30,6 +30,7 @@ if [ -n "$ARDUINO_DIR" ]; then TRIMMED_ARGS+=(-c /arduino-esp32) fi +DOCKER_ARGS+=(-e TERM=xterm-256color) DOCKER_ARGS+=(-e HOST_UID=$UID) if [ -n "$LIBBUILDER_GIT_SAFE_DIR" ]; then From 1e327a2ed2e68c9e511dc836e33b351e3e03b63e Mon Sep 17 00:00:00 2001 From: Lucas Saavedra Vaz <32426024+lucasssvaz@users.noreply.github.com> Date: Thu, 29 Feb 2024 00:03:45 -0300 Subject: [PATCH 09/29] Test --- tools/docker/Dockerfile | 2 +- tools/docker/run.ps1 | 17 +++++++++++++++++ tools/docker/run.sh | 41 +++++------------------------------------ 3 files changed, 23 insertions(+), 37 deletions(-) create mode 100644 tools/docker/run.ps1 diff --git a/tools/docker/Dockerfile b/tools/docker/Dockerfile index 2e543a2cd..a9574bdac 100644 --- a/tools/docker/Dockerfile +++ b/tools/docker/Dockerfile @@ -83,4 +83,4 @@ COPY entrypoint.sh $LIBBUILDER_PATH/entrypoint.sh WORKDIR /opt/esp/lib-builder ENTRYPOINT [ "/opt/esp/lib-builder/entrypoint.sh" ] -CMD [ "bash" ] +CMD [ "python3", "tools/config_editor/app.py" ] diff --git a/tools/docker/run.ps1 b/tools/docker/run.ps1 new file mode 100644 index 000000000..c292e26f2 --- /dev/null +++ b/tools/docker/run.ps1 @@ -0,0 +1,17 @@ +$ARDUINO_DIR = $args[0] -replace '\\', '/' +if (-not $ARDUINO_DIR) { + $ARDUINO_DIR = (Get-Location).Path + '/../' +} + +$ARDUINO_DIR = (Get-Item -Path $ARDUINO_DIR).FullName +$DOCKER_ARGS = @() +$DOCKER_ARGS += '-v', "$ARDUINO_DIR:/arduino-esp32" +$DOCKER_ARGS += '-e', 'TERM=xterm-256color' +$DOCKER_ARGS += '-e', "HOST_UID=$env:UID" + +if ($env:LIBBUILDER_GIT_SAFE_DIR) { + $DOCKER_ARGS += '-e', "LIBBUILDER_GIT_SAFE_DIR=$env:LIBBUILDER_GIT_SAFE_DIR" +} + +Write-Output "Running: docker run $($DOCKER_ARGS -join ' ') lucassvaz/esp32-arduino-lib-builder:latest" +docker run @($DOCKER_ARGS) lucassvaz/esp32-arduino-lib-builder:latest python3 tools/config_editor/app.py diff --git a/tools/docker/run.sh b/tools/docker/run.sh index 2c7471174..1533bee07 100755 --- a/tools/docker/run.sh +++ b/tools/docker/run.sh @@ -1,35 +1,10 @@ #!/usr/bin/env bash -i=0 -NEXT_ARG="false" -ARDUINO_DIR="" +ARDUINO_DIR=${1:-$PWD/../} DOCKER_ARGS=() -ORIGINAL_ARGS=("$@") -TRIMMED_ARGS=() - -while [ $i -lt ${#ORIGINAL_ARGS[@]} ]; do - arg=${ORIGINAL_ARGS[$i]} - if [ $arg == "-c" ]; then - NEXT_ARG="true" - elif [ $NEXT_ARG == "true" ]; then - ARDUINO_DIR=$arg - NEXT_ARG="false" - else - TRIMMED_ARGS+=($arg) - fi - i=$((i + 1)) -done - -if [ -n "$ARDUINO_DIR" ]; then - if [ ! -d "$ARDUINO_DIR" ]; then - echo "Arduino directory \"$ARDUINO_DIR\" does not exist" - exit 1 - fi - ARDUINO_DIR=$(echo $(cd $ARDUINO_DIR; pwd)) - DOCKER_ARGS+=(-v $ARDUINO_DIR:/arduino-esp32) - TRIMMED_ARGS+=(-c /arduino-esp32) -fi +ARDUINO_DIR=$(echo $(cd $ARDUINO_DIR; pwd)) +DOCKER_ARGS+=(-v $ARDUINO_DIR:/arduino-esp32) DOCKER_ARGS+=(-e TERM=xterm-256color) DOCKER_ARGS+=(-e HOST_UID=$UID) @@ -37,11 +12,5 @@ if [ -n "$LIBBUILDER_GIT_SAFE_DIR" ]; then DOCKER_ARGS+=(-e LIBBUILDER_GIT_SAFE_DIR=$LIBBUILDER_GIT_SAFE_DIR) fi -if [ "$VERBOSE_OUTPUT" -eq 1 ]; then - echo "Arguments:" - echo "DOCKER_ARGS = ${DOCKER_ARGS[@]}" - echo "TRIMMED_ARGS = ${TRIMMED_ARGS[@]}" - echo "Running: docker run ${DOCKER_ARGS[@]} lucassvaz/esp32-arduino-lib-builder ./build.sh ${TRIMMED_ARGS[@]}" -fi - -docker run ${DOCKER_ARGS[@]} lucassvaz/esp32-arduino-lib-builder ./build.sh ${TRIMMED_ARGS[@]} +echo "Running: docker run ${DOCKER_ARGS[@]} lucassvaz/esp32-arduino-lib-builder:latest" +docker run ${DOCKER_ARGS[@]} lucassvaz/esp32-arduino-lib-builder:latest python3 tools/config_editor/app.py From 9a74157bc6496e01b6586ea7ac7c3dc06dcf60d9 Mon Sep 17 00:00:00 2001 From: Lucas Saavedra Vaz <32426024+lucasssvaz@users.noreply.github.com> Date: Thu, 29 Feb 2024 10:12:41 -0300 Subject: [PATCH 10/29] Fix --- tools/docker/run.ps1 | 1 + tools/docker/run.sh | 1 + 2 files changed, 2 insertions(+) diff --git a/tools/docker/run.ps1 b/tools/docker/run.ps1 index c292e26f2..d0f908b88 100644 --- a/tools/docker/run.ps1 +++ b/tools/docker/run.ps1 @@ -5,6 +5,7 @@ if (-not $ARDUINO_DIR) { $ARDUINO_DIR = (Get-Item -Path $ARDUINO_DIR).FullName $DOCKER_ARGS = @() +$DOCKER_ARGS += '-it' $DOCKER_ARGS += '-v', "$ARDUINO_DIR:/arduino-esp32" $DOCKER_ARGS += '-e', 'TERM=xterm-256color' $DOCKER_ARGS += '-e', "HOST_UID=$env:UID" diff --git a/tools/docker/run.sh b/tools/docker/run.sh index 1533bee07..0ef5bbeac 100755 --- a/tools/docker/run.sh +++ b/tools/docker/run.sh @@ -4,6 +4,7 @@ ARDUINO_DIR=${1:-$PWD/../} DOCKER_ARGS=() ARDUINO_DIR=$(echo $(cd $ARDUINO_DIR; pwd)) +DOCKER_ARGS+=(-it) DOCKER_ARGS+=(-v $ARDUINO_DIR:/arduino-esp32) DOCKER_ARGS+=(-e TERM=xterm-256color) DOCKER_ARGS+=(-e HOST_UID=$UID) From d87db7d543040261b36ae2e0681b7a2719d025a9 Mon Sep 17 00:00:00 2001 From: Lucas Saavedra Vaz <32426024+lucasssvaz@users.noreply.github.com> Date: Mon, 8 Apr 2024 15:01:45 -0300 Subject: [PATCH 11/29] Add UI checks --- tools/config_editor/app.py | 7 +++++-- tools/config_editor/compile.py | 10 ++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/tools/config_editor/app.py b/tools/config_editor/app.py index 9ab882c41..c38ba6ec8 100755 --- a/tools/config_editor/app.py +++ b/tools/config_editor/app.py @@ -86,7 +86,6 @@ def compose(self) -> ComposeResult: def on_mount(self) -> None: # Event handler called when the app is mounted for the first time - self.title = "Configurator" self.sub_title = "Main Menu" print("Main screen mounted.") @@ -131,6 +130,7 @@ def on_mount(self) -> None: print("IDF Branch: " + str(self.setting_idf_branch)) print("IDF Commit: " + str(self.setting_idf_commit)) print("IDF Debug Level: " + str(self.setting_debug_level)) + self.title = "Configurator" self.push_screen("main") def arduino_default_path(): @@ -256,8 +256,11 @@ def main() -> None: elif args.arduino_path == arduino_default_path(): print("Warning: Default Arduino path not found. Disabling copy to Arduino.") app.setting_enable_copy = False + elif args.arduino_path == "/arduino-esp32": # Docker mount point + print("Error: Arduino folder not mounted to /arduino-esp32 in Docker container.") + exit(1) else: - print("Invalid path to Arduino core: " + os.path.abspath(args.arduino_path)) + print("Error: Invalid path to Arduino core: " + os.path.abspath(args.arduino_path)) exit(1) else: app.setting_enable_copy = False diff --git a/tools/config_editor/compile.py b/tools/config_editor/compile.py index 3cfb056b7..9dc95c887 100644 --- a/tools/config_editor/compile.py +++ b/tools/config_editor/compile.py @@ -72,6 +72,11 @@ def compile_libs(self) -> None: label = self.query_one("#compile-title", Static) self.child_process = None + + if not self.app.setting_target: + self.print_error("No target selected") + label.update("No target selected") + return if self.app.setting_target == ",".join(self.app.supported_targets): target = "all targets" else: @@ -161,3 +166,8 @@ def compose(self) -> ComposeResult: self.button_widget = Button("Back", id="compile-back-button") yield self.button_widget yield Footer() + + def on_mount(self) -> None: + # Event handler called when the screen is mounted + print("Compile screen mounted") + self.sub_title = "Compilation" From e98f2271a6ee3fdc56895e16238bedee6e8f5114 Mon Sep 17 00:00:00 2001 From: Lucas Saavedra Vaz <32426024+lucasssvaz@users.noreply.github.com> Date: Mon, 8 Apr 2024 16:11:40 -0300 Subject: [PATCH 12/29] Fix docker image --- tools/config_editor/app.py | 9 +++++++++ tools/config_editor/compile.py | 15 +++++++++++++++ tools/docker/Dockerfile | 10 +--------- tools/docker/entrypoint.sh | 18 ++++-------------- 4 files changed, 29 insertions(+), 23 deletions(-) diff --git a/tools/config_editor/app.py b/tools/config_editor/app.py index c38ba6ec8..6b0a0958b 100755 --- a/tools/config_editor/app.py +++ b/tools/config_editor/app.py @@ -103,6 +103,7 @@ class ConfigEditorApp(App): # Options to be set by the command line arguments setting_target = "" setting_arduino_path = "" + setting_arduino_permissions = "" setting_arduino_branch = "" setting_idf_branch = "" setting_idf_commit = "" @@ -199,6 +200,13 @@ def main() -> None: required=False, help="Path to arduino-esp32 directory. Default: " + arduino_default_path()) + parser.add_argument("-p", "--arduino-permissions", + metavar="", + type=str, + default="", + required=False, + help=argparse.SUPPRESS) # Hidden option. It is only supposed to be used by the docker container + parser.add_argument("-A", "--arduino-branch", metavar="", type=str, @@ -267,6 +275,7 @@ def main() -> None: # Set the other options app.setting_arduino_path = os.path.abspath(args.arduino_path) + app.setting_arduino_permissions = args.arduino_permissions app.setting_arduino_branch = args.arduino_branch app.setting_idf_branch = args.idf_branch app.setting_idf_commit = args.idf_commit diff --git a/tools/config_editor/compile.py b/tools/config_editor/compile.py index 9dc95c887..01c97305d 100644 --- a/tools/config_editor/compile.py +++ b/tools/config_editor/compile.py @@ -1,6 +1,7 @@ import sys import subprocess import os +import re from rich.console import RenderableType @@ -138,6 +139,20 @@ def compile_libs(self) -> None: print("Error reading child process errors: " + str(e)) label.update("Compilation failed for " + target) else: + regex = r"^[1-9][0-9]*:[1-9][0-9]*$" # Regex to match the line:column format + if self.app.setting_arduino_permissions and re.match(regex, self.app.setting_arduino_permissions): + chown_process = None + try: + chown_process = subprocess.run(["chown", "-R", self.app.setting_arduino_permissions, self.app.setting_arduino_path]) + except Exception as e: + print("Error changing permissions: " + str(e)) + + if chown_process and chown_process.returncode != 0: + self.print_error("Error changing permissions.") + self.print_error("Please change the ownership of generated files manually") + else: + self.print_success("Permissions changed successfully") + self.print_success("Compilation successful for " + target) label.update("Compilation successful for " + target) diff --git a/tools/docker/Dockerfile b/tools/docker/Dockerfile index a9574bdac..6c4507705 100644 --- a/tools/docker/Dockerfile +++ b/tools/docker/Dockerfile @@ -37,13 +37,6 @@ RUN : \ && rm -rf /var/lib/apt/lists/* \ && : -# install gosu for a better su+exec command -ARG GOSU_VERSION=1.17 -RUN dpkgArch="$(dpkg --print-architecture | awk -F- '{ print $NF }')" \ - && wget -O /usr/local/bin/gosu "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$dpkgArch" \ - && chmod +x /usr/local/bin/gosu \ - && gosu nobody true - # To build the image for a branch or a tag of the lib-builder, pass --build-arg LIBBUILDER_CLONE_BRANCH_OR_TAG=name. # To build the image with a specific commit ID of lib-builder, pass --build-arg LIBBUILDER_CHECKOUT_REF=commit-id. # It is possibe to combine both, e.g.: @@ -60,7 +53,6 @@ ARG LIBBUILDER_CLONE_SHALLOW_DEPTH=1 ARG LIBBUILDER_TARGETS=all ENV LIBBUILDER_PATH=/opt/esp/lib-builder -ENV ARDUINO_PATH=/opt/esp/lib-builder/arduino-esp32 # Ccache is installed, enable it by default ENV IDF_CCACHE_ENABLE=1 @@ -83,4 +75,4 @@ COPY entrypoint.sh $LIBBUILDER_PATH/entrypoint.sh WORKDIR /opt/esp/lib-builder ENTRYPOINT [ "/opt/esp/lib-builder/entrypoint.sh" ] -CMD [ "python3", "tools/config_editor/app.py" ] +CMD [ "python3", "tools/config_editor/app.py", "-c", "/arduino-esp32" ] diff --git a/tools/docker/entrypoint.sh b/tools/docker/entrypoint.sh index 12e715ff3..0f8a07022 100755 --- a/tools/docker/entrypoint.sh +++ b/tools/docker/entrypoint.sh @@ -15,19 +15,9 @@ then done fi -if [ "$(id -u)" = "0" ] && [ -n "${HOST_UID}" ]; then - groupadd -g ${HOST_UID} host_user - useradd -m -u ${HOST_UID} -g ${HOST_UID} host_user - - if [ -d /arduino-esp32 ]; then - chown -R ${HOST_UID}:${HOST_UID} /arduino-esp32 - fi - - chown -R ${HOST_UID}:${HOST_UID} /opt/esp +exec "$@" - # Add call to gosu to drop from root user to host_user - # when running original entrypoint - set -- gosu host_user "$@" +if [ -d /arduino-esp32 ]; then + echo "Fixing permissions on /arduino-esp32" + chown -R `stat -c "%u:%g" /arduino-esp32` /arduino-esp32 fi - -exec "$@" From c3c1587c59d44fe3f2282bd4d3624835cfcbde57 Mon Sep 17 00:00:00 2001 From: Lucas Saavedra Vaz <32426024+lucasssvaz@users.noreply.github.com> Date: Mon, 8 Apr 2024 16:59:15 -0300 Subject: [PATCH 13/29] Fix exec in docker --- tools/config_editor/app.py | 4 ++-- tools/config_editor/compile.py | 4 +++- tools/docker/entrypoint.sh | 12 +++++++----- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/tools/config_editor/app.py b/tools/config_editor/app.py index 6b0a0958b..05fb4b4a7 100755 --- a/tools/config_editor/app.py +++ b/tools/config_editor/app.py @@ -265,8 +265,8 @@ def main() -> None: print("Warning: Default Arduino path not found. Disabling copy to Arduino.") app.setting_enable_copy = False elif args.arduino_path == "/arduino-esp32": # Docker mount point - print("Error: Arduino folder not mounted to /arduino-esp32 in Docker container.") - exit(1) + print("Warning: Docker mount point not found. Disabling copy to Arduino.") + app.setting_enable_copy = False else: print("Error: Invalid path to Arduino core: " + os.path.abspath(args.arduino_path)) exit(1) diff --git a/tools/config_editor/compile.py b/tools/config_editor/compile.py index 01c97305d..8be50ca44 100644 --- a/tools/config_editor/compile.py +++ b/tools/config_editor/compile.py @@ -139,11 +139,13 @@ def compile_libs(self) -> None: print("Error reading child process errors: " + str(e)) label.update("Compilation failed for " + target) else: - regex = r"^[1-9][0-9]*:[1-9][0-9]*$" # Regex to match the line:column format + regex = r"^[1-9][0-9]*:[1-9][0-9]*$" # Regex to match the uid:gid format if self.app.setting_arduino_permissions and re.match(regex, self.app.setting_arduino_permissions): + print_info("Changing permissions of generated files") chown_process = None try: chown_process = subprocess.run(["chown", "-R", self.app.setting_arduino_permissions, self.app.setting_arduino_path]) + chown_process.wait() except Exception as e: print("Error changing permissions: " + str(e)) diff --git a/tools/docker/entrypoint.sh b/tools/docker/entrypoint.sh index 0f8a07022..57be74e72 100755 --- a/tools/docker/entrypoint.sh +++ b/tools/docker/entrypoint.sh @@ -15,9 +15,11 @@ then done fi -exec "$@" - -if [ -d /arduino-esp32 ]; then - echo "Fixing permissions on /arduino-esp32" - chown -R `stat -c "%u:%g" /arduino-esp32` /arduino-esp32 +# Check if /arduino-esp32 exists +if [ -d "/arduino-esp32" ]; then + # If it exists, add the -p argument + exec "$@" -p `stat -c "%u:%g" /arduino-esp32` +else + # If it doesn't exist, just execute the command without the -p argument + exec "$@" fi From 69d157311f18547379ca6336dc4d7efe71f45396 Mon Sep 17 00:00:00 2001 From: Lucas Saavedra Vaz <32426024+lucasssvaz@users.noreply.github.com> Date: Mon, 8 Apr 2024 17:03:18 -0300 Subject: [PATCH 14/29] Move argument --- tools/docker/Dockerfile | 2 +- tools/docker/entrypoint.sh | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/tools/docker/Dockerfile b/tools/docker/Dockerfile index 6c4507705..a6daa010f 100644 --- a/tools/docker/Dockerfile +++ b/tools/docker/Dockerfile @@ -75,4 +75,4 @@ COPY entrypoint.sh $LIBBUILDER_PATH/entrypoint.sh WORKDIR /opt/esp/lib-builder ENTRYPOINT [ "/opt/esp/lib-builder/entrypoint.sh" ] -CMD [ "python3", "tools/config_editor/app.py", "-c", "/arduino-esp32" ] +CMD [ "python3", "tools/config_editor/app.py" ] diff --git a/tools/docker/entrypoint.sh b/tools/docker/entrypoint.sh index 57be74e72..f26342251 100755 --- a/tools/docker/entrypoint.sh +++ b/tools/docker/entrypoint.sh @@ -15,11 +15,11 @@ then done fi -# Check if /arduino-esp32 exists +# Check if the mount point /arduino-esp32 exists if [ -d "/arduino-esp32" ]; then - # If it exists, add the -p argument - exec "$@" -p `stat -c "%u:%g" /arduino-esp32` + # If it exists, add the -p and -c arguments + exec "$@" -c /arduino-esp32 -p `stat -c "%u:%g" /arduino-esp32` else - # If it doesn't exist, just execute the command without the -p argument + # If it doesn't exist, just execute the command without them exec "$@" fi From 74290efe7753b028581cfe3a20f57f4c41755df5 Mon Sep 17 00:00:00 2001 From: Lucas Saavedra Vaz <32426024+lucasssvaz@users.noreply.github.com> Date: Mon, 8 Apr 2024 18:32:10 -0300 Subject: [PATCH 15/29] Add workflow --- .github/workflows/docker.yml | 83 ++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 .github/workflows/docker.yml diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml new file mode 100644 index 000000000..586a8202f --- /dev/null +++ b/.github/workflows/docker.yml @@ -0,0 +1,83 @@ +name: Build and push Docker image + +on: + push: + branches: + - 'master' + - 'release/*' + tags: + - 'v*.*' + +env: + # Platforms to build the image for amd64 and arm64. + BUILD_PLATFORMS: linux/amd64,linux/arm64 + DOCKERHUB_REPO: ${{ github.repository_owner }}/esp32-arduino-lib-builder + +jobs: + docker: + # Disable the job in forks + if: ${{ github.repository_owner == 'espressif' }} + + runs-on: ubuntu-latest + steps: + # Depending on the branch/tag, set CLONE_BRANCH_OR_TAG variable (used in the Dockerfile + # as a build arg) and TAG_NAME (used when tagging the image). + # + # The following 3 steps cover the alternatives (tag, release branch, master branch): + - name: Set variables (tags) + if: ${{ github.ref_type == 'tag' }} + run: | + echo "CLONE_BRANCH_OR_TAG=$GITHUB_REF_NAME" >> $GITHUB_ENV + echo "TAG_NAME=$GITHUB_REF_NAME" >> $GITHUB_ENV + - name: Set variables (release branches) + if: ${{ github.ref_type == 'branch' && startsWith(github.ref_name, 'release/') }} + run: | + echo "CLONE_BRANCH_OR_TAG=$GITHUB_REF_NAME" >> $GITHUB_ENV + echo "TAG_NAME=release-${GITHUB_REF_NAME##release/}" >> $GITHUB_ENV + - name: Set variables (main branch) + if: ${{ github.ref_type == 'branch' && github.ref_name == 'master' }} + run: | + echo "CLONE_BRANCH_OR_TAG=master" >> $GITHUB_ENV + echo "TAG_NAME=latest" >> $GITHUB_ENV + + # Display the variables set above, just in case. + - name: Check variables + run: | + echo "CLONE_BRANCH_OR_TAG: $CLONE_BRANCH_OR_TAG" + echo "CHECKOUT_REF: $CHECKOUT_REF" + echo "TAG_NAME: $TAG_NAME" + + # The following steps are the standard boilerplate from + # https://github.com/marketplace/actions/build-and-push-docker-images + - name: Checkout + uses: actions/checkout@v4 + - name: Login to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + - name: Set up QEMU for multiarch builds + uses: docker/setup-qemu-action@v3 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - name: Build and push + uses: docker/build-push-action@v5 + with: + context: tools/docker + push: true + tags: ${{ env.DOCKERHUB_REPO }}:${{ env.TAG_NAME }} + platforms: ${{ env.BUILD_PLATFORMS }} + cache-from: type=registry,ref=${{ env.DOCKERHUB_REPO }}:${{ env.TAG_NAME }} + cache-to: type=inline + build-args: | + LIBBUILDER_CLONE_URL=${{ github.server_url }}/${{ github.repository }}.git + LIBBUILDER_CLONE_BRANCH_OR_TAG=${{ env.CLONE_BRANCH_OR_TAG }} + + - name: Update Docker Hub repository description (master branch) + if: ${{ github.ref_type == 'branch' && github.ref_name == 'master' }} + uses: peter-evans/dockerhub-description@v4 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + repository: ${{ env.DOCKERHUB_REPO }} + readme-filepath: ./tools/docker/README.md From a11164ca7258eeeb7a8d7298a558fccc79be7c6a Mon Sep 17 00:00:00 2001 From: Lucas Saavedra Vaz <32426024+lucasssvaz@users.noreply.github.com> Date: Tue, 9 Apr 2024 10:02:00 -0300 Subject: [PATCH 16/29] Add checks to entrypoint --- tools/docker/entrypoint.sh | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/tools/docker/entrypoint.sh b/tools/docker/entrypoint.sh index f26342251..db7dbc13e 100755 --- a/tools/docker/entrypoint.sh +++ b/tools/docker/entrypoint.sh @@ -7,19 +7,19 @@ set -e # see git-config manual page. if [ -n "${LIBBUILDER_GIT_SAFE_DIR+x}" ] then - echo "Adding following directories into git's safe.directory" - echo "$LIBBUILDER_GIT_SAFE_DIR" | tr ':' '\n' | while read -r dir - do - git config --global --add safe.directory "$dir" - echo " $dir" - done + echo "Adding following directories into git's safe.directory" + echo "$LIBBUILDER_GIT_SAFE_DIR" | tr ':' '\n' | while read -r dir + do + git config --global --add safe.directory "$dir" + echo " $dir" + done fi # Check if the mount point /arduino-esp32 exists -if [ -d "/arduino-esp32" ]; then - # If it exists, add the -p and -c arguments +if [ -d "/arduino-esp32" ] && [[ "$@" == "python3 tools/config_editor/app.py"* ]]; then + # Running UI with mount point detected, adding -p and -c arguments exec "$@" -c /arduino-esp32 -p `stat -c "%u:%g" /arduino-esp32` else - # If it doesn't exist, just execute the command without them + # Running UI without mount point detected or running another command exec "$@" fi From 52e00bd3bb223bf2b24177549a51af8d5f9b599f Mon Sep 17 00:00:00 2001 From: Lucas Saavedra Vaz <32426024+lucasssvaz@users.noreply.github.com> Date: Tue, 9 Apr 2024 10:02:18 -0300 Subject: [PATCH 17/29] Improvements to Dockerfile --- tools/docker/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/docker/Dockerfile b/tools/docker/Dockerfile index a6daa010f..1742b9833 100644 --- a/tools/docker/Dockerfile +++ b/tools/docker/Dockerfile @@ -2,6 +2,7 @@ FROM ubuntu:22.04 # switch to root, let the entrypoint drop back to host user USER root +SHELL ["/bin/bash", "-c"] ARG DEBIAN_FRONTEND=noninteractive @@ -50,7 +51,6 @@ ARG LIBBUILDER_CLONE_BRANCH_OR_TAG=master ARG LIBBUILDER_CHECKOUT_REF= ARG LIBBUILDER_CLONE_SHALLOW= ARG LIBBUILDER_CLONE_SHALLOW_DEPTH=1 -ARG LIBBUILDER_TARGETS=all ENV LIBBUILDER_PATH=/opt/esp/lib-builder # Ccache is installed, enable it by default From c4f4ce3d4b8b89f65d8740f5860deac475ea9f2c Mon Sep 17 00:00:00 2001 From: Lucas Saavedra Vaz <32426024+lucasssvaz@users.noreply.github.com> Date: Tue, 9 Apr 2024 10:47:30 -0300 Subject: [PATCH 18/29] Test example run scripts --- tools/docker/run.ps1 | 29 +++++++++++++++++++++-------- tools/docker/run.sh | 29 +++++++++++++++++++++++------ 2 files changed, 44 insertions(+), 14 deletions(-) diff --git a/tools/docker/run.ps1 b/tools/docker/run.ps1 index d0f908b88..e63e95e7a 100644 --- a/tools/docker/run.ps1 +++ b/tools/docker/run.ps1 @@ -1,18 +1,31 @@ -$ARDUINO_DIR = $args[0] -replace '\\', '/' -if (-not $ARDUINO_DIR) { - $ARDUINO_DIR = (Get-Location).Path + '/../' +# This is an example of how to run the docker container. +# This script is not part of the container, it is meant to be run on the host machine. +# Usage: ./run.ps1 + +if (-not (Test-Path -Path (Get-Command docker).Source)) { + Write-Host "ERROR: Docker is not installed! Please install docker first." + exit 1 +} + +if ($args.Count -gt 0) { + $ARDUINO_DIR = $args[0] -replace '\\', '/' +} else { + $ARDUINO_DIR = '' } -$ARDUINO_DIR = (Get-Item -Path $ARDUINO_DIR).FullName $DOCKER_ARGS = @() $DOCKER_ARGS += '-it' -$DOCKER_ARGS += '-v', "$ARDUINO_DIR:/arduino-esp32" $DOCKER_ARGS += '-e', 'TERM=xterm-256color' -$DOCKER_ARGS += '-e', "HOST_UID=$env:UID" + +if ((Test-Path $ARDUINO_DIR)) { + $DOCKER_ARGS += '-v', "$ARDUINO_DIR:/arduino-esp32" +} else { + Write-Output "Warning: Invalid arduino directory: '$ARDUINO_DIR'. Ignoring it." +} if ($env:LIBBUILDER_GIT_SAFE_DIR) { $DOCKER_ARGS += '-e', "LIBBUILDER_GIT_SAFE_DIR=$env:LIBBUILDER_GIT_SAFE_DIR" } -Write-Output "Running: docker run $($DOCKER_ARGS -join ' ') lucassvaz/esp32-arduino-lib-builder:latest" -docker run @($DOCKER_ARGS) lucassvaz/esp32-arduino-lib-builder:latest python3 tools/config_editor/app.py +Write-Output "Running: docker run $($DOCKER_ARGS -join ' ') lucassvaz/esp32-arduino-lib-builder" +#docker run @($DOCKER_ARGS) lucassvaz/esp32-arduino-lib-builder diff --git a/tools/docker/run.sh b/tools/docker/run.sh index 0ef5bbeac..fc74d8117 100755 --- a/tools/docker/run.sh +++ b/tools/docker/run.sh @@ -1,17 +1,34 @@ #!/usr/bin/env bash -ARDUINO_DIR=${1:-$PWD/../} +# This is an example of how to run the docker container. +# This script is not part of the container, it is meant to be run on the host machine. +# Usage: ./run.sh + +if ! [ -x "$(command -v docker)" ]; then + echo "ERROR: Docker is not installed! Please install docker first." + exit 1 +fi + +if [ -n "$1" ]; then + ARDUINO_DIR=$(realpath "$1") +else + ARDUINO_DIR="" +fi + DOCKER_ARGS=() -ARDUINO_DIR=$(echo $(cd $ARDUINO_DIR; pwd)) DOCKER_ARGS+=(-it) -DOCKER_ARGS+=(-v $ARDUINO_DIR:/arduino-esp32) DOCKER_ARGS+=(-e TERM=xterm-256color) -DOCKER_ARGS+=(-e HOST_UID=$UID) + +if [ -d "$ARDUINO_DIR" ]; then + DOCKER_ARGS+=(-v $ARDUINO_DIR:/arduino-esp32) +else + echo "Warning: Invalid arduino directory: '$ARDUINO_DIR'. Ignoring it." +fi if [ -n "$LIBBUILDER_GIT_SAFE_DIR" ]; then DOCKER_ARGS+=(-e LIBBUILDER_GIT_SAFE_DIR=$LIBBUILDER_GIT_SAFE_DIR) fi -echo "Running: docker run ${DOCKER_ARGS[@]} lucassvaz/esp32-arduino-lib-builder:latest" -docker run ${DOCKER_ARGS[@]} lucassvaz/esp32-arduino-lib-builder:latest python3 tools/config_editor/app.py +echo "Running: docker run ${DOCKER_ARGS[@]} lucassvaz/esp32-arduino-lib-builder" +docker run ${DOCKER_ARGS[@]} lucassvaz/esp32-arduino-lib-builder From 36acb433df57194b74580b497d351493d7ccea34 Mon Sep 17 00:00:00 2001 From: Lucas Saavedra Vaz <32426024+lucasssvaz@users.noreply.github.com> Date: Tue, 9 Apr 2024 12:04:07 -0300 Subject: [PATCH 19/29] Fix powershell script --- tools/docker/run.ps1 | 48 +++++++++++++++++++++++++++++++++++--------- 1 file changed, 39 insertions(+), 9 deletions(-) diff --git a/tools/docker/run.ps1 b/tools/docker/run.ps1 index e63e95e7a..b3ae51589 100644 --- a/tools/docker/run.ps1 +++ b/tools/docker/run.ps1 @@ -1,24 +1,54 @@ # This is an example of how to run the docker container. # This script is not part of the container, it is meant to be run on the host machine. -# Usage: ./run.ps1 +# Usage: .\run.ps1 -if (-not (Test-Path -Path (Get-Command docker).Source)) { - Write-Host "ERROR: Docker is not installed! Please install docker first." +# Exit on error +$ErrorActionPreference = "stop" + +# https://devblogs.microsoft.com/scripting/use-a-powershell-function-to-see-if-a-command-exists/ +# Check if command exists +Function Test-CommandExists +{ + Param ($command) + try { + if (Get-Command $command) { + RETURN $true + } + } + catch { + RETURN $false + } +} + +# Check if path exists +Function Test-PathExists +{ + Param ($path) + try { + if (Test-Path -Path $path) { + RETURN $true + } + } + catch { + RETURN $false + } +} + +if (-not (Test-CommandExists docker)) { + Write-Host "ERROR: Docker is not installed! Please install docker first." -ForegroundColor red exit 1 } if ($args.Count -gt 0) { - $ARDUINO_DIR = $args[0] -replace '\\', '/' -} else { - $ARDUINO_DIR = '' + $ARDUINO_DIR = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($args[0]) } $DOCKER_ARGS = @() $DOCKER_ARGS += '-it' $DOCKER_ARGS += '-e', 'TERM=xterm-256color' -if ((Test-Path $ARDUINO_DIR)) { - $DOCKER_ARGS += '-v', "$ARDUINO_DIR:/arduino-esp32" +if ((Test-PathExists $ARDUINO_DIR)) { + $DOCKER_ARGS += '-v', "${ARDUINO_DIR}:/arduino-esp32" } else { Write-Output "Warning: Invalid arduino directory: '$ARDUINO_DIR'. Ignoring it." } @@ -28,4 +58,4 @@ if ($env:LIBBUILDER_GIT_SAFE_DIR) { } Write-Output "Running: docker run $($DOCKER_ARGS -join ' ') lucassvaz/esp32-arduino-lib-builder" -#docker run @($DOCKER_ARGS) lucassvaz/esp32-arduino-lib-builder +docker run @($DOCKER_ARGS) lucassvaz/esp32-arduino-lib-builder From 1cf54a34b729e6318e445393b61ac8a2e4175689 Mon Sep 17 00:00:00 2001 From: Lucas Saavedra Vaz <32426024+lucasssvaz@users.noreply.github.com> Date: Tue, 9 Apr 2024 12:57:53 -0300 Subject: [PATCH 20/29] Change parameter name --- tools/config_editor/app.py | 6 +++--- tools/config_editor/compile.py | 4 ++-- tools/docker/entrypoint.sh | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/tools/config_editor/app.py b/tools/config_editor/app.py index 05fb4b4a7..fcba827d2 100755 --- a/tools/config_editor/app.py +++ b/tools/config_editor/app.py @@ -103,7 +103,7 @@ class ConfigEditorApp(App): # Options to be set by the command line arguments setting_target = "" setting_arduino_path = "" - setting_arduino_permissions = "" + setting_output_permissions = "" setting_arduino_branch = "" setting_idf_branch = "" setting_idf_commit = "" @@ -200,7 +200,7 @@ def main() -> None: required=False, help="Path to arduino-esp32 directory. Default: " + arduino_default_path()) - parser.add_argument("-p", "--arduino-permissions", + parser.add_argument("--output-permissions", metavar="", type=str, default="", @@ -275,7 +275,7 @@ def main() -> None: # Set the other options app.setting_arduino_path = os.path.abspath(args.arduino_path) - app.setting_arduino_permissions = args.arduino_permissions + app.setting_output_permissions = args.output_permissions app.setting_arduino_branch = args.arduino_branch app.setting_idf_branch = args.idf_branch app.setting_idf_commit = args.idf_commit diff --git a/tools/config_editor/compile.py b/tools/config_editor/compile.py index 8be50ca44..dc4a77f14 100644 --- a/tools/config_editor/compile.py +++ b/tools/config_editor/compile.py @@ -140,11 +140,11 @@ def compile_libs(self) -> None: label.update("Compilation failed for " + target) else: regex = r"^[1-9][0-9]*:[1-9][0-9]*$" # Regex to match the uid:gid format - if self.app.setting_arduino_permissions and re.match(regex, self.app.setting_arduino_permissions): + if self.app.setting_output_permissions and re.match(regex, self.app.setting_output_permissions): print_info("Changing permissions of generated files") chown_process = None try: - chown_process = subprocess.run(["chown", "-R", self.app.setting_arduino_permissions, self.app.setting_arduino_path]) + chown_process = subprocess.run(["chown", "-R", self.app.setting_output_permissions, self.app.setting_arduino_path]) chown_process.wait() except Exception as e: print("Error changing permissions: " + str(e)) diff --git a/tools/docker/entrypoint.sh b/tools/docker/entrypoint.sh index db7dbc13e..cb4426a99 100755 --- a/tools/docker/entrypoint.sh +++ b/tools/docker/entrypoint.sh @@ -17,8 +17,8 @@ fi # Check if the mount point /arduino-esp32 exists if [ -d "/arduino-esp32" ] && [[ "$@" == "python3 tools/config_editor/app.py"* ]]; then - # Running UI with mount point detected, adding -p and -c arguments - exec "$@" -c /arduino-esp32 -p `stat -c "%u:%g" /arduino-esp32` + # Running UI with mount point detected, adding -c and --output-permissions arguments + exec "$@" -c /arduino-esp32 --output-permissions `stat -c "%u:%g" /arduino-esp32` else # Running UI without mount point detected or running another command exec "$@" From 7f792875ff5ce7c6b2e0103dc8aa404e99de9f01 Mon Sep 17 00:00:00 2001 From: Lucas Saavedra Vaz <32426024+lucasssvaz@users.noreply.github.com> Date: Tue, 9 Apr 2024 12:58:02 -0300 Subject: [PATCH 21/29] Add comment --- tools/docker/Dockerfile | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/docker/Dockerfile b/tools/docker/Dockerfile index 1742b9833..a46733a34 100644 --- a/tools/docker/Dockerfile +++ b/tools/docker/Dockerfile @@ -1,3 +1,4 @@ +# To Do: Check if it is worth to use espressif/idf as base image (image size will be much bigger) FROM ubuntu:22.04 # switch to root, let the entrypoint drop back to host user From 22b8489b2287cf78c9e7e59d414593d14a4edbb6 Mon Sep 17 00:00:00 2001 From: Lucas Saavedra Vaz <32426024+lucasssvaz@users.noreply.github.com> Date: Tue, 9 Apr 2024 12:59:21 -0300 Subject: [PATCH 22/29] Add Readme --- tools/docker/README.md | 48 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 tools/docker/README.md diff --git a/tools/docker/README.md b/tools/docker/README.md new file mode 100644 index 000000000..bc1355af5 --- /dev/null +++ b/tools/docker/README.md @@ -0,0 +1,48 @@ + + +# ESP-IDF Docker Image + +This is a Docker image for the [ESP32 Arduino Lib Builder](https://github.com/espressif/esp32-arduino-lib-builder). It is intended for building the static libraries of ESP-IDF components for use in Arduino projects. + +This image contains a copy of the esp32-arduino-lib-builder repository and already include or will obtain all the required tools and dependencies to build the Arduino static libraries. + +## Tags + +Multiple tags of this image are maintained: + + - `latest`: tracks `master` branch of esp32-arduino-lib-builder + - `release-vX.Y`: tracks `release/vX.Y` branch of esp32-arduino-lib-builder + +## Basic Usage + +```bash +docker run --rm -it -e "TERM=xterm-256color" -v :/arduino-esp32 espressif/esp32-arduino-lib-builder:latest +``` + +The above command explained: + + - `docker run`: Runs a command in a new container. + - `--rm`: Optional. Automatically removes the container when it exits. Remove this flag if you plan to use the container multiple times. + - `-i`: Runs the container in interactive mode. + - `-t`: Allocates a pseudo-TTY. + - `-e "TERM=xterm-256color"`: Optional. Sets the terminal type to `xterm-256color` to display colors correctly. + - `-v :/arduino-esp32`: Optional. Mounts the Arduino Core for ESP32 repository at `/arduino-esp32` inside the container. Replace `` with the path to the repository on the host machine. If not provided, the container will not copy the compiled libraries to the host machine. + - `espressif/esp32-arduino-lib-builder:latest`: The Docker image to use. + +After running the above command, you will be inside the container and can build the libraries using the user interface. + +By default the docker container will run the user interface script. If you want to run a specific command, you can pass it as an argument to the docker run command. For example, to run a terminal inside the container, you can run: + +```bash +docker run -it espressif/esp32-arduino-lib-builder:latest /bin/bash +``` + +## Documentation + + + +For more information about this image and the detailed usage instructions, please refer to the Arduino Core for ESP32 documentation. From d0ada4acc9102f4b20829745bb3cbd5254f86117 Mon Sep 17 00:00:00 2001 From: Lucas Saavedra Vaz <32426024+lucasssvaz@users.noreply.github.com> Date: Tue, 9 Apr 2024 13:00:35 -0300 Subject: [PATCH 23/29] Fix comparison --- tools/config_editor/compile.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/config_editor/compile.py b/tools/config_editor/compile.py index dc4a77f14..c44885311 100644 --- a/tools/config_editor/compile.py +++ b/tools/config_editor/compile.py @@ -78,7 +78,7 @@ def compile_libs(self) -> None: self.print_error("No target selected") label.update("No target selected") return - if self.app.setting_target == ",".join(self.app.supported_targets): + elif self.app.setting_target == ",".join(self.app.supported_targets): target = "all targets" else: target = self.app.setting_target.replace(",", ", ").upper() From 16e4611697ff74a4998321654039836adc2bdf22 Mon Sep 17 00:00:00 2001 From: Lucas Saavedra Vaz <32426024+lucasssvaz@users.noreply.github.com> Date: Tue, 9 Apr 2024 13:03:56 -0300 Subject: [PATCH 24/29] Remove cache --- .github/workflows/docker.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 586a8202f..f30688263 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -67,8 +67,6 @@ jobs: push: true tags: ${{ env.DOCKERHUB_REPO }}:${{ env.TAG_NAME }} platforms: ${{ env.BUILD_PLATFORMS }} - cache-from: type=registry,ref=${{ env.DOCKERHUB_REPO }}:${{ env.TAG_NAME }} - cache-to: type=inline build-args: | LIBBUILDER_CLONE_URL=${{ github.server_url }}/${{ github.repository }}.git LIBBUILDER_CLONE_BRANCH_OR_TAG=${{ env.CLONE_BRANCH_OR_TAG }} From 203237db06d970234841de67e9cc4f86ae264c69 Mon Sep 17 00:00:00 2001 From: Lucas Saavedra Vaz <32426024+lucasssvaz@users.noreply.github.com> Date: Tue, 9 Apr 2024 13:51:30 -0300 Subject: [PATCH 25/29] Fix comment --- .github/workflows/docker.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index f30688263..8952015a2 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -9,7 +9,7 @@ on: - 'v*.*' env: - # Platforms to build the image for amd64 and arm64. + # Build the image for amd64 and arm64 BUILD_PLATFORMS: linux/amd64,linux/arm64 DOCKERHUB_REPO: ${{ github.repository_owner }}/esp32-arduino-lib-builder From 297b88bdec98b1768d39763ae30de64810ad0f71 Mon Sep 17 00:00:00 2001 From: Lucas Saavedra Vaz <32426024+lucasssvaz@users.noreply.github.com> Date: Tue, 9 Apr 2024 14:31:06 -0300 Subject: [PATCH 26/29] Improve permission settings --- tools/config_editor/compile.py | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/tools/config_editor/compile.py b/tools/config_editor/compile.py index c44885311..e6d1045ca 100644 --- a/tools/config_editor/compile.py +++ b/tools/config_editor/compile.py @@ -139,21 +139,25 @@ def compile_libs(self) -> None: print("Error reading child process errors: " + str(e)) label.update("Compilation failed for " + target) else: - regex = r"^[1-9][0-9]*:[1-9][0-9]*$" # Regex to match the uid:gid format - if self.app.setting_output_permissions and re.match(regex, self.app.setting_output_permissions): - print_info("Changing permissions of generated files") - chown_process = None - try: - chown_process = subprocess.run(["chown", "-R", self.app.setting_output_permissions, self.app.setting_arduino_path]) - chown_process.wait() - except Exception as e: - print("Error changing permissions: " + str(e)) - - if chown_process and chown_process.returncode != 0: - self.print_error("Error changing permissions.") - self.print_error("Please change the ownership of generated files manually") + if self.app.setting_output_permissions: + regex = r"^[1-9][0-9]*:[1-9][0-9]*$" # Regex to match the uid:gid format. Note that 0:0 (root) is not allowed + if re.match(regex, self.app.setting_output_permissions): + print_info("Setting permissions to: " + self.app.setting_output_permissions) + chown_process = None + try: + chown_process = subprocess.run(["chown", "-R", self.app.setting_output_permissions, self.app.setting_arduino_path]) + chown_process.wait() + except Exception as e: + print("Error changing permissions: " + str(e)) + + if chown_process and chown_process.returncode != 0: + self.print_error("Error changing permissions") + self.print_error("Please change the ownership of generated files manually") + else: + self.print_success("Permissions changed successfully") else: - self.print_success("Permissions changed successfully") + self.print_error("Invalid permissions format: " + self.app.setting_output_permissions) + self.print_error("Please change the ownership of generated files manually") self.print_success("Compilation successful for " + target) label.update("Compilation successful for " + target) From cfe8da771647d7a0e0a76671dc7bbb5656ad7928 Mon Sep 17 00:00:00 2001 From: Lucas Saavedra Vaz <32426024+lucasssvaz@users.noreply.github.com> Date: Tue, 9 Apr 2024 14:42:13 -0300 Subject: [PATCH 27/29] Add warning --- tools/config_editor/compile.py | 9 +++++++++ tools/docker/entrypoint.sh | 1 + 2 files changed, 10 insertions(+) diff --git a/tools/config_editor/compile.py b/tools/config_editor/compile.py index e6d1045ca..efb812174 100644 --- a/tools/config_editor/compile.py +++ b/tools/config_editor/compile.py @@ -61,6 +61,11 @@ def print_success(self, message: str) -> None: self.button_widget.add_class("-success") #print("Success: " + message) # For debugging + def print_warning(self, message: str) -> None: + # Print warning message to the RichLog widget + self.log_widget.write("[b bright_yellow]" + message) + #print("Warning: " + message) # For debugging + def print_info(self, message: str) -> None: # Print info message to the RichLog widget self.log_widget.write("[b bright_cyan]" + message) @@ -155,6 +160,10 @@ def compile_libs(self) -> None: self.print_error("Please change the ownership of generated files manually") else: self.print_success("Permissions changed successfully") + elif self.app.setting_output_permissions == "0:0": + self.print_warning("Permissions settings are set to root (0:0)") + self.print_warning("Please change the ownership of generated files manually") + self.print_warning("If you are compiling for Windows, you may ignore this warning") else: self.print_error("Invalid permissions format: " + self.app.setting_output_permissions) self.print_error("Please change the ownership of generated files manually") diff --git a/tools/docker/entrypoint.sh b/tools/docker/entrypoint.sh index cb4426a99..4b3826713 100755 --- a/tools/docker/entrypoint.sh +++ b/tools/docker/entrypoint.sh @@ -18,6 +18,7 @@ fi # Check if the mount point /arduino-esp32 exists if [ -d "/arduino-esp32" ] && [[ "$@" == "python3 tools/config_editor/app.py"* ]]; then # Running UI with mount point detected, adding -c and --output-permissions arguments + echo "Output folder permissions: `stat -c "%u:%g" /arduino-esp32`" exec "$@" -c /arduino-esp32 --output-permissions `stat -c "%u:%g" /arduino-esp32` else # Running UI without mount point detected or running another command From a6ae4a6ec55419119c4b2ebc945d2618096f3695 Mon Sep 17 00:00:00 2001 From: Lucas Saavedra Vaz <32426024+lucasssvaz@users.noreply.github.com> Date: Tue, 9 Apr 2024 14:44:02 -0300 Subject: [PATCH 28/29] Update readme --- tools/docker/README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tools/docker/README.md b/tools/docker/README.md index bc1355af5..109665c4a 100644 --- a/tools/docker/README.md +++ b/tools/docker/README.md @@ -10,6 +10,10 @@ This is a Docker image for the [ESP32 Arduino Lib Builder](https://github.com/es This image contains a copy of the esp32-arduino-lib-builder repository and already include or will obtain all the required tools and dependencies to build the Arduino static libraries. +Currently supported architectures are: + - `amd64` + - `arm64` + ## Tags Multiple tags of this image are maintained: From 671b1b63123fd7067c3332fe7176f268774596d1 Mon Sep 17 00:00:00 2001 From: Lucas Saavedra Vaz <32426024+lucasssvaz@users.noreply.github.com> Date: Tue, 9 Apr 2024 19:27:28 -0300 Subject: [PATCH 29/29] Fix repositories --- tools/docker/run.ps1 | 4 ++-- tools/docker/run.sh | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tools/docker/run.ps1 b/tools/docker/run.ps1 index b3ae51589..4c49ac505 100644 --- a/tools/docker/run.ps1 +++ b/tools/docker/run.ps1 @@ -57,5 +57,5 @@ if ($env:LIBBUILDER_GIT_SAFE_DIR) { $DOCKER_ARGS += '-e', "LIBBUILDER_GIT_SAFE_DIR=$env:LIBBUILDER_GIT_SAFE_DIR" } -Write-Output "Running: docker run $($DOCKER_ARGS -join ' ') lucassvaz/esp32-arduino-lib-builder" -docker run @($DOCKER_ARGS) lucassvaz/esp32-arduino-lib-builder +Write-Output "Running: docker run $($DOCKER_ARGS -join ' ') espressif/esp32-arduino-lib-builder" +docker run @($DOCKER_ARGS) espressif/esp32-arduino-lib-builder diff --git a/tools/docker/run.sh b/tools/docker/run.sh index fc74d8117..59e967363 100755 --- a/tools/docker/run.sh +++ b/tools/docker/run.sh @@ -30,5 +30,5 @@ if [ -n "$LIBBUILDER_GIT_SAFE_DIR" ]; then DOCKER_ARGS+=(-e LIBBUILDER_GIT_SAFE_DIR=$LIBBUILDER_GIT_SAFE_DIR) fi -echo "Running: docker run ${DOCKER_ARGS[@]} lucassvaz/esp32-arduino-lib-builder" -docker run ${DOCKER_ARGS[@]} lucassvaz/esp32-arduino-lib-builder +echo "Running: docker run ${DOCKER_ARGS[@]} espressif/esp32-arduino-lib-builder" +docker run ${DOCKER_ARGS[@]} espressif/esp32-arduino-lib-builder