I’m trying to containerize my spring boot application which is a basic spring API that hooks up to a Postgres database. I’m having issues with this process I’m currently using jib to containerize my application, but I keep running into errors.
Here is my POM:
<?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.3.3</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>org.example</groupId>
<artifactId>korfballteamapi</artifactId>
<version>0.0.1</version>
<name>KorfballTeamAPI</name>
<description>KorfballTeamAPI</description>
<organization>
<name>GlasgowKorfball</name>
<url>https://GlasgowKorfball.com</url>
</organization>
<properties>
<java.version>17</java.version>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<docker.username>rsmithuchot1</docker.username>
</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-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.github.javafaker</groupId>
<artifactId>javafaker</artifactId>
<version>1.0.2</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-core</artifactId>
</dependency>
<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-database-postgresql</artifactId>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>
<dependency>
<groupId>io.projectreactor</groupId>
<artifactId>reactor-core</artifactId>
<version>3.5.0</version> <!-- Use the latest stable version -->
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>postgresql</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<!-- This plug in provides support for the mvn build, and mvn packing, such as commands like mvn:run etc,
it helps manage different stages of the build life cycle. In this case, through the IDs, it is making sure the
application is running for when the integration tests start, and when they are finished.
-->
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<id>pre-integration-test</id>
<goals>
<goal>start</goal>
</goals>
<configuration>
<arguments>
<argument>--server.port=${tomcat.http.port}</argument>
</arguments>
</configuration>
</execution>
<execution>
<id>post-integration-test</id>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- This plug is programed to run the unit tests, so any set of tests, that end in test -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<excludes>
<exclude>**/*IntegrationTest.java</exclude>
</excludes>
</configuration>
</plugin>
<!-- This is for runing the integration tests -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<configuration>
<classesDirectory>${project.build.outputDirectory}</classesDirectory>
<includes>
<include>**/*IntegrationTest.java</include>
<include>**/*IT.java</include>
</includes>
<systemPropertyVariables>
<test.server.port>${tomcat.http.port}</test.server.port>
</systemPropertyVariables>
</configuration>
</plugin>
<!--Provides additional features to build life cycle to help support -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<id>reserve-tomcat-port</id>
<goals>
<goal>reserve-network-port</goal>
</goals>
<phase>process-resources</phase>
<configuration>
<portNames>
<portName>tomcat.http.port</portName>
</portNames>
</configuration>
</execution>
</executions>
</plugin>
<!-- Automatic toll to build a docker image-->
<plugin>
<groupId>com.google.cloud.tools</groupId>
<artifactId>jib-maven-plugin</artifactId>
<version>3.4.3</version>
<configuration>
<from>
<image>eclipse-temurin:22</image>
<platforms>
<platform>
<architecture>arm64</architecture>
<os>linux</os>
</platform>
<platform>
<architecture>amd64</architecture>
<os>linux</os>
</platform>
</platforms>
</from>
<to>
<image>docker.io/${docker.username}/${project.artifactId}:${project.version}</image>
<tags>
<tag>latest</tag>
</tags>
</to>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>build</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
And here is my output using mvn clean package -DskipTests
INFO] Executing tasks: [INFO] [========================= ] 83.3% complete [INFO] > launching layer pushers [INFO] > launching layer pushers [INFO] [INFO] ------------------------------------------------------------------------ [INFO] BUILD FAILURE [INFO] ------------------------------------------------------------------------ [INFO] Total time: 13:20 min [INFO] Finished at: 2024-09-05T15:17:43+01:00 [INFO] ------------------------------------------------------------------------ [ERROR] Failed to execute goal com.google.cloud.tools:jib-maven-plugin:3.4.3:build (default) on project korfballteamapi: 416 Requested Range Not Satisfiable [ERROR] PATCH https://registry-1.docker.io/v2/rsmithuchot1/korfballteamapi/blobs/uploads/d4e7632e-4092-4732-bf68-f24ef2c3e734?_state=iX2bXP9vNXih8-aOmMFOINGsRf5c19SBhcXv6nBHnFF7Ik5hbWUiOiJyc21pdGh1Y2hvdDEva29yZmJhbGx0ZWFtYXBpIiwiVVVJRCI6ImQ0ZTc2MzJlLTQwOTItNDczMi1iZjY4LWYyNGVmMmMzZTczNCIsIk9mZnNldCI6MCwiU3RhcnRlZEF0IjoiMjAyNC0wOS0wNVQxNDowNTowMC43MjgwODYxNzVaIn0%3D [ERROR] {"errors":[{"code":"RANGE_INVALID","message":"invalid content range"}]} [ERROR] [ERROR] -> [Help 1] [ERROR] [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. [ERROR] Re-run Maven using the -X switch to enable full debug logging. [ERROR] [ERROR] For more information about the errors and possible solutions, please read the following articles: [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
What I am finding confusing is that I have copied the instructors POM, and have previously used his code to push to docker with no issues, but now if I run his code I also get errors. I even made a small spring app from default, and tried to push it to docker but got errors also. I made sure my path has no caps in it (image path).
I do not know if this is relevant, but my current JAVA_HOME is set to C:Usersricha.jdkscorretto-17.0.12
And then my MAVEN_HOME is set to: C:Program FilesApacheMavenapache-maven-3.9.8
For this project, I am using SDK Amazon Corretto 17.0.12
I have tried a lot of different things the first thing that I did was to make sure that I was logged into docker on my console and that was fine because I got authenticated. I then tried playing around with the jib palm trying different combinations of things, but got different errors. I even tried running the different code of a different project and I also then made a very tiny spring boot application from spring initializer and then try to add jib to that. Been stuck on this for quite a while and quite new to this area.