diff --git a/kolla/common/config.py b/kolla/common/config.py index e2520bcf1c..933db4fe8f 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 2f19baadc4..cd59aa260a 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 be2dce7e94..9c3dc8abd3 100644 --- a/kolla/tests/test_build.py +++ b/kolla/tests/test_build.py @@ -87,11 +87,28 @@ 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): @@ -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 0000000000..d17e448ba8 --- /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