-
Notifications
You must be signed in to change notification settings - Fork 645
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support to stop docker containers during VM shutdown #1492
Conversation
SonarCloud Quality Gate failed. |
Codecov Report
@@ Coverage Diff @@
## master #1492 +/- ##
============================================
- Coverage 62.12% 62.02% -0.11%
Complexity 2174 2174
============================================
Files 166 166
Lines 9559 9575 +16
Branches 1442 1443 +1
============================================
Hits 5939 5939
- Misses 3108 3124 +16
Partials 512 512
|
I am not sure how to test VM shutdown hooks in unit tests. |
Thanks a lot for your PR, I'll test and review this within this week. I'm okay with merging this if this fixes the issue. |
* If true, the containers are not stopped right away, but when the build is finished (success or failed). | ||
*/ | ||
@Parameter(property = "docker.executeStopOnVMShutdown", defaultValue = "false") | ||
private boolean executeStopOnVMShutdown; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would appreciate if you could add documentation regarding this field in docker:stop
configuration[0]. Source for this doc section is located here[1]
[0] http://dmp.fabric8.io/#docker:stop
[1] https://github.com/fabric8io/docker-maven-plugin/blob/master/src/main/asciidoc/inc/_docker-stop.adoc
// possible to load classes in the shutdown hook as | ||
Class.forName("org.apache.http.client.methods.HttpDelete", true, this.getClass().getClassLoader()); | ||
} catch (ClassNotFoundException e) { | ||
e.printStackTrace(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sonar reports this as a security hotspot: https://sonarcloud.io/project/security_hotspots?id=fabric8io_docker-maven-plugin&pullRequest=1492&hotspots=AXv_23_LXkHjdTy7bc6z
Do you think we can avoid this by just logging some message instead of printing whole stacktrace?
private boolean executeStopOnVMShutdown; | ||
|
||
@Override | ||
public void execute() throws MojoExecutionException, MojoFailureException { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All goals in this plugin override executeInternal
method which contains goal related functionality. I'm not sure why you're overriding execute
method. Is this possible to move this stop on VM shutdown logic to executeInternal
method instead?
We do have some integration tests which run on CircleCI on a docker daemon located in |
I will have a look on the comments. About IT tests. This functionality can be checked if the JVM is actually shutting down. So I must check how these IT tests are written. If it is possible to do forking the Mojo execution somehow, there is a chance. But finding the time to go through all comments and this topic will take several weeks to me. |
@rohanKanojia Sorry, I had no time in the last weeks to take care of the comments. I am not sure when I can find the time. Do you still expect the PR to be upgraded? |
I'm planning to cut a release this weekend and was thinking of adding this to the release. If it's difficult to add tests, maybe we can merge this as it is and ask users for feedback. We can revert in case it's not working for them. |
Thanks you very much! |
SonarCloud Quality Gate failed. |
…g in StopMojo + Add `executeStopOnVMShutdown` flag documentation + Fix sonar security hotspot reports related to pull request Signed-off-by: Rohan Kumar <[email protected]>
…g in StopMojo + Add `executeStopOnVMShutdown` flag documentation + Fix sonar security hotspot reports related to pull request Signed-off-by: Rohan Kumar <[email protected]>
…Mojo + Add `executeStopOnVMShutdown` flag documentation + Fix sonar security hotspot reports related to pull request Signed-off-by: Rohan Kumar <[email protected]>
@rohanKanojia To test, have a docker-maven-plugin coupled with flyway with a faulty SQL migration script. |
The stop execution is never reached because the build will fail before |
@alahaouas Please use the property docker.executeStopOnVMShutdown and set it to true. This will call the stop goal of the plugin in a shutdown hook when the JVM stops gracefully. |
@balazs-zsoldos I mentioned that the issue is still not fixed, even with docker.executeStopOnVMShutdown set to true. |
@alahaouas Can you share a git repo (or at least a pom file) that has the project that does not work for you and some description how to reproduce? |
@balazs-zsoldos I can't share the git repo because it is private but plz find attached the edited pom.xml (I modified it to remove our internal dependencies). To reproduce, have a basic unit test + faulty or missing liquibase changeset for example. Any cause at the pre-test phase that will fail the build. |
I believe @alahaouas probably has it resolved by now, but for everyone else finding this via Google: You still need to execute the Basically, you can issue |
Fix #915
I tried several approaches and this hacky one worked. The problem is that the classloader of the Mojo is closed at the time of the shutdown hook.
What did not work:
This works as in case StartMojo was called before, only HttpDelete is not loaded by the classloader. In case no goal is called before this Mojo, more classes should be loaded programmatically, but I did not want to check how many, and by changing the dependencies, the list of classes could change.
Please check if this solution is OK for you!