diff mbox series

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

Message ID 31538ce771c6cd9f4719a969740b6ff04e3c8e62.1698747732.git.yann.morin@orange.com
State Accepted
Headers show
Series [1/2] utils/docker: use host's network setup | expand

Commit Message

Yann E. MORIN Oct. 31, 2023, 10:22 a.m. UTC
From: "Yann E. MORIN" <yann.morin@orange.com>

When dealing in 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 exists another type of proxy, socks4 or socks5, that
also requires custom setup that is not trivial to replicate in a
container, so is also left out as an exrcise 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>
---
 utils/docker-run | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
diff mbox series

Patch

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