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

How to push the image at the end during the deploy stage in a moduler build #745

Open franklini opened 7 years ago

franklini commented 7 years ago

Moduler project with deploy phase fails to deploy the image at the end

Info

The problem I encounter is that my image gets pushed right after it gets created. my other jars gets pushed at the end correctly when all my modules and tests have passed correctly (added a maven-deploy-plugin with configuration.deployAtEnd set to true to enable this).

The image getting pushed this early is problematic as if a problem occurs during the build then you have a faulty image already in you repository

Is their anyway you can make the plugin push the image in the deploy lifecycle in a modular build?

Thanks you in advance


* Docker version : 1.12.6
Gengar003 commented 7 years ago

It sounds like you're running mvn deploy and getting this result?

Maven will sort all the modules in your reactor, and run your desired command (deploy in this case) against each module in order. If push configuration for your image is in context in the module where the image is built (and it would be, if it was in your root pom and your root pom is the parent pom of each submodule), then Maven will figure out that it needs to build the submodule that builds your image, and run mvn deploy on it - which will push the image since you've bound the d-m-p's push to the deploy phase.

You want the execution of d-m-p that configures the push goal happen after everything else, right? Without seeing your project structure and the dependency relationships between your modules and the root pom, it is hard to give specific advice, but it sounds like your best bet would be to add a new submodule to your reactor that depends on the "last" submodule that gets built normally. Keep the configuration of the execution of the d-m-p that configures push in your root pom (a <pluginManagement> block would be the best place), but bind it to the deploy phase only in this new submodule.

Then, when you run mvn deploy,

  1. the module that builds your JAR will build your JAR, but not push a Docker image because there is no d-m-p execution configured for any lifecycle phase.
  2. the module that builds your image will build your image, but not push a it because there is no d-m-p execution configured for any lifecycle phase.
  3. the module that does your integration tests will do your integration tests, but not push a Docker image because there is no d-m-p execution configured for any lifecycle phase.
  4. Finally, the module that does bind d-m-p's push to the deploy phase will have mvn deploy run on it, and it will push a Docker image.
franklini commented 7 years ago

Hi Gengar003,

May I start first by thanking you for your excellent tips. tried it this morning and it actually worked although I had to recreate the image (for some reason I couldn't push the image I created at the service-docker module). The only side effect was that i then couldn't push the jars created by the other modules. Any tip on how to overcome this?

Thanks in advance