GoogleContainerTools / jib

🏗 Build container images for your Java applications.
Apache License 2.0
13.58k stars 1.43k forks source link

How to activate debugging in a JIB image ? #4166

Closed nicolasduminil closed 7 months ago

nicolasduminil commented 7 months ago

Environment:

Description of the issue: Can't activate the debug mode in a JIB image. Using the following config:

      <plugin>
        <groupId>com.google.cloud.tools</groupId>
        <artifactId>jib-maven-plugin</artifactId>
        <configuration>
          <containerizingMode>packaged</containerizingMode>
            <to>
            <image>wildfly-bootable/server-layer</image>
          </to>
          <container>
            <mainClass>org.wildfly.core.jar.boot.Main</mainClass>
            <args>
              <arg>-b=0.0.0.0</arg>
              <arg>--deployment=/deployments/ROOT.war/</arg>
            </args>
            <jvmFlags>-Xdebug</jvmFlags>
            <jvmFlags>-Xrunjdwp:transport=dt_socket,address=8787,suspend=n,server=y</jvmFlags>
            <ports>
              <port>8080</port>
              <port>8787</port>
            </ports>
          </container>
        </configuration>
        <executions>
          <execution>
            <phase>package</phase>
            <goals>
              <goal>dockerBuild</goal>
            </goals>
          </execution>
        </executions>
      </plugin>

But I get : java.lang.RuntimeException: WFLYJAR0011: Unknown argument -Xdebug. I also tried:

...
<args>
  <arg>-Xdebug</arg>
  <arg>-Xrunjdwp:transport=dt_socket,address=8787,suspend=n,server=y</arg>
</args>
...     

but still doesn't work.

Expected behavior: When I start the container, I expect to see in the log file that the debugging is active.

Steps to reproduce:

  1. Run a POM havin a configuration as below to create the image
  2. Run the image
  3. Notice the error message

jib-maven-plugin Configuration:

jib-gradle-plugin Configuration:

      <plugin>
        <groupId>com.google.cloud.tools</groupId>
        <artifactId>jib-maven-plugin</artifactId>
        <configuration>
          <containerizingMode>packaged</containerizingMode>
            <to>
            <image>wildfly-bootable/server-layer</image>
          </to>
          <container>
            <mainClass>org.wildfly.core.jar.boot.Main</mainClass>
            <args>
              <arg>-b=0.0.0.0</arg>
              <arg>--deployment=/deployments/ROOT.war/</arg>
            </args>
            <jvmFlags>-Xdebug</jvmFlags>
            <jvmFlags>-Xrunjdwp:transport=dt_socket,address=8787,suspend=n,server=y</jvmFlags>
            <ports>
              <port>8080</port>
              <port>8787</port>
            </ports>
          </container>
        </configuration>
        <executions>
          <execution>
            <phase>package</phase>
            <goals>
              <goal>dockerBuild</goal>
            </goals>
          </execution>
        </executions>
      </plugin>

Log output:

docker run --name jsr375 -p 8080:8080 -p 8787:8787 wildfly-bootable/app-layer:latest 
java.lang.RuntimeException: WFLYJAR0011: Unknown argument -Xdebug
nicolasduminil commented 7 months ago

Sorry for having submitted this issue which doesn't have anything to do with the wildfly-jar-maven-plugin. In order to enable debugging in the running container, I just need to do:

docker run --name jsr375 -p 8080:8080 -p 8787:8787 -e JAVA_TOOL_OPTIONS="-agentlib:jdwp=transport=dt_socket,address=8787,server=y,suspend=n" wildfly-bootable/app-layer:latest

There is no need to try doing that in the image.

Kind regards, Nicolas