-
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
added build-args support #409
Conversation
Signed-off-by: Balazs Nemeth <balazs.nemeth@edudoo.com> ---------------------- branch [[support-build-args]]
Addresses this issue: #334 |
Awesome! This will fix my problem that my build VM is behind a proxy and the container doesn't know of it at build time :D |
Thanks a lot ! 'will have a look ASAP and integrate it. |
|
||
private Map<String, String> addBuildArgs() { | ||
HashMap<String, String> args = new HashMap<>(); | ||
String[] argPairs = buildArgs.split(","); |
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 think that a bit too simplistic because of missing escape hanlding (think about values containing ,
).
What do you think about the idea to allow properties of the form -Ddocker.build.arg.<variable_1>=<value_1> -Ddocker.build.arg.<variable_2>=<value_2> ...
. Thats how we model maps in the property handler anyway.
Of course then simple injection wouldn't work here but one would need to look it up actively from the project
as properties when looking up.
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.
Also wonder whether we need a distinction for individual images here since a build can contain many images (e.g. docker.build.<image|alias>.arg.<varname>
To make thinks shorter what about:
docker.arg.<varname>
--> Used for all imagesdocker.iarg.<image>.<varname>
--> Used for image<image>
.
Thanks again for the PR. Maybe you could have a look in the way how to provide build args from the outside (see above) ? On a second thought, I don't see so much value for Docker ARGs when internally creating the Dockerfile from the build information (in contrast of using an external Dockerfile) since everything could be filled in with Maven properties, too. Also, the resulting Dockerfile is 'fixed' so that it can be better versioned (using the Dockerfile in multiple build will allways result in the same image because no external vars can be provided). Thats also important for 'docker:source' which is supposed to create the same image regardless how often used. So maybe we can change the handling to use It might make more sense when using an external Dockerfile (however we will get problems when using Maven property filtering because of the same variable syntax with |
Thanks for having a look at it. But I'd need some more clarification on the second one. How can you fill in the ARGs into the Dockerfile with Maven properties? I didn't really get this when I had looked at #334 for the first time and it's still unclear. |
@balazsmaria currently there are two canonical ways to build images: Building up an own Dockerfile with information given in the in plugin configuration (thats what the <build>
<from>${baseImage}</from>
<runCmds>
<run>${proxyEnv} apt-get update</run>
</runCmds>
....
</build>
This properties can be configured the Maven way: In Hence i think for this case we don't need support for adding Or there is the build mode with an external Dockerfile when the property However one should be aware, if one used external Dockerfiles and ARG then one could have a problem when the standard Maven property filtering is used (which use the same variable syntax as ARG with Unfortunately the build configuration for both quite distinct use cases is interwoven, but I plan to detangle this to make it more clear what to use (i.e. to use complete separate config syntax format when using either of these configuration modes). 'hope that makes my thought a bit clearer .... |
Yes, it's much clearer now. But: "The problem is then also, that the generated Dockerfile (which can be deployed and distributed with docker:source) is then not fixed (but depends on the args given when building)". Why is that a problem? It depends on the args given when building, this is by design so. If an ARG has no default value, it has to be specified during building. This way you can have very different images only by changing an ARG at build time. I'm not sure I like this, but that's how it is. If you can do this with a vanilla Dockerfile, you should be able to do that with this plugin as well. What am I missing here? |
@balazsmaria you are right, that with vanilla Docker the same Dockerfile can result in different images, but that doesn't necessarily mean thats a good thing when it comes to versioning ;-) (e.g. wonder how Docker Hub deals with build args) With However I'm still not fully convinced that we need ARGs for the internal Dockerfile use case:
Not that I'm completely against it, just looking for some reasons ;) |
I don't really have any reasons at the moment, it just seemed natural to include something that I could write to an external Dockerfile. |
@balazsmaria yes, perfectly fine for me. |
…outside ---------------------- branch [[support-build-args]]
---------------------- branch [[support-build-args]]
Have you had a chance to look at the latest commits? |
will do it today |
I looked at it briefly, and will comment on it with some suggestions soon (maybe over the weekend) |
This is based on the work done in #409 (thanks @ balazsmaria !) and allows the usage of ARG in external Dockerfiles. Documentation and external property config hanlder has been updated, too.
Thanks a lot again ! I made things a bit simpler by moving the args configuration to the plugin configuration (in order to avoid support for external properties in the main configuration section. You can always do a <image>
<build>
<args>
<HTTP_PROXY>${myHttpProxy}</HTTP_PROXY>
<args>
</build>
</imag> and then run Maven with
Or alternatively you could also use the external property config handler. 'hope this still fits your use case. |
Thanks for the merge! So previously we said this should be possible:
But now how do I do that without modifying the plugin configuration? The problem is that these are predefined ARG variables:
so you don't want to re-define them. |
This could be done as described above, however with an update to the configuration (which make explicit which ARGs are used). Maybe that was a misunderstanding on my side. We intentionally don't want to expose image specific configuration via properties to the outside because as experience told us this leads easily to nasty hidden dependencies (e.g. the d-m-p and the fabric8-maven-plugin are coupled with the Said that, there is a way to configure the build via properties alone. You can use an external property configuration handler as described in http://fabric8io.github.io/docker-maven-plugin/external-configuration.html which probably comes close to the usage scenario you describe above (but you have to decide which configuration style you want to chose, my recommendation is the standard one :) I wonder whether you could live this extra step of mentioning the args in the plugin configuration. If not, I would consider to introduce a global configuration option wdyt ? |
The problem is that I don't want to change anything at all in order to use a proxy. The proxy has nothing to do with the business goal, and in my case it has to be there in one office location and in others not, especially not in a cloud environment. So it's not OK to change the pom just because one location uses the proxy. (The bad thing about it is that currently I have to put the proxy there manually and remove it before commit. Very fishy!) I think this is a very stupid but valid scenario. |
But you need to craft the Dockerfile accordingly for using the ARGs, aren't you ? With the setup i described above, you also don't have to change the pom when you are changing the environment: <project>
...
<properties>
<!-- Empty by default -->
<my.http.proxy></my.http.proxy>
</properties>
....
....
<plugin><configuration><images><image><build>
<args>
<HTTP_PROXY_ENV>${my.http.proxy}</HTTP_PROXY_ENV>
</args>
.... with a Dockerfile
and then run either So you can use the same pom.xml in all environments (if this is your requirement). + you can infer from reading the pom.xml what to set for enabling the proxy (its explicit, that's my point). |
No, you don't need to alter your Dockerfile, this is all implicit. That's the point of the predefined ARG values. So the simple
works if you just do |
Sorry, then I misunderstood the Docker documentation which states that a certain set of predefined args need not to be declared with ARG but you still need to use them in the Dockerfile. Or do they automatically end up as environment variables (thats new to me, but tbh I never used this feature) ? |
Yes, this is how they work. During build they act as if they were environmental variables. |
Then it makes definitively sense to provide suche props from the outside. I wonder though whether it would make sense to add a dedicated, global proxy option like '-Ddocker.buildProxy |
I'd prefer our original approach with |
Agreed. we shouldn't be too clever (always in danger of premature featuritis ;). I will then add the support as described above, e.g. a global configuration option for setting build args for all configured images at once. Thanks for the discussion and the heads wrt to predefined args (tbh didn't really know that). I'm currently on another PR but will add this afterwards. |
Could you please let me know how is that different from what I implemented? In case it's similar and you are not happy with something, I could fix that. |
The difference is that its not specific to an image (name or alias), but globally applicable for every image. not a biggie, if you like you can pick that up from branch |
Does this go to |
It should go into |
…rom project and system properties ---------------------- branch [[build-args-from-outside]]
I checked and System.properties are not in Project properties, so I added both. |
#409 - docker.buildArg.myBuildArg to docker build-arg both from proje…
Also related to #409, only minor updates.
Signed-off-by: Balazs Nemeth balazs.nemeth@edudoo.com
branch [[support-build-args]]