Skip to content

Proposal: Add "runtime" labels support when building (related to #13178) [WIP] - #13412

Closed
vdemeester wants to merge 1 commit into
moby:masterfrom
vdemeester:13178-build-runtime-label
Closed

vdemeester wants to merge 1 commit into
moby:masterfrom
vdemeester:13178-build-runtime-label

Conversation

@vdemeester

Copy link
Copy Markdown
Member

From the issue #13178 :

External tools, like docker/compose are currently using name convention to identify image they build as part as their workflow, in order to find them back and manage them. As proposed in this issue docker/compose#1403, it would be easier and more flexible to use labels for this use cases.

The current way to add labels to images are to add LABEL lines in Dockerfile. This proposal aims to add a flag(s) to the build command to allow settings labels to images when building them and support this in the API as well (so external tools can work with it).

This pull-request is a proposition of implementation to add the support for this. It does the following :

  • Update API documentation to add the fact that it's possible to set labels when commiting (already working in master).
  • Add --label and --label-file flags to the build and commit commands.
  • When using the --label or --label-file flags for the build command, create a layer with labels at the end of the build.
  • Update API documentation to add the fact that it's possible to set labels when building.
  • Add integration tests (for commit and build).

One thing that is important too is, this implementation makes it that the labels defined in the Dockerfile will 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:

  1. I tried to not refactor too much, but the --label and label-file are defined in 3 files now, api/client/commit.go, api/client/build.go and runconfig/parse.go ; I don't think it's ideal but I wanted to have external opinions on that.
  2. Using the label command 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.
  3. I moved ReadKVStrings and ConvertKVStringsToMap away, in the opts package, 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 tells.

I'll update the commit message to automatically close #13178 if needed.

Signed-off-by: Vincent Demeester [email protected]

- 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]>
@thaJeztah

Copy link
Copy Markdown
Member

Thanks @vdemeester!

One thing that is important too is, this implementation makes it that the labels defined in the Dockerfile will take precedence over the one passed as argument, at runtime when commiting or building.

I wonder if this should be reversed; otherwise, defining e.g. ENV com.docker.compose.project=foobar would make it impossible to run the container in any other project, when using it with compose.

ping @aanand @dnephin for runtime labels

@icecrime

Copy link
Copy Markdown
Contributor

@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 ENV? EXPOSE? VOLUME? I don't want to open this door.

I'm closing this, but as usual I'm open for discussion (especially from Compose maintainers @aanand @dnephin)!

@icecrime icecrime closed this Jun 12, 2015
@vdemeester

Copy link
Copy Markdown
Member Author

@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.

@vdemeester
vdemeester deleted the 13178-build-runtime-label branch June 26, 2015 20:05
@ghost

ghost commented Aug 18, 2015

Copy link
Copy Markdown

@icecrime, I would argue that the nature of labels is different from the nature of ENV, EXPOSE or VOLUME. The latter three instructions are capable of modifying the behavior of containers derived from the image -- in fact, that is the purpose of those instructions, to define the interface between the image and the system that will run it.

In contrast, LABEL is more like the MAINTAINER instruction -- a way to attach metadata to an image, to be consumed by clients who docker inspect a container or image. Labels help me to categorize my images, to make higher-level business decisions based on image contents without having to dig into the filesystem or launch containers.

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 build command line, just like one can specify an arbitrary tag for an image that's being built.

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 docker build to remain the predominant way to build images, then IMHO it needs to accommodate these fairly normal use cases. I understand the complexity involved in secret management at build time, so I don't expect that problem to be solved any time soon -- but surely, attaching metadata is more straightforward and less contentious?

@jonmoter

Copy link
Copy Markdown

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.

@kleptog

kleptog commented Oct 8, 2015

Copy link
Copy Markdown

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...

@thaJeztah

Copy link
Copy Markdown
Member

@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"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Proposal: Add "runtime" labels support when building

6 participants