如何通过Spotify插件在多模块maven项目中构builddocker镜像?
我有一个由2个模块组成的maven项目,结构如下
pom.xml | x----module-1 | | | x----pom.xml | x----module-2 | x----pom.xml
我想build立这两个模块作为docker图像,并推送到dockerregistry。
这就是我在孩子的生活中所拥有的
第一单元
<build> <finalName>module-1</finalName> <plugins> <plugin> <groupId>com.spotify</groupId> <artifactId>docker-maven-plugin</artifactId> <version>1.0.0</version> <configuration> <imageName>${project.artifactId}</imageName> <baseImage>openjdk:8-jre-alpine</baseImage> <entryPoint>["java", "-jar", "/opt/${project.build.finalName}.war"]</entryPoint> <serverId>docker-hub</serverId> <registryUrl>http://10.100.25.216:5000/v2/</registryUrl> <resources> <resource> <targetPath>/opt</targetPath> <directory>${project.build.directory}</directory> <include>${project.build.finalName}.war</include> </resource> </resources> </configuration> </plugin> </plugins> </build>
第二单元
<build> <finalName>module-2</finalName> <plugins> <plugin> <groupId>com.spotify</groupId> <artifactId>docker-maven-plugin</artifactId> <version>1.0.0</version> <configuration> <imageName>${project.artifactId}</imageName> <baseImage>openjdk:8-jre-alpine</baseImage> <entryPoint>["java", "-jar", "/opt/${project.build.finalName}.war"]</entryPoint> <serverId>docker-hub</serverId> <registryUrl>http://10.100.25.216:5000/v2/</registryUrl> <resources> <resource> <targetPath>/opt</targetPath> <directory>${project.build.directory}</directory> <include>${project.build.finalName}.war</include> </resource> </resources> </configuration> </plugin> </plugins> </build>
但是,当我用下面的命令build立项目
mvn clean package docker:build -DpushImage
我得到以下错误
ERROR] Failed to execute goal com.spotify:docker-maven-plugin:1.0.0:build (default) on project spotify: Exception caught: Must specify baseImage if dockerDirectory is null -> [Help 1] [ERROR] [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. [ERROR] Re-run Maven using the -X switch to enable full debug logging. [ERROR] [ERROR] For more information about the errors and possible solutions, please read the following articles: [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
据我所知,我需要configuration父POM运行子模块的构build,但没有一个线索如何做到这一点。
PS我发现涉及到Dockerfile-s的解决scheme,但是如果可能的话我更喜欢maven版本,只使用插件。 有什么办法吗?
提前致谢