3

I'm struggling to synthesise how to correctly use the maven-failsafe and fabric8-maven plugins together.

I Want to run integration tests, but in the pre-integration-tests phase, start a docker container running a DB, and in the post-integration-phase stop the container.

Looking at the fabric8 docker-maven-plugin documentation, it states this is possible, but none of the examples seem to illustrate this.

Update #1:

This is the configuration that successfully worked for me:

<plugin>
    <groupId>io.fabric8</groupId>
    <artifactId>docker-maven-plugin</artifactId>
    <version>0.15.9</version>
    <executions>
        <execution>
            <id>start-neo4j</id>
            <phase>pre-integration-test</phase>
            <goals>
                <goal>start</goal>
            </goals>
        </execution>
        <execution>
            <id>stop-neo4j</id>
            <phase>post-integration-test</phase>
            <goals>
                <goal>stop</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <images>
            <image>
                <alias>neo4j</alias>
                <name>neo4j:2.3.2-enterprise</name>
                <run>
                    <ports>
                        <port>7474</port>
                    </ports>
                    <wait>
                        <log>Starting...</log>
                        <time>20000</time>
                    </wait>
                </run>
            </image>
        </images>
    </configuration>
</plugin>
neuronotic
  • 487
  • 7
  • 18
  • where in the pom is this located? and what goal do you execute? and what isn't working? the way you go seems correct, if you run the pre-integration-test phase the fabric8 plugin should do something. – wemu Jul 13 '16 at 17:41

2 Answers2

3

There are serveral examples for the docker-maven-plugin which show how the bindings work:

  • https://github.com/fabric8io/docker-maven-plugin/blob/master/samples/data-jolokia-demo/ contains various configurations variants for running integrations tests where in the pre-test phase a tomcat is fired up, the application deployed, the tests run, and then the tomcat teared down.

  • https://github.com/rhuss/docker-maven-sample is probably more interesting for you as it covers your use case with starting a Postgres db before the integration test (inclusive waiting until the DB is completely started). The binding is shown here :

    <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>
    

But I recommend to examine the pom.xml there in more details, since it has even more info e.g. for how to setup the wait section. Feel free to open issues in this project if something is still unclear.

Roland Huß
  • 2,507
  • 15
  • 30
0

The way we recommend integration and system testing in maven with docker is via the fabric8 arquillian plugin. That takes care of creating a new namespace for the test and provisioning all the kubernetes resources then running your JUnit test case to run the assertions etc.

You'll need a docker image for the database and to wrap that up in a kubernetes yaml/json file so that it can be run up front as your app is deployed by fabric8-arquillian

James Strachan
  • 9,168
  • 34
  • 31
  • I'm not that clued up on the dev-ops side of things, but I'm not sure what Kubernetes has to do with this situation? All I wanted to do was start a docker container before running integration tests. – neuronotic Jul 15 '16 at 10:43
  • ah - didn't grok you were just using docker on a single machine. Apologies; see Roland's reply for working with a single machine with pure docker and no orchestration – James Strachan Jul 17 '16 at 07:58