I have a maven project that consists of 2 modules with the following structure:
pom.xml
|
x----module-1
| |
| x----pom.xml
|
x----module-2
|
x----pom.xml
I want to build both modules as docker images and push them to a docker registry.
Here's what I have in the child poms:
Module 1
<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>
Module 2
<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>
But when I build the project with the following command:
mvn clean package docker:build -DpushImage
I get the following error:
[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
As far as I know, I need to configure parent pom to run the submodule builds, but don't have a clue on how to do it.
P.S. I found solutions that were involving Dockerfile-s to the project, but I would prefer maven only version if possible, using the plugin only. Is there any way?