How a Generic IOC Developer Container Works#
This page explains what happens when you open a Generic IOC project in its developer container, what the container holds, and how it is kept in line with the project folder on your host. The tutorial Developer Containers shows the same steps in use.
Developer container and runtime container#
Every Generic IOC image is built in two targets from the project’s
Dockerfile:
the developer target holds the build tools, the compiled support modules and the compiled IOC. It is the image the developer container runs.
the runtime target holds only what the IOC needs to run, copied from the developer target. It is the image that IOC instances deploy.
The developer container is where you work on a Generic IOC and its support modules. It mounts host folders into the container so that:
the developer container looks as similar as possible to the runtime container;
you can change things and recompile them without building a new image;
the work you keep happens in the host filesystem, so it is not lost when the container is rebuilt or deleted.
The developer image#
The developer container runs a published image rather than building one when
it opens. .devcontainer/devcontainer.json names it:
Git platform |
Developer image |
|---|---|
GitHub |
|
DLS GitLab |
|
.devcontainer/initializeCommand names the same image. A repository that
changes one must change the other.
When CI builds a full release tag, such as 2.11ec1, it also gives that
release’s developer image the tag latest. A pre-release tag,
such as 2.11ec1b1, does not move latest, and the runtime image never has a
latest tag. So:
the image is the one built from the full release tag pushed most recently, which is usually the latest release. Changes merged to main since that release are not in it:
ibek dev syncreports each difference (see Keeping the container in line with the project);a repository that has made no full release has no
latest, so the first start builds the image locally (see What happens when the container opens).
To pull from the DLS GitLab registry the host must be logged in to it, with
podman login gitlab.diamond.ac.uk:5050 (or docker login). Without a login
the pull fails, and the image is the local one, or a local build when there is
none (see What happens when the container opens).
What happens when the container opens#
When you choose Reopen in Container, VSCode runs
.devcontainer/initializeCommand on the host. It:
creates the host folders that the container mounts:
$HOME/.config/terminal-config,$HOME/.cache/uvand the project’sopi/auto-generated;runs
git submodule update --initwhen theibek-supportsubmodule is not checked out, which is the case in a fresh clone made without--recursive(see The ibek-support submodule);gets the developer image, in this order:
when the marker file
.devcontainer/local-buildexists, it builds the image from the project folder with./build(see Building the image locally);otherwise it pulls the image;
when the pull fails, it uses the local image of that name;
when there is no local image either, it builds one with
./build;
records the ID of that image in
.devcontainer/image-id, which theibek devcommands compare with the image the container was created from (see Reopen and Rebuild).
It prints one coloured line that says which way it got the image. It uses
docker when docker works, and podman otherwise or when USE_PODMAN is set, as
./build does.
VSCode then starts the container. A container being created for the first
time also runs .devcontainer/postCreateCommand, which runs
make clean uninstall in /epics/ioc to remove the IOC build products from the
project’s ioc folder (see The ioc folder), and records which image
the container was created from. On every start, including
the first, the container runs ibek dev sync, which brings the container in
line with the project folder (see Keeping the container in line with the project).
Building the image locally#
To run an image built from your own project folder instead of the published
one, for example after changing the Dockerfile, or on a branch far from the
last release, create the marker file on the host and then use
Dev Containers: Rebuild Container:
# on the host, in the project folder
touch .devcontainer/local-build
While that file exists, every start builds the image with ./build instead of
pulling it. The build is quick when its layers are cached. It gives the image
the same name as the published one, so the container runs it in the same way.
The file’s content is ignored and git ignores the file. Delete it to go back
to the published image.
A repository with no full release builds its image locally the first time, as
above. Later starts cannot pull either, so they use that local image as it is,
even after the Dockerfile changes. Create the marker file to build it again.
./build builds the image from the project folder and leaves the folder as it
is, apart from checking out the ibek-support submodule when it is missing.
.dockerignore keeps the IOC build products and the ioc/config link out of
the image.
What is mounted where#
The developer container mounts the parent of the project folder at
/workspaces, so the project and all its peers, such as your services repo,
are in the container. It also mounts the project folder a second time, at
/epics/generic-source. The image build copies the project’s source to that
same path, so the source is found in the same place in the developer container
and in the runtime container. In the developer container the mount hides the
image’s copy: what you see at /epics/generic-source is your host project
folder.
The rest of /epics belongs to the image:
/epics/supportholds the support modules, cloned and compiled when the image was built./epics/ibek-defs,/epics/pvi-defsand/epics/autosavehold one symbolic link per definition file: the*.ibek.support.yaml,*.pvi.device.yamland*.reqfiles of each support module. Each link points into/epics/generic-source/ibek-support*/<module>/, so in the developer container it resolves to your host checkout ofibek-support./epics/ibek-defsalso holdsioc.schema.json, the IOC schema generated from those files./epics/iocis a link to/epics/generic-source/ioc.
The tutorial’s Generic IOC container filesystem layout table lists every mount.
Important
What is in the image, such as /epics/support, lives in the container’s own
filesystem. Changes there are lost when the container is rebuilt or deleted.
Keep the work you want in the host folders.
The ioc folder#
The ioc folder of the project holds the Generic IOC source. It is much the
same for every Generic IOC, but each project has its own copy so that it can be
changed when needed. The image build compiles it, so the runtime image has the
IOC binary.
In the developer container /epics/ioc resolves to the ioc folder of your
host project, which holds the source only: the binary that the image build
compiled is hidden. So you build the IOC in the container:
# in the container
cd /epics/ioc
make
What make builds lands in the host project folder, and it is linked against
the support modules of the container that built it. A container from a
different image may have different support modules, so when a container is
created, .devcontainer/postCreateCommand runs make clean uninstall in
/epics/ioc. That removes the IOC’s O.* build folders and what it installed
in bin, lib, dbd and db, and keeps all source files and the
ioc/config link that ibek dev instance makes. A failure there only prints a message: the
container is still created. Run make in /epics/ioc to build the IOC again.
Reopening an existing container keeps its build products, which still match
it.
Your changes to the IOC source are in the host project folder, so they are under version control and survive the container.
Keeping the container in line with the project#
The image was built from the project as it was at that time. Your host project
folder may differ from it: you may have pulled changes merged since the last
release, edited a support module’s definition files, or changed the
Dockerfile. As the last step of the image build, ibek dev stamp records
what the image was built from in /epics/dev-stamp.json. The ibek dev
commands compare that record with the project folder mounted at
/epics/generic-source:
Command |
What it does |
|---|---|
|
prints the comparison and changes nothing |
|
fixes what needs no build and reports the rest. The container runs it on every start |
|
also rebuilds what needs a build |
|
links an IOC instance’s config folder to |
Each part of the report names the command that fixes it, where there is one. What is compared:
What changed in the project |
|
|
|---|---|---|
A support module’s definition files: |
Fixes it: links the files again, removes links that point at nothing, and regenerates |
The same |
A support module’s other files in |
Reports it |
Rebuilds that module and every module after it in the |
What a module clones: the version, repository or patch in its |
Reports it, and names the folder that a rebuild removes |
Removes |
The list of |
Reports it |
Rebuilds from the first place where the list differs, then the IOC. A removed module stays installed, and reported, until the container is created from an image built without it |
|
Reports it |
Rebuilds every module, then the IOC |
|
Reports it |
Upgrades the Python packages and regenerates the schema, then stops: run it again for anything more |
The |
Reports it |
Reports it: pull a newer developer image, or build one locally |
The IOC binary: missing, older than the IOC source, or older than the last module rebuild |
Reports it: run |
Builds the IOC |
ibek dev sync never compiles anything. Its output on container start is easy
to miss, so run ibek dev status when you want to see where the container
stands.
What ibek dev sync --build rebuilds lives in the container’s own filesystem.
A container created again starts from the image, so run it again there if
ibek dev status asks for it.
An image built without ibek dev stamp has nothing to compare: the commands
say so in one line.
Reopen and Rebuild#
VSCode keeps a project’s container between sessions. The two commands that open the project differ:
Reopen in Container starts the existing container if there is one. It stays on the image it was created from, and keeps everything in its own filesystem.
Dev Containers: Rebuild Container deletes the container and creates another from the image that
.devcontainer/initializeCommandhas just pulled or built. Changes to the container’s own filesystem are lost, and the IOC build products are removed.
So a newer image that initializeCommand pulls takes effect only after
Rebuild Container. While the existing container was created from a
different image than the one initializeCommand recorded in
.devcontainer/image-id, the ibek dev commands in the container print a
WARNING: that says so. Dev Containers: Rebuild Container clears it.
The ibek-support submodule#
The ibek-support submodule holds the build recipes and definition files of
the support modules. .devcontainer/initializeCommand and ./build check it
out only when it is not checked out at all. Once it is, they leave it alone,
so a branch or commit you have checked out in it stays as it is.
After a git pull that moves the project’s ibek-support commit, update the
submodule yourself:
# on the host, in the project folder
git submodule update
Then run ibek dev sync in the container, which fixes or reports what the
move changed (it also runs on every container start), and ibek dev status to
see what is left.
Working on a support module#
The support modules in /epics/support were cloned and compiled when the image
was built, and they live in the container’s own filesystem. To change the
source of one, rather than its ibek-support recipe, build it from a clone on
the host with ibek dev support:
# in the container
ibek dev support ADSimDetector
For each module it names, the command:
clones the repository of the module’s
install.ymlto/workspaces/<module>, at theversionof itsinstall.yml. That folder is on the host, next to the project, so the clone and your edits in it outlive the container. A clone that is already there is used as it is, on whatever branch or commit it has checked out, as long as one of its remotes is the repository of theinstall.yml. A clone of some other repository, a folder that is not the top of a git clone, and a module folder that is already a link somewhere else are refused, each with a line that says what to do;removes the module that the image built from
/epics/support/<module>and makes that path a link to the clone;builds the module with its own
RUN ansible.shline of theDockerfile, then every module after it in theDockerfile, then the IOC.
Run the same command again to build again after you change the source. A
module that ibek dev support has linked is never cloned again: the clone is
yours, and the commands build it as it is. The ibek dev commands report each
module that is linked to its clone.
You can name several modules at once. They are built in the order of the
Dockerfile, starting from the first of them.
The build changes the clone:
files that the build makes are added to the clone’s
.git/info/exclude, sogit statusdoes not show them. The command names those thatgit statuswould otherwise show; most modules’.gitignorealready ignoreslib,bin,dbandO.*;the build edits some tracked files to build the module in this container, such as
configure/RELEASE. They show ingit status, and the command names them: do not commit those edits;a
patch_filein theinstall.ymlis not applied to the clone. The command says so; apply the patch withgit applyin the clone if the build needs it.
Declarations and a container created again#
ibek dev support records each module in .ibek-dev.yaml in the project
folder, which git ignores. The file is on the host, so it outlives the
container, but the link and the build are in the container’s own filesystem.
In a container created again, from the same image or another:
ibek dev syncandibek dev statusreport each declared module that is not linked to its clone, and nameibek dev sync --build. They compile nothing;ibek dev sync --buildchecks each clone again, links it, and builds it, the modules after it and the IOC.
Going back to the version of install.yml#
# in the container
ibek dev support --release ADSimDetector
ibek dev sync --build
--release removes the link and the declaration and builds nothing. The clone
is left as it is. ibek dev status then reports the module folder as missing,
and ibek dev sync --build clones the module at the version of its
install.yml and builds it, the modules after it and the IOC.
The tutorial Change a Support Module uses these commands to change a support module and publish the change.
The ibek version#
ibek dev support needs ibek 4.12.0 or later in the container, and a project
generated from ioc-template 5.1.0 or later (see
Generic IOCs from earlier templates): it compares the container with the stamp
that ibek dev stamp wrote when the image was built. Check the version in
the container with ibek --version. The image installs ibek from the
project’s requirements.txt, which holds a lower bound such as
ibek>=4.11.1,<5. To move to a later ibek:
raise the lower bound in
requirements.txton the host, for example toibek>=4.12.0,<5;run
ibek dev sync --buildin the container. It sees thatrequirements.txthas changed, upgrades the Python packages in the container and stops. Run it again for anything else it reports.
The change to requirements.txt goes into the next image that the project
builds or releases. Until then, a container created again from the published
image has its ibek, and ibek dev sync --build upgrades it again.
Generic IOCs from earlier templates#
A Generic IOC generated from a version of
ioc-template below 5.1.0
works differently. Its .devcontainer/devcontainer.json has a build block
in place of an image, so VSCode builds the developer target from the
project’s Dockerfile when it creates the container, and the ibek dev sync
checks above do not run. epics-containers builds all support from source, so
building something as large as AreaDetector takes a few minutes the first
time; the layers are cached, so later builds are quick up to the first line
that changed. The _commit line of the project’s
.copier-answers.yml shows the template version. To move the project to the
published-image flow, update it from the template (see
Updating User Repositories with Copier).
Summing up#
For the most part you can ignore the details and remember:
Reopen in Container to carry on; Dev Containers: Rebuild Container when a WARNING asks for it, or to move to a newer image;
run
makein/epics/iocto build the IOC, and./start.shthere to run it;run
ibek dev statusto see how the container differs from the project, andibek dev sync --buildwhen it asks for a rebuild;run
ibek dev support <module>to work on the source of a support module in a clone on the host, andibek dev support --release <module>to go back to the version of itsinstall.yml;your changes to the project folder are on the host and under version control.