的所有文件(连在一个Maven的部署“任务”)的-SNAPSHOT
部分将由时间戳版本在deploy:deploy
阶段所取代。
1)创建泊坞图像文件
扩展与docker-maven-plugin
工件POM(由Spotify的提供在https://github.com/spotify/docker-maven-plugin)。
[...]
您也可以构建目标结合到包装阶段,所以当你只运行MVN包装容器将建成。
[...]
<plugin>
<groupId>com.spotify</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>0.2.11</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>build</goal>
</goals>
<configuration>
<imageName>${project.build.finalName}</imageName>
<baseImage>java</baseImage>
<entryPoint>["java", "-jar", "/${project.build.finalName}.jar"]</entryPoint>
<!-- copy the service's jar file from target into the root directory of the image -->
<resources>
<resource>
<targetPath>/</targetPath>
<directory>${project.build.directory}</directory>
<include>${project.build.finalName}.jar</include>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
的泊坞图像名称将在<imageName />
被定义和使用的工件的文件名(${project.build.finalName}
)。
imageName:建立的图像将被赋予这个名字。有关build
目标
的更多信息:mvn com.spotify:docker-maven-plugin:help -Ddetail=true -Dgoal=build
或https://github.com/spotify/docker-maven-plugin
2)附加泊坞映像文件Maven的部署任务
连接 - 如果docker-maven-plugin
不为你做 - 泊坞窗图像文件与build-helper-maven-plugin
(http://www.mojohaus.org/build-helper-maven-plugin/usage.html)。
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.9.1</version>
<executions>
<execution>
<id>attach-artifacts</id>
<phase>package</phase>
<goals>
<goal>attach-artifact</goal>
</goals>
<configuration>
<artifacts>
<artifact>
<file>${project.build.finalName}</file>
<type>...</type>
<classifier>docker</classifier>
</artifact>
...
</artifacts>
</configuration>
</execution>
</executions>
</plugin>
完成这些步骤后,工件文件本身和Docker镜像工件被部署到具有相同版本字符串的Maven仓库中。
在ONE POM中可以将工件的部署和Docker镜像结合起来吗?工件和Docker镜像部署在相同的Maven任务中 - 两个-SNAPSHOT别名被替换为相同的时间戳版本字符串。如果它是您的工作解决方案,我会创建一个反映该问题的新答案。 – barthel
@barthel我做了一些关于在一个pom中发布神器和码头图像的研究,并且发现它很有趣。但他们(2 poms)顺序改变时间戳。您是否能够帮助我更好地了解如何在工件部署中添加docker build + deploy。我发现[这](https://github.com/spotify/docker-maven-plugin)是一个很好的参考,以防您需要,但我相信您会知道它已经:) –