diff options
| -rw-r--r-- | doc/source/admin/image-building.rst | 22 | ||||
| -rw-r--r-- | kolla/common/config.py | 8 | ||||
| -rw-r--r-- | kolla/image/tasks.py | 1 | ||||
| -rw-r--r-- | kolla/tests/test_build.py | 13 | ||||
| -rw-r--r-- | releasenotes/notes/support-image-cross-compile-3b1dc348d742e96d.yaml | 5 |
5 files changed, 44 insertions, 5 deletions
diff --git a/doc/source/admin/image-building.rst b/doc/source/admin/image-building.rst index f0c0e84c1..81e04f401 100644 --- a/doc/source/admin/image-building.rst +++ b/doc/source/admin/image-building.rst @@ -526,6 +526,28 @@ variables that will be picked up from the user env: Also these variables could be overwritten using ``--build-args``, which have precedence. +Cross-compiling +--------------- + +It is possible to cross-compile container images in order to, e.g., build +``aarch64`` images on a ``x86_64`` machine. + +To build ``ARM`` images on ``x86_64`` platform, pass the ``--base-arch`` and +``--platform`` arguments: + +.. code-block:: console + + kolla-build --platform linux/arm64 --base-arch aarch64 + +.. note:: + + To make this work on x86_64 platform you can use tools like: `qemu-user-static + <https://github.com/multiarch/qemu-user-static>`_ or `binfmt + <https://github.com/tonistiigi/binfmt>`_. + + To make this work on Apple Silicon you can use Docker Desktop or Podman + Desktop to build ``x86_64`` or native ``ARM`` images. + Known issues ============ diff --git a/kolla/common/config.py b/kolla/common/config.py index 2d12314a8..3a74c7dc6 100644 --- a/kolla/common/config.py +++ b/kolla/common/config.py @@ -143,6 +143,10 @@ if hostarch == 'aarch64': elif hostarch == 'x86_64': debianarch = 'amd64' +# NOTE: Apple Silicon reports as arm64 which is aarch64 +if hostarch == "arm64": + hostarch = "aarch64" + _CLI_OPTS = [ cfg.StrOpt('base', short='b', default='rocky', choices=BASE_OS_DISTRO, @@ -183,6 +187,10 @@ _CLI_OPTS = [ help='The network mode for Docker build. Example: host'), cfg.BoolOpt('cache', default=True, help='Use the container engine cache when building'), + cfg.StrOpt('platform', default=None, + help=('The platform to use for a cross-compile build. Should ' + 'be set in conjunction with "--base-arch" argument. ' + 'Example: "--platform linux/arm64 --base-arch aarch64"')), cfg.MultiOpt('profile', types.String(), short='p', help=('Build a pre-defined set of images, see [profiles]' ' section in config. The default profiles are:' diff --git a/kolla/image/tasks.py b/kolla/image/tasks.py index e9790b708..1242ecd8d 100644 --- a/kolla/image/tasks.py +++ b/kolla/image/tasks.py @@ -412,6 +412,7 @@ class BuildTask(EngineTask): network_mode=self.conf.network_mode, pull=pull, forcerm=self.forcerm, + platform=self.conf.platform, buildargs=buildargs, **kwargs)[1]: if self.conf.engine == engine.Engine.PODMAN.value: diff --git a/kolla/tests/test_build.py b/kolla/tests/test_build.py index 7ffa6827a..afbfe009c 100644 --- a/kolla/tests/test_build.py +++ b/kolla/tests/test_build.py @@ -168,7 +168,7 @@ class TasksTest(base.TestCase): mock_client().images.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.build_kwargs) + forcerm=True, platform=None, buildargs=None, **self.build_kwargs) self.assertTrue(builder.success) @@ -185,7 +185,7 @@ class TasksTest(base.TestCase): mock_client().images.build.assert_called_once_with( path=self.image.path, tag=self.image.canonical_name, network_mode='bridge', nocache=False, rm=True, pull=True, - forcerm=True, buildargs=None, **self.build_kwargs) + forcerm=True, platform=None, buildargs=None, **self.build_kwargs) self.assertTrue(builder.success) @@ -205,7 +205,8 @@ class TasksTest(base.TestCase): mock_client().images.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=build_args, **self.build_kwargs) + forcerm=True, platform=None, buildargs=build_args, + **self.build_kwargs) self.assertTrue(builder.success) @@ -224,7 +225,8 @@ class TasksTest(base.TestCase): mock_client().images.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=build_args, **self.build_kwargs) + forcerm=True, platform=None, buildargs=build_args, + **self.build_kwargs) self.assertTrue(builder.success) @@ -245,7 +247,8 @@ class TasksTest(base.TestCase): mock_client().images.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=build_args, **self.build_kwargs) + forcerm=True, platform=None, buildargs=build_args, + **self.build_kwargs) self.assertTrue(builder.success) diff --git a/releasenotes/notes/support-image-cross-compile-3b1dc348d742e96d.yaml b/releasenotes/notes/support-image-cross-compile-3b1dc348d742e96d.yaml new file mode 100644 index 000000000..76e12ee53 --- /dev/null +++ b/releasenotes/notes/support-image-cross-compile-3b1dc348d742e96d.yaml @@ -0,0 +1,5 @@ +--- +features: + - | + Add support for cross-compile. Enable creation of container images + on emulated architectures. |
