Providing arbitrary Dockerfile to LAVA docker worker

To enable nitrogen board in LAVA for testing Oniro zephyr builds, we need to use latest version pyocd installed via pip3 to flash and reset the board. However, the tool is not included in lavasoftware/lava-dispatcher docker image that used by LAVA docker worker. Keep adding test device related dependencies to the image doesn’t sound like a good idea either.

We decided to patch LAVA docker worker to allow users to have a custom Dockerfile so they can provide the container additional packages that they may require. The feature has been released in LAVA release 2021.09 and newer versions.

LAVA docker docker will build and use customized image if custom /etc/lava-dispatcher-host/build/Dockerfile exists. A new Dockerfile.lava will be generated under the same directory with the base image that matches your LAVA server version for building the customized image. All the FROM commands defined in your Dockerfile will be ignored.

To customized the above directory, first edit /etc/lava-dispatcher-host/lava-docker-worker and set the BUILD_DIR parameter to a directory with a Dockerfile inside.

# Docker build directory
# Should be set to a directory with a Dockerfile inside.

Then restart the lava-docker-worker service.

sudo systemctl restart lava-docker-worker.service

Custom Dockerfile example we use on remote LAVA docker worker running on Raspberry pi4.

FROM lavasoftware/lava-dispatcher

# Copy power control scripts
COPY power-control/ /root/power-control/

# Install required packages for pyocd installation via pip.
RUN apt-get update && \
    apt-get install -y python3 python3-pip python3-testresources libusb-dev libffi-dev expect

# install latest rust for building capstone and cmsis-pack-manager
RUN curl -sSf | sh -s -- -y
RUN . ~/.cargo/env

RUN pip3 install pyocd==0.31