Merge "Pick up proxy buildargs from environment"

This commit is contained in:
Jenkins 2016-01-26 11:50:04 +00:00 committed by Gerrit Code Review
commit 87355c231a
2 changed files with 57 additions and 1 deletions

View File

@ -203,6 +203,23 @@ class WorkerThread(threading.Thread):
return dest_archive
def update_buildargs(self):
buildargs = dict()
if self.conf.build_args:
buildargs = dict(self.conf.build_args)
proxy_vars = ('HTTP_PROXY', 'http_proxy', 'HTTPS_PROXY',
'https_proxy', 'FTP_PROXY', 'ftp_proxy',
'NO_PROXY', 'no_proxy')
for proxy_var in proxy_vars:
if proxy_var in os.environ and proxy_var not in buildargs:
buildargs[proxy_var] = os.environ.get(proxy_var)
if not buildargs:
return None
return buildargs
def builder(self, image):
LOG.debug('%s:Processing', image['name'])
if image['status'] == 'unmatched':
@ -255,13 +272,14 @@ class WorkerThread(threading.Thread):
pull = True if image['parent'] is None else False
image['logs'] = str()
buildargs = self.update_buildargs()
for response in self.dc.build(path=image['path'],
tag=image['fullname'],
nocache=self.nocache,
rm=True,
pull=pull,
forcerm=self.forcerm,
buildargs=self.conf.build_args):
buildargs=buildargs):
stream = json.loads(response.decode('utf-8'))
if 'stream' in stream:

View File

@ -12,6 +12,7 @@
import fixtures
import mock
import os
from kolla.cmd import build
from kolla.tests import base
@ -34,6 +35,7 @@ class WorkerThreadTest(base.TestCase):
# NOTE(jeffrey4l): use a real, temporary dir
FAKE_IMAGE['path'] = self.useFixture(fixtures.TempDir()).path
@mock.patch.dict(os.environ, clear=True)
@mock.patch('docker.Client')
def test_build_image(self, mock_client):
queue = mock.Mock()
@ -48,6 +50,7 @@ class WorkerThreadTest(base.TestCase):
nocache=False, rm=True, pull=True, forcerm=True,
buildargs=None)
@mock.patch.dict(os.environ, clear=True)
@mock.patch('docker.Client')
def test_build_image_with_build_arg(self, mock_client):
build_args = {
@ -64,3 +67,38 @@ class WorkerThreadTest(base.TestCase):
path=FAKE_IMAGE['path'], tag=FAKE_IMAGE['fullname'],
nocache=False, rm=True, pull=True, forcerm=True,
buildargs=build_args)
@mock.patch.dict(os.environ, {'http_proxy': 'http://FROM_ENV:8080'},
clear=True)
@mock.patch('docker.Client')
def test_build_arg_from_env(self, mock_client):
build_args = {
'http_proxy': 'http://FROM_ENV:8080',
}
worker = build.WorkerThread(mock.Mock(),
mock.Mock(),
self.conf)
worker.builder(FAKE_IMAGE)
mock_client().build.assert_called_once_with(
path=FAKE_IMAGE['path'], tag=FAKE_IMAGE['fullname'],
nocache=False, rm=True, pull=True, forcerm=True,
buildargs=build_args)
@mock.patch.dict(os.environ, {'http_proxy': 'http://FROM_ENV:8080'},
clear=True)
@mock.patch('docker.Client')
def test_build_arg_precedence(self, mock_client):
build_args = {
'http_proxy': 'http://localhost:8080',
}
self.conf.set_override('build_args', build_args)
worker = build.WorkerThread(mock.Mock(),
mock.Mock(),
self.conf)
worker.builder(FAKE_IMAGE)
mock_client().build.assert_called_once_with(
path=FAKE_IMAGE['path'], tag=FAKE_IMAGE['fullname'],
nocache=False, rm=True, pull=True, forcerm=True,
buildargs=build_args)