Skip to content

Add support for advanced ${} uses - #11149

Merged
tiborvass merged 1 commit into
moby:masterfrom
duglin:8667-AdvancedVars
Apr 2, 2015
Merged

tiborvass merged 1 commit into
moby:masterfrom
duglin:8667-AdvancedVars

Conversation

@duglin

@duglin duglin commented Mar 4, 2015

Copy link
Copy Markdown
Contributor

In particular ${xxx:+...} and ${xxx:-...}

This depends on #10431

Closes #8667

@moxiegirl

Copy link
Copy Markdown
Contributor

LGTM

@duglin

duglin commented Mar 5, 2015

Copy link
Copy Markdown
Contributor Author

Interesting usecase: #9731

@ahmetb

ahmetb commented Mar 6, 2015

Copy link
Copy Markdown
Contributor

94379ae and 76ac2e3 have the same commit message. can you squash/edit?

@tiborvass

Copy link
Copy Markdown
Contributor

I'm closing this until we merge the dependency. We can reopen after :)

@duglin

duglin commented Mar 10, 2015

Copy link
Copy Markdown
Contributor Author

Huh? Is that really the normal process? Seems odd to me.

@tiborvass

Copy link
Copy Markdown
Contributor

@duglin yes :) We actually had a discussion this morning about PR dependencies, and we do this every now and then, we may not be enforcing it well enough.

@duglin

duglin commented Mar 10, 2015

Copy link
Copy Markdown
Contributor Author

Obviously that means the other PR needs to be approved. ☺

-Doug

Sent from my iPhone

On Mar 10, 2015, at 3:39 PM, Tibor Vass [email protected] wrote:

@duglin yes :) We actually had a discussion this morning about PR dependencies, and we do this every now and then, we may not be enforcing it well enough.

—
Reply to this email directly or view it on GitHub.

@icecrime

Copy link
Copy Markdown
Contributor

Moving this in 1-design-review.

I like the feature, and the implementation is simple enough, so +1.

@duglin

duglin commented Mar 30, 2015

Copy link
Copy Markdown
Contributor Author

ping @tiborvass

@tiborvass

Copy link
Copy Markdown
Contributor

@duglin what would be the ways people could abuse it?

@duglin

duglin commented Mar 31, 2015

Copy link
Copy Markdown
Contributor Author

@tiborvass can you elaborate? I'm not sure what you're looking for. Not sure how people could "abuse" an environment variable.

@tiborvass

Copy link
Copy Markdown
Contributor

I mean the reason this PR exists is because of PATH=$PATH:/foo/bar would result in :/foo/bar if $PATH was not set initially. I understand the need for ${} in that case, but want to understand what other usecases does ${} affect. Also I wonder whether that usecase alone is worthy of a new feature.

@tianon can you think of anything? Actually, now that I think about it, we should have kept ENV only for runtime and never for buildtime. For buildtime environments, just use RUN export foo=bar and ENV foo=$foo (and make it work).

@duglin to be honest, at this point, you are right, I don't see why we wouldn't support ${}.

@duglin

duglin commented Mar 31, 2015

Copy link
Copy Markdown
Contributor Author

@tiborvass yes {$..:-...} is the primary usecase but I added support for ${...:+...} too since it was trivial to add - mainly for symmetry with ${...:-...}. I don't think adding this should be much of a concern since ${} has been supported for a while and we simply error-out if someone uses a modifier (like - or +) we don't understand. So all we're really doing is changing an error case to a valid case to allow more bash-like semantics. No invention here, just giving the user more stuff that they're used to seeing.

@tianon

tianon commented Mar 31, 2015

Copy link
Copy Markdown
Member

@tianon

tianon commented Mar 31, 2015

Copy link
Copy Markdown
Member

More seriously, with what we've already got support for, this does make sense. It hurts that we're reimplementing so many shell features, but we're already down the hole a ways and can't back out now. 👍

@erikh

erikh commented Mar 31, 2015

Copy link
Copy Markdown
Contributor

Nope I've no argument, sorry if I communicated otherwise.

@duglin

duglin commented Mar 31, 2015

Copy link
Copy Markdown
Contributor Author

@erikh if you get a chance, I wouldn't mind your thoughts on: https://github.com/duglin/docker/tree/Script cd into 'test' and then build that Dockerfile.

Comment thread builder/shell_parser.go Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What about:

switch modifier {
case "-":
newValue := sw.getEnv(name)
// ...
case "+":
newValue := sw.getEnv(name)
// ...
default:
// return error
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

As you wish....

On Mar 31, 2015, at 5:08 PM, Tibor Vass [email protected] wrote:

In builder/shell_parser.go #11149 (comment):

@@ -157,7 +157,38 @@ func (sw *shellWord) processDollar() (string, error) {
sw.next()
return sw.getEnv(name), nil
}

  •   return "", fmt.Errorf("Unsupported ${} substitution: %s", sw.word)
    
  •   if ch == ':' {
    
  •       // Special ${xx:...} format processing
    
  •       // Yes it allows for recursive $'s in the ... spot
    
  •       sw.next()
    
  •       modifier := sw.next()
    
  •       if strings.Index("-+", string(modifier)) < 0 {
    
    What about:

switch modifier {
case "-":
newValue := sw.getEnv(name)
// ...
case "+":
newValue := sw.getEnv(name)
// ...
default:
// return error
}
—
Reply to this email directly or view it on GitHub https://github.com/docker/docker/pull/11149/files#r27523426.

@duglin
duglin force-pushed the 8667-AdvancedVars branch from 00ef54c to 23a1a5f Compare March 31, 2015 23:22
@tiborvass

Copy link
Copy Markdown
Contributor

LGTM

Ping @erikh

@erikh

erikh commented Apr 1, 2015

Copy link
Copy Markdown
Contributor

Just noticing this whole lib now; nice! LGTM.

Comment thread docs/sources/reference/builder.md Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

${variable_name}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@jamtur01 fixed

Just ${xxx:+...} and ${xxx:-...} for now

Signed-off-by: Doug Davis <[email protected]>
@duglin
duglin force-pushed the 8667-AdvancedVars branch from 23a1a5f to 39908fc Compare April 1, 2015 15:11
@duglin

duglin commented Apr 1, 2015

Copy link
Copy Markdown
Contributor Author

fixed @jamtur01's docs comment

@jamtur01

jamtur01 commented Apr 1, 2015

Copy link
Copy Markdown
Contributor

Docs LGTM

@duglin

duglin commented Apr 2, 2015

Copy link
Copy Markdown
Contributor Author

is this ready to merge?

@tiborvass

Copy link
Copy Markdown
Contributor

@duglin Yes :)

tiborvass added a commit that referenced this pull request Apr 2, 2015
Add support for advanced ${} uses
@tiborvass
tiborvass merged commit 9707286 into moby:master Apr 2, 2015
@duglin

duglin commented Apr 2, 2015

Copy link
Copy Markdown
Contributor Author

thanks!!

@thaJeztah

Copy link
Copy Markdown
Member

🎉😃

@duglin
duglin deleted the 8667-AdvancedVars branch April 3, 2015 20:24
@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.

It's difficult to correctly construct values for common environment variables