0

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?

saw303
  • 8,051
  • 7
  • 50
  • 90

2 Answers2

0

I am suppose that this is happening because you are using native image. The application has been compiled already and you can't substitute these environment variables. May be you should try to do it on compiling step?

  • That's not the case. See my answer I reposted. The binary application is still capable of reading environment vars. – saw303 Oct 14 '22 at 14:26
0

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.

saw303
  • 8,051
  • 7
  • 50
  • 90