Skip to content
This repository was archived by the owner on Jun 16, 2021. It is now read-only.

Support interpolating environment variables #47

Merged
merged 1 commit into from
Oct 7, 2015

Conversation

joshwget
Copy link
Contributor

@joshwget joshwget commented Sep 7, 2015

Fixes #40

Signed-off-by: Josh Curl hello@joshcurl.com

@ibuildthecloud
Copy link
Contributor

@joshwget You have one go vet issue

project/interpolation.go:66: unreachable code

Thanks for the contribution, I'll try to provide some feedback tonight.

@@ -0,0 +1,161 @@
package project
Copy link
Contributor

Choose a reason for hiding this comment

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

From what I've seen there is a convention to name the test file interpolation_test.go. What's the reason for deviating from that convention ?

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 thought it was necessary for internal tests. I'll rename it!

for k, v := range *config {
for k2, v2 := range v {
err := interpolate(k2, k, &v2, func(s string) string {
values := environmentLookup.Lookup(s, k, nil)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Wasn't sure what to do with the third argument here since a ServiceConfig isn't created until after interpolation is performed. This works fine using the OsEnvLookup implementation, which is currently the only one, but it might not be a good idea in general.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, that makes sense. I think it's fine to say that the serviceConfig could be nil and the impl of EnvironmentLookup so be programmed so.

@ibuildthecloud
Copy link
Contributor

LGTM

ping @aduermael @gdevillele

testInterpolatedLine(t, "ABC", "${A}", variables)

testInterpolatedLine(t, "ABC DE", "$A DE", variables)
testInterpolatedLine(t, "ABCDE", "${A}DE", variables)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would add a testInterpolatedLine(t, "", "$ADE", variables) case

@vdemeester
Copy link
Collaborator

@joshwget looks good 😉. Two things before merging 😉 :

  • Could you rebase against master. You will need to lint your changes (should be small changes), you can check if it's valid using make validate (or just use golint and go vet 😝).
  • If I run the interpolation/docker-compose.yml with any environment defined, I get :
WARN[0000] The IMAGE variable is not set. Substituting a blank string. 
INFO[0000] [0/1] [base]: Starting
ERRO[0000] Failed Starting base : 500 Internal Server Error: No command specified
ERRO[0000] Failed to start: base : 500 Internal Server Error: No command specified
FATA[0000] 500 Internal Server Error: No command specified

Using docker-compose I get :

# […] long stack >_<
    do_build=do_build,
  File "/code/compose/service.py", line 317, in ensure_image_exists
    self.image()
  File "/code/compose/service.py", line 332, in image
    return self.client.inspect_image(self.image_name)
  File "/code/.tox/py27/lib/python2.7/site-packages/docker/utils/decorators.py", line 18, in wrapped
    'image or container param is undefined'
docker.errors.NullResource: image or container param is undefined

The warning is good enough I think but I feel the 500 errors are a little bit weird.. But docker-compose doesn't do too much better it seems so.. for now I guess it's ok 😅.

Anyway, this looks good 😉.

Edit : also, could you squash your commits ? 😉

Fixes docker#40

Signed-off-by: Josh Curl <hello@joshcurl.com>
@vdemeester
Copy link
Collaborator

@joshwget what do you think of my comments on the tests ? 😸 (I'm okay merging without it, i't just nits 😉)

@joshwget
Copy link
Contributor Author

joshwget commented Oct 7, 2015

@vdemeester I think the 500 errors will go away when #34 is fixed, and I'm currently working on a PR for that! I also added the test cases you recommended.

@vdemeester
Copy link
Collaborator

@joshwget ah you're right 😝 I might need some sleep or glasses 😅.

LGTM

vdemeester added a commit that referenced this pull request Oct 7, 2015
Support interpolating environment variables
@vdemeester vdemeester merged commit 58ee701 into docker:master Oct 7, 2015
return "$", pos, true
case c == '{':
return parseVariableWithBraces(line, pos+1, mapping)
case c >= 'A' && c <= 'Z':
Copy link
Contributor

Choose a reason for hiding this comment

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

This is missing lowercase letters, which are valid in variable names.

Copy link
Contributor

Choose a reason for hiding this comment

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

I created #70 to address this.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants