Red Hat Fuse image size

Red Hat Fuse is a leading integration platform, which is capable of solving any given problem with simple enterprise integration patterns (EIP).  Over time, Red Hat Fuse has evolved to cater to a wide range of infrastructure needs.

For more information on each of these, check out the Red Hat Fuse documentation. The Fuse on Red Hat OpenShift flavor uses a Fuse image that has runtime components packaged inside a Linux container image.  This article will discuss how to reduce the size of the Fuse image. The same principle can be used for other images.

Deep dive

Before reducing the size, we need to first understand the basics of the Fuse container image provided by Red Hat.

Let's dive into the Fuse image to understand its layers at a high level.  The following diagram shows six critical layers. Note, that for the sake of simplification, I have merged layers into one logical layer. For instance, Environment and Labels are shown as one layer, which provides the Metadata information.

Current Fuse Image layeringFigure 1: High-level image layers of Red Hat Fuse images.

The current version of the Red Hat Fuse image is about 171.8 MB in size. In Figure 1, we can see several layers. Each layer can be replaced by various alternatives.  That's good, but how do we know what the alternatives are?

Let's take an example. Red Hat released a new Universal Base Image in April, and it's generally offered in two versions:

  1. Standard Red Hat base image — Contains a robust set of software features like yum, utils, and more.
  2. Minimal Red Hat base image — This is a stripped-down version. Some alternatives are provided, such as microdnf for software installation.

The Minimal version is about half the size of the Standard Red Hat base image. This can be used as a replacement for the "openjdk18-rhel7" layer in a Fuse image. But this version cannot be used as is, because it does not contain JVM.

Let's use the headless Open JDK to keep the JRE light. The image file will look like this:

FROM registry.access.redhat.com/ubi7/ubi-minimal:7.7-98
MAINTAINER Pramod Padmamabhan[ppadmana@redhat.com]

#Adding env details
ENV FIS_JAVA_IMAGE_NAME="jboss-fuse/minimal-fuse-openshift" \
FIS_JAVA_IMAGE_VERSION="7.7-98" \
PATH=$PATH:"/usr/local/s2i" \
JAVA_DATA_DIR="/deployments/data" # BASE version information
LABEL name="$FIS_JAVA_IMAGE_NAME" \
version="$FIS_JAVA_IMAGE_VERSION" \
architecture="x86_64" \
summary="Platform for building and running plain Java applications (fat-jar and flat classpath)" \
com.redhat.component="jboss-fuse-x-fuse-java-openshift-container" \
io.fabric8.s2i.version.maven="3.3.3-1.el7" \
io.k8s.description="Platform for building and running plain Java applications (fat-jar and flat classpath)" \
io.k8s.display-name="Fuse Integration Services - Java" \
io.openshift.tags="builder,java" \
io.openshift.s2i.scripts-url="image:///usr/local/s2i" \
io.openshift.s2i.destination="/tmp" \
org.jboss.deployments-dir="/deployments" \
description="Fuse Base Image With minimal UBI" \ group="ubi-minimal"

USER root
ADD run-java/ /opt/run-java
ADD s2i/ /usr/local/s2i
ADD jolokia /opt/jolokia #install OpenJDK 1.8 / use only when getting ubi minimal image
RUN microdnf --enablerepo=rhel-7-server-rpms install java-1.8.0-openjdk-headless \
&& microdnf clean all \
&& echo securerandom.source=file:/dev/urandom >> /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.212.b04-0.el7_6.x86_64/jre/lib/security/java.security \
&& useradd -r jboss \
&& usermod -g root -G jboss jboss \
&& chmod -R 755 /opt/run-java ; chmod -R 755 /usr/local/s2i \
&& mkdir -p /deployments/data \
&& chmod -R "g+rwX" /deployments \
&& chown -R jboss:root /deployments \
&& chmod 444 /opt/jolokia/jolokia.jar \
&& chmod 755 /opt/jolokia/jolokia-opts \
&& chmod 775 /opt/jolokia/etc \
&& chgrp root /opt/jolokia/etc

#fis user
USER 185
CMD [ "/usr/local/s2i/run" ]

For the complete source and library of the minimal-UBI project, refer to the GitHub repo.

Building the above will generate a Fuse image of about 130 MB. Compared to the original Fuse image size of 171.8 MB. We have reduced the image by about 40 MB in size.

What's next?

The size reduction is good, but every custom change comes with a few drawbacks. In this case, we need to manage the S2i, Jolokia, and any other libraries or scripts we add to the UBI. Coming up, I will show how to reduce the Final-S2i image size. Until then, happy open sourcing!

Last updated: July 1, 2020