From 8f6024153032d4f7a3406f43aaebe6c2c6be5cf6 Mon Sep 17 00:00:00 2001 From: "Yann E. MORIN" Date: Tue, 31 Oct 2023 11:22:17 +0100 Subject: [PATCH] utils/docker-run: propagate user's proxy settings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Cc: Ricardo Martincoski Signed-off-by: Thomas Petazzoni --- utils/docker-run | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/utils/docker-run b/utils/docker-run index 464cbf691f..79694474c1 100755 --- a/utils/docker-run +++ b/utils/docker-run @@ -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