utils/docker-run: propagate user's proxy settings

When dealing with enterprise-grade networks, it is more often than not
the case that the wider internet is unreachable but through proxies.

There is a usual set of variables that users can set in the
environment to point various tools (curl, git...) to use those
proxies.

Propagate those variables inside the container.

Note that there are a few tools (e.g. cvs, svn) that may not recognise
those variables; instead, they require custom setup that is too
complex to handle, so is left as an exercise to interested parties.

Similarly, there are other types of proxy, socks4 or socks5, that also
require custom setup that is not trivial to replicate in a container,
so is also left out as an exercise for interested parties.

In the large majority of cases, those few variables are enough to Make
Things Work™.

Signed-off-by: Yann E. MORIN <yann.morin@orange.com>
Cc: Ricardo Martincoski <ricardo.martincoski@datacom.com.br>
Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
This commit is contained in:
Yann E. MORIN 2023-10-31 11:22:17 +01:00 committed by Thomas Petazzoni
parent 893bd56974
commit 8f60241530

View File

@ -29,6 +29,26 @@ declare -a mountpoints=(
"$(pwd)"
)
# curl lists (and recognises and uses) other types of *_proxy variables,
# but only those make sense for Buildroot:
for env in all_proxy http_proxy https_proxy ftp_proxy no_proxy; do
if [ "${!env}" ]; then
docker_opts+=( --env "${env}" )
# The lower-case variant takes precedence on the upper-case one
# (dixit curl)
continue
fi
# http_proxy is only lower-case (dixit curl)
if [ "${env}" = http_proxy ]; then
continue
fi
# All the others also exist in the upper-case variant
env="${env^^}"
if [ "${!env}" ]; then
docker_opts+=( --env "${env}" )
fi
done
# Empty GIT_DIR means that we are not in a workdir, *and* git is too old
# to know about worktrees, so we're not in a worktree either. So it means
# we're in the main git working copy, and thus we don't need to mount the