From 5e2ee3838d10ab3a2a37b711dbbbafba9815d06a Mon Sep 17 00:00:00 2001 From: Stuart Campbell Date: Tue, 1 Apr 2014 17:57:03 +1100 Subject: [PATCH] Trim trailing newlines from file-based envs Many editors add a trailing newline to files. This can result in slightly unexpected values for environment variables read from /etc/container_environment. --- image/my_init | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/image/my_init b/image/my_init index bb69a40..c7bb576 100755 --- a/image/my_init +++ b/image/my_init @@ -59,7 +59,10 @@ def import_envvars(clear_existing_environment = True): for envfile in listdir("/etc/container_environment"): name = os.path.basename(envfile) with open("/etc/container_environment/" + envfile, "r") as f: - value = f.read() + # Text files often end with a trailing newline, which we + # don't want to include in the env variable value. See + # https://github.com/phusion/baseimage-docker/pull/49 + value = re.sub('\n\Z', '', f.read()) new_env[name] = value if clear_existing_environment: os.environ.clear()