如果有人对此感到困惑:我有一个类似的用例,我想利用 jib(Dockerfile-less + 可以在没有 docker daemon 的情况下使用),但由于其他原因我目前无法拒绝使用 fat jar。
根据 Chanseok 的评论(在问题下),我想出了以下内容:
- 删除 jib 添加的任何图层
- 将 fatjar(默认在 中
target/${build.finalName}.jar
)添加到它自己的层中
- 覆盖入口点以执行“java -jar ...”而不是指向您的 Main 的常规入口点
- Jib 被显式调用并且不绑定到生命周期(至少在我的示例中),因此必须使用以下显式调用它
mvn package jib:dockerBuild
(或... jib:build
用于 docker-daemon-less 构建)
- 使用潜水,您会看到只添加了一层并且它相当大(== fat jar)
资料来源:https ://gitter.im/google/jib?at=5fad68c5d37a1a13d6a12174 + https://github.com/GoogleContainerTools/jib/tree/master/jib-maven-plugin#extradirectories-object
该示例至少适用于 spring boot 2.4.X
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>com.google.cloud.tools</groupId>
<artifactId>jib-maven-plugin</artifactId>
<version>3.0.0</version>
<dependencies>
<dependency>
<groupId>com.google.cloud.tools</groupId>
<artifactId>jib-layer-filter-extension-maven</artifactId>
<version>0.2.0</version>
</dependency>
</dependencies>
<configuration>
<container>
<entrypoint>java,-jar,/app/${project.build.finalName}.jar</entrypoint>
</container>
<extraDirectories>
<paths>
<path>
<from>target/</from>
<includes>*.jar</includes>
<into>/app</into>
</path>
</paths>
</extraDirectories>
<pluginExtensions>
<pluginExtension>
<implementation>com.google.cloud.tools.jib.maven.extension.layerfilter.JibLayerFilterExtension</implementation>
<configuration implementation="com.google.cloud.tools.jib.maven.extension.layerfilter.Configuration">
<filters>
<filter>
<!-- exclude all jib layers, which is basically anything in /app -->
<glob>/app/**</glob>
</filter>
<filter>
<!-- this is our fat jar, this should be kept by adding it into its own layer -->
<glob>/app/${project.build.finalName}.jar</glob>
<toLayer>jib-custom-fatJar</toLayer>
</filter>
</filters>
</configuration>
</pluginExtension>
</pluginExtensions>
</configuration>
</plugin>
</plugins>
</build>