background image

Quarkus Cloud Deployment on render.com hosting

by pp
Updated:

In this tutorial, we will guide you through the steps to deploy a Quarkus application on Render.com. Render.com is a fully-managed cloud platform that automates the deployment process, making it a breeze to maintain and scale your applications. It offers a free plan for deploying Java microservices like Quarkus, making it an excellent resource for learning and experimentation.

Prerequisites

Before we start, make sure you have the following:

  1. A Render.com account.
  2. Docker installed on your local machine.
  3. Git installed on your local machine.

Create skeleton of Quarkus application

That can be done with Quarkus CLI:

quarkus create app com.lambdacoder:quarkus-cloud-deployment --extension='resteasy-reactive'
cd quarkus-cloud-deployment

This implements /hello endpoint and is just fine for our tutorial.

Adjust Dockerfile

Let's have a look at a Dockerfile ./src/main/docker/Dockerfile.jvm which was generated in previous step:

FROM registry.access.redhat.com/ubi8/openjdk-21:1.18

ENV LANGUAGE='en_US:en'


# We make four distinct layers so if there are application changes the library layers can be re-used
COPY --chown=185 target/quarkus-app/lib/ /deployments/lib/
COPY --chown=185 target/quarkus-app/*.jar /deployments/
COPY --chown=185 target/quarkus-app/app/ /deployments/app/
COPY --chown=185 target/quarkus-app/quarkus/ /deployments/quarkus/

EXPOSE 8080
USER 185
ENV JAVA_OPTS_APPEND="-Dquarkus.http.host=0.0.0.0 -Djava.util.logging.manager=org.jboss.logmanager.LogManager"
ENV JAVA_APP_JAR="/deployments/quarkus-run.jar"

ENTRYPOINT [ "/opt/jboss/container/java/run/run-java.sh" ]

This Dockerfile is not ideal because it assumes that the application and its dependencies will be in the target/quarkus-app path during the build phase. You can create this target on your development machine using the mvn package command, for example.

The issue with this Dockerfile arises on machines where you cannot build the target directory in advance. This is often the case on cloud platforms. Fortunately, you can build the target within the Docker image itself. Without going into too much detail about Docker builds, we will utilize what is known as a multi-stage build. This allows us to use the Maven build tool in one stage and then use the result of the build in the next stage without unnecessarily enlarging the final stage by including Maven, which is not needed for executing the Java process. Fixed dockerfile looks like this:

FROM maven:3.9.6 as build

WORKDIR /app

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

# Download all required dependencies into one layer
RUN mvn dependency:go-offline -B

# Copy your source code
COPY src /app/src

# Build the application
RUN mvn package


FROM registry.access.redhat.com/ubi8/openjdk-21:1.18

ENV LANGUAGE='en_US:en'

# We make four distinct layers so if there are application changes the library layers can be re-used
COPY --chown=185 --from=build /app/target/quarkus-app/lib/ /deployments/lib/
COPY --chown=185 --from=build /app/target/quarkus-app/*.jar /deployments/
COPY --chown=185 --from=build /app/target/quarkus-app/app/ /deployments/app/
COPY --chown=185 --from=build /app/target/quarkus-app/quarkus/ /deployments/quarkus/

EXPOSE 8080
USER 185
ENV JAVA_OPTS_APPEND="-Dquarkus.http.host=0.0.0.0 -Djava.util.logging.manager=org.jboss.logmanager.LogManager"
ENV JAVA_APP_JAR="/deployments/quarkus-run.jar"

ENTRYPOINT [ "/opt/jboss/container/java/run/run-java.sh" ]

Unfortunately, the projects generated with Quarkus CLI have .dockerignore which prevents the new dockerfile from working. The .dockerignore has rules

*
!target/*-runner
!target/*-runner.jar
!target/lib/*
!target/quarkus-app/*

The asterisk (*) symbol above indicates that the pom.xml file and the src folder are being prevented from being copied to the Docker build process. If you delete the .dockerignore file, the build process specified in ./src/main/docker/Dockerfile.jvm will start functioning correctly.

Create new Web Service in Render.com

Select New Web Service dashboard.render.com_step1.png

Connect to Github or Gitlab repository

Connect to your Girhub or Gitlab repository as shown in following pictures dashboard.render.com_step2.png dashboard.render.com_step3.png

Configure Web Service Settings and create the Service

Similarly to the following picture, do following changes:

  • For Runtime, select Docker
  • For Instance Type, Free type is sufficient for our tutorial.
  • Click on Advanced button to show more configuration settings
  • For Dockerfile Path, fill in ./src/main/docker/Dockerfile.jvm, because we don't have Dockerfile in repository root.
  • Click Create Web Service button and launch creation of the service dashboard.render.com_step4.png

Observe building of images and start of the container

Once you clicked Create Web Service in previous step, you can watch docker logs. You should finally see something like this: dashboard.render.com_step5.png

Check service in browser

You should be able to see Web Service endpoint, starting with https://. After you follow the link, you should see something like: quarkus-cloud-deployment.onrender.com.png

That is proof, that your new Web Service is running fine. You can now also check context /hello.

Further Deployments

Once you push to your main branch, a new image is built from the newly updated GitHub or GitLab sources. The container running the previous version is then stopped, and a new container with the updated image is started. This streamlined process eliminates any additional tasks for deploying your application.

Conclusion

In this tutorial, we've demonstrated how to deploy a Quarkus application on Render.com. By following these steps, you can efficiently deploy and scale your applications using Render.com's automated platform. With a focus on simplicity and effectiveness, this tutorial equips you to deploy your Quarkus applications effortlessly.