Skip to content
This repository was archived by the owner on Jul 18, 2025. It is now read-only.

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

Open
vito-c wants to merge 2 commits into
docker-archive-public:masterfrom
vito-c:parser
Open

Make defaults work with nested env variables ie: ${FOO:-${HOME}/bar}#496
vito-c wants to merge 2 commits into
docker-archive-public:masterfrom
vito-c:parser

Conversation

@vito-c

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

Copy link
Copy Markdown
Contributor

Signed-off-by: GodFather vito.blog@gmail.com

Signed-off-by: GodFather <vito.blog@gmail.com>
Signed-off-by: GodFather <vito.blog@gmail.com>
@jwreagor

Copy link
Copy Markdown

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

@vito-c

vito-c commented Oct 23, 2017

Copy link
Copy Markdown
Contributor Author

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

@vdemeester vdemeester left a comment

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.

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

vito-c commented Oct 30, 2017

Copy link
Copy Markdown
Contributor Author

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
Copy Markdown
Contributor

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

vito-c commented Nov 2, 2017

Copy link
Copy Markdown
Contributor Author

sweet how would I go about adding the optional flag?

@vdemeester

Copy link
Copy Markdown
Contributor

@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