Skip to content

Commit

Permalink
Add entrypoint script which automatically propagates *_PROXY env vars…
Browse files Browse the repository at this point in the history
… to docker config
  • Loading branch information
g-braeunlich committed Jan 13, 2021
1 parent b464a5e commit e04a14a
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
35 changes: 35 additions & 0 deletions docker/entrypoint
Original file line number Diff line number Diff line change
@@ -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 <<EOF > "$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 <<EOF >> "$docker_cfg"
}
}
}
EOF
}

write_config /root/.docker/config.json

exec "$@"

0 comments on commit e04a14a

Please sign in to comment.