Skip to content

builder: dockerfile: allow LABEL w/o a value#17344

Closed
runcom wants to merge 1 commit into
moby:masterfrom
runcom:labels-name-only-build
Closed

builder: dockerfile: allow LABEL w/o a value#17344
runcom wants to merge 1 commit into
moby:masterfrom
runcom:labels-name-only-build

Conversation

@runcom

@runcom runcom commented Oct 25, 2015

Copy link
Copy Markdown
Member

Also add a bunch of tests about labels

Fix #16526
I don't see why the Dockerfile shouldn't allow LABEL w/o value, if anyone remembers this was intentional I'll close this
I also noticed we're allowing the old KEY name value format for LABEL which seems wrong given we should allow LABEL w/o value

Signed-off-by: Antonio Murdaca [email protected]

@thaJeztah

Copy link
Copy Markdown
Member

Thanks @runcom, yes it was the intent to be able to set a label without value (using an empty string "" as a default value)

@runcom

runcom commented Oct 25, 2015

Copy link
Copy Markdown
Member Author

@thaJeztah the only issue I see here now is that we allowed this:

LABEL key1 key2=value2

which produces key1="key2=value2"
now this will be key1="", key2="value2" (which is correct to me now)

@thaJeztah

Copy link
Copy Markdown
Member

Hm, good one. I never really liked LABEL key value, but you're right that this would be a breaking change because of that

@runcom

runcom commented Oct 25, 2015

Copy link
Copy Markdown
Member Author

I'd say it's still a fix to a wrong behavior in LABEL, ppl relying on this bug should change their code possibly

@runcom
runcom force-pushed the labels-name-only-build branch from 136a733 to 3471484 Compare October 25, 2015 10:41
@thaJeztah

Copy link
Copy Markdown
Member

I agree that this is a more user-friendly UX.

I think that at some point in the (build time) ARG option, there was a preference for name= to define an empty "arg", so I'm interested in other maintainers opinion.

@runcom

runcom commented Oct 25, 2015

Copy link
Copy Markdown
Member Author

I think that at some point in the (build time) ARG option, there was a preference for name= to define an empty "arg", so I'm interested in other maintainers opinion.

oh, that would definitely help here

@thaJeztah

Copy link
Copy Markdown
Member

/cc @tiborvass @duglin ^^

@runcom

runcom commented Oct 25, 2015

Copy link
Copy Markdown
Member Author

I'll fix the failing tests (as they rely on the old behavior) as soon as we decide what's good to do here

@duglin

duglin commented Oct 25, 2015

Copy link
Copy Markdown
Contributor

ping @rhatdan since I think he added LABEL support and might be able to say whether its ok to do this, or not.

@duglin

duglin commented Oct 25, 2015

Copy link
Copy Markdown
Contributor

I'm not a fan of the LABEL name value format, same for ENV, but I believe the intent was to make LABEL and ENV work the same way. Note that LABEL foo="" works just fine.

@runcom

runcom commented Oct 25, 2015

Copy link
Copy Markdown
Member Author

As you said @duglin I think this has been done to maintain the same behavior as ENV but we're actually allowing docker run with just a label key. Either we edit the doc and add ="" or fix this for LABEL :(

@thaJeztah

Copy link
Copy Markdown
Member

ping @rhatdan since I think he added LABEL support and might be able to say whether its ok to do this, or not.

@rhatdan started the initial implementation, and @ibuildthecloud completed it :-)

@rhatdan

rhatdan commented Oct 26, 2015

Copy link
Copy Markdown
Contributor

I just intended to match the --env behaviour. Although I would prefer name=value. And I would recomend

LABEL NAME=""

@runcom

runcom commented Oct 26, 2015

Copy link
Copy Markdown
Member Author

LABEL="" could work and that will need only doc update. However, there's currently a difference between docker run allowing us to define a label w/o ="" and the Dockerfile which requires to use ="" to define a label w/o a key.

@rhatdan

rhatdan commented Oct 26, 2015

Copy link
Copy Markdown
Contributor

runcon could you build a patch to prevent use of no ="" or no NAME VALUE

@runcom

runcom commented Oct 29, 2015

Copy link
Copy Markdown
Member Author

ping @cpuguy83

@runcom

runcom commented Nov 10, 2015

Copy link
Copy Markdown
Member Author

any thoughts on this? O:)

@cpuguy83

Copy link
Copy Markdown
Member

This is supported for --label on docker run, so it seems to make sense here.

@thaJeztah

Copy link
Copy Markdown
Member

However, there's currently a difference between docker run allowing us to define a label w/o ="" and the Dockerfile which requires to use ="" to define a label w/o a key.

True, it's a difference, but cli is a different UX in general, i.e. -e foo bar will not create two env-vars, or assign foo=bar.

@runcom will this PR break backward compatibility? i.e., will LABEL name value still work?

I do prefer the name=value notation, as it's less ambiguous.

@runcom

runcom commented Nov 10, 2015

Copy link
Copy Markdown
Member Author

@runcom will this PR break backward compatibility? i.e., will LABEL name value still work?

it will right now..

@LK4D4

LK4D4 commented Nov 14, 2015

Copy link
Copy Markdown
Contributor

Makes sense I think

Also add a bunch of tests about labels

Signed-off-by: Antonio Murdaca <[email protected]>
@runcom
runcom force-pushed the labels-name-only-build branch from 3471484 to ff559b3 Compare December 14, 2015 08:18
@runcom

runcom commented Dec 14, 2015

Copy link
Copy Markdown
Member Author

rebased :)

@runcom will this PR break backward compatibility? i.e., will LABEL name value still work?

@thaJeztah this PR break backward compatibility and LABEL name value won't work the same way it was.

maybe it is better to just update the doc, but I really believe this is the correct way to handle LABEL(s) even if you can do LABEL="".

ping @tiborvass @duglin @LK4D4

@thaJeztah

Copy link
Copy Markdown
Member

I looked at the documentation; https://docs.docker.com/engine/userguide/labels-custom-metadata/ and https://docs.docker.com/engine/reference/builder/#label

All examples and the documentation mention that = should be used to set a value, and can be omitted to use an "empty" string. For example this section;

LABEL [<namespace>.]<key>[=<value>] ...

We may want to update this line to more explicitly mention that =<value> is optional (i.e. change it to [=<value>]);

LABEL <key>=<value> <key>=<value> <key>=<value> ...

Reading those; I agree, and I think we should use = to use a value, and if omitted, create an empty label (using "" as value). People currently using LABEL key value are relying on undocumented behavior.

@LK4D4

LK4D4 commented Dec 15, 2015

Copy link
Copy Markdown
Contributor

@runcom yeah, however making breaking changes is worse :/
Maybe @ibuildthecloud as active LABEL user can say his word too.

@runcom

runcom commented Dec 15, 2015

Copy link
Copy Markdown
Member Author

@runcom yeah, however making breaking changes is worse :/

I'm fine updating docs then, really :)

@ibuildthecloud

Copy link
Copy Markdown
Contributor

I'm not particularly a fan of this. As @rhatdan pointed out the intended behavior was just to follow the same logic as ENV. Personally I'd rather not have to remember that ENV A B and LABEL A B are parsed differently. I thinks LABEL A="" is perfectly fine.

@ibuildthecloud

Copy link
Copy Markdown
Contributor

Oh wait. will LABEL A B now become two keys? If so, then that is way too breaking of a change. But then what will LABEL A B C become?

@duglin

duglin commented Dec 15, 2015

Copy link
Copy Markdown
Contributor

Ignoring any inconsistency between the docker cmd line and what people see in the Dockerfile, I think

ENV env1 env2
LABEL label1 label2

should be parsed the same way. Which, right now, will produce one env var (env1) with a value of "env2" and one label (label1) with a value of "label2".

Now, to the -l on the command line. I might be doing it wrong but I'm not seeing an inconsistent there. When I do -l foo it doesn't set foo to "", it sets it to the value of the env var "foo", which might be empty but that's a side effect of using the env var.

So, while it might appear that we allow labels and env vars to be specified on the cmd line w/o values, I don't think we do. Instead what we allow people to say is "grab the value from an env var".

Net: I think this might be a doc issue.

@ibuildthecloud

Copy link
Copy Markdown
Contributor

@duglin Doing -l foo and having it read and env variable I would think is a bug. That was never intended to be supported. The parsing logic was just supposed to the simple in that if you didn't put a = then the value is ""

@duglin

duglin commented Dec 15, 2015

Copy link
Copy Markdown
Contributor

@ibuildthecloud that could be - I don't use labels so I'm not sure what the expected behavior should be, but even if we did change it so that it used "" instead of the corresponding env var I think keeping the current Dockerfile syntax/behavior is probably correct. IOW, forcing them to add ="" seems ok to me.

@thaJeztah

Copy link
Copy Markdown
Member

Alright, looks like the majority is for making this a documentation-only change, and keep the current behavior.

@runcom shall we close this one, and create a new, fresh PR?

@thaJeztah thaJeztah closed this Dec 15, 2015
@runcom

runcom commented Dec 15, 2015

Copy link
Copy Markdown
Member Author

@thaJeztah I'll update docs to mention that users should add ="" to specify a label w/o a value in Dockerfiles, sounds good?

@runcom
runcom deleted the labels-name-only-build branch December 15, 2015 19:39
@thaJeztah

Copy link
Copy Markdown
Member

@runcom sounds good, also https://docs.docker.com/engine/userguide/labels-custom-metadata/#add-labels-to-images should be updated, changing

LABEL [<namespace>.]<key>[=<value>] ...

to

LABEL [<namespace>.]<key>=<value> ...

(I don't think we should explicitly mention <key> <value> without =)

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.

LABEL com.example.version.is-beta

8 participants