0

I try to use Virtual Threads in a Quarkus application but cannot find a way to build a Quarkus Docker image with JDK19.

Local development works fine and application runs without problems. However, the official Red-Hat Docker images only support JDK17.

Tried to tune the official build image for JDK17 but without success.

How would you build a quarkus image with openjdk-19?

sysid
  • 55
  • 1
  • 4
  • Given that OpenJDK 19 has about a week of life left I don't know that I would put much time into it but there are [JDK 19 docker images](https://github.com/docker-library/docs/blob/master/eclipse-temurin/README.md#supported-tags-and-respective-dockerfile-links) available to build your own. A project like Quarkus is likely to focus on LTS releases as they last longer than 6 months. – stdunbar Mar 08 '23 at 17:20
  • @stdunbar is right. We don't create docker images for non LTS versions – geoand Mar 09 '23 at 05:30
  • Thanks guys for being so responsive! I know how to build Docker images, but I have no experience with building quarkus. So any hint to some helpful resources to understand, what needs to be part of Docker image for quarkus to work properly would be very appreciated. – sysid Mar 09 '23 at 08:10
  • Are you compiling to native, or are you running Quarkus in Java mode? If it is in Java mode, I can't see that it should be a problem. Native, I don't know. Probably not something I would run in production if not officially supported... – ewramner Mar 11 '23 at 19:11
  • JVM mode. Probably not a problem, I just don't know, what quarkus needs in the image in order to work properly. And I have not found any documentation for this (except the official build image as noted). – sysid Mar 13 '23 at 16:56

1 Answers1

0

In case someone looks for a similar solution, this is how I solved the problem with a staged Docker build:

# Use the official JDK 19 image as the base image for the build stage
FROM openjdk:19-jdk AS build

# Enable preview features
ENV JAVA_OPTS="--enable-preview"

# Set the working directory
WORKDIR /app

# Copy the Maven wrapper
COPY mvnw .
COPY .mvn .mvn

# Copy the pom.xml file
COPY pom.xml .

ENV HTTP_PROXY="http://host.docker.internal:3128"
ENV HTTPS_PROXY="http://host.docker.internal:3128"
ENV http_proxy="http://host.docker.internal:3128"
ENV https_proxy="http://host.docker.internal:3128"
ENV MAVEN_OPTS="-Dhttp.proxyHost=host.docker.internal -Dhttp.proxyPort=3128 -Dhttps.proxyHost=host.docker.internal -Dhttps.proxyPort=3128 --enable-preview"

# Download dependencies and cache them
RUN ./mvnw dependency:go-offline -B

# Copy the source code
COPY ./src ./src

# Compile and package the application
RUN ./mvnw package -Dmaven.test.skip=true -Dmaven.javadoc.skip=true -B -V


# Use the official JDK 19 image as the base image for the runtime stage
FROM openjdk:19-jdk AS runtime

# Enable preview features
ENV JAVA_OPTS="-Dquarkus.http.host=0.0.0.0 -Djava.util.logging.manager=org.jboss.logmanager.LogManager --enable-preview"

# Set the working directory
WORKDIR /app

# Copy the build artifacts from the build stage
#COPY --from=build /app/target/quarkus-app/quarkus-run.jar /app/app.jar
COPY --from=build /app/target/quarkus-app/lib/ /app/lib/
COPY --from=build /app/target/quarkus-app/*.jar /app/
COPY --from=build /app/target/quarkus-app/app/ /app/app/
COPY --from=build /app/target/quarkus-app/quarkus/ /app/quarkus/

# Set the entrypoint and command to run the application
ENTRYPOINT ["sh", "-c", "java $JAVA_OPTS -jar /app/quarkus-run.jar"]
sysid
  • 55
  • 1
  • 4