Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#250: Jib maven plugin added to make the containerization easier. #317

Closed
wants to merge 25 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions documentation/guide-jib.asciidoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
:toc:
toc::[]

= JIB
jib is a tool from Google to create Docker images in simple and faster way. No dockerfile or no docker compose file is required. Using Jib, image can be created and uploaded to the registery even without Docker daemon.

The JIB maven plugin configured to build the image using mvn command.

== Build and run the image locally
The Docker daemon should be available locally.

To build the docker image.
[source]
----
mvn compile -Pcontainer

docker images

REPOSITORY TAG IMAGE ID CREATED SIZE
myapp-server/java 0.0.1-SNAPSHOT c521c9800c48 51 years ago 206MB
myapp-api/java 0.0.1-SNAPSHOT 7004670aa31e 51 years ago 161MB
myapp-core/java 0.0.1-SNAPSHOT 82d949c3daa3 51 years ago 205MB
----

To run the image.

[source]
----
docker run --publish 8081:8081 <image>
----

== Upload the image to the registery

No docker daemon required to be installed on your machine for this.

The first step is to configure the registery details in .m2/settings.xml.

[source]
----
<servers>
<server>
<id>«registery»</id>
<username>«username»</username>
<password>«password»</password>
</server>
</servers>
----
Keep the password encrypted (`mvn -ep`). Refer the documentation for the password encryption
https://maven.apache.org/guides/mini/guide-encryption.html

Run the below command to create and push the image to the image repository.
[source]
----
mvn compile -P release,container

----


2 changes: 2 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
<!-- Spring boot and spring cloud version has to match -->
<spring.cloud.dependencies.version>2020.0.0</spring.cloud.dependencies.version>
<jackson.version>2.11.2</jackson.version> <!-- Overriding Jackson for fixing vulnerabilities -->
<jib.version>2.8.0</jib.version>
<jib.container.image>adoptopenjdk/openjdk11:jre-11.0.4_11-alpine</jib.container.image>
<guava.version>30.0-jre</guava.version>
<junit.version>5.7.0</junit.version>
<cxf.version>3.4.1</cxf.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,4 @@
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>${groupId}</groupId>
<artifactId>${rootArtifactId}</artifactId>
<version>${app.version}</version>
<version>${app.version}</version>
</parent>
<artifactId>${rootArtifactId}-api</artifactId>
<packaging>jar</packaging>
Expand Down Expand Up @@ -42,4 +42,15 @@
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>com.google.cloud.tools</groupId>
<artifactId>jib-maven-plugin</artifactId>
<configuration>
<skip>true</skip>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is what I wrote in my review comment. It is not so good to add it to then parent pom and then having the need to disable (skip) it in all other modules. Please therefore move the plugin only to the server module that provides the deliverable of the entire app by design.

Copy link
Member Author

@sujith-mn sujith-mn Feb 3, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JIB plugin configured in server/pom.xml

  • Devon mvn clean package – builds the image successfully.
  • docker run --publish 8081:8081 not running, no error message also.

Copy link
Member Author

@sujith-mn sujith-mn Feb 3, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternatively tried different way to build:

  • mvn compile jib:build – build is failing, jib plugin is not found. the plugin is configured in the server-pom.

</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>${groupId}</groupId>
<artifactId>${rootArtifactId}</artifactId>
<version>${app.version}</version>
<version>${app.version}</version>
</parent>
<artifactId>${rootArtifactId}-core</artifactId>
<packaging>jar</packaging>
Expand Down Expand Up @@ -66,7 +66,7 @@

<!-- auto-configure datasource
https://stackoverflow.com/questions/34964066/spring-boot-doesnt-use-datasource-properties
-->
-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
Expand Down Expand Up @@ -132,7 +132,7 @@
#elseif ($dbType == 'postgresql')
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<!--<version>9.4.1211.jre7</version>-->
<!--<version>9.4.1211.jre7</version> -->
#elseif ($dbType == 'mysql')
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
Expand Down Expand Up @@ -165,7 +165,7 @@
<artifactId>h2</artifactId>
<scope>test</scope>
</dependency>
#end
#end

<!-- Flyway for DB Schema version management and migration -->
<dependency>
Expand Down Expand Up @@ -230,7 +230,7 @@
<profile>
<id>embedded</id>
<activation>
<activeByDefault>true</activeByDefault>
<activeByDefault>true</activeByDefault>
</activation>
<dependencies>
<dependency>
Expand Down
55 changes: 51 additions & 4 deletions templates/server/src/main/resources/archetype-resources/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,21 @@
<guava.version>$[guava.version]</guava.version>
<devonfw.test.excluded.groups>system</devonfw.test.excluded.groups>
<app.version>${revision}${changelist}</app.version>
<jib.version>$[jib.version]</jib.version>
<jib.container.image>$[jib.container.image]</jib.container.image>
<jib.app.port>8081</jib.app.port>
<jib.goal>buildTar</jib.goal>
</properties>

<modules>
<module>api</module>
<module>core</module>
#if ($earProjectName != '.')
#if ($earProjectName != '.')
<module>${earProjectName}</module>
#end
#if ($batch == 'batch')
#end
#if ($batch == 'batch')
<module>batch</module>
#end
#end
<module>server</module>
</modules>

Expand Down Expand Up @@ -328,6 +332,49 @@
</build>

<profiles>
<profile>
<id>release</id>
<properties>
<jib.goal>build</jib.goal>
</properties>
</profile>
<profile>
<id>container</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<build>
<plugins>
<plugin>
<groupId>com.google.cloud.tools</groupId>
<artifactId>jib-maven-plugin</artifactId>
<version>${jib.version}</version>
<configuration>
<from>
<image>${jib.container.image}</image>
</from>
<to>
<image>${project.name}/java:${project.version}</image>
</to>
<container>
<mainClass>${package}.SpringBootApp</mainClass>
<ports>
<port>${jib.app.port}</port>
</ports>
</container>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>${jib.goal}</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>moduletest</id>
<properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>${groupId}</groupId>
<artifactId>${rootArtifactId}</artifactId>
<version>${app.version}</version>
<version>${app.version}</version>
</parent>
<artifactId>${rootArtifactId}-server</artifactId>
<packaging>war</packaging>
Expand Down Expand Up @@ -145,8 +145,13 @@
</execution>
</executions>
</plugin>

<plugin>
<groupId>com.google.cloud.tools</groupId>
<artifactId>jib-maven-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
</build>

</project>