-
Notifications
You must be signed in to change notification settings - Fork 643
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 for docker.runEnv properties and -D flags #938
Conversation
Env vars for creating contains can now be set with docker.runEnv using both Maven properties and -D flags, similar to how docker.buildArg is supported. Signed-off-by: Johan Ström <johan@stromnet.se>
Partially related: #386 |
Codecov Report
@@ Coverage Diff @@
## master #938 +/- ##
============================================
+ Coverage 51.57% 51.99% +0.42%
- Complexity 1232 1270 +38
============================================
Files 144 144
Lines 7250 7301 +51
Branches 981 991 +10
============================================
+ Hits 3739 3796 +57
+ Misses 3195 3183 -12
- Partials 316 322 +6
|
@stromnet thanks for the PR ! I see clearly your use case and think that is useful. However, I would strive for another approach: We already have the possibility to make external configuration via properties by adding to an image configuration: <image>
<external>
<type>properties</type>
<prefix>docker</prefix> <!-- this is the default -->
</external>
</image> This means you can fully configure your application (build and runtime aspects) via system properties. As this functionality overlaps which your PR (having a Currently, the only problems we have that this not already works out of the box are:
So, ideally, the configuraton should look like: <image>
<external> <type>properties</type> </external>
<name>myimage</name>
<build>
...
</build>
<run>
....
</run>
</image> Then you can overwrite or add to the configuration by providing the corresponding properties. This also would fit nicely into our current configuration scheme. If you feel fancy, it would be awesome if you could add this. (happy to help and give pointers). If not, I would tackle this but cannot promise any ETA (so busy until May right now ;-( |
@rhuss, thanks for response! We've looked at the externalised solution, but since the pom file needs total rewrite to use only params and no XML, we rather avoid that. With customers ~100 projects it would be quite messy (hm.. must have counted wrong somewhere, can't really be that many.. but close!) A merging of XML parameters with properties would indeed be an useful solution, especially if it can be made without adding additional The only gotcha is that we don't want to set Feel free to give some pointers on what would have to be done, and depending on how much work it is I might be able to get some time to do it. |
Cool. I think its not so hard:
|
Right, ok will try to take a look at it, probably Friday or next week. Any preferences on priority, properties overrides XML I guess, and if external is configured we ignore any XML like is done today? General maven question, not too sure about all the internals: Should we evaluate System properties too (-D flags), I don't think maven merges those into project properties, but is there some other source of those perhaps? |
Actually, I really like to have this merging when I see your use case that you want to have the property provider enabled by default (to not touch existing configuration), but this would break backwards compatibility, and also, what would you do when multiple images are configured ? (therefor you have the possibility to provide some Maybe a good compromise would be to add a new global configuration option Yeah, sorry for docker.buildArgs being handled differently as the other property based configuration. Actually, when we already had this generic merge, I think this wouldn't have been necessary. Probably I will reconsider this option when the merging is in place. wdyt ? btw, I on PTO next week, so don't be surprised if I answer only slowly (well, in the recent busy times my response time was already suboptimal already ... :) |
A property such as Will give it a try! |
Awesome, thanks ! |
On good way today, created a separate #941 for run/build env, and started on looking into merging too. Basically, as you mentioned, I start with For simple String property, this could work:
I.e, if it is explicitly set by property (which comes as param here), we use that, else we use that from base (which is null if not set). Then we have for example Same questions applies to Maps, such as Thoughts? |
Ok, got some more done now. Here is WIP work, no nice descriptive text here yet but if you have feedback please give it :) |
Opened new PR in #948 |
Background:
When running in an environment which requires http_proxy to be set in a container, it's usually environment specific and not something to be specified in an image or the project's POM file.
Since there is already "specific" support for
docker.buildArg
through properties & -D flags, I thought it would not be too weird to add a docker.runEnv as well. Ideally I'd want to have all things configurable with property overrides (without requiring externalized config), but that is a much greater change I recon.Example:
Instead of adding
hardcoded in every project POM,
I can instead add
in either my .m2 settings.xml,
or, I could add as -D flag during build (for example in my default Jenkins template)
Change
This moves helper methods used for existing
docker.buildArg
into EnvUtil and uses the same when creating theContainerCreateConfig
inRunService
.