fabric8io / docker-maven-plugin

Maven plugin for running and creating Docker images
https://dmp.fabric8.io
Apache License 2.0
1.88k stars 643 forks source link

docker:stop with executeStopOnVMShutdown fails but should be skipped #1543

Open gwenaskell opened 2 years ago

gwenaskell commented 2 years ago

Description

I use the following plugin configuration in my pom.xml:

<plugin>
  <groupId>io.fabric8</groupId>
  <artifactId>docker-maven-plugin</artifactId>
  <version>0.39.1</version>
  <executions>
    <execution>
      <id>run-docker-db</id>
      <configuration>
        <skip>${dockerdb.skip}</skip>
        <executeStopOnVMShutdown>true</executeStopOnVMShutdown>
        <images>
          <image>
            <name>${dockerdb.image}:${dockerdb.tag}</name>
            <alias>database</alias>
            <run>
              <namingStrategy>alias</namingStrategy>
              <env>
                <POSTGRES_USER>usr</POSTGRES_USER>
                <POSTGRES_PASSWORD>pwd</POSTGRES_PASSWORD>
                <POSTGRES_DB>db</POSTGRES_DB>
              </env>
              <ports>
                <port>5432:5432</port>
              </ports>
              <wait>
                <time>30000</time>
                <log>(?s)ready to accept connections</log>
              </wait>
            </run>
          </image>
        </images>
      </configuration>
      <phase>initialize</phase>
      <goals>
        <goal>start</goal>
        <goal>stop</goal>
      </goals>
    </execution>
  </executions>
</plugin>

I try to use executeStopOnVMShutdown option so that the docker stop is deferred to the end of the lifecycle even in case of failure.

However in some situations we want to skip the execution of the plugin because the container start/stop is handled separately. I will thus execute maven with:

$ mvn verify -Ddockerdb.skip=true

Unfortunately, with the option executeStopOnVMShutdown, I get this error:

[ERROR] Failed to execute goal io.fabric8:docker-maven-plugin:0.39.1:stop (run-docker-db) on project engine: docker:stop with executeStopOnVMShutdown is only possible if the docker containers started within the same maven session. -> [Help 1]

What I expected

Since skip option is set to true, the docker:stop goal should return without raising the error.

How to reproduce

gwenaskell commented 2 years ago

Note: as a workaround, I will use profiles to set executeStopOnVMShutdown to false when skip is set to true.

rhuss commented 2 years ago

Thanks for the report! Sounds like a valid bug that should be easy to fix (i.e. just don't throw that error if skip is enabled). Happy to review a PR if someone is included to fix it.