docker-nginx icon indicating copy to clipboard operation
docker-nginx copied to clipboard

FIX argument list too long by not collecting env

Open lagerspetz-starship opened this issue 1 year ago • 0 comments

When there are many environment variables defined for the image that nginx runs in, the envsubst script fails to work with the following error message:

20-envsubst-on-templates.sh: Running envsubst on /etc/nginx/templates/default.conf.template to /etc/nginx/conf.d/default.conf
/docker-entrypoint.d/20-envsubst-on-templates.sh: line 26: envsubst: Argument list too long

This is because defined_envs is used to collect the whole environment into one line and passed to envsubst, making for a very long command. We can fix this by not using defined_envs at all; this way envsubst will look for anything in current environment by default. However variables like $uri will get replaced by empty strings in this case, so some special handling is needed.

If we limit the environment lookups to variables actually defined in any template files in the templates directory, reading those files for ${variable} style references, and creating defined_envs based on that, we avoid overriding simple format references like $uri. However once the number of variables used in a template grows long enough, it would hit the same problem. In this case, users can avoid the issue by splitting their variable use to different templates.

This could still be improved by grepping env for the found template variable references so only non-empty substitutions are done. However that might result in a lot of grep statements. What do you think?

lagerspetz-starship avatar Aug 02 '22 08:08 lagerspetz-starship