- Dockerfile 86.4%
- Java 13.6%
| src | ||
| .gitignore | ||
| BuidConfig.yaml | ||
| Dockerfile | ||
| m2-settings.xml | ||
| pom.17.xml | ||
| pom.21.xml | ||
| Readme.md | ||
Demo for a minimalized Java Container
Goal is:
Build a minimalized Java Container, which can run in an internet connected and a disconnected environment. The complete build is made in a single "docker build" run, though it's not required to have a local JDK installation or a pipelining tool like Jenkins, gitlab, ...
The resulting image has nearly nothing unused installed.
Size comparison:
- the build container has (on Arm64) a size of 1.42GB
- the resulting run container has (also on Arm64) a size of 215MB
We're using a 2 phase build:
-
Phase 1:
- Build artefacts with maven
- Generate a minimal JRE runtime with jlink
-
Phase 2:
- Copy the minimal JRE runtime and the artefacts in an UBI9 minimal container
All builds can be made in an OpenShift / OKD cluster as BuildConfigs, with ShipWirght or with podman / podman-desktop or docker.
Connected build
Your build environment has internet access (can reach the redhat container registry and maven central).
# Java 17
podman build \
-t reg.pflaeging.net/public/minijavacontainer:latest \
--env JAVA_VERSION=17 \
.
# Java 21
podman build \
-t reg.pflaeging.net/public/minijavacontainer:latest \
--env JAVA_VERSION=21 \
.
Disconnected build
Your in an intranet and your build infrastructure has its own registry for base images and a maven central mirror (you should also have an RPM repo mirror and the base images configured to use it).
# Java 17
podman build \
-t reg.pflaeging.net/public/minijavacontainer:latest \
--build-arg BASE_IMAGE=registry.internal.pflaeging.net/ubi9-minimal:9.4 \
--env JAVA_VERSION=17 \
--env MAVEN_REPO_MIRROR=https://centralrepo.myorg.net/artifactory/mirror-maven \
.
# Java 21
podman build \
-t reg.pflaeging.net/public/minijavacontainer:latest \
--build-arg BASE_IMAGE=registry.internal.pflaeging.net/ubi9-minimal:9.4 \
--env JAVA_VERSION=21 \
--env MAVEN_REPO_MIRROR=https://centralrepo.myorg.net/artifactory/mirror-maven \
.
Openshift BuildConfig
A sample BuildConfig for OpenShift / OKD is added as ./BuildConfig.yaml.
This is only an example. Adopt it to your settings
Execute
To test this container if it'S running simply start it :-):
podman run -ti reg.pflaeging.net/public/minijavacontainer:latest
Multi-architecture build
For all of us using a MacBook with Apple M processor and deploying in an AMD64 / Intel64 structure:
Make a multi-arch build:
- Install on Mac:
- podman-desktop
- podman
Build a multi-arch image:
# create a manifest for a multi-arch container
podman manifest create \
reg.pflaeging.net/public/minijavacontainer:multiarch-latest
# build for both architectures and link it to the manifest
podman build --platform linux/amd64 \
-t localhost/minijavacontainer:amd64-latest \
--env JAVA_VERSION=17 .
podman build --platform linux/aarch64 \
-t localhost/minijavacontainer:aarch64-latest \
--env JAVA_VERSION=17 .
# link to manifest
podman manifest add \
reg.pflaeging.net/public/minijavacontainer:multiarch-latest \
localhost/minijavacontainer:amd64-latest
podman manifest add \
reg.pflaeging.net/public/minijavacontainer:multiarch-latest \
localhost/minijavacontainer:aarch64-latest
# push the result to the registry
podman manifest push \
reg.pflaeging.net/public/minijavacontainer:multiarch-latest \
docker:reg.pflaeging.net/public/minijavacontainer:multiarch-latest