Skip to content

Add support for ENV of the form: ENV name=value ...#8251

Merged
crosbymichael merged 1 commit intomoby:masterfrom
duglin:Issue2333
Nov 20, 2014
Merged

Add support for ENV of the form: ENV name=value ...#8251
crosbymichael merged 1 commit intomoby:masterfrom
duglin:Issue2333

Conversation

@duglin
Copy link
Contributor

@duglin duglin commented Sep 26, 2014

still supports the old form: ENV name value.
Notes:

  • presence of "=" in the first word is the trigger to know if we're going the old vs new form
  • new form supports quoting and 's the same way the cmd line does

since shells support:
abc=123 def=456
I think supporting:
ENV abc=123 def=456
makes a lot of sense. This isn't just about doing some kind of batching (which is being worked on in other PRs), this aligns ENV with what shells supports.

Keeping old description for posterity:
I have mixed feelings about this. While it works and is kind of cool to be able to do:
ENV abc=def foo="feed the dog" hungry=eat\ a\ pizza late="go to bed 'now' I said"
and each key=value is parsed like you'd expect it to be on the command line, the ability to do more than
one ENV at a time really should be done under some kind of batching mechanism. But, of course,
that's not there yet and we're not sure when it will be. So, unlike the RUN command where we can
concat things together with &&'s, the ENV command doesn't have that option - not without this feature.

Closes #2333

Signed-off-by: Doug Davis [email protected]

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about the entire string after the first space will be treated as the <value>?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed per your suggestion.

@SvenDowideit
Copy link
Contributor

@jamtur01 @fredlf @ostezer

essentially Docs LGTM, but some tweaks would be nice

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've just tested (using make docs) and these indented code sections need an extra line feed:

For example:

    ENV myName="John Doe" myDog=Rex\ The\ Dog

and

    ENV myName John Doe
    ENV myDog Rex The Dog

will yield the same net results in the final container, but the first form
does it all in one layer.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

@SvenDowideit
Copy link
Contributor

Docs LGTM

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

needs to be <value> I reckon.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume you meant that I needed to add single-back-quotes around it, if so, done. If not, can you elaborate?

@ghost
Copy link

ghost commented Sep 26, 2014

Docs LGTM.

@jessfraz
Copy link
Contributor

I don't exactly understand why this is necessary though.

@jessfraz
Copy link
Contributor

@erikh ?

@erikh
Copy link
Contributor

erikh commented Sep 26, 2014

I think solomon needs to weigh in on this before we can merge it.

As for the feature, it could reduce layers, so I’m all for it.

On Sep 26, 2014, at 1:55 PM, Jessie Frazelle [email protected] wrote:

@erikh ?


Reply to this email directly or view it on GitHub.

@thaJeztah
Copy link
Member

If I understand this correctly, it would reduce the number of layers produced, so for that, I'm +1, but possibly an improved builder could automatically optimise this? Multiple ENV instructions are more readable.

edit
Erik just beat me on that comment, lol

@duglin
Copy link
Contributor Author

duglin commented Sep 27, 2014

Yep, as I mentioned, I have mixed feelings and am ok either way we go - as long as we come to a decision and close the original issue.

To @thaJeztah's comment... yep, multiple ENVs are easier, but with this you can write:
ENV foo=bar
abc=def
dog=cat
which is similar to multiple ENVs, but all in one layer.

@shykes - any thoughts on this one?

@thaJeztah
Copy link
Member

multiple ENVs are easier, but with this you can write ........ which is similar to multiple ENVs, but all in one layer.

Well, I think that points to the underlying problem. In the current implementation of the Dockerfile / builder, users have to "jump through hoops" to make docker do what they intended, or to optimise the results (reduce layers and/or reduce image-size).

In some cases, this results in "mangling" a perfectly readable Dockerfile into something that's hard to grasp, just for the sake of optimisation.

In short, even though I want this functionality (for optimisation), if there's a chance that the builder is able to optimise this automatically in the short future, I'm hesitant to introduce a new syntax as a stop-gap solution.

If such optimisation will not be possibly in the foreseeable future, OR this syntax has other advantages that I'm overseeing, then it's fine with me.

note
I know several issues exist to have more control over layers (caching/temporary build-contexts/build results), but I'm not sure there's an issue/proposal for (automatic) optimisation.

@erikh since you did the last major rewrite of the builder/parser, do you know if such issue already exists? Should one be created?

@fredlf
Copy link
Contributor

fredlf commented Sep 29, 2014

Docs LGTM and thanks for the contribution.

@crosbymichael
Copy link
Contributor

I think the design and UI looks good. We wanted the feature, we just did not like using the json syntax for it.

@duglin
Copy link
Contributor Author

duglin commented Oct 2, 2014

How do we decide if we want to move forward with this?

@duglin
Copy link
Contributor Author

duglin commented Oct 21, 2014

@crosbymichael thoughts?

@erikh erikh self-assigned this Oct 21, 2014
@erikh
Copy link
Contributor

erikh commented Oct 21, 2014

I don't object to it; we're kicking out a 1.3.1 probably today with some builder fixes. Can we wait until after that?

@erikh
Copy link
Contributor

erikh commented Oct 21, 2014

Oh and this needs a rebase.

@duglin
Copy link
Contributor Author

duglin commented Oct 21, 2014

@erikh - rebase is done!

@erikh
Copy link
Contributor

erikh commented Oct 21, 2014

Thanks Doug. Ping me on IRC if I don’t get to this in the next few days, please.

On Oct 21, 2014, at 12:06 PM, Doug Davis [email protected] wrote:

@erikh https://github.com/erikh - rebase is done!


Reply to this email directly or view it on GitHub #8251 (comment).

@erikh
Copy link
Contributor

erikh commented Oct 25, 2014

So, looking at this again, I would like to ask for a few things:

  • Use constants for PHASE, (an enum, see go's iota keyword) with a switch statement for handling the phases. Ideally, we could break these phases into their own, functional routines, but I'm not sure how feasible that is.
  • Handle the AST generation differently; set an even number of args == key and value, not parsing the = in a second place. This should result in very little code change to the evaluator's env dispatcher, I think, and result in a less coupled feature.

@jessfraz jessfraz added this to the 1.4 milestone Nov 18, 2014
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👯

@erikh
Copy link
Contributor

erikh commented Nov 18, 2014

We need one more maintainer LGTM -- that means @tiborvass or @crosbymichael

@duglin
Copy link
Contributor Author

duglin commented Nov 19, 2014

@tiborvass @crosbymichael any comments?

@milosgajdos
Copy link

It would be nice to have this available on cli arguments not just within a Dockerfile. At the moment when I set an env variable as FOO="bar" Docker carries the quotes (single and double) inside the container

@duglin
Copy link
Contributor Author

duglin commented Nov 19, 2014

@milosgajdos83 normally the cmd line processing would do the right thing. For me I don't see quotes:

$ docker run -ti -e foo="bar" ubuntu env
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
HOSTNAME=59fb35fdf2e7
TERM=xterm
foo=bar
HOME=/root

@erikh
Copy link
Contributor

erikh commented Nov 19, 2014

What shells are you two using?

-Erik

On Nov 19, 2014, at 8:47 AM, Doug Davis [email protected] wrote:

@milosgajdos83 https://github.com/milosgajdos83 normally the cmd line processing would do the right thing. For me I don't see quotes:

docker run -ti -e foo="bar" ubuntu env

PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
HOSTNAME=59fb35fdf2e7
TERM=xterm
foo=bar
HOME=/root


Reply to this email directly or view it on GitHub #8251 (comment).

@duglin
Copy link
Contributor Author

duglin commented Nov 19, 2014

I get the same results from bash and sh.

@erikh
Copy link
Contributor

erikh commented Nov 19, 2014

Same result on zsh 5 here.

On Nov 19, 2014, at 10:13 AM, Doug Davis [email protected] wrote:

I get the same results from bash and sh.


Reply to this email directly or view it on GitHub #8251 (comment).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe add a third example with ENV <key1>=<value1> <key2>=<value2> ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line 357 isn't good enough?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's good as well, but since this is right after the ENV title, it seems to me, it's a general template of what's possible with the keyword. Line 357 goes into even more detail with quotes. Anyway, it was just a suggestion. I guess docs people are better suited to answer this.

/cc @SvenDowideit @fredlf @jamtur01

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually I was about to add it (just for you :-) ) but then I realized, isn't the ... in there good enough since it means "repeat the last thing" ? If I added:
ENV = <key2=value2> ...
people might wonder what the difference is between that line and the previous one. And are we really saying we have a special syntax where we specify two or more and not just one or more?

At least my interpretation of that chunk of docs is that its not a sample but more like a pseudo-schema of what's expected. But I could be wrong.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yeah maybe that's sufficient then :) If we don't hear from the docs guys about this issue, then let's just leave it.

@duglin
Copy link
Contributor Author

duglin commented Nov 20, 2014

ok I think I got all of @tiborvass 's suggested changes pushed now.

still supports the old form: ENV name value

Also, fixed an issue with the parser where it would ignore lines
at the end of the Dockerfile that ended with \

Closes moby#2333

Signed-off-by: Doug Davis <[email protected]>
@crosbymichael
Copy link
Contributor

LGTM

crosbymichael added a commit that referenced this pull request Nov 20, 2014
Add support for ENV of the form: ENV name=value ...
@crosbymichael crosbymichael merged commit 58b6f31 into moby:master Nov 20, 2014
@duglin duglin deleted the Issue2333 branch November 21, 2014 20:11
@duglin duglin unassigned erikh Feb 5, 2015
@thaJeztah thaJeztah added area/builder Build impact/dockerfile kind/enhancement Enhancements are not bugs or new features but can improve usability or performance. labels Dec 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/builder Build impact/dockerfile kind/enhancement Enhancements are not bugs or new features but can improve usability or performance.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow ENV to set multiple variables in one layer

10 participants