Skip to content

Commit 3817eb8

Browse files
committed
BAEL-6007: add example with jib
1 parent 8e6569f commit 3817eb8

File tree

5 files changed

+62
-45
lines changed

5 files changed

+62
-45
lines changed
Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,26 @@
1-
FROM maven:3.8.5-openjdk-17 AS MAVEN_TOOL_CHAIN
1+
FROM maven:3.8.5-openjdk-17 AS DEPENDENCEIS
22

3-
COPY pom.xml /tmp/
4-
COPY api /tmp/api/
5-
COPY domain /tmp/domain/
3+
WORKDIR /opt/app
4+
COPY api/pom.xml api/pom.xml
5+
COPY domain/pom.xml domain/pom.xml
6+
COPY pom.xml .
67

7-
WORKDIR /tmp/
8-
RUN mvn clean install -X
8+
RUN mvn -B -e org.apache.maven.plugins:maven-dependency-plugin:3.1.2:go-offline -DexcludeArtifactIds=domain
99

10-
FROM openjdk:17
10+
FROM maven:3.8.5-openjdk-17 AS BUILDER
1111

12-
COPY --from=MAVEN_TOOL_CHAIN /tmp/api/target/docker-multi-module-maven-api-0.0.1-SNAPSHOT.jar /app.jar
12+
WORKDIR /opt/app
13+
COPY --from=DEPENDENCEIS /root/.m2 /root/.m2
14+
COPY --from=DEPENDENCEIS /opt/app/ /opt/app
15+
COPY api/src /opt/app/api/src
16+
COPY domain/src /opt/app/domain/src
17+
18+
RUN mvn -B -e clean install -DskipTests
19+
20+
FROM openjdk:17-slim
21+
22+
WORKDIR /opt/app
23+
COPY --from=BUILDER /opt/app/api/target/*.jar /app.jar
24+
EXPOSE 8080
1325

1426
ENTRYPOINT ["java", "-jar", "/app.jar"]

docker-modules/docker-multi-module-maven/api/pom.xml

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
44
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
55
<modelVersion>4.0.0</modelVersion>
6-
<artifactId>docker-multi-module-maven-api</artifactId>
6+
<artifactId>api</artifactId>
77

88
<parent>
9-
<groupId>com.baeldung</groupId>
10-
<artifactId>docker-multi-module-maven-parent</artifactId>
9+
<groupId>com.baeldung.docker-multi-module-maven</groupId>
10+
<artifactId>parent</artifactId>
1111
<version>0.0.1-SNAPSHOT</version>
1212
</parent>
1313

@@ -17,8 +17,8 @@
1717
<artifactId>spring-boot-starter-web</artifactId>
1818
</dependency>
1919
<dependency>
20-
<groupId>com.baeldung</groupId>
21-
<artifactId>docker-multi-module-maven-domain</artifactId>
20+
<groupId>com.baeldung.docker-multi-module-maven</groupId>
21+
<artifactId>domain</artifactId>
2222
<version>0.0.1-SNAPSHOT</version>
2323
</dependency>
2424

@@ -28,4 +28,32 @@
2828
<scope>test</scope>
2929
</dependency>
3030
</dependencies>
31+
32+
<build>
33+
<plugins>
34+
<plugin>
35+
<groupId>org.springframework.boot</groupId>
36+
<artifactId>spring-boot-maven-plugin</artifactId>
37+
</plugin>
38+
<plugin>
39+
<groupId>com.google.cloud.tools</groupId>
40+
<artifactId>jib-maven-plugin</artifactId>
41+
<version>3.4.0</version>
42+
<configuration>
43+
<from>
44+
<image>openjdk:17-slim</image>
45+
</from>
46+
<to>
47+
<image>baeldung-demo:v2.2</image>
48+
</to>
49+
<container>
50+
<mainClass>com.baeldung.api.Application</mainClass>
51+
<ports>
52+
<port>8080</port>
53+
</ports>
54+
</container>
55+
</configuration>
56+
</plugin>
57+
</plugins>
58+
</build>
3159
</project>

docker-modules/docker-multi-module-maven/api/src/main/java/com/baeldung/api/controller/CountriesController.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@ public CountriesController(CountryRepository countries) {
2020

2121
@GetMapping("api/countries")
2222
public List<CountryDto> index() {
23+
2324
Iterable<Country> all = countries.findAll();
2425
return stream(all.spliterator(), false)
25-
.map(it -> new CountryDto(it.getId(), it.getName(), it.getIso(), null))
26+
.map(it -> new CountryDto(it.getId(), it.getName(), it.getIso(), it.getEmoji()))
2627
.collect(toList());
2728
}
2829

docker-modules/docker-multi-module-maven/domain/pom.xml

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
44
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
55
<modelVersion>4.0.0</modelVersion>
6-
<artifactId>docker-multi-module-maven-domain</artifactId>
6+
<artifactId>domain</artifactId>
77
<packaging>jar</packaging>
88

99
<parent>
10-
<groupId>com.baeldung</groupId>
11-
<artifactId>docker-multi-module-maven-parent</artifactId>
10+
<groupId>com.baeldung.docker-multi-module-maven</groupId>
11+
<artifactId>parent</artifactId>
1212
<version>0.0.1-SNAPSHOT</version>
1313
</parent>
1414

@@ -28,21 +28,4 @@
2828
<scope>test</scope>
2929
</dependency>
3030
</dependencies>
31-
32-
<build>
33-
<plugins>
34-
<!-- Override Spring Boot plugin in this module to prevent it from running -->
35-
<plugin>
36-
<groupId>org.springframework.boot</groupId>
37-
<artifactId>spring-boot-maven-plugin</artifactId>
38-
<executions>
39-
<execution>
40-
<id>repackage</id>
41-
<phase>none</phase>
42-
</execution>
43-
</executions>
44-
</plugin>
45-
</plugins>
46-
</build>
47-
4831
</project>

docker-modules/docker-multi-module-maven/pom.xml

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,21 @@
33
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
44
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
55
<modelVersion>4.0.0</modelVersion>
6-
<groupId>com.baeldung</groupId>
7-
<artifactId>docker-multi-module-maven-parent</artifactId>
6+
7+
<groupId>com.baeldung.docker-multi-module-maven</groupId>
8+
<artifactId>parent</artifactId>
89
<packaging>pom</packaging>
910
<version>0.0.1-SNAPSHOT</version>
1011

1112
<parent>
1213
<groupId>org.springframework.boot</groupId>
1314
<artifactId>spring-boot-starter-parent</artifactId>
1415
<version>3.3.2</version>
16+
<relativePath/>
1517
</parent>
1618

1719
<modules>
1820
<module>api</module>
1921
<module>domain</module>
2022
</modules>
21-
22-
<build>
23-
<plugins>
24-
<plugin>
25-
<groupId>org.springframework.boot</groupId>
26-
<artifactId>spring-boot-maven-plugin</artifactId>
27-
</plugin>
28-
</plugins>
29-
</build>
3023
</project>

0 commit comments

Comments
 (0)