Debug Quarkus app packaged with quarkus-container-image-jib

Viewed 1077

I would like to run the same image in our dev, staging and production environments. For our dev environment I would like to be able to connect a debugger.

I build the image for our Quarkus app like this (mvn package):

<dependencies>
    <dependency>
        <groupId>io.quarkus</groupId>
        <artifactId>quarkus-container-image-jib</artifactId>
    </dependency>
    ...
</dependencies

<properties>
    <quarkus.container-image.build>true</quarkus.container-image.build>
    <quarkus.jib.ports>8080,5005</quarkus.jib.ports>
    <quarkus.container-image.image>...</quarkus.container-image.image>
    ...
</properties>

<build>
    <plugins>
        <plugin>
            <groupId>io.quarkus</groupId>
            <artifactId>quarkus-maven-plugin</artifactId>
            <version>1.12.1.Final</version>
            <executions>
                <execution>
                    <goals>
                        <goal>build</goal>
                    </goals>
                    <phase>package</phase>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

Is it possible to start the application in debug mode while otherwise running with prod profile? Passing JAVA_OPTIONS=-Ddebug=true via an environment variable to the container causes a Exception in thread "main" java.nio.file.NoSuchFileException: /work/lib/deployment/deployment-class-path.dat.

If not, what would be the appropriate way to accomplish such a setup?

1 Answers

There are a few ways to do that, but they all rely on the fact that in Quarkus you can control Jib to use whatever launch script you want for the container image. By default the container-image is created with a minimal java -jar ... style ENTRYPOINT, but that can be changed using the quarkus.jib.jvm-entrypoint.

If you use the default base image which already contains a run-java.sh script that provides a host of options (see https://hub.docker.com/r/fabric8/java-alpine-openjdk11-jre#startup-script-run-javash) then what you are trying to accomplish could be done by setting the following in application.properties:

quarkus.jib.jvm-entrypoint=/deployments/run-java.sh
quarkus.jib.environment-variables."JAVA_APP_DIR"=/work # this is needed so the script knows where the Quarkus jar is

Then launch the application using:

docker run --rm -p 8080:8080 -p 5005:5005 -e JAVA_DEBUG=true gandrian/getting-started:1.0.0-SNAPSHOT

Now the application will have the debug port open (but won't suspend) and you can connect to it with a debugger

Related