Debugging Generic IOC Builds#

This tutorial continues from Create a Generic IOC, where we built the ioc-adsim-demo Generic IOC and re-authored its ADSimDetector recipe. Here we look at what to do when such a build fails.

The developer container opens from a developer image that was built already: the one CI published with the project’s latest full release, or a local one (see What happens when the container opens). So a recipe that no longer builds does not stop the container opening. You find the failure and fix it inside the container, which is the exact environment the image is built in.

Only when the image itself has to be built as the container opens can a failing recipe stop it opening. That case has its own trick, described in When the image build fails.

The steps below need ibek 4.12.0 or later in the container: check with ibek --version, and see The ibek version if it is earlier.

Break the build#

Let us introduce a realistic mistake into the ADSimDetector recipe you authored in Create a Generic IOC. Open the ioc-adsim-demo project in VSCode and use Ctrl-Shift-P -> Dev Containers: Rebuild Container. That creates the container afresh from the developer image of your 2.11ec1 release (or from your local image, if it cannot pull that one), rather than reopening the container in which you built ADSimDetector by hand. Then open ibek-support/ADSimDetector/ADSimDetector.install.yml and change version to a tag that does not exist:

module: ADSimDetector
version: R2-111          # typo — there is no such tag

Ask the container how it differs from the project, in a terminal in the container (Terminal -> New Terminal):

# in the container
ibek dev status

It reports that ADSimDetector needs a rebuild, and names the command that does it, ibek dev sync --build. Run that:

# in the container
ibek dev sync --build

It clones the module afresh at the version in install.yml, removing any /epics/support/ADSimDetector that the image has first, before building it with the module’s own line of the Dockerfile, ansible.sh ADSimDetector. The clone fails because the requested ref is not in the upstream repo, with an error that includes:

Failed to checkout R2-111
error: pathspec 'R2-111' did not match any file(s) known to git

Note

A wrong organization (or a private repo with no credentials) fails at the same step with an authentication or repository not found error — same place, different message.

Fix it live inside the container#

Correct the version in ibek-support/ADSimDetector/ADSimDetector.install.yml back to the real tag:

version: R2-11

and run the rebuild again:

# in the container
ibek dev sync --build

The failed clone may have left a checkout of the module’s default branch in /epics/support/ADSimDetector. ibek dev sync --build recorded the clone as not finished, so it clones the module again at the version in install.yml before it builds it. Until a clone succeeds, ibek dev status reports that ADSimDetector needs a rebuild: clone not finished when the failed clone left a folder, or that the folder is missing.

This time the module clones and builds, then the IOC is built. You can re-run it as often as you like: it carries on from the module that failed. You can also run ansible.sh ADSimDetector by hand while you iterate; it is idempotent. ansible.sh builds the folder that is there, without cloning it, so if you change the version in install.yml before running it by hand, or after a clone fails, remove /epics/support/ADSimDetector first so that it is cloned at the version in install.yml. ibek dev status keeps reporting the module until ibek dev sync --build has built it.

Make the fix permanent#

The fix is in your ibek-support checkout on the host. To confirm that the image builds cleanly with it, run a full build from a terminal outside the container:

cd ioc-adsim-demo     # wherever you cloned it
./build

Note

This is the same try-it-live-then-make-it-permanent loop you used to add modules in Create a Generic IOC — only here it starts from a failure. Anything you can fix interactively with ansible.sh can be recorded in the recipe or Dockerfile and replayed by ./build.

When the image build fails#

.devcontainer/initializeCommand builds the image as the container opens when the marker file .devcontainer/local-build exists, or when it can neither pull the image nor find a local one, as for a repository with no release (see Building the image locally). If a recipe fails in that build, there is no image and so no container to open. The fix is a small trick:

  1. Comment out the failing RUN ansible.sh … line in the Dockerfile, leaving its matching COPY in place:

    COPY ibek-support/ADSimDetector/ ADSimDetector
    # RUN ansible.sh ADSimDetector
    

    The image now builds again — it simply omits the ADSimDetector support for the moment.

  2. Open the container with Ctrl-Shift-P -> Dev Containers: Rebuild Container, so that the image is built from the edited Dockerfile and the container is created from it.

  3. Run the failing command by hand inside the container, ansible.sh ADSimDetector, and fix the recipe until it passes. After a clone failure, remove /epics/support/ADSimDetector before running it again: ansible.sh builds a module folder that is there without cloning it.

  4. Uncomment the line and run a full ./build on the host to confirm.

Aside: a missing system header#

A different class of failure is a module that clones fine but fails to compile with a missing header:

fatal error: tiffio.h: No such file or directory

A missing header almost always means a missing system -dev package. Inside the container you are root, so find which package provides the header and install it with no sudo:

apt update
apt install apt-file
apt-file update
apt-file search tiffio.h

Once you know the package, record it in the module’s *.install.yml so the next build installs it automatically. Recipes split their system packages into two keys:

Key

Installed

Holds

apt_developer

in the build stage only

headers and -dev packages needed to compile the module

apt_runtime

into the slim runtime image

shared libraries the IOC needs at run time

For example ADCore.install.yml lists libtiff-dev under apt_developer and libtiff6 under apt_runtime.

Tools inside the container#

The dev container is Ubuntu-based and you are root (podman maps that back to your own user on the host), so you can apt-get install anything you need to investigate a build. It also ships busybox, which provides network diagnostics such as ifconfig plus many small utilities — run busybox to list them.