paketo-buildpacks / spring-boot

A Cloud Native Buildpack that contributes Spring Boot dependency information and slices an application into multiple layers
Apache License 2.0
180 stars 21 forks source link

JAVA_OPTS was ignored when app started #14

Closed SergeyMagid closed 4 years ago

SergeyMagid commented 4 years ago

Hi, In last version of buildpack I can not add my custom JAVA_OPTS.

Steps:

  1. I have created simple app via https://start.spring.io/ with Spring-boot 2.3.3
  2. Create docker image with ./mvnw spring-boot:build-image.
  3. Run docker docker run -e "JAVA_OPTS=-Xmx400m" library/awesome_app:0.0.1-SNAPSHOT

Then I see at logs my params.

Setting Active Processor Count to 4 Adding $JAVA_OPTS to $JAVA_TOOL_OPTIONS WARNING: Container memory limit unset. Configuring JVM for 1G container. Calculated JVM Memory Configuration: -XX:MaxDirectMemorySize=10M -XX:MaxMetaspaceSize=95268K -XX:ReservedCodeCacheSize=240M -Xss1M (Total Memory: 1G, Thread Count: 250, Loaded Class Count: 14406, Headroom: 0%) Adding 127 container CA certificates to JVM truststore Spring Cloud Bindings Enabled Picked up JAVA_TOOL_OPTIONS: -Djava.security.properties=/layers/paketo-buildpacks_bellsoft-liberica/java-security-properties/java-security.properties -agentpath:/layers/paketo-buildpacks_bellsoft-liberica/jvmkill/jvmkill-1.16.0-RELEASE.so=printHeapHistogram=1 -XX:ActiveProcessorCount=4 -Xmx400m -XX:MaxDirectMemorySize=10M -XX:MaxMetaspaceSize=95268K -XX:ReservedCodeCacheSize=240M -Xss1M -Dorg.springframework.cloud.bindings.boot.enable=true

But any params was passed to jar

cnb@ae43ae18befc:/$ ps ax | grep jav 1 ? Ssl 0:11 java org.springframework.boot.loader.JarLauncher 126 pts/0 S+ 0:00 grep --color=auto jav

nebhale commented 4 years ago

The line

Picked up JAVA_TOOL_OPTIONS: -Djava.security.properties=/layers/paketo-buildpacks_bellsoft-liberica/java-security-properties/java-security.properties -agentpath:/layers/paketo-buildpacks_bellsoft-liberica/jvmkill/jvmkill-1.16.0-RELEASE.so=printHeapHistogram=1 -XX:ActiveProcessorCount=4 -Xmx400m -XX:MaxDirectMemorySize=10M -XX:MaxMetaspaceSize=95268K -XX:ReservedCodeCacheSize=240M -Xss1M -Dorg.springframework.cloud.bindings.boot.enable=true

is printed by the JVM itself, not by any part of the buildpack. So the JVM is telling you that it's seen your -Xmx400m when it starts. $JAVA_TOOL_OPTIONS is a JVM-native way of passing in JVM flags in headless environments since $JAVA_OPTS is a convention, but is not understood by the JVM directly. If you were to fire up JVisualVM, and looked at the memory configuration from inside the JVM, you'd see that you configuration took.

SergeyMagid commented 4 years ago

Thank you.