最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

java - Run tests + startstop docker containers multiple times (maven-failsafe-plugin + docker-maven-plugin) - Stack Overflow

programmeradmin2浏览0评论

I have the following pom.xml.

It does the following:

  • Starts (lots of) docker containers, starts worker container with MY_ENV_VAR=123
  • Runs integration tests
  • Stops docker containers

I would like to update it so that it does the above 3 things two times, the first time as it is shown in the pom.xml, but the second time, I want the worker container to be run with a different value for its MY_ENV_VAR environment variable, i.e.:

1st execution:

  • Starts (lots of) docker containers, starts worker container with MY_ENV_VAR=123
  • Runs integration tests
  • Stops docker containers

2nd execution:

  • Starts (lots of) docker containers, starts worker container with MY_ENV_VAR=456
  • Runs integration tests
  • Stops docker containers

I want both executions to run one after the other via mvn clean install (I do not want to have to specify a profile).

Not shown in the below pom.xml are lots of other containers that are also run as part of the build.

I can run multiple maven-failsafe-plugin executions, but that just runs the tests again against the existing containers.

I had been trying using profiles, but have not found anything that works and that does not involve duplicating the 1000s of lines of images and their config.

<?xml version="1.0" encoding="UTF-8"?>

<project xmlns:xsi="; xmlns=".0.0"
         xsi:schemaLocation=".0.0 .0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <artifactId>my-repo</artifactId>
    <packaging>pom</packaging>

    <properties>
    </properties>

    <dependencies>
    </dependencies>

    <build>
        <plugins>

            <plugin>
                <groupId>.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <executions>
                    <execution>
                        <phase>test-compile</phase>
                        <goals>
                            <goal>testCompile</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>.apache.maven.plugins</groupId>
                <artifactId>maven-failsafe-plugin</artifactId>
                <version>3.1.2</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>integration-test</goal>
                            <goal>verify</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <systemPropertyVariables>
                        <docker.host.address>${docker.host.address}</docker.host.address>
                        <worker.port>${worker.port}</worker.port>
                    </systemPropertyVariables>
                    <environmentVariables>
                    </environmentVariables>
                </configuration>
            </plugin>

            <plugin>
                <groupId>io.fabric8</groupId>
                <artifactId>docker-maven-plugin</artifactId>
                <version>0.43.4</version>
                <executions>
                    <execution>
                        <id>build-docker-container</id>
                        <phase>compile</phase>
                        <goals>
                            <goal>build</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>start</id>
                        <phase>pre-integration-test</phase>
                        <goals>
                            <goal>start</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>stop</id>
                        <phase>post-integration-test</phase>
                        <goals>
                            <goal>stop</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <watchInterval>500</watchInterval>
                    <logDate>default</logDate>
                    <verbose>true</verbose>
                    <containerNamePattern>%a-%t</containerNamePattern>
                    <images>
                        <image>
                            <alias>worker</alias>
                            <name>${targetDockerRegistryPath}/worker:${project.version}</name>
                            <build>
                                <from>${projectDockerRegistry}/worker</from>
                                <cmd>
                                    <exec>
                                        <args>/maven/worker.sh</args>
                                    </exec>
                                </cmd>
                            </build>
                            <run>
                                <ports>
                                    <port>${worker.port}:8080</port>
                                </ports>
                                <env>
                                    <MY_ENV_VAR>123</MY_ENV_VAR>
                                </env>
                                <wait>
                                    <http>
                                        <url>http://${docker.host.address}:${worker.port}/health-check?type=READY</url>
                                    </http>
                                    <time>120000</time>
                                    <shutdown>500</shutdown>
                                </wait>
                            </run>
                        </image>

                        <!-- Lots more images here -->

                    </images>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论