Skip to content

Commit e04a14a

Browse files
committed
Add entrypoint script which automatically propagates *_PROXY env vars to docker config
1 parent b464a5e commit e04a14a

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

Dockerfile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,10 @@ RUN pip3 install --no-cache-dir /tmp/wheelhouse/*.whl \
3030
COPY ./docker/git-credential-env /usr/local/bin/git-credential-env
3131
RUN git config --system credential.helper env
3232

33+
# add entrypoint
34+
COPY ./docker/entrypoint /usr/local/bin/entrypoint
35+
RUN chmod +x /usr/local/bin/entrypoint
36+
ENTRYPOINT ["/usr/local/bin/entrypoint"]
37+
3338
# Used for testing purpose in ports.py
3439
EXPOSE 52000

docker/entrypoint

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/bin/sh
2+
set -e
3+
4+
function write_config() {
5+
# Checks for the environment variables *_PROXY.
6+
# If at least one variables is found, it writes all found variables
7+
# into a docker config file
8+
docker_cfg="$1"
9+
httpProxy="${HTTP_PROXY:-$http_proxy}"
10+
httpsProxy="${HTTPS_PROXY:-$https_proxy}"
11+
noProxy="${NO_PROXY:-$no_proxy}"
12+
# If no proxy vars are set, do nothing
13+
[ -z "$httpProxy" ] && [ -z "$httpsProxy" ] && [ -z "$noProxy" ] && return
14+
[ -f "$1" ] && echo "$1 already exists. Not touching it. You are responsible for setting your proxy vars there yourself" >&2 && return
15+
sep=""
16+
mkdir -p "$(dirname $docker_cfg)"
17+
cat <<EOF > "$docker_cfg"
18+
{
19+
"proxies": {
20+
"default": {
21+
EOF
22+
[ -n "$httpProxy" ] && echo -ne "$sep"' "httpProxy": "'"$httpProxy"'"' >> "$docker_cfg" && sep=",\n"
23+
[ -n "$httpsProxy" ] && echo -ne "$sep"' "httpsProxy": "'"$httpsProxy"'"' >> "$docker_cfg" && sep=",\n"
24+
[ -n "$noProxy" ] && echo -ne "$sep"' "noProxy": "'"$noProxy"'"' >> "$docker_cfg" && sep=",\n"
25+
cat <<EOF >> "$docker_cfg"
26+
27+
}
28+
}
29+
}
30+
EOF
31+
}
32+
33+
write_config /root/.docker/config.json
34+
35+
exec "$@"

0 commit comments

Comments
 (0)