Repository navigation
NMS-20668: Optimize RPM/DEB packages and Docker images - #9223
mershad-manesh wants to merge 8 commits into
Conversation
…duplicates
Every release shipped the whole assembly as one layer whose digest changes
on every build, so an upgrade pulled ~1.07 GB (Horizon), ~430 MB (Minion)
and ~316 MB (Sentinel) even though most files were byte-identical to the
previous release.
common/split-layers.sh now splits the unpacked assembly into four layers,
added with COPY --link from most to least stable:
deps third-party jars and the third-party part of system/ and
repositories/ (directly on top of the base image)
onms OpenNMS-built jars and org/opennms in the Karaf repositories
app scripts, config, web assets, directories (real mtimes kept, Jetty
derives Last-Modified/ETag from them)
src the bundled source archive
Files with identical content, mode and owner are hardlinked, removing the
lib/ <-> system/ (Horizon) and repositories/ <-> system/ (Minion) copies:
Horizon 2.18 -> 1.94 GB, Minion 1.01 GB -> 911 MB with a test assembly.
The deps and onms layers get a constant mtime so an unchanged layer keeps
the same digest across builds.
Verified with no-cache builds of all three images: the filesystem of the
old and new image is identical in path, type, mode, owner, size and
content; rebuilding from a re-touched assembly keeps the deps and onms
layer digests, and changing one OpenNMS file only changes the onms layer.
The script is passed to the builds as the "container-common" named build
context (docker buildx --build-context).
The tarball stage only unpacks, chmods, hashes, hardlinks and copies files from an architecture-independent tarball, so it can run natively on the build host instead of under QEMU when building the other architecture. Measured with an emulated linux/amd64 build on an arm64 host, split step: Horizon 50.3s -> 20.2s, Minion 24.9s -> 6.5s, Sentinel 12.0s -> 3.7s. The image filesystems are identical to the previous build (path, type, mode, owner, size, content), and the deps and onms layers now have the same digest on amd64 and arm64, so registries store them once. Minion no longer copies /opt from that stage: after the split it only held the base image's /opt (prom-jmx-exporter), which the final image already has with the same content, owner and mode, and which would now come from the build host's architecture.
The core RPM already replaces system/ jars that also ship in lib/ with
symlinks; the DEBs and the Minion packages carried every copy.
Core DEB (debian/rules): each jar in opennms-common's system/ that is
byte-identical to one that libopennms-java or libopennmsdeps-java install
into /usr/share/java/opennms becomes a symlink to it. opennms-server
depends on all three packages at the same version.
Minion RPM and DEB: jars with the same SHA-256 under lib/, system/ and
the repositories/*/ Karaf repositories are hardlinked; they are all in
the one package, so a plain hardlink works for rpm and dpkg.
Built from the same CI assemblies with the CI build image and compared
with packages built from the previous packaging:
opennms-common 455.2 MB -> 234.6 MB (462 jars become symlinks)
opennms-minion DEB 425.3 MB -> 335.3 MB, RPM 429.8 MB -> 338.9 MB
(204 jars become hardlinks, /opt/minion 459M -> 362M)
Every path is present in both builds and every link resolves to the
same content; install, upgrade from the previous packaging, dpkg -V /
rpm -V, and a Minion start show the same bundles and features.
split-layers.sh hardlinked any files with identical content, including config under etc/. Docker keeps hardlinks when it populates a VOLUME from the image, so an in-place edit of one such file (e.g. snmp-adhoc-graph.properties) also changed its twin (response-adhoc-graph.properties). Only *.jar, *.kar and *.war are linked now, and never under etc/, data/ or deploy/. Also: - restore directory mtimes changed by "ln -f", and give each layer root the source directory's mtime, so all four layers are reproducible - fail on file types other than files, directories and symlinks instead of dropping them - avoid a SIGPIPE race under pipefail in the file name check - rebuild the image when split-layers.sh changes
debian/rules recipes run under /bin/sh. With dash, "read -d ''" fails and the loop silently created no symlinks.
marshallmassengill
left a comment
There was a problem hiding this comment.
- Revert commit 91e6d46 before you merge this PR. This commit contains temporary CI changes.
- Update opennms-container/README.md. The docker build commands in this file do not work with the new Dockerfiles.
- Add these two parameters to the README commands: --build-context container-common=../common and --build-arg VERSION=.
- I installed the core DEB packages from the CI build of ef79967 on Debian 12 with JDK 25. OpenNMS started correctly.
- 462 JAR files in system/ are symbolic links. No link is broken. Karaf loaded 253 bundles from these links.
- I installed the Minion DEB on Ubuntu 26.04 and the Minion RPM on Rocky Linux 9. The Minion started correctly on each system.
- In each Minion installation, 378 JAR files are hardlinked. karaf.log contains no errors.
- Some Minion bundles stayed in the GracePeriod or Starting state. The test had no core server. This is the probable cause.
- Optional: put the Minion JAR deduplication commands in one shared script. The same commands are in minion.spec and in the Minion debian/rules file.
- Optional: make these commands safe for paths that contain spaces. Such paths do not occur now.
- Not related to this PR: the opennms-server post-installation script fails when it does not find JDK 25. The fix-permissions command stops because java.conf does not exist.
dino2gnt
left a comment
There was a problem hiding this comment.
Looks good to me. No notes.
|
I've just spent some time in the container part in depth. What I don't like is the layer split you have introduced building the image. That comes with a very high prize tag and creates a lot of fragility into the container build. Here is some of my reasoning: The only thing a release upgrade fetches is the assembly layer. So the question is only whether cutting that one layer into four reduces what gets fetched. Measured, it does not:
Some other points why I would not do the split:
What really pays off is the hardlink deduplication and that would be something we should keep. What I measured
What I suggest
Two ideas I have not tested: the bundled source archive is a 72 MB layer in 36.0.6 and may not be needed in the runtime image, and creating the hardlinks in the assembly tarball itself could give images and packages the same gain without a build-time script. Example: the patched Karaf jars Two jars in
Both patches are needed. The problem is how they meet the split:
With a single assembly layer this never mattered. With the split it cancels the gain, and nothing in the build reports it. I only saw it by comparing the published 36.0.5 and 36.0.6 images. Any future patch module of this kind would do the same. |
|
Just some context how I have looked at this problem without AI and why I think this should conceptually solved differently and your approach with the split bash script is on the wrong layer. The script tries to recover structure during image build time. The whole Maven build already knew all that and throws it away when it gives you that one tarball. Maven knows which jar is a third-party and which is OpenNMS code. Your bash script has to guess that back from file names. The Karaf jar is an example what a wrong guess looks like. If we fix it with with Maven and smaller assemblies that would fix that problem at the source. I see it as two separate things. The main benefit of smaller assemblies is modularity and a smaller footprint, and that deserves its own issue and design. |
Thanks @indigo423, agreed.
Changes in this PR:
|
The four-layer split did not reduce what an upgrade pulls: about ten jars are rebuilt in-tree under their upstream names and land in deps, so every layer changes on every build. All of the size saving comes from the hardlinks. common/hardlink-duplicates.sh replaces split-layers.sh. It only hardlinks identical *.jar/*.kar/*.war files and fails the build if a linked file ends up under etc/, data/ or deploy/. It runs as the last step of the tarball stage, since a later chmod would break the links, and the images go back to a single COPY with real mtimes. The script is copied into each build context by "make unpack-tarball", so the named build context is gone and a plain docker build works again. The Minion staging stage now uses /opt/usr-share/minion like core and Sentinel, so only the Minion directory is copied from the build-platform stage.
Smaller images, faster upgrades and smaller packages by deduplicating jars
Images (core, Minion, Sentinel)
common/split-layers.shsplits the assembly into four layers, ordered from least to most likely to change:deps(third-party jars),onms(OpenNMS jars),app(everything else) andsrc. Each is added withCOPY --link.karandwarfiles are hardlinked within a layer. Nothing underetc/,data/ordeploy/is linked, because those are volumes and contain editable config.depslayer keeps its digest across releases, so upgrades skip it.Packages
system/*.jarcopies are now symlinks intolibopennms-javaandlibopennmsdeps-java, as the RPM already does.lib/,system/andrepositories/are hardlinked.Estimated Savings (37.0.0-SNAPSHOT)
opennms-commonDEBNotes
All Contributors
External References