Repository navigation
Proposal: Add "runtime" labels support when building (related to #13178) [WIP] - #13412
vdemeester wants to merge 1 commit into
Conversation
- Update API documentation to add the fact that it's possible to set labels when commiting (already). - Add --label and --label-file flags to build command, and create a last layer with labels at the end of the build. - Add integration tests (for commit and build). Signed-off-by: Vincent Demeester <[email protected]>
|
Thanks @vdemeester!
I wonder if this should be reversed; otherwise, defining e.g. |
|
@vdemeester Thanks for the contribution! I'm sorry but I'm going to be -1 on this one for a single reason: if we can have a command-line flag to basically provide additional instructions, why not I'm closing this, but as usual I'm open for discussion (especially from Compose maintainers @aanand @dnephin)! |
|
@icecrime Don't be sorry 😉. I totally get your point, and the more I think of it, the more I do agree with it so, it's more than fine to me. |
|
@icecrime, I would argue that the nature of labels is different from the nature of In contrast, In my mind, an image's label is more like its tag than its exposed ports or environment variables. Correspondingly, it makes sense to me that one should be able to specify labels on the The quintessential use case for labels in my organization is to tag images with the Git commit ref from which they were built. This is supremely useful to my ops team and currently we must achieve it by editing the Dockerfile before every build. Our image build process is already complicated by the fact that we need to install a language runtime and fetch dependencies before the build (because some of our dependencies live in private Git repositories and there's no safe way to inject secrets into a build); requiring us to tweak the Dockerfile for labels only makes the problem worse. If your goal is for |
|
I agree with @tony-spataro-rs. We have the exact same requirement, wanting to include the Git commit ref at build time. Attaching metadata to an image seems different than altering the behavior of an image. |
|
I have to say I agree with @tony-spataro-rs as well. Labels are fundamentally different from ENV, EXPOSE and VOLUME. The latter affect the container, the former not. Adding a label is more like setting the tag, which can only be done from the command line. Like other commenters I'd like to be able to be able to determine by looking at an image which version of the Dockerfile was used, this information obviously cannot be stored in the Dockerfile itself. Tags get lost, so you end up with images without tags with no method of identification. Tags don't survive export/import for example, and can only be used for one image at a time. Anyway, the workaround I'm looking at is having a Makefile generate the Dockerfile on the fly, does anyone have anything better? It looks like you might be able to do some dance with create/commit but that seems messier somehow... |
|
@tony-spataro-rs @jonmoter @kleptog please see my comment on the original issue: #13178 (comment). TL;DR; this will be possible in docker 1.9 through "build time args" |
From the issue #13178 :
This pull-request is a proposition of implementation to add the support for this. It does the following :
--labeland--label-fileflags to thebuildandcommitcommands.--labelor--label-fileflags for thebuildcommand, create a layer with labels at the end of the build.One thing that is important too is, this implementation makes it that the labels defined in the
Dockerfilewill take precedence over the one passed as argument, at runtime when building. On the other hand, I think the actual implementation when commiting is the opposite (which is making me think that it should have the same behviour for both — either take precedence the already defined or not).There a few things to review at least in this PR:
--labelandlabel-fileare defined in 3 files now,api/client/commit.go,api/client/build.goandrunconfig/parse.go; I don't think it's ideal but I wanted to have external opinions on that.labelcommand and create a last layer felt like the more simple way to this. It might be naive or not good at all, let me know 😉. The other way would be to use the last commit to add labels, but seems a little more difficult to handle/grasp.ReadKVStringsandConvertKVStringsToMapaway, in theoptspackage, not sure that was the best package to put it either — and as they are now exported, I will have to add tests cases for it.Looking forward to have reviews and opinions 😄 .
I add trouble on my machine with the integration test that used.--privileged, don't think it was due to my modifications but we'll see what janky tellsI'll update the commit message to automatically close #13178 if needed.
Signed-off-by: Vincent Demeester [email protected]