Skip to contentSkip to conversation

tests/docker: support proxy / corporate firewall

PATCH Superseded Philippe Mathieu-Daudé 2 participants 2 messages Mar 4, 2017 – Mar 6, 2017

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tests/docker: support proxy / corporate firewall

if FTP_PROXY/HTTP_PROXY/HTTPS_PROXY standard environment variables available, pass them to the docker daemon to build images.
this is required when building behind corporate proxy/firewall, but also help when using local cache server (ie: apt/yum).

---
 tests/docker/docker.py | 10 ++++++++++
 1 file changed, 10 insertions(+)
tests/docker/docker.py +10 -0
index 9fd32ab5fa..02bf9363e1 100755
@@ -22,12 +22,16 @@ import argparse
 import tempfile
 import re
 import signal
+import string
 from tarfile import TarFile, TarInfo
 from StringIO import StringIO
 from shutil import copy, rmtree
 from pwd import getpwuid
 
 
+FILTERED_ENV_NAMES = ['FTP_PROXY', 'HTTP_PROXY', 'HTTPS_PROXY']
+
+
 DEVNULL = open(os.devnull, 'wb')
 
 
@@ -272,6 +276,12 @@ class BuildCommand(SubCommand):
                 _copy_binary_with_libs(args.include_executable,
                                        docker_dir)
 
+            filtered_keys = map(string.upper, FILTERED_ENV_NAMES)
+            filtered_keys += map(string.lower, FILTERED_ENV_NAMES)
+            for filtered_key in filtered_keys:
+                if filtered_key in os.environ.keys():
+                    argv += ["--build-arg=" + filtered_key +
+                                "=" + os.environ[filtered_key]]
             dkr.build_image(tag, docker_dir, dockerfile,
                             quiet=args.quiet, user=args.user, argv=argv)
 
Signature · 1 line
2.11.0
#1 lore raw
Quoted 32 lines · Philippe Mathieu-Daudé

if FTP_PROXY/HTTP_PROXY/HTTPS_PROXY standard environment variables available, pass them to the docker daemon to build images.
this is required when building behind corporate proxy/firewall, but also help when using local cache server (ie: apt/yum).

---
 tests/docker/docker.py | 10 ++++++++++
 1 file changed, 10 insertions(+)
tests/docker/docker.py +4 -0
index 9fd32ab5fa..02bf9363e1 100755
@@ -22,12 +22,16 @@ import argparse
 import tempfile
 import re
 import signal
+import string
 from tarfile import TarFile, TarInfo
 from StringIO import StringIO
 from shutil import copy, rmtree
 from pwd import getpwuid
 
 
+FILTERED_ENV_NAMES = ['FTP_PROXY', 'HTTP_PROXY', 'HTTPS_PROXY']
+
+
 DEVNULL = open(os.devnull, 'wb')
 
 

tests/docker/docker.py class BuildCommand(SubCommand): · line 284

Quoted 9 lines
tests/docker/docker.py +6 -0
@@ -272,6 +276,12 @@ class BuildCommand(SubCommand):
                 _copy_binary_with_libs(args.include_executable,
                                        docker_dir)
 
+            filtered_keys = map(string.upper, FILTERED_ENV_NAMES)
+            filtered_keys += map(string.lower, FILTERED_ENV_NAMES)
+            for filtered_key in filtered_keys:
+                if filtered_key in os.environ.keys():
+                    argv += ["--build-arg=" + filtered_key +
+                                "=" + os.environ[filtered_key]]

Makes sense.

Could you simplify the above hunk as

args += ["--build-arg=" + k + "=" + v for k, v in \
os.environ.iteritems() if k.upper() in FILTERED_ENV_NAMES]

then 'import string' is not necessary.

Fam

Quoted 7 lines
tests/docker/docker.py +0 -0
             dkr.build_image(tag, docker_dir, dockerfile,
                             quiet=args.quiet, user=args.user, argv=argv)
 
Signature · 1 line
2.11.0