Using Maven parameters on Buildconfig in OCP 4
Environment
- Red Hat Enterprise Application Platform
- 7.x
- template deployment
- Red hat OpenShift Container Platform (OCP)
- 4.x
Issue
- How to set Maven Build parameters on OCP 4?
- How to change the default Maven build parameters?
Resolution
In OCP 4 the Build configuration can be set to do a build using Source to Image, for example with Git repository inputs.
Maven is a java process and therefore will use a series of settings in the build, and this can be set via MAVEN_OPTS environment property on the build configuration. Basically, MAVEN_OPTS is an environment variable used by the scripts that start/launch the Maven's JVM.
Whereas MAVEN_ARGS is used by the actual mvn command; Finally MAVEN_ARGS_APPEND is used for final maven arguments.
So for JVM arguments use: MAVEN_OPTS
And for maven mvn options use: MAVEN_ARGS or MAVEN_ARGS_APPEND
Example:
Default EAP template BuildConfig:
- name: MAVEN_OPTS
value: >-
-XX:+UseParallelGC -XX:MinHeapFreeRatio=10 -XX:MaxHeapFreeRatio=20
-XX:GCTimeRatio=4 -XX:AdaptiveSizePolicyWeight=90
-XX:+ExitOnOutOfMemoryError
- name: MAVEN_ARGS_APPEND
value: '-Dcom.redhat.xpaas.repo.jbossorg' <--- adding -X for adding debug log
Adding -X and G1GC on the BuildConfig for Maven usage:
- name: MAVEN_OPTS
value: >-
-XX:+UseG1GC -XX:MinHeapFreeRatio=10 -XX:MaxHeapFreeRatio=20 <------- G1GC
-XX:GCTimeRatio=4 -XX:AdaptiveSizePolicyWeight=90
-XX:+ExitOnOutOfMemoryError
- name: MAVEN_ARGS_APPEND
value: '-X -Dcom.redhat.xpaas.repo.jbossorg' <--- adding -X for adding debug log
Confirming setting G1GC on MAVEN_OPTS:
INFO Using MAVEN_OPTS -XX:+UseG1GC -XX:MinHeapFreeRatio=10 -XX:MaxHeapFreeRatio=20 -XX:GCTimeRatio=4 -XX:AdaptiveSizePolicyWeight=90 -XX:+ExitOnOutOfMemoryError
Confirming -X usage for more details on build:
... /home/jboss/.m2/settings.xml -Dmaven.repo.local=/tmp/artifacts/m2 -X -Dcom.redhat.xpaas.repo.jbossorg package, jdk.debug=release, maven.version=3.6.2, java.vm.specification.vendor=Oracle Corporation,
For more information on the settings see the reference documentation This page is not included, but the link has been rewritten to point to the nearest parent document.Openshift S2I process.
EAP 8 troubleshotting
For EAP 8 builds, use GALLEON_MAVEN_ARGS="-X -e", such as below:
ENV GALLEON_PROVISION_CHANNELS=org.jboss.eap.channels:eap-8.0
ENV GALLEON_MAVEN_ARGS="-X -e" <------------------------
RUN /usr/local/s2i/assemble
Maven settings can be added, such as -Djavax.net.debug=all, or proxy settings, such as -DproxySet=true. And proxy settings can be set on settings.xml/pom.xml as well, such as connectionTimeout and readTimeout.
Podman troubleshooting
For podman debug the option --log-level debug provides more output.
However, for more information, it is used for capture a pprof profile by starting the podman service with the following:
$ podman system service --log-level=debug --time 0 --pprof-address=localhost:9999
This will have the pprof service listen on the localhost port of 9999, via TCP; we can restart the process with this, and when the CPU rises again we can gather a performance profile:
$ curl -o trace.out http://localhost:9090/debug/pprof/trace?seconds=60
That will get a 60-second performance profile and callgraph from podman-system-service which should tell where the time is being spent. Replace the port with the one adequate for the use case.
Root Cause
The Source to Build process see the environment variable below:
| Env variable | Purpose |
|---|---|
MAVEN_OPTS | Used for JVM settings |
MAVEN_ARGS | Maven commands, i.e. overwrite the default build command. |
MAVEN_ARGS_APPEND | Additional arguments |
For JBoss EAP using Galleon, as long as you use GALLEON_PROVISION_LAYERS other Environment variables can be used:
| Galleon Env variable | Purpose |
|---|---|
GALLEON_MAVEN_ARGS | Can be used for proxy for example |
For more details see EAP 8 Galleon legacy vs non-legacy build.
Related solutions
| Solution | Purpose |
|---|---|
| Customizing EAP 7 Template buildconfig deployment in OCP 4 | For customizing the build config |
| How to build an EAP 7 image in OCP and send to Quay? | Details about sending images to an (external) registry. |
| Troubleshooting EAP 7 local BuildConfig in OCP 4 | Details on the EAP Buildconfig |
Diagnostic Steps
- During the build verify the info output log:
INFO Using MAVEN_OPTS -XX:+UseParallelGC -XX:MinHeapFreeRatio=10 -XX:MaxHeapFreeRatio=20 -XX:GCTimeRatio=4 -XX:AdaptiveSizePolicyWeight=90 -XX:+ExitOnOutOfMemoryError
- Use
printenvto print all enviroment variables:
JBOSS_CONTAINER_MAVEN_DEFAULT_MODULE=/opt/jboss/container/maven/default/
GALLEON_VERSION=4.2.9.Final
S2I_FP_VERSION=23.0.0.Final
GALLEON_WILDFLY_VERSION=5.2.6.Final
JBOSS_CONTAINER_UTIL_LOGGING_MODULE=/opt/jboss/container/util/logging/
GALLEON_LOCAL_MAVEN_REPO=/opt/jboss/container/wildfly/s2i/galleon/galleon-m2-repository
JBOSS_CONTAINER_EAP_GALLEON_FP_PACKAGES=/opt/jboss/container/eap/galleon/eap-s2i-galleon-pack/src/main/resources/packages
OFFLINER_URLS=--url https://repo1.maven.org/maven2/ --url https://repository.jboss.org/nexus/content/groups/public/ --url https://maven.repository.redhat.com/ga/
JBOSS_CONTAINER_JAVA_JVM_MODULE=/opt/jboss/container/java/jvm
JBOSS_MODULES_SYSTEM_PKGS=jdk.nashorn.api,com.sun.crypto.provider
JBOSS_CONTAINER_WILDFLY_S2I_MODULE=/opt/jboss/container/wildfly/s2i
DELETE_BUILD_ARTIFACTS=true
NSS_WRAPPER_PASSWD=/home/jboss/passwd
container=oci
JBOSS_CONTAINER_MAVEN_36_MODULE=/opt/jboss/container/maven/36/
DEFAULT_ADMIN_USERNAME=eapadmin
JBOSS_EAP_VERSION=7.4.15
TMP_GALLEON_LOCAL_MAVEN_REPO=/opt/jboss/container/wildfly/s2i/galleon/tmp-galleon-m2-repository
- To print the local repository and verify its jar contents:
$ cat /opt/jboss/container/wildfly/s2i/galleon/settings.xml
<localRepository>/opt/jboss/container/wildfly/s2i/galleon/galleon-m2-repository</localRepository>
$ cd /opt/jboss/container/wildfly/s2i/galleon/galleon-m2-repository
$ cd /xom/xom/xom-1.3.7.redhat-00001; ls
xom-1.3.7.redhat-00001.jar xom-1.3.7.redhat-00001.jar.md5 xom-1.3.7.redhat-00001.jar.sha1 xom-1.3.7.redhat-00001.pom xom-1.3.7.redhat-00001.pom.md5 xom-1.3.7.redhat-00001.pom.sha1
Content from maven.apache.org is not included.The local repository is a directory on the computer where Maven runs. It caches remote downloads and contains temporary build artifacts that you have not yet released.
This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.