aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Schultz <aschultz@redhat.com>2018-04-19 16:49:06 -0600
committerMartin André <m.andre@redhat.com>2018-04-20 06:28:05 +0000
commit00bdb6d01f9492f40f9091df7905f751b54c98bf (patch)
tree042bb9b51fd44683b9cf7da90ba7545c64b82295
parentda329dd7be0a4693b947272929581741906f33ad (diff)
downloadkolla-00bdb6d01f9492f40f9091df7905f751b54c98bf.tar.gz
kolla-00bdb6d01f9492f40f9091df7905f751b54c98bf.zip
Add network_mode for image building
Add the ability to specify a different network_mode when running the image builds. Under the covers the default is to use bridge networking but if that is unavailable or a user would like to specify a different networking method they can now do so using the [DEFAULT]\network_mode configuration. Change-Id: I1d2398273b57ca4d52bbfacbc896ffecc58bc54b
-rwxr-xr-xkolla/common/config.py2
-rwxr-xr-xkolla/image/build.py1
-rw-r--r--kolla/tests/test_build.py25
-rw-r--r--releasenotes/notes/network_mode-build-configuration-5e7c15b84dae9199.yaml8
4 files changed, 32 insertions, 4 deletions
diff --git a/kolla/common/config.py b/kolla/common/config.py
index e2520bcf1..933db4fe8 100755
--- a/kolla/common/config.py
+++ b/kolla/common/config.py
@@ -204,6 +204,8 @@ _CLI_OPTS = [
help='Show all available images (filtering supported)'),
cfg.StrOpt('namespace', short='n', default='kolla',
help='The Docker namespace name'),
+ cfg.StrOpt('network_mode', default=None,
+ help='The network mode for Docker build. Example: host'),
cfg.BoolOpt('cache', default=True,
help='Use the Docker cache when building'),
cfg.MultiOpt('profile', types.String(), short='p',
diff --git a/kolla/image/build.py b/kolla/image/build.py
index 2f19baadc..cd59aa260 100755
--- a/kolla/image/build.py
+++ b/kolla/image/build.py
@@ -570,6 +570,7 @@ class BuildTask(DockerTask):
tag=image.canonical_name,
nocache=not self.conf.cache,
rm=True,
+ network_mode=self.conf.network_mode,
pull=pull,
forcerm=self.forcerm,
buildargs=buildargs):
diff --git a/kolla/tests/test_build.py b/kolla/tests/test_build.py
index be2dce7e9..9c3dc8abd 100644
--- a/kolla/tests/test_build.py
+++ b/kolla/tests/test_build.py
@@ -87,13 +87,30 @@ class TasksTest(base.TestCase):
mock_client().build.assert_called_once_with(
path=self.image.path, tag=self.image.canonical_name,
- nocache=False, rm=True, pull=True, forcerm=True,
+ network_mode=None, nocache=False, rm=True, pull=True, forcerm=True,
buildargs=None)
self.assertTrue(builder.success)
@mock.patch.dict(os.environ, clear=True)
@mock.patch('docker.APIClient')
+ def test_build_image_with_network_mode(self, mock_client):
+ self.dc = mock_client
+ push_queue = mock.Mock()
+ self.conf.set_override('network_mode', 'host')
+
+ builder = build.BuildTask(self.conf, self.image, push_queue)
+ builder.run()
+
+ mock_client().build.assert_called_once_with(
+ path=self.image.path, tag=self.image.canonical_name,
+ network_mode='host', nocache=False, rm=True, pull=True,
+ forcerm=True, buildargs=None)
+
+ self.assertTrue(builder.success)
+
+ @mock.patch.dict(os.environ, clear=True)
+ @mock.patch('docker.APIClient')
def test_build_image_with_build_arg(self, mock_client):
self.dc = mock_client
build_args = {
@@ -107,7 +124,7 @@ class TasksTest(base.TestCase):
mock_client().build.assert_called_once_with(
path=self.image.path, tag=self.image.canonical_name,
- nocache=False, rm=True, pull=True, forcerm=True,
+ network_mode=None, nocache=False, rm=True, pull=True, forcerm=True,
buildargs=build_args)
self.assertTrue(builder.success)
@@ -126,7 +143,7 @@ class TasksTest(base.TestCase):
mock_client().build.assert_called_once_with(
path=self.image.path, tag=self.image.canonical_name,
- nocache=False, rm=True, pull=True, forcerm=True,
+ network_mode=None, nocache=False, rm=True, pull=True, forcerm=True,
buildargs=build_args)
self.assertTrue(builder.success)
@@ -147,7 +164,7 @@ class TasksTest(base.TestCase):
mock_client().build.assert_called_once_with(
path=self.image.path, tag=self.image.canonical_name,
- nocache=False, rm=True, pull=True, forcerm=True,
+ network_mode=None, nocache=False, rm=True, pull=True, forcerm=True,
buildargs=build_args)
self.assertTrue(builder.success)
diff --git a/releasenotes/notes/network_mode-build-configuration-5e7c15b84dae9199.yaml b/releasenotes/notes/network_mode-build-configuration-5e7c15b84dae9199.yaml
new file mode 100644
index 000000000..d17e448ba
--- /dev/null
+++ b/releasenotes/notes/network_mode-build-configuration-5e7c15b84dae9199.yaml
@@ -0,0 +1,8 @@
+---
+features:
+ - |
+ Adds new configuration parameter `[DEFAULT]\network_mode` that is used
+ when building the images. By default this is unset which will default to
+ the docker environment's default setting. You can specify 'host' which
+ would use the host's network when building the images. For other options,
+ see https://docs.docker.com/engine/reference/run/#network-settings