-
Notifications
You must be signed in to change notification settings - Fork 370
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add entrypoint script which automatically propagates *_PROXY env vars…
… to docker config
- Loading branch information
1 parent
b464a5e
commit e04a14a
Showing
2 changed files
with
40 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 "$@" |