Search code examples
javamavendockermaven-failsafe-pluginfabric8

Multiple usage of docker-maven-plugin (fabric8)


I want to use the docker-maven-plugin from io.fabric8 for multiple purposes:

  1. Starting a DB server with docker for the integration tests (failsafe).
  2. Building a Dockerfile of my product

Both are working separatly.

1:

<plugin>
  <groupId>io.fabric8</groupId>
  <artifactId>docker-maven-plugin</artifactId>
  <version>0.24.0</version>
  <executions>
    <execution>
     <id>start</id>
     <phase>pre-integration-test</phase>
     <goals>
       <goal>build</goal>
       <goal>start</goal>
     </goals>
   </execution>
   <execution>
     <id>stop</id>
     <phase>post-integration-test</phase>
     <goals>
       <goal>stop</goal>
     </goals>
   </execution>
 </executions>
 <configuration>
   <dockerHost>#HOST#</dockerHost>
     <images>
       <image>
         <name>sath89/oracle-xe-11g:latest</name>
         <run>
          <ports>
            <port>1521:1521</port>
          </ports>
          <wait>
            <log>Database ready to use. Enjoy!</log>
            <time>900000</time>
          </wait>
        </run>
      </image>
    </images>
  </configuration>
</plugin>

2:

<plugin>
  <groupId>io.fabric8</groupId>
  <artifactId>docker-maven-plugin</artifactId>
  <version>0.24.0</version>
  <configuration>
    <verbose>true</verbose>
    <dockerHost>#HOST#</dockerHost>
    <registry>#REGISTERY#</registry>
    <images>
      <image>
        <name>#NAME#</name>
        <build>
          <dockerFileDir>${project.basedir}</dockerFileDir>
        </build>
      </image>
    </images>
  </configuration>
  <executions>
    <execution>
      <id>build-image-and-push</id>
      <phase>install</phase>
      <goals>
        <goal>build</goal>
        <goal>push</goal>
      </goals>
    </execution>
  </executions>
</plugin>

When I merge this two configurations it is all messed up. Is there a way, to use an image only for the integration tests? How can I define that the image of my project shouldn't be build in the image of the database?


Solution

  • Moving the image configuration to <execution> helped!