Skip to content

Commit e07b988

Browse files
committed
Use layered Spring Boot container building
Resolves #4.
1 parent 97296ec commit e07b988

File tree

3 files changed

+37
-7
lines changed

3 files changed

+37
-7
lines changed

.dockerignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
.git/
22
target/
3+
Dockerfile

Dockerfile

+30-5
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
#
99
# Build the .jar file in a build container.
1010
#
11-
FROM maven:3.5.3-jdk-11 AS build-jar
11+
FROM maven:3.5.3-jdk-11 AS builder
1212
MAINTAINER Ian Young <[email protected]>
1313

14-
WORKDIR /user
14+
WORKDIR /application
1515
COPY pom.xml ./
1616
COPY swagger swagger
1717
COPY src src
@@ -20,14 +20,39 @@ RUN mvn --batch-mode \
2020
-Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn \
2121
package
2222

23+
#
24+
# Extract the layers.
25+
#
26+
RUN java -Djarmode=layertools \
27+
-jar target/md-validator-0.1.0-SNAPSHOT.jar \
28+
extract
29+
2330
#
2431
# Build the deployable image.
2532
#
2633
FROM amazoncorretto:11
2734
MAINTAINER Ian Young <[email protected]>
2835

29-
WORKDIR /user
30-
COPY --from=build-jar /user/target/md-validator-0.1.0-SNAPSHOT.jar .
36+
#
37+
# Copy the layers extracted from the JAR.
38+
#
39+
WORKDIR /application
40+
COPY --from=builder application/dependencies/ ./
41+
COPY --from=builder application/spring-boot-loader/ ./
42+
COPY --from=builder application/snapshot-dependencies/ ./
43+
COPY --from=builder application/application/ ./
44+
45+
#
46+
# At this point, we have:
47+
#
48+
# /application/org... containing the Spring Boot loader
49+
# /application/META-INF containing the application metadata
50+
# /application/BOOT-INF containing the application and its dependencies
51+
# /application/BOOT-INF/classes contain the application classes and resources
52+
#
53+
# To customise, add layers modifying /application/BOOT-INF/classes...
54+
#
3155

3256
EXPOSE 8080
33-
CMD ["java", "-jar", "md-validator-0.1.0-SNAPSHOT.jar"]
57+
58+
ENTRYPOINT ["java", "org.springframework.boot.loader.JarLauncher"]

pom.xml

+6-2
Original file line numberDiff line numberDiff line change
@@ -266,13 +266,17 @@
266266
</plugin>
267267

268268
<!--
269-
Ask Spring Boot to enhance the resulting .jar so that it is
270-
directly executable.
269+
Build a directly executable, layered JAR.
271270
-->
272271
<plugin>
273272
<groupId>org.springframework.boot</groupId>
274273
<artifactId>spring-boot-maven-plugin</artifactId>
275274
<version>${spring.boot.version}</version>
275+
<configuration>
276+
<layers>
277+
<enabled>true</enabled>
278+
</layers>
279+
</configuration>
276280
<executions>
277281
<execution>
278282
<goals>

0 commit comments

Comments
 (0)