question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Quarkus native image process doesn't allow additional environment variable during docker build

See original GitHub issue

Describe 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:

  1. Try to add any environment variable to the Docker build via quarkus.native.additional-build-args, either in the POM or in application.properties

Configuration

This is not configuration-dependent.

Environment:

  • Output of uname -a or ver: 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 or gradlew --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:open
  • Created 3 years ago
  • Comments:12 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
nfrankelcommented, Jul 21, 2020

Thanks @geoand!

I am currently on vacations, I’ll try it when I get back.

0reactions
sdehors-ibmcommented, Jan 6, 2021

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Building a Native Executable - Quarkus
Set GRAALVM_HOME environment variable to the GraalVM installation directory ... to configure the native image building process in the Configuring the Native ......
Read more >
Container Images - Quarkus
The extension quarkus-container-image-docker is using the Docker binary and the generated Dockerfiles under src/main/docker in order to perform Docker builds.
Read more >
Native Reference Guide - Quarkus
This guide builds and executes Quarkus native executables within a Linux environment. To offer a homogeneous experience across all environments, the guide ...
Read more >
Tips for writing native applications - Quarkus
By default, when building a native executable, GraalVM will not include any of the ... Error: No instances are allowed in the image...
Read more >
Configuration Reference Guide - Quarkus
(400) System properties. (300) Environment variables. (295) .env file in the current working directory. (260) Quarkus Application ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found