h__
h__

Reputation: 793

Running docker-maven-plugin on the very end of parent pom building

I'm trying to build the docker image containing a group of .jar files built during building parent POM file. What I found till now was the case where the single build of particular module creates separate docker image.

My docker image contains Karaf with the deployed bundles. At some point I achieved the creating docker, but when everything was build. I'm afraid that docker-maven-plugin may not support the case where I want to create docker image from particular folders of bundles (each child project is deploying its bundles to particular folder).

For now I found that parent POM package types supports only three phases, but anyway - all of them are run just as first project during the build. So the question is:

Is it possible to create docker image

Below some part of parent POM which finally may not be related to my needs

<build>
  <plugins>
     <plugin>
       <groupId>com.spotify</groupId>
       <artifactId>docker-maven-plugin</artifactId>
       <inherited>false</inherited>
       <version>0.4.10</version>
       <configuration>
         <imageName>test1</imageName>
         <dockerDirectory>../karaf-deploy</dockerDirectory>
         <resources>
           <resource>
              <targetPath>../karaf-deploy/</targetPath>
              <directory>../karaf-deploy/</directory>
              <include>${project.build.finalName}.jar</include>
            </resource>
          </resources>
        </configuration>
     </plugin>
   </plugins>
</build>

Upvotes: 1

Views: 2318

Answers (1)

Anton Koscejev
Anton Koscejev

Reputation: 4847

Child-parent relationship is simply a special form of dependency, where child depends on parent. As such, parent is always built first, before any children. This also means you cannot build anything in parent that depends on children, because parent depending on a child would be basically a cyclic dependency.

So if you want to bundle just a single artifact, you can add docker plugin to the lifecycle of that single project. But if you want to bundle multiple artifacts, you should follow advice by @khmarbaise:

  1. Define a new separate distribution project (can even be pom packaging or use a special extension)
  2. Add distribution project as child module to existing parent
  3. Add normal Maven dependencies on any artifacts you want to bundle/wrap/include
  4. Define copy-dependencies step for prepare-package phase to copy dependencies to build directory
  5. Define docker-maven-plugin settings for package phase to bundle copied dependencies

Skip step 4 if your distribution plugin can pick dependencies from Maven directly. We're using io.fabric8 docker-maven-plugin where you can define assembly-style descriptor such as this:

<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3 http://maven.apache.org/xsd/assembly-1.1.3.xsd">
    <id>all-artifacts</id>
    <dependencySets>
        <dependencySet>
            <outputDirectory>/</outputDirectory>
            <useProjectArtifact>true</useProjectArtifact>
        </dependencySet>
    </dependencySets>
</assembly>

Upvotes: 2

Related Questions