Search code examples
javamicronautgraalvmgraalvm-native-image

Native Image: Overwrite configuration settings


I'm trying to run a Micronaut application as a native image in a Docker container. With the fat jar approach I could overwrite fields in my Micronaut configuration (application.yml) using the environment variable JAVA_TOOL_OPTIONS and then set a new value to my configuration fields (see listing below).

version: "3.9"
services:
  temposec:
    image: ghcr.io/onstructive/tempo-security/tempo-security:0.2.25-native
    environment:
      JAVA_TOOL_OPTIONS: "\
        -Dmicronaut.http.services.temposec.url=http://host.docker.internal:8090 \
        -Dlog.level.ch.onstructive=DEBUG \
        -Dmicronaut.caches.tempo-cache.maximumSize=0 \
        -Dmicronaut.caches.decision-cache.maximumSize=0 \
        -Dmicronaut.caches.attribute-cache.maximumSize=0 \
        -Dmicronaut.http.services.temposec.read-timeout=1s
        "
    ports:
      - "127.0.0.1:6000:8080"
      - "127.0.0.1:6001:8090"

I guess that the native image does not care about the environment variable JAVA_TOOL_OPTIONS, so I was wondering how to do this with a GraalVM native image. Do I have to declare specific application env variables for each field? Or is there a more elegant way to achieve the same as with the Java VM?


Solution

  • Repost of answer in Micronaut discussion.

    You can pass properties as environment variables:

    version: "3.9"
    services:
      temposec:
        image: ghcr.io/onstructive/tempo-security/tempo-security:0.2.25-native
        environment:
          MICRONAUT_HTTP_SERVICES_TEMPOSEC_URL: http://host.docker.internal:8090
          ....
    

    I believe this is more readable than a multi-line string variable. Alternatively, you can set the MICRONAUT_CONFIG_FILES env variable to a local file, and include all the configuration there.