Quarkus native image process doesn't allow additional environment variable during docker build
See original GitHub issueDescribe the bug
I’m using Quarkus Hazelcast integration. Because Quarkus uses Java 11, Hazelcast warns me during the native image compilation process I should open some modules according to JPMS.
12:34:13,002 WARNING [com.haz.ins.imp.HazelcastInstanceFactory] Hazelcast is starting in a Java modular environment (Java 9 and newer) but without proper access to required Java packages. Use additional Java arguments to provide Hazelcast access to Java internal API. The internal API access is used to get the best performance results. Arguments to be used:
--add-modules java.se --add-exports java.base/jdk.internal.ref=ALL-UNNAMED --add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.nio=ALL-UNNAMED --add-opens java.base/sun.nio.ch=ALL-UNNAMED --add-opens java.management/sun.management=ALL-UNNAMED --add-opens jdk.management/com.sun.management.internal=ALL-UNNAMED
To fix this, I use the quarkus.native.additional-build-args
option.
Expected behavior
By using the quarkus.native.additional-build-args
option in the POM (or in application.properties
), I could add -e JAVA_OPTS="--add-modules java.se --add-exports java.base/jdk.internal.ref=ALL-UNNAMED --add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.nio=ALL-UNNAMED --add-opens java.base/sun.nio.ch=ALL-UNNAMED --add-opens java.management/sun.management=ALL-UNNAMED --add-opens jdk.management/com.sun.management.internal=ALL-UNNAMED"
.
This way, the docker build would use the JAVA_OPTS
environment variable, and open/export the required JPMS modules.
Actual behavior
The way it’s coded (cf. NativeImageBuildStep), additional build arguments are appended after the image name. Docker cannot parse environment variables at this point, and I get the following message:
[INFO] [io.quarkus.deployment.pkg.steps.NativeImageBuildStep] docker run -v /Users/nico/projects/hazelcast/quarkus-integration/target/url-shortener-1.0-native-image-source-jar:/project:z --env LANG=C --rm quay.io/quarkus/ubi-quarkus-native-image:19.3.1-java11 -J-Dsun.nio.ch.maxUpdateArraySize=100 -J-Djava.util.logging.manager=org.jboss.logmanager.LogManager -J-Dvertx.logger-delegate-factory-class-name=io.quarkus.vertx.core.runtime.VertxLogDelegateFactory -J-Dvertx.disableDnsResolver=true -J-Dio.netty.leakDetection.level=DISABLED -J-Dio.netty.allocator.maxOrder=1 -J-Duser.language=en -J-Dfile.encoding=UTF-8 -e JAVA_OPTS="--add-modules java.se --add-exports java.base/jdk.internal.ref=ALL-UNNAMED --add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.nio=ALL-UNNAMED --add-opens java.base/sun.nio.ch=ALL-UNNAMED --add-opens java.management/sun.management=ALL-UNNAMED --add-opens jdk.management/com.sun.management.internal=ALL-UNNAMED" --initialize-at-build-time= -H:InitialCollectionPolicy=com.oracle.svm.core.genscavenge.CollectionPolicy$BySpaceAndTime -H:+JNI -jar url-shortener-1.0-runner.jar -H:FallbackThreshold=0 -H:+ReportExceptionStackTraces -H:-AddAllCharsets -H:-IncludeAllTimeZones -H:EnableURLProtocols=http,https --enable-all-security-services --no-server -H:-UseServiceLoaderFeature -H:+StackTrace url-shortener-1.0-runner
Error: Unrecognized option: -e JAVA_OPTS="--add-modules java.se --add-exports java.base/jdk.internal.ref=ALL-UNNAMED --add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.nio=ALL-UNNAMED --add-opens java.base/sun.nio.ch=ALL-UNNAMED --add-opens java.management/sun.management=ALL-UNNAMED --add-opens jdk.management/com.sun.management.internal=ALL-UNNAMED"
To Reproduce
Steps to reproduce the behavior:
- Try to add any environment variable to the Docker build via
quarkus.native.additional-build-args
, either in the POM or inapplication.properties
Configuration
This is not configuration-dependent.
Environment:
-
Output of
uname -a
orver
:Darwin Nico 19.5.0 Darwin Kernel Version 19.5.0: Tue May 26 20:41:44 PDT 2020; root:xnu-6153.121.2~2/RELEASE_X86_64 x86_64
-
Output of
java -version
:openjdk 11.0.7 2020-04-14 OpenJDK Runtime Environment AdoptOpenJDK (build 11.0.7+10) OpenJDK 64-Bit Server VM AdoptOpenJDK (build 11.0.7+10, mixed mode)
-
GraalVM version (if different from Java): It’s using GraalVM from the Docker image
-
Quarkus version or git rev: 1.5.2.Final
-
Build tool (ie. output of
mvnw --version
orgradlew --version
):Maven home: /Users/nico/.m2/wrapper/dists/apache-maven-3.6.3-bin/1iopthnavndlasol9gbrbg6bf2/apache-maven-3.6.3 Java version: 11.0.7, vendor: GraalVM Community, runtime: /Library/Java/JavaVirtualMachines/graalvm-ce-java11-20.1.0/Contents/Home Default locale: en_GB, platform encoding: UTF-8 OS name: "mac os x", version: "10.15.5", arch: "x86_64", family: "mac"
Issue Analytics
- State:
- Created 3 years ago
- Comments:12 (7 by maintainers)
Thanks @geoand!
I am currently on vacations, I’ll try it when I get back.
Hello, is there any updates on this ? I’m trying to set environment variables in the build container for my app as well and hit the same problem. Passing java props instead works with the -J-Dxxx. Still, would be good to be able to pass environment variable.