Skip to content

Conversation

dfndr-1
Copy link
Contributor

@dfndr-1 dfndr-1 commented Jul 2, 2021

In case when env contain variables with newlines, the variables
substitution script fails, trying to use non-existent variables. Change
env mode to delim different env vars in output with NULL-byte instead of
newline.

In case when env contain variables with newlines, the variables substitution script fails, trying to use non-existent variables. Change env mode to delim different env vars in output with NULL-byte instead of newline.

local template defined_envs relative_path output_path subdir
defined_envs=$(printf '${%s} ' $(env | cut -d= -f1))
defined_envs=$(printf '${%s} ' $(env -0 | cut -z -d= -f1 | tr -d "\0"))
Copy link
Contributor

Choose a reason for hiding this comment

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

This probably won't work with Alpine's env right? 😬 😞

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm, yep, it won't... It's sad... Will try to find solution suitable for alpine as well.

BusyBox env have no -0 command option, so prev implementation isn't suitable for alpine based images.
Co-authored-by: Tianon Gravi <admwiggin@gmail.com>
@thresheek
Copy link
Member

Hi @dfndr-1, can you squash the commits please? I'd rather have one commit in the repo history.

Thanks!

thresheek pushed a commit that referenced this pull request Sep 13, 2022
In case when env contain variables with newlines, the variables substitution script fails, trying to use non-existent variables. See #560 for more details. Co-authored-by: Tianon Gravi <admwiggin@gmail.com>
@thresheek
Copy link
Member

Merged in 0d38d49

@karlderkaefer
Copy link
Contributor

@dfndr-1 I could not reproduce the issue with multiline values. Could give an example for issue? https://gist.github.com/karlderkaefer/c5059afd4c4432b0093d0b08d4128e44#file-nginx-envsubst-sh-L5-L12

@thresheek
Copy link
Member

Looking at busybox 3.14 release notes:

 env: implement -0 

alpine:3.16, which we currently use, has busybox 3.15, so we're safe to use env -0 there. I'll adapt the entrypoint to use it. Note that using xargs and a shell spawned for each variable seems to use a lot of CPU unneccessary, see nginx/docker-nginx-unprivileged#107 for more details.

@thresheek
Copy link
Member

Or maybe we don't even need env | cut here, and can do it with awk

@thresheek
Copy link
Member

I think something like that would do, but I'm going to do some more testing tomorrow:

defined_envs=$(printf '${%s} ' $(awk "END { for (name in ENVIRON) { print ( name ~ /${filter}/ ) ? name : \"\" } }" < /dev/null )) 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

5 participants