diff options
author | Louis Blin <45168934+lbpdt@users.noreply.github.com> | 2021-03-25 16:38:37 +0000 |
---|---|---|
committer | Louis Blin <45168934+lbpdt@users.noreply.github.com> | 2021-03-25 23:29:54 +0000 |
commit | b3f68289df646a82c9b87d866244510ff1d2866a (patch) | |
tree | 67e0cfe413bf7f94974c738ea9d12d3626d6a46a /pkgs/build-support | |
parent | 06733bcf290555154666410f2fb30ee4a2aba6c0 (diff) |
dockerTools.streamLayeredImage: resolve duplicate env vars
For images running on Kubernetes, there is no guarantee on how duplicate
environment variables in the image config will be handled. This seems
to be different from Docker, where the last environment variable value
is consistently selected.
The current code for `streamLayeredImage` was exploiting that assumption
to easily propagate environment variables from the base image, leaving
duplicates unchecked. It should rather resolve these duplicates to
ensure consistent behavior on Docker and Kubernetes.
Diffstat (limited to 'pkgs/build-support')
-rw-r--r-- | pkgs/build-support/docker/stream_layered_image.py | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/pkgs/build-support/docker/stream_layered_image.py b/pkgs/build-support/docker/stream_layered_image.py index 3e5781ba1c80..d7c63eb43a78 100644 --- a/pkgs/build-support/docker/stream_layered_image.py +++ b/pkgs/build-support/docker/stream_layered_image.py @@ -202,7 +202,9 @@ def overlay_base_config(from_image, final_config): # Preserve environment from base image final_env = base_config.get("Env", []) + final_config.get("Env", []) if final_env: - final_config["Env"] = final_env + # Resolve duplicates (last one wins) and format back as list + resolved_env = {entry.split("=", 1)[0]: entry for entry in final_env} + final_config["Env"] = list(resolved_env.values()) return final_config |