Build JHipster application for and Run on Docker or Podman

Lucas Jellema
0 0
Read Time:3 Minute, 32 Second

For the Open Day we organize shortly for our family, friends, neighbours and other interested parties, my colleagues create a custom web application to support our QR Scavenger Hunt through the offices and surrounding premises. This (progressive) web application is created using JHipster – leveraging Java, Angular, Spring, PostgreSQL and many more libraries and frameworks.

Early work in progress looks like this:

image

I have taken it upon myself to make this application available on a public cloud infrastructure so all our visitors can access it on their mobile phones. To keep things simple, I decided that I would build this JHipster application into a Container Image and run the application using Docker (or Podman) Compose on a cloud VM. (the step to take to Kubernetes seemed just a little too much for now).

I am by no means an expert in JHipster. Fortunately, for this particular challenge I do not have to know how to develop the application – only how to build and deploy it. The deployment is fairly straightforward: JHipster generates a yaml file that I can feed to Docker Compose or Podman Compose. Based on that file, two containers are started – one for a PostgreSQL database and a second one for the application (containing the Java backend based on Spring and handling HTTP requests from the browser that runs the also included Angular web application and using Hibernate and a JDBC connection to talk to the database in the first container). 

Once the application container image is built and pushed, running the application is as easy as:

docker-compose -f src/main/docker/app.yml up

or

podman-compose -f src/main/docker/app.yml up

The real challenge for me was how to build the JHipster Application Container Image. Part of the challenge was caused by the fact that I locally run a (not ideally configured) Podman based environment.

Build the JHipster Application Container Image

The Maven, Gradle and NPM build approaches for JHipster are extensive and well documented. They can easily be used to produce a Docker Container Image leveraging the local Docker daemon process. (read details in the docs).

However, in my environment I do not have a Docker daemon process running. JHipster also caters for that situation – using the Jib library that helps create container images for Java applications. The NPM build process cannot work with jib in this way, but both Maven and Gradle can. I am more familiar with Maven, so that is the option I go for.

All I should have to do at this point is determine what the artifact identifier for the container image should be and run this command:

./mvnw package -Pprod verify jib:build -Djib.to.image=<dockerhub-username>/<artifact-id>

Unfortunately, with the way I have set up Podman in my Ubuntu environment within Windows WSL2, the authentication details for connecting to Docker Hub cannot be retrieved by jib. I did not want to spend too much time on this almost one time only activity so I decided to go for the quick and dirty approach: including the registry authentication details in the command line statement. Really dirty – and also really quick.

The command that did it for me:

./mvnw package -Pprod verify jib:build -Djib.to.image=lucasjellema/amis-open-dag:0.0.1 -Djib.to.auth.username=lucasjellema -Djib.to.auth.password=$DOCKER_HUB_PASSWORD

image

The build process ran for a while and after creating the JAR file – where it normally might have stopped – dutifully continued to build the container image:

image

The image was built, tagged as lucasjellema\amis-open-dag:0.0.1 and pushed to Docker Hub.

The generated app.yml (in directory src/main/docker) needed a small edit – to set the proper name for the container image.

image

With this taken care of, the JHipster application (including its PostgreSQL database) could be started with a single and very simple command:

podman-compose -f src/main/docker/app.yml up

(I do not have docker-compose, that’s why podman-compose).

image

Note: this command will run the application in any environment, provided that environment has:

  • the app.yml file
  • Docker Compose or Podman Compose
  • access to Docker Hub (to retrieve container image)

Resources

JHipster Documentation – Docker and Docker Compose

jib documentation – what is Unauthorized?

About Post Author

Lucas Jellema

Lucas Jellema, active in IT (and with Oracle) since 1994. Oracle ACE Director and Oracle Developer Champion. Solution architect and developer on diverse areas including SQL, JavaScript, Kubernetes & Docker, Machine Learning, Java, SOA and microservices, events in various shapes and forms and many other things. Author of the Oracle Press book Oracle SOA Suite 12c Handbook. Frequent presenter on user groups and community events and conferences such as JavaOne, Oracle Code, CodeOne, NLJUG JFall and Oracle OpenWorld.
Happy
Happy
0 %
Sad
Sad
0 %
Excited
Excited
0 %
Sleepy
Sleepy
0 %
Angry
Angry
0 %
Surprise
Surprise
0 %

Average Rating

5 Star
0%
4 Star
0%
3 Star
0%
2 Star
0%
1 Star
0%

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Next Post

Oracle Cloud’s marching order: win developers’ hearts and minds

There are two public cloud. AWS and Azure. That is not actually the case – but that is how sometimes it may seem. A third cloud is frequently listed alongside the two main players. A cloud that has made serious efforts to be seen by developers and architects. By somehow […]
%d bloggers like this: