No Dockerfile Required: Deploying Spring Boot App with Google Jib

Ntepp Jean Marc
3 min readNov 16, 2023

--

Welcome to the first article in our three-part series where we embark on a journey to streamline the development, deployment, and observability of Spring Boot applications. Have you ever wanted fellow developers to test your application without the hassle of pulling your code and rebuilding it? Docker comes to the rescue by packaging your application and environment, making it runnable across various operating systems and environments.

In this series, we’ve chosen Jib, a Google-developed dependency that simplifies the process of building Docker images for Java applications without the need for a Dockerfile. Before we dive into the intricacies of deploying Spring Boot applications on Kubernetes and enhancing observability, let’s start by building a Spring Boot application with Jib.

Step I: Let’s Develop the Application

Our journey begins with the development of a straightforward Spring Boot web application. This application fetches a random Bible verse from the Bible API. The stack includes:

  • Java 17,
  • Spring Boot, and Thymeleaf.

You can find the application on GitHub. Ready to dive in?

Clone the project:

mvn clone https://github.com/ntepp/random-bible-verse.git

You will see the initial pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.1.5</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.perinfinity.com</groupId>
<artifactId>random-verse</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>random verses</name>
<description>Bible random verses</description>
<properties>
<java.version>17</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

</project>

Run the project using the Maven command:

mvn spring-boot:run

But why Jib? In the world of containerization, we’ll explore how Jib streamlines the process of packaging our application without the need for a Dockerfile, offering a seamless alternative to traditional approaches.

Step II: Add the Jib Dependency and Configuration

To enable Jib in your project, add the following configuration to the <plugins> section of your pom.xml:

<build>
<plugins>
<plugin>
<groupId>com.google.cloud.tools</groupId>
<artifactId>jib-maven-plugin</artifactId>
<version>3.4.0</version>
<configuration>
<to>
<image>docker.io/your-docker-id/random-bible-verse</image>
<auth>
<username>${env.REGISTRY_USERNAME}</username>
<password>${env.REGISTRY_PASSWORD}</password>
</auth>
</to>
</configuration>
</plugin>
</plugins>
</build>

Step III: Build and Push Your Image

To build and push your image, run the following Maven command:

mvn compile jib:build

Step IV: Run the Application

You can now run the container image locally with Docker:

docker run -p 8080:8080 your-docker-id/random-bible-verse

Note: if you want to build the image without pushing it to a registry, just replace docker.io/your-docker-id/random-bible-verse with your image-name and run the command mvn compile jib:dockerBuild instead of mvn compile jib:build.

Key Takeaways and Insights:

  • Simplicity Redefined: Jib eliminates the need for complex Dockerfiles, offering a seamless alternative. It simplifies the packaging process, making it accessible to developers of all levels.
  • Speed and Efficiency: With Jib, the image build process is optimized, significantly reducing build times.

In the next article, we will demonstrate how to deploy this Docker image with Kubernetes. Stay tuned for an exploration of Kubernetes deployment strategies and best practices.

Resources:

I am a software engineer, passionate about AI and Cloud Architecture. You can find more information about me on LinkedIn.

--

--