Expose the docker build_arg to build.py
With this implement, we can add variables at building stage. For example, add HTTP_PROXY and NO_PROXY when needed like below. build.py --build-args \ HTTP_PROXY:http://127.0.0.1:8080,NO_PROXY:127.0.0.1 More info about build_arg, pls check[0] [0] https://docs.docker.com/engine/reference/commandline/build/#set-build-time-variables-build-arg DocImpact Implements: bp add-buildargs Change-Id: I29ed7f536670fef59d697603dc562a69d90743c9
This commit is contained in:
parent
d4490ea2bc
commit
7093d37f18
@ -261,7 +261,8 @@ class WorkerThread(Thread):
|
|||||||
nocache=self.nocache,
|
nocache=self.nocache,
|
||||||
rm=True,
|
rm=True,
|
||||||
pull=pull,
|
pull=pull,
|
||||||
forcerm=self.forcerm):
|
forcerm=self.forcerm,
|
||||||
|
buildargs=self.conf.build_args):
|
||||||
stream = json.loads(response.decode('utf-8'))
|
stream = json.loads(response.decode('utf-8'))
|
||||||
|
|
||||||
if 'stream' in stream:
|
if 'stream' in stream:
|
||||||
|
@ -63,6 +63,8 @@ _CLI_OPTS = [
|
|||||||
cfg.BoolOpt('debug', short='d', default=False,
|
cfg.BoolOpt('debug', short='d', default=False,
|
||||||
deprecated_group='kolla-build',
|
deprecated_group='kolla-build',
|
||||||
help='Turn on debugging log level'),
|
help='Turn on debugging log level'),
|
||||||
|
cfg.DictOpt('build-args',
|
||||||
|
help='Set docker build time variables'),
|
||||||
cfg.StrOpt('include-header', short='i',
|
cfg.StrOpt('include-header', short='i',
|
||||||
deprecated_group='kolla-build',
|
deprecated_group='kolla-build',
|
||||||
help=('Path to custom file to be added at '
|
help=('Path to custom file to be added at '
|
||||||
|
@ -45,4 +45,22 @@ class WorkerThreadTest(base.TestCase):
|
|||||||
|
|
||||||
mock_client().build.assert_called_once_with(
|
mock_client().build.assert_called_once_with(
|
||||||
path=FAKE_IMAGE['path'], tag=FAKE_IMAGE['fullname'],
|
path=FAKE_IMAGE['path'], tag=FAKE_IMAGE['fullname'],
|
||||||
nocache=False, rm=True, pull=True, forcerm=True)
|
nocache=False, rm=True, pull=True, forcerm=True,
|
||||||
|
buildargs=None)
|
||||||
|
|
||||||
|
@mock.patch('docker.Client')
|
||||||
|
def test_build_image_with_build_arg(self, mock_client):
|
||||||
|
build_args = {
|
||||||
|
'HTTP_PROXY': 'http://localhost:8080',
|
||||||
|
'NO_PROXY': '127.0.0.1'
|
||||||
|
}
|
||||||
|
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)
|
||||||
|
Loading…
Reference in New Issue
Block a user