Containerized Yocto Builds

Containerized Yocto Builds

· 565 Wörter · 3 Minuten Lesezeit English Yocto Docker

Motivation

There is a requirement, that your releases of Yocto based Linux distribution need to be reproducible. Reproducibility requires the exact replay of build recipes on the very same build host with the build tools installed at a certain pinned version.

Instead of physically keeping a build host untouched forever, it is easier to have a virtual containerized build host. The used virtual build host is easy to to reproduce by starting the previously archived virtual build host image.

Furthermore, a virtualized Yocto build environment, allows to

  • Bootstrap developer's , Yocto integrator's build environment faster

  • Versionize build environments and gain efficient build toolchain maintenance across team members and CI.

    I.e. if everywhere the same virtual build environment is used, no time is wasted in figuring out why a certain build works on one machine but not on the other,
    especially works on a local developers build host but not on the CI host.

The Yocto version that is used for the build requires a certain Linux distribution version of the build host. Older Yocto versions cannot be build with recent Linux versions of the build host. So, wrapping the build host into a container decouples the build host from Yocto version used at the build.

Step by step

We maintain a docker image spec for

  • general docker image
  • user customized docker image

at [https://github.com/almedso/docker-yocto].

This docker image spec is used to build the general docker image uploaded to the dockerhub

Prerequisite

Install docker on your developer machine, such that it can be used as docker host.

Build the privatized container image

git clone git@github.com:almedso/docker-yocto.git
cd docker-yocto
./privatized-docker-image/build-my-image.sh

Alternatively, download the privatized docker script and run it

wget https://github.com/almedso/docker-yocto/blob/master/privatized-docker-image/build-my-image.sh
chmod 755 build-my-image.sh
./build-my-image.sh

This script generates a docker image that is personalized to your Linux user id and group id. (i.e. does not run as root). It is named my-yocto-bitbaker:latest.

Start the container

The my-yocto-bitbaker:latest container image allows you to build Yocto distribution at least starting at least at Yocto version 4.0 (Kirkstone).

Start the container with an interactive terminal as described in more detail in the README of the docker image spec git repository.

docker run --rm \
    --volume $YOCTO_ROOT:/yocto/root \
    --volume $YOCTO_CACHE:/yocto/cache \
    --volume $YOCTO_PUBLISH:/yocto/publish \
    --interactive --tty my-yocto-bitbaker:latest

You need to inject data volumes such that you can reuse the download and state caches as well as the working data. If you want to publish build artifacts (sdk, packages or images) a dedicated publish volume is helpful as well.

Run the build inside the container

Inside the container, build as you would do without a build container. In it's simplest way it is:

# bring the sources into shape
repo init -u git@github.com:almedso/yocto-ams.git
repo sync
# prepare the build environment
source sources/poky/oe-init-build-env
# build
bitbake core-image-minimal

Final thoughts

A containerized Yocto build environment has a lot of advantages. It is an excellent solution, if you need to assure release reproducibility.

However, if you just start with Yocto based Linux distributions, postpone build virtualization since additional complexity needs to be handled.