Skip to content

Commit a98cf7e

Browse files
committed
docs(lib-builder): Add docker image documentation
1 parent e8e251a commit a98cf7e

File tree

2 files changed

+122
-2
lines changed

2 files changed

+122
-2
lines changed

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,7 @@ libraries/Insights/examples/*/*.ino.zip
5050
!.vale/styles/Vocab/
5151
.vale/styles/Vocab/*
5252
!.vale/styles/Vocab/Espressif/
53+
54+
# Ignore Lib Builder Docker run scripts
55+
/run.sh
56+
/run.ps1

docs/en/lib_builder.rst

+118-2
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,11 @@ This build command will build for the ESP32-S3 target. You can specify other tar
152152

153153
* esp32
154154
* esp32s2
155-
* esp32c3
156155
* esp32s3
156+
* esp32c2
157+
* esp32c3
158+
* esp32c6
159+
* esp32h2
157160

158161
Set Build Type
159162
^^^^^^^^^^^^^^
@@ -169,11 +172,124 @@ Set the build type. ex. 'build' to build the project and prepare for uploading t
169172
Additional Configuration
170173
^^^^^^^^^^^^^^^^^^^^^^^^
171174

172-
Specify additional configs to be applied. ex. 'qio 80m' to compile for QIO Flash@80MHz. Requires -b
175+
Specify additional configs to be applied. ex. 'qio 80m' to compile for QIO Flash@80MHz.
173176

174177
.. note:: This command requires the ``-b`` to work properly.
175178

176179

177180
.. code-block:: bash
178181
179182
./build.sh -t esp32 -b idf_libs qio 80m
183+
184+
Docker Image
185+
------------
186+
187+
You can use a docker image that for building the static libraries of ESP-IDF components for use in Arduino projects.
188+
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.
189+
190+
The current supported architectures by the Docker image are:
191+
192+
* ``amd64``
193+
* ``arm64``
194+
195+
.. note::
196+
Building the libraries using the Docker image is much slower than building them natively on the host machine.
197+
It is recommended to use the Docker image only when the host machine does not meet the requirements for building the libraries.
198+
199+
Tags
200+
****
201+
202+
Multiple tags of this image are maintained:
203+
204+
- ``latest``: tracks ``master`` branch of the Lib Builder
205+
- ``release-vX.Y``: tracks ``release/vX.Y`` branch of the Lib Builder
206+
207+
.. note::
208+
Versions of Lib Builder released before this feature was introduced do not have corresponding Docker image versions.
209+
You can check the up-to-date list of available tags at https://hub.docker.com/r/espressif/esp32-arduino-lib-builder/tags.
210+
211+
Usage
212+
*****
213+
214+
Before using the ``espressif/esp32-arduino-lib-builder`` Docker image locally, make sure you have Docker installed.
215+
Follow the instructions at https://docs.docker.com/install/, if it is not installed yet.
216+
217+
If using the image in a CI environment, consult the documentation of your CI service on how to specify the image used for the build process.
218+
219+
Building the Libraries
220+
^^^^^^^^^^^^^^^^^^^^^^
221+
222+
You have two options to run the Docker image to build the libraries. Manually or using the provided run script.
223+
224+
To run the Docker image manually, use the following command from the root of the ``arduino-esp32`` repository:
225+
226+
.. code-block:: bash
227+
228+
docker run --rm -it -v $PWD:/arduino-esp32 -e TERM=xterm-256color espressif/esp32-arduino-lib-builder
229+
230+
This will start the Lib Builder UI for compiling the libraries. The above command explained:
231+
232+
- ``docker run``: Runs a command in a container;
233+
- ``--rm``: Optional. Automatically removes the container when it exits. Remove this flag if you plan to use the container multiple times;
234+
- ``-i`` Run the container in interactive mode;
235+
- ``-t`` Allocate a pseudo-TTY;
236+
- ``-e TERM=xterm-256color``: Optional. Sets the terminal type to ``xterm-256color`` to display colors correctly;
237+
- ``-v $PWD:/arduino-esp32``: Optional. Mounts the current folder at ``/arduino-esp32`` inside the container. If not provided, the container will not copy the compiled libraries to the host machine;
238+
- ``espressif/esp32-arduino-lib-builder``: uses Docker image ``espressif/esp32-arduino-lib-builder`` with tag ``latest``. The ``latest`` tag is implicitly added by Docker when no tag is specified.
239+
240+
.. warning::
241+
The ``-v`` option is used to mount a folder from the host machine to the container. Make sure the folder already exists on the host machine before running the command.
242+
Otherwise, the folder will be created with root permissions and files generated inside the container might cause permission issues and compilation errors.
243+
244+
After running the above command, you will be inside the container and can build the libraries using the user interface.
245+
246+
By default the docker container will run the user interface script.
247+
If you want to run a specific command, you can pass it as an argument to the docker run command.
248+
For example, to run a terminal inside the container, you can run:
249+
250+
.. code-block:: bash
251+
252+
docker run -it espressif/esp32-arduino-lib-builder:latest /bin/bash
253+
254+
To run the Docker image using the provided run script it will depend on the host OS.
255+
Use the following command from the root of the ``arduino-esp32`` repository to execute the image in a Linux or macOS environment:
256+
257+
.. code-block:: bash
258+
259+
curl -LJO https://raw.githubusercontent.com/espressif/esp32-arduino-lib-builder/master/tools/docker/run.sh
260+
chmod +x run.sh
261+
./run.sh $PWD
262+
263+
For Windows, use the following command in PowerShell from the root of the ``arduino-esp32`` repository:
264+
265+
.. code-block:: powershell
266+
267+
Invoke-WebRequest -Uri "https://raw.githubusercontent.com/espressif/esp32-arduino-lib-builder/master/tools/docker/run.ps1" -OutFile "run.ps1"
268+
.\run.ps1 $PWD
269+
270+
.. warning::
271+
It is always a good practice to understand what the script does before running it.
272+
Make sure to analyze the content of the script to ensure it is safe to run and won't cause any harm to your system.
273+
274+
Building Custom Images
275+
**********************
276+
277+
To build a custom Docker image, you need to clone the Lib Builder repository and use the provided Dockerfile in the Lib Builder repository. The Dockerfile is located in the ``tools/docker`` directory.
278+
279+
The `Docker file in the Lib Builder repository <https://github.com/espressif/esp32-arduino-lib-builder/blob/master/tools/docker/Dockerfile>`_ provides several build arguments which can be used to customize the Docker image:
280+
281+
- ``LIBBUILDER_CLONE_URL``: URL of the repository to clone Lib Builder from. Can be set to a custom URL when working with a fork of Lib Builder. The default is ``https://github.com/espressif/esp32-arduino-lib-builder.git``;
282+
- ``LIBBUILDER_CLONE_BRANCH_OR_TAG``: Name of a git branch or tag used when cloning Lib Builder. This value is passed to the ``git clone`` command using the ``--branch`` argument. The default is ``master``;
283+
- ``LIBBUILDER_CHECKOUT_REF``: If this argument is set to a non-empty value, ``git checkout $LIBBUILDER_CHECKOUT_REF`` command performs 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;
284+
- ``LIBBUILDER_CLONE_SHALLOW``: If this argument is set to a non-empty value, ``--depth=1 --shallow-submodules`` arguments are used when performing ``git clone``. Depth can be customized using ``LIBBUILDER_CLONE_SHALLOW_DEPTH``. Doing a shallow clone significantly reduces the amount of data downloaded and the size of the resulting Docker image. However, if switching to a different branch in such a "shallow" repository is necessary, an additional ``git fetch origin <branch>`` command must be executed first;
285+
- ``LIBBUILDER_CLONE_SHALLOW_DEPTH``: This argument specifies the depth value to use when doing a shallow clone. If not set, ``--depth=1`` will be used. This argument has effect only if ``LIBBUILDER_CLONE_SHALLOW`` is used. Use this argument if you are building a Docker image for a branch, and the image has to contain the latest tag on that branch. To determine the required depth, run ``git describe`` for the given branch and note the offset number. Increment it by 1, then use it as the value of this argument. The resulting image will contain the latest tag on the branch, and consequently ``git describe`` command inside the Docker image will work as expected;
286+
287+
To use these arguments, pass them via the ``--build-arg`` command line option. For example, the following command builds a Docker image with a shallow clone of Lib Builder from a specific repository and branch:
288+
289+
.. code-block:: bash
290+
291+
docker buildx build -t lib-builder-custom:master \
292+
--build-arg LIBBUILDER_CLONE_BRANCH_OR_TAG=master \
293+
--build-arg LIBBUILDER_CLONE_SHALLOW=1 \
294+
--build-arg LIBBUILDER_CLONE_URL=https://github.com/espressif/esp32-arduino-lib-builder \
295+
tools/docker

0 commit comments

Comments
 (0)