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

Make defaults work with nested env variables ie: ${FOO:-${HOME}/bar} #496

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

vito-c
Copy link
Contributor

@vito-c vito-c commented Sep 29, 2017

Signed-off-by: GodFather [email protected]

@jwreagor
Copy link

👍 It would be great to get this in since I've seen this fail on some of my compose files.

@vito-c
Copy link
Contributor Author

vito-c commented Oct 23, 2017

@vdemeester how's it looking on this one? :)

Copy link
Collaborator

@vdemeester vdemeester left a comment

Choose a reason for hiding this comment

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

Overall looks good to me, but I don't think it's supported on docker-compose.. So I wonder if we should make it optional somehow 👼

@vito-c
Copy link
Contributor Author

vito-c commented Oct 30, 2017

It feels like they actually have a bug in their code. The default string is not interpolated correctly. If you try something like this echo ${ABC:-${HOME}} you'll notice it will output your homedir.

---
version: '3'
services:
    test.env:
        container_name: test.env
        image: alpine
        environment:
            FOO: ${ABC:-foo}
        command: env

output:

Recreating test.env ...
Recreating test.env ... done
Attaching to test.env
test.env    | PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
test.env    | HOSTNAME=0e6eab0bcf66
test.env    | FOO=foo
test.env    | no_proxy=*.local, 169.254/16
test.env    | HOME=/root
test.env exited with code 0

and

---
version: '3'
services:
    test.env:
        container_name: test.env
        image: alpine
        environment:
            FOO: ${ABC:-${HOME}}
        command: env

output:

Recreating test.env ...
Recreating test.env ... done
Attaching to test.env
test.env    | PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
test.env    | HOSTNAME=6fa2fe19685b
test.env    | FOO=${HOME}
test.env    | no_proxy=*.local, 169.254/16
test.env    | HOME=/root
test.env exited with code 0

@vdemeester
Copy link
Collaborator

Yeah, that's why I would like to make this behavior optional (so ppl can opt-in or opt-out of the behavior to get the same as docker-compose.)

@vito-c
Copy link
Contributor Author

vito-c commented Nov 2, 2017

sweet how would I go about adding the optional flag?

@vdemeester
Copy link
Collaborator

@vito-c I'm not sure yet. I would probably make Interpolate configurable (https://github.com/vito-c/libcompose/blob/628498254cf9da3ab00dad397b64a17d11d65140/config/interpolation.go#L184) that would be disabled by default (on libcompose binary).

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.

3 participants