|
| 1 | +.. _build-flow: |
| 2 | + |
| 3 | +Build Flow |
| 4 | +========== |
| 5 | + |
| 6 | +The Kuiper build process uses Docker to create a controlled environment for |
| 7 | +building Debian-based images for Analog Devices products. The build follows |
| 8 | +these high-level steps: |
| 9 | + |
| 10 | +1. ``build-docker.sh`` creates a Docker container with all necessary build |
| 11 | + dependencies |
| 12 | +2. Inside the container, ``kuiper-stages.sh`` orchestrates a series of build |
| 13 | + stages |
| 14 | +3. Each stage performs specific tasks like system configuration, tool |
| 15 | + installation, and boot setup |
| 16 | +4. The final image is exported as a zip file to the ``kuiper-volume`` |
| 17 | + directory on your host machine |
| 18 | + |
| 19 | +This approach ensures consistent builds across different host systems while |
| 20 | +allowing full customization through the ``config`` file. |
| 21 | + |
| 22 | +The ``config`` file is first read by ``build-docker.sh`` on the host system |
| 23 | +to set up environment variables and Docker options. It is then copied into |
| 24 | +the container where ``kuiper-stages.sh`` reads it again to determine which |
| 25 | +stages to execute and how to configure them. |
| 26 | + |
| 27 | +.. svg:: sources/build_flow.svg |
| 28 | + :align: center |
| 29 | + |
| 30 | +---- |
| 31 | + |
| 32 | +Docker Build Environment |
| 33 | +------------------------ |
| 34 | + |
| 35 | +Docker is used to perform the build inside a container, which partially |
| 36 | +isolates the build from the host system. This allows the script to work on |
| 37 | +non-Debian based systems (e.g., Fedora Linux). The isolation is not total |
| 38 | +due to the need to use some kernel-level services for ARM emulation (binfmt) |
| 39 | +and loop devices (losetup). |
| 40 | + |
| 41 | +The ``build-docker.sh`` script handles: |
| 42 | + |
| 43 | +- Checking prerequisites and permissions |
| 44 | +- Building a Docker image with all necessary dependencies |
| 45 | +- Running a Docker container with appropriate options |
| 46 | +- Mounting volumes to share data between the host and container |
| 47 | +- Setting environment variables based on the ``config`` file |
| 48 | +- Starting the internal build process by calling ``kuiper-stages.sh`` |
| 49 | +- Cleaning up the container after completion (if ``PRESERVE_CONTAINER=n``) |
| 50 | + |
| 51 | +Running the Build |
| 52 | +~~~~~~~~~~~~~~~~~ |
| 53 | + |
| 54 | +To build: |
| 55 | + |
| 56 | +.. code-block:: bash |
| 57 | +
|
| 58 | + sudo ./build-docker.sh |
| 59 | +
|
| 60 | +Your Kuiper image will be in the ``kuiper-volume/`` folder inside the cloned |
| 61 | +repository on your machine as a zip file named |
| 62 | +``image_YYYY-MM-DD-ADI-Kuiper-Linux-[arch].zip``. After successful build, |
| 63 | +the Docker image and the build container are removed if |
| 64 | +``PRESERVE_CONTAINER=n``. |
| 65 | + |
| 66 | +If needed, you can remove the build container with: |
| 67 | + |
| 68 | +.. code-block:: bash |
| 69 | +
|
| 70 | + docker rm -v debian_<DEBIAN_VERSION>_rootfs_container |
| 71 | +
|
| 72 | +If you choose to preserve the Docker container, you can access the Kuiper |
| 73 | +root filesystem by copying it from the container to your machine with this |
| 74 | +command: |
| 75 | + |
| 76 | +.. code-block:: bash |
| 77 | +
|
| 78 | + CONTAINER_ID=$(docker inspect --format="{{.Id}}" debian_<DEBIAN_VERSION>_rootfs_container) |
| 79 | + sudo docker cp $CONTAINER_ID:<TARGET_ARCHITECTURE>_rootfs . |
| 80 | +
|
| 81 | +You need to replace ``<DEBIAN_VERSION>`` and ``<TARGET_ARCHITECTURE>`` with |
| 82 | +the ones in the configuration file. |
| 83 | + |
| 84 | +Example: |
| 85 | + |
| 86 | +.. code-block:: bash |
| 87 | +
|
| 88 | + CONTAINER_ID=$(docker inspect --format="{{.Id}}" debian_bookworm_rootfs_container) |
| 89 | + sudo docker cp $CONTAINER_ID:armhf_rootfs . |
| 90 | +
|
| 91 | +Docker Container Configuration |
| 92 | +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 93 | + |
| 94 | +When the Docker container is run, various required command line arguments |
| 95 | +are provided: |
| 96 | + |
| 97 | +- ``-t``: Allocates a pseudo-TTY allowing interaction with container's shell |
| 98 | +- ``--privileged``: Provides elevated privileges required by the chroot |
| 99 | + command |
| 100 | +- ``-v /dev:/dev``: Mounts the host system's device directory |
| 101 | +- ``-v /lib/modules:/lib/modules``: Mounts kernel modules from the host |
| 102 | +- ``-v ./kuiper-volume:/kuiper-volume``: Creates a shared volume for the |
| 103 | + output |
| 104 | +- ``-e "DEBIAN_VERSION={value}"``: Sets environment variables from the config |
| 105 | + file |
| 106 | + |
| 107 | +The ``--name`` and ``--privileged`` options are already set by the script and |
| 108 | +should not be redefined. |
| 109 | + |
| 110 | +---- |
| 111 | + |
| 112 | +Stage-Based Build Process |
| 113 | +------------------------- |
| 114 | + |
| 115 | +Inside the Docker container, ``kuiper-stages.sh`` orchestrates the entire |
| 116 | +build process. This script reads the ``config`` file, sets up environment |
| 117 | +variables, and executes a series of stages in a specific order. |
| 118 | + |
| 119 | +How Stages Are Processed |
| 120 | +~~~~~~~~~~~~~~~~~~~~~~~~ |
| 121 | + |
| 122 | +The build process follows these steps inside the Docker container: |
| 123 | + |
| 124 | +1. ``kuiper-stages.sh`` loops through the ``stages`` directory in |
| 125 | + alphanumeric order |
| 126 | +2. Within each stage, it processes subdirectories in alphanumeric order |
| 127 | +3. For each subdirectory, it runs the following files if they exist: |
| 128 | + |
| 129 | + - ``run.sh`` - A shell script executed in the Docker container's context |
| 130 | + - ``run-chroot.sh`` - A shell script executed within the Kuiper image |
| 131 | + using chroot |
| 132 | + - Package installation files: |
| 133 | + |
| 134 | + - ``packages-[*]`` - Lists packages to install with |
| 135 | + ``--no-install-recommends`` |
| 136 | + - ``packages-[*]-with-recommends`` - Lists packages to install with |
| 137 | + their recommended dependencies |
| 138 | + |
| 139 | +The package installation files (``packages-[*]``) are processed if the |
| 140 | +corresponding configuration option is enabled. For example, |
| 141 | +``packages-desktop`` is only processed if ``CONFIG_DESKTOP=y`` in the config |
| 142 | +file. |
| 143 | + |
| 144 | +Key Stages Overview |
| 145 | +~~~~~~~~~~~~~~~~~~~ |
| 146 | + |
| 147 | +The build process is divided into several stages for logical clarity and |
| 148 | +modularity: |
| 149 | + |
| 150 | +- **01.bootstrap** - Creates a usable filesystem using ``debootstrap`` |
| 151 | +- **02.set-locale-and-timezone** - Configures system locale and timezone |
| 152 | + settings |
| 153 | +- **03.system-tweaks** - Sets up users, passwords, and system configuration |
| 154 | +- **04.configure-desktop-env** - Installs and configures desktop environment |
| 155 | + (if enabled) |
| 156 | +- **05.adi-tools** - Installs Analog Devices libraries and tools (based on |
| 157 | + config) |
| 158 | +- **06.boot-partition** - Adds boot files for different platforms |
| 159 | +- **07.extra-tweaks** - Applies custom scripts and additional configurations |
| 160 | +- **08.export-stage** - Creates and exports the final image |
| 161 | + |
| 162 | +Each stage contains multiple substages that handle specific aspects of the |
| 163 | +build process. The stages are designed to be modular, allowing for easy |
| 164 | +customization and extension. |
| 165 | + |
| 166 | +For a more detailed description of each stage and its purpose, see the |
| 167 | +:doc:`Stage Reference <stage-reference>` section. |
| 168 | + |
| 169 | +Stage Execution Logic |
| 170 | +~~~~~~~~~~~~~~~~~~~~~ |
| 171 | + |
| 172 | +The ``kuiper-stages.sh`` script contains a helper function called |
| 173 | +``install_packages`` that handles package installation for each stage. This |
| 174 | +function: |
| 175 | + |
| 176 | +1. Checks if package files exist for the current stage |
| 177 | +2. Verifies if the corresponding configuration option is enabled |
| 178 | +3. Installs the packages using the appropriate apt-get command |
| 179 | + |
| 180 | +The script then executes each stage's ``run.sh`` script, which may perform |
| 181 | +additional configuration steps, compile software from source, or prepare |
| 182 | +files for the final image. |
| 183 | + |
| 184 | +This modular approach allows users to easily customize the build process by |
| 185 | +modifying existing stages or adding new ones. |
0 commit comments