-
Notifications
You must be signed in to change notification settings - Fork 644
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 possiblity to use docker.imagePropertyConfiguration with multipe images #1001
Add possiblity to use docker.imagePropertyConfiguration with multipe images #1001
Conversation
… images By default it will not work, but if explicit <external> is added to each image, it work. Also add support for docker.imagePropertyConfiguration=skip, for i.e. overriding parents config and disable it.
d51a1ac
to
72f81f3
Compare
Codecov Report
@@ Coverage Diff @@
## master #1001 +/- ##
============================================
+ Coverage 51.8% 51.89% +0.08%
- Complexity 1365 1379 +14
============================================
Files 147 147
Lines 7460 7503 +43
Branches 1132 1141 +9
============================================
+ Hits 3865 3894 +29
- Misses 3229 3243 +14
Partials 366 366
|
@rhuss Follow up for my previous work, any chance of merge & release? :) |
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.
Technically the PR look good, thanks ! (have some minor comments, though).
However I'm afraid that it makes things even more complex as they are already and its also hard to explain and understand whats going on.
Do you have a use case in hand where you want to mix explicit configured <external>
property handlers and implicit added via the global property ?
Actually, I would prefer to ignore the external property docker.imagePropertyConfiguration
when one image used an explicit external property handler (because then you already "in this business").
Everything makes things so much harder to understand and debug, especially when combined with other external handlers like docker-compose.
But maybe you have a convincing use case at hand where this would make sense ? ;)
@@ -71,11 +69,41 @@ public void externalPropertyActivation() throws MojoFailureException { | |||
ConfigHelper.validateExternalPropertyActivation(project, images); | |||
fail(); | |||
}catch(MojoFailureException ex) { | |||
assertTrue(ex.getMessage().contains("Configuration error: Cannot use property")); | |||
assertEquals("Configuration error: Cannot use property " + ConfigHelper.EXTERNALCONFIG_ACTIVATION_PROPERTY + " on projects with multiple images without explicit image external configuration.", |
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.
I would only check on parts with a essential to provide a meaningful context in the error message. That way the check is more robust on changes wrt rewording of the message. So, I always prefer contains on the essential parts (like contains(ConfigHelper.EXTERNALCONFIG_ACTIVATION_PROPERTY)
)
int imagesWithoutExternalConfig = 0; | ||
for (ImageConfiguration image : images) { | ||
if(PropertyConfigHandler.canCoexistWithOtherPropertyConfiguredImages(image.getExternalConfig())) | ||
continue; |
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.
can we please agree on adding brackets even around single line conditionals ? This is according to the existing style and less error-prone (believe, I hit that when adding a second line).
Also, would prefer to have spaces between if(
but I'm less dogmatic here ;-)
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.
Gah, I thought I configured IntelliJ to do that...
If set globally (i.e. parent POM), but not wanted locally, the property could be overriden to `skip` to disabled it. | ||
Note that settings.xml properties take precedence over any properties defined in pom.xml. | ||
|
||
For configurations with multiple images, using this property will produce an error. All images would use the docker prefix, |
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.
maybe highlight "docker" as this is a literal.
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.
maybe: "All images would use the same docker
prefix ..." ?
global settings.xml). | ||
|
||
If set globally (i.e. parent POM), but not wanted locally, the property could be overriden to `skip` to disabled it. | ||
Note that settings.xml properties take precedence over any properties defined in pom.xml. |
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.
How would one then could add 'skip' in the pom.xml when the properties in settings.xml has higher prio ? It probably only makes sense when used in pom.xml inheritance.
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.
That comment is more in general for all properties, inherently by maven any properties in settings.xml seems to override my projects properties.
[[combining-property-config-externally]] | ||
.Activating property configuration externally | ||
It also possible to activate property configuration by setting the property `docker.imagePropertyConfiguration` to a | ||
valid `property mode`, without adding an `<external>` section. |
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 add here, that the configuration then looks for the default prefix of docker
.
Note that settings.xml properties take precedence over any properties defined in pom.xml. | ||
|
||
For configurations with multiple images, using this property will produce an error. All images would use the docker prefix, | ||
they would all be given the same configuration, and that is probably not intended. |
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.
"probably" is a bit weak.
Maybe: "All images would then use the same docker
property prefix, resulting in multiple identical configurations"
The use case is actually not mixing and docker.imagePropertyConfiguration. The use case here was that I globally (through settings.xml) set Thus I don't really have a need to add to either of the images, that was more of a way to work around it.. since both images cannot use the same prefix :) The opposite solution would be, if more than one image exists, we ignore any |
All code comments fixed. Also adjusted the external activation & multi-image check a bit: if prefix is explicitly set (to anything), allow any number of images with same prefix. It is useful if most of config is set in POM, but still want to use override for some properties such as |
@rhuss any additional feedback? :) |
@stromnet just back from Red Hat Summit, tomorrow is docker-maven-plugin day ;-) 'hope to work on as many PRs as possible, including this one. |
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.
hey. Still not 100% convinced, let me sleep one night over it :) maybe some good example in the doc would help.
My point is, that you can quickly run into situation which are not easily understandable whats happening if the configuration comes from different places (like mixing property and XML handling).
At least we should add some more diagnostic message on verbose
level so that people can understand whats going on.
images (or at least all but one). Normally you'd want to use different prefix for each image, but if explicitly set | ||
it does allow you to use the same prefix (even `docker`) on all images. This is useful in case you just want to share | ||
a few properties. This only makes sense when `property mode` is _override_ or _fallback_ and image-specific configuration | ||
are defined in the POM configuration. |
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.
Can we add an example here please, e.g. the example for setting the http proxy for all configured images with a single property (i.e. you use case) ? I think this would help to understand people why it would make sense sometimes to use one property for all configured images.
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.
Good point. An example has been added for http_proxy and a single image, as well as an example with two images (using the same prefix).
Improved docs, and added some verbose logging when the external activation property is handled. I was thinking of adding something like "for image ", but that is tricky to fetch since it does not necessarily have a name at that time (we don't yet know if it is from config or from properties). Not sure what more verbose log to add. Perhaps dump the whole image configuration after they have been resolved, or is that more suitable for debug perhaps? |
Looks good to me, thanks for the docs and examples. Let's get that merged, also to gather some feedback. thanks ! |
Great, thanks! Hoping for a 0.25.3 soon then (and hopefully no more bugs...) :) |
By default it works as previous, but if explicit is added to each image, and i.e. setting a custom prefix, it work.
This is useful when i.e. env has
docker.imagePropertyConfiguration
set globally (i.e. settings.xml), and a Maven project happens to have multiple images.Also add support for docker.imagePropertyConfiguration=skip, for i.e. overriding parents config and disable it (note that setting this in pom will not override a value in settings.xml, mostly useful to override parent pom).