jboss-container-images / openjdk

Source To Image (S2I) image for Red Hat OpenShift providing OpenJDK
Apache License 2.0
54 stars 58 forks source link

[OPENJDK-2968] JAVA_ARGS has no effect in ubi9/openjdk-17-runtime #483

Open linustornkrantz opened 5 months ago

linustornkrantz commented 5 months ago

According to https://jboss-container-images.github.io/openjdk/ubi9/ubi9-openjdk-17-runtime.html, it should be possible to set arguments with JAVA_ARGS in ubi9/openjdk-17-runtime, just as it works in ubi9/openjdk-17. However, JAVA_ARGS has no effect in ubi9/openjdk-17-runtime.

To reproduce:

cat > ArgsTest.java <<EOF
import java.util.Arrays;

class ArgsTest {

    public static void main(String[] args) {
        System.out.println("Number of args: " + args.length);
        Arrays.stream(args).forEach(System.out::println);
    }

}
EOF

javac ArgsTest.java

podman run -v ./:/app -e JAVA_APP_DIR=/app/ -e JAVA_MAIN_CLASS=ArgsTest -e JAVA_ARGS=Hello registry.access.redhat.com/ubi9/openjdk-17:1.18-1

podman run -v ./:/app -e JAVA_APP_DIR=/app/ -e JAVA_MAIN_CLASS=ArgsTest -e JAVA_ARGS=Hello registry.access.redhat.com/ubi9/openjdk-17-runtime:1.18-1

For ubi9/openjdk-17, this produces:

Starting the Java application using /opt/jboss/container/java/run/run-java.sh ...
INFO exec -a "java" java -XX:MaxRAMPercentage=80.0 -XX:+UseParallelGC -XX:MinHeapFreeRatio=10 -XX:MaxHeapFreeRatio=20 -XX:GCTimeRatio=4 -XX:AdaptiveSizePolicyWeight=90 -XX:+ExitOnOutOfMemoryError -cp ".:/app//*" ArgsTest Hello
INFO running in /app
Number of args: 1
Hello

For ubi9/openjdk-17-runtime, this produces:

INFO exec -a "java" java -XX:MaxRAMPercentage=80.0 -XX:+UseParallelGC -XX:MinHeapFreeRatio=10 -XX:MaxHeapFreeRatio=20 -XX:GCTimeRatio=4 -XX:AdaptiveSizePolicyWeight=90 -XX:+ExitOnOutOfMemoryError -cp ".:/app//*" ArgsTest 
INFO running in /app
Number of args: 0
jerboaa commented 5 months ago

@jhuttana Please take a look at this. Thanks!

jhuttana commented 5 months ago

@jhuttana Please take a look at this. Thanks!

Sure

schedin commented 5 months ago

If I where to guess this is because the ubi9/openjdk-17 uses the source 2 image start script that has support for JAVA_ARGS:

[builder@97032af7e5d2 operator]$ podman inspect registry.access.redhat.com/ubi9/openjdk-17:1.18-1 | grep CMD
                    "created_by": "/bin/sh -c #(nop) CMD [\"/bin/bash\"]",
                    "created_by": "/bin/sh -c #(nop) CMD [\"/usr/local/s2i/run\"]",

https://github.com/jboss-container-images/openjdk/blob/b7ac43bf0f0c46fd83d764c345ff1355cf44e6cf/modules/s2i/bash/artifacts/usr/local/s2i/run#L21

But the ubi9/openjdk-17-runtime uses another start script does not have support for JAVA_ARGS. It only has support for "normal" arguments passed via CMD:

[builder@97032af7e5d2 operator]$ podman inspect registry.access.redhat.com/ubi9/openjdk-17-runtime:1.18-1 | grep CMD
                    "created_by": "/bin/sh -c #(nop) CMD [\"/bin/bash\"]",
                    "created_by": "/bin/sh -c #(nop) CMD [\"/opt/jboss/container/java/run/run-java.sh\"]",

https://github.com/jboss-container-images/openjdk/blob/b7ac43bf0f0c46fd83d764c345ff1355cf44e6cf/modules/run/artifacts/opt/jboss/container/java/run/run-java.sh#L222

jmtd commented 5 months ago

@schedin 's analysis looks correct; JAVA_ARGS is handled in the s2i/run script, rather than run-java.sh. Awkward!

We should probably move all the logic to run-java.sh and have the s2i CMD be as thin as possible, or get rid of it.

jmtd commented 5 months ago

Corresponding JIRA :https://issues.redhat.com/browse/OPENJDK-2968