Skip to content

Commit 4817b64

Browse files
rohanKanojiarhuss
andauthored
Support for JIB(Java Image Builder) mode in dmp (#1277)
* Support for JIB(Java Image Builder) mode in dmp This ports Jib support added in https://github.com/eclipse/jkube * Update src/main/asciidoc/inc/_global-configuration.adoc Co-authored-by: Roland Huß <[email protected]> Co-authored-by: Roland Huß <[email protected]>
1 parent 1da5d29 commit 4817b64

File tree

19 files changed

+1412
-14
lines changed

19 files changed

+1412
-14
lines changed

doc/changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
- Add `skipPush` option to build image configuration ([#1243](https://github.com/fabric8io/docker-maven-plugin/issues/1243))
1010
- docker.container.<alias>.ip property is no longer set ([#1242](https://github.com/fabric8io/docker-maven-plugin/issues/1242))
1111
- Support `squash` in build options to squash newly built layers into a single layer ([#785](https://github.com/fabric8io/docker-maven-plugin/issues/785))
12+
- Support for JIB mode([#1277](https://github.com/fabric8io/docker-maven-plugin/pull/1277))
1213

1314
* **0.33.0** (2020-01-21)
1415
- Update to jnr-unixsocket 0.25 to solve concurrency issues ([#552](https://github.com/fabric8io/docker-maven-plugin/issues/552))

pom.xml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
<maven.version>3.3.9</maven.version>
3838
<jmockit.version>1.43</jmockit.version>
3939
<surefire.version>3.0.0-M2</surefire.version>
40+
<jib-core.version>0.12.0</jib-core.version>
4041
</properties>
4142

4243
<dependencies>
@@ -157,6 +158,12 @@
157158
</exclusions>
158159
</dependency>
159160

161+
<dependency>
162+
<groupId>com.google.cloud.tools</groupId>
163+
<artifactId>jib-core</artifactId>
164+
<version>${jib-core.version}</version>
165+
</dependency>
166+
160167
<dependency>
161168
<groupId>org.yaml</groupId>
162169
<artifactId>snakeyaml</artifactId>
@@ -166,7 +173,7 @@
166173
<dependency>
167174
<groupId>com.google.guava</groupId>
168175
<artifactId>guava</artifactId>
169-
<version>29.0-android</version>
176+
<version>27.0.1-jre</version>
170177
</dependency>
171178

172179
<dependency>

samples/spring-boot-with-jib/README.md

Lines changed: 274 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
4+
5+
<modelVersion>4.0.0</modelVersion>
6+
<parent>
7+
<groupId>io.fabric8.dmp.samples</groupId>
8+
<artifactId>dmp-sample-parent</artifactId>
9+
<version>0.33-SNAPSHOT</version>
10+
<relativePath>../pom.xml</relativePath>
11+
</parent>
12+
13+
<artifactId>dmp-sample-spring-boot-jib</artifactId>
14+
<version>0.33-SNAPSHOT</version>
15+
<packaging>jar</packaging>
16+
17+
<name>Docker Maven Plugin :: Spring Boot JIB</name>
18+
<description>Docker Maven Plugin Example with Spring Boot With Build Mode JIB</description>
19+
20+
<distributionManagement>
21+
<snapshotRepository>
22+
<id>sonatype-nexus-snapshots</id>
23+
<name>Sonatype Nexus Snapshots</name>
24+
<url>https://oss.sonatype.org/content/repositories/snapshots/</url>
25+
</snapshotRepository>
26+
<repository>
27+
<id>sonatype-nexus-staging</id>
28+
<name>Nexus Release Repository</name>
29+
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
30+
</repository>
31+
</distributionManagement>
32+
<properties>
33+
<maven.compiler.source>1.8</maven.compiler.source>
34+
<maven.compiler.target>1.8</maven.compiler.target>
35+
<docker.build.jib>true</docker.build.jib>
36+
<docker.user>fabric8</docker.user>
37+
<spring.version>2.3.3.RELEASE</spring.version>
38+
</properties>
39+
40+
<dependencies>
41+
42+
<!-- Boot generator -->
43+
<dependency>
44+
<groupId>org.springframework.boot</groupId>
45+
<artifactId>spring-boot-starter-web</artifactId>
46+
<version>${spring.version}</version>
47+
</dependency>
48+
49+
<dependency>
50+
<groupId>org.springframework.boot</groupId>
51+
<artifactId>spring-boot-starter-actuator</artifactId>
52+
<version>${spring.version}</version>
53+
</dependency>
54+
55+
<!-- API, java.xml.bind module -->
56+
<dependency>
57+
<groupId>jakarta.xml.bind</groupId>
58+
<artifactId>jakarta.xml.bind-api</artifactId>
59+
<version>2.3.2</version>
60+
</dependency>
61+
62+
<!-- Runtime, com.sun.xml.bind module -->
63+
<dependency>
64+
<groupId>org.glassfish.jaxb</groupId>
65+
<artifactId>jaxb-runtime</artifactId>
66+
<version>2.3.2</version>
67+
</dependency>
68+
69+
</dependencies>
70+
71+
<build>
72+
<plugins>
73+
<plugin>
74+
<groupId>org.springframework.boot</groupId>
75+
<artifactId>spring-boot-maven-plugin</artifactId>
76+
<version>${spring.version}</version>
77+
<executions>
78+
<execution>
79+
<goals>
80+
<goal>repackage</goal>
81+
</goals>
82+
</execution>
83+
</executions>
84+
</plugin>
85+
<plugin>
86+
<groupId>io.fabric8</groupId>
87+
<artifactId>docker-maven-plugin</artifactId>
88+
<version>0.33-SNAPSHOT</version>
89+
<configuration>
90+
<images>
91+
<image>
92+
<name>${docker.user}/spring-boot-dmp-sample-jib</name>
93+
<build>
94+
<from>fabric8/java-centos-openjdk8-jdk:1.5.6</from>
95+
<assembly>
96+
<descriptorRef>artifact</descriptorRef>
97+
</assembly>
98+
<cmd>java -jar /maven/${project.artifactId}-${project.version}.jar</cmd>
99+
<ports>
100+
<port>8080</port>
101+
</ports>
102+
</build>
103+
</image>
104+
</images>
105+
</configuration>
106+
</plugin>
107+
</plugins>
108+
</build>
109+
110+
<profiles>
111+
<profile>
112+
<id>Jib-With-Assembly</id>
113+
<build>
114+
<plugins>
115+
<plugin>
116+
<groupId>io.fabric8</groupId>
117+
<artifactId>docker-maven-plugin</artifactId>
118+
<version>0.33-SNAPSHOT</version>
119+
<configuration>
120+
<images>
121+
<image>
122+
<name>${docker.user}/spring-boot-dmp-sample-jib</name>
123+
<build>
124+
<from>fabric8/java-centos-openjdk8-jdk:1.5.6</from>
125+
<assembly>
126+
<name>my-project-assembly</name>
127+
<inline>
128+
<id>copy-test-file</id>
129+
<files>
130+
<file>
131+
<source>
132+
${project.basedir}/static/testFile.txt
133+
</source>
134+
<outputDirectory>static</outputDirectory>
135+
</file>
136+
<file>
137+
<source>${project.basedir}/target/${project.artifactId}-${project.version}.jar</source>
138+
<outputDirectory>.</outputDirectory>
139+
</file>
140+
</files>
141+
</inline>
142+
<targetDir>/deployments</targetDir>
143+
</assembly>
144+
<cmd>java -jar /my-project-assembly/${project.artifactId}-${project.version}.jar</cmd>
145+
<ports>
146+
<port>8080</port>
147+
</ports>
148+
</build>
149+
</image>
150+
</images>
151+
</configuration>
152+
</plugin>
153+
154+
</plugins>
155+
</build>
156+
</profile>
157+
</profiles>
158+
159+
</project>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package io.fabric8.maven.sample.springboot.jib;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
6+
@SpringBootApplication
7+
public class Application {
8+
9+
public static void main(String[] args) {
10+
SpringApplication.run(Application.class, args);
11+
}
12+
13+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package io.fabric8.maven.sample.springboot.jib;
2+
3+
import org.springframework.web.bind.annotation.RequestMapping;
4+
import org.springframework.web.bind.annotation.RestController;
5+
6+
7+
@RestController
8+
public class HelloController {
9+
10+
@RequestMapping("/")
11+
public String index() {
12+
return "<h1>Greetings from Spring Boot(Powered by JIB)!!</h1>";
13+
}
14+
15+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
I should be present

src/main/asciidoc/inc/_global-configuration.adoc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,10 @@ By default a progress meter is printed out on the console, which is omitted when
105105
| Number of parallel connections are allowed to be opened to the Docker Host. For parsing log output, a connection needs to be kept open (as well for the wait features), so don't put that number to low. Default is 100 which should be suitable for most of the cases.
106106
| `docker.maxConnections`
107107

108+
| *jib*
109+
| Delegate Image Build process to https://github.com/GoogleContainerTools/jib[JIB], `false` by default. Note that this option is applicable only for <<docker:build,build>> and <<docker:push,push>> goals, other goals won't work if this is enabled (since they dependend on Docker specific features)
110+
| `docker.build.jib`
111+
108112
| *outputDirectory*
109113
| Default output directory to be used by this plugin. The default value is `target/docker` and is only used for the goal `{plugin}:build`.
110114
| `docker.target.dir`

src/main/java/io/fabric8/maven/docker/AbstractBuildSupportMojo.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,6 @@ abstract public class AbstractBuildSupportMojo extends AbstractDockerMojo {
3939
@Parameter(property = "docker.pull.registry")
4040
private String pullRegistry;
4141

42-
@Parameter(property = "docker.source.dir", defaultValue="src/main/docker")
43-
private String sourceDirectory;
44-
45-
@Parameter(property = "docker.target.dir", defaultValue="target/docker")
46-
private String outputDirectory;
47-
4842
@Parameter( defaultValue = "${reactorProjects}", required = true, readonly = true )
4943
private List<MavenProject> reactorProjects;
5044

src/main/java/io/fabric8/maven/docker/AbstractDockerMojo.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import io.fabric8.maven.docker.util.GavLabel;
3131
import io.fabric8.maven.docker.util.ImageNameFormatter;
3232
import io.fabric8.maven.docker.util.Logger;
33+
import io.fabric8.maven.docker.util.MojoParameters;
3334
import org.apache.maven.execution.MavenSession;
3435
import org.apache.maven.plugin.AbstractMojo;
3536
import org.apache.maven.plugin.MojoExecution;
@@ -167,6 +168,15 @@ public abstract class AbstractDockerMojo extends AbstractMojo implements Context
167168
@Parameter(property = "docker.maxConnections", defaultValue = "100")
168169
private int maxConnections;
169170

171+
@Parameter(property = "docker.build.jib", defaultValue = "false")
172+
public boolean jib;
173+
174+
@Parameter(property = "docker.source.dir", defaultValue="src/main/docker")
175+
public String sourceDirectory;
176+
177+
@Parameter(property = "docker.target.dir", defaultValue="target/docker")
178+
public String outputDirectory;
179+
170180
// Authentication information
171181
@Parameter
172182
private RegistryAuthConfiguration authConfig;
@@ -370,7 +380,7 @@ public List<ImageConfiguration> customizeConfig(List<ImageConfiguration> imageCo
370380
* @return <code >true</code> as the default value
371381
*/
372382
protected boolean isDockerAccessRequired() {
373-
return true;
383+
return Boolean.FALSE.equals(jib);
374384
}
375385

376386
/**

0 commit comments

Comments
 (0)