From e04a14a7ccb45a3e0d3ee242a123b71626067f96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gerhard=20Br=C3=A4unlich?= Date: Wed, 13 Jan 2021 13:32:17 +0100 Subject: [PATCH] Add entrypoint script which automatically propagates *_PROXY env vars to docker config --- Dockerfile | 5 +++++ docker/entrypoint | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100755 docker/entrypoint diff --git a/Dockerfile b/Dockerfile index 54f5a24e..818bf865 100644 --- a/Dockerfile +++ b/Dockerfile @@ -30,5 +30,10 @@ RUN pip3 install --no-cache-dir /tmp/wheelhouse/*.whl \ COPY ./docker/git-credential-env /usr/local/bin/git-credential-env RUN git config --system credential.helper env +# add entrypoint +COPY ./docker/entrypoint /usr/local/bin/entrypoint +RUN chmod +x /usr/local/bin/entrypoint +ENTRYPOINT ["/usr/local/bin/entrypoint"] + # Used for testing purpose in ports.py EXPOSE 52000 diff --git a/docker/entrypoint b/docker/entrypoint new file mode 100755 index 00000000..9400a6d9 --- /dev/null +++ b/docker/entrypoint @@ -0,0 +1,35 @@ +#!/bin/sh +set -e + +function write_config() { + # Checks for the environment variables *_PROXY. + # If at least one variables is found, it writes all found variables + # into a docker config file + docker_cfg="$1" + httpProxy="${HTTP_PROXY:-$http_proxy}" + httpsProxy="${HTTPS_PROXY:-$https_proxy}" + noProxy="${NO_PROXY:-$no_proxy}" + # If no proxy vars are set, do nothing + [ -z "$httpProxy" ] && [ -z "$httpsProxy" ] && [ -z "$noProxy" ] && return + [ -f "$1" ] && echo "$1 already exists. Not touching it. You are responsible for setting your proxy vars there yourself" >&2 && return + sep="" + mkdir -p "$(dirname $docker_cfg)" + cat < "$docker_cfg" +{ +"proxies": { + "default": { +EOF + [ -n "$httpProxy" ] && echo -ne "$sep"' "httpProxy": "'"$httpProxy"'"' >> "$docker_cfg" && sep=",\n" + [ -n "$httpsProxy" ] && echo -ne "$sep"' "httpsProxy": "'"$httpsProxy"'"' >> "$docker_cfg" && sep=",\n" + [ -n "$noProxy" ] && echo -ne "$sep"' "noProxy": "'"$noProxy"'"' >> "$docker_cfg" && sep=",\n" + cat <> "$docker_cfg" + + } +} +} +EOF +} + +write_config /root/.docker/config.json + +exec "$@"