Building Docker on Yocto

Yocto in containers

Yocto is a tool for building a custom Linux-based OS for your chosen hardware target (e.g. Raspberry Pi, x86-64 PC, etc.). It also fully supports various devices emulated by QEMU, which is helpful for development and testing.

It is quite straightforward to run your Yocto builds inside containers during development (e.g. using a ubuntu-20.04 container), and this helpfully keeps your development environment consistent.

However, if you would like to use Yocto to build a container that you can then run using Docker (rather than building for a specific board or emulator), then this is more complex and not supported out-of-the-box. Containers typically don't need a complete filesystem and kernel to run (this is Yocto's usual output), and so there is quite a lot of work required to trim it down and configure it to do this. There was a presentation at ELC 2018 about it (video, slides).

Perhaps take a look through the Overview and Concepts Manual, which explains a bit more information about the architecture, QEMU emulator, and development environment.

Can I build a Docker image to cache a yocto/bitbake build?

1. Yes.

I've used docker to build Yocto images for many different reasons, always with positive results.

2. Yes, with some work.

You want to take advantage of the fact that Yocto caches all the stuff you need to do your build in what it calls "Shared State Cache". This is normally located in your build directory under ${BUILDDIR}/sstate-cache, and it contains exactly what you are looking for in this case. There are a couple of options for how to get these files to your build machines.

Option 1 is using sstate mirrors:

This isn't completely offline, but lets you download a much smaller cache and build from that cache, rather than from source.

Here's what's in my local.conf file:

SSTATE_MIRRORS ?= "\
file://.* http://my.shared-computer.com/some-folder/PATH"

Don't forget the PATH at the end. That is required. The build system substitutes the correct path within the directory structure.

Option 2 lets you keep a local copy of your sstate-cache and build from that locally.

In your dockerfile, create the sstate-cache directory (location isn't important here, I like /opt for my purposes):

RUN mkdir -p /opt/yocto/sstate-cache

Then be sure to bindmount these directories when you run your build in order to preserve the contents, like this:

docker run ... -v /place/to/save/cache:/opt/yocto/sstate-cache

Edit the local.conf in your build directory so that it points at these folders:

SSTATE_DIR ?= "/opt/yocto/sstate-cache"

In this way, you can get your cache onto your build machines in whatever way is best for you (scp, nfs, sneakernet).

Hope this helps!

yocto crops container's PATH variable cannot be modified

You can create your own Dockerfile based on the crops one, and add things to /etc/skel/ which is the default skeleton directory used for creating the pokyuser.

Example Dockerfile:

FROM crops/poky:ubuntu-16.04
USER root
RUN echo 'export PATH=$PATH:/foo/bar' >> /etc/skel/.bashrc


Related Topics



Leave a reply



Submit