Hopp til hovedinnhold

Teknologi / 2 minutter /

Hot deployment of Quarkus & Node (React) through Docker

As a developer you’d like hot deployment of both your backend REST service and your frontend UI, but hot deployment of frontend is currently an unresolved issue in Quarkus.
Let’s solve it using Docker!

Docker logo

Copyright 2013-2015 Docker, Inc. All rights reserved


The scenario

You’d like hot deployment of both backend and frontend, with minimum hassle for all developers in your team.
Your project consists of a Quarkus REST backend and in this case, a React frontend UI. Maven is used as the build tool for this example.
A similar approach can likely be used by many other combinations of backends, frontends & build tools. For brevity only one combination is covered here.

If you don't already have a project with a setup like this, then you can check out this demo project.

The project layout

The standard Maven layout is used, with the addition of frontend code residing in src/main/frontend/, and a docker-compose.yml file at the root of the project:

In this example I’m using the latest version of Node and Maven. When this was written, the versions were maven:3.6.3-jdk-14 and node:14.1.0-stretch.

Creating this docker-compose.yml is almost all you have to do. There's one more thing, and that's adding "proxy": "http://backend:8080" to your package.json. The proxy ensures that requests sent to the Node HTTP server will be forwarded to the Quarkus HTTP server when the Node HTTP server can't process the request.

Your src/main/frontend/package.json should then look something like this:

Ready, set, go

Open a terminal, go to the root of your project and execute command docker-compose up.
That’s it. Your frontend is now available at http://localhost:3000, and your backend REST service at http://localhost:8080. You can modify both frontend and backend code, both will automatically be recompiled and deployed without intervention.
Some changes, for instance to pom.xml or package.json, may require a restart of Quarkus or Node. Pressing ctrl-c in the terminal where you started docker-compose will stop both services.

An additional bonus; developers don’t need to manually install (the right version of) neither Node nor JDK in their OS, Docker will handle it. This is useful when you’re working on multiple projects where some might be stuck on Java 8, while other projects use a more recent Java version.