From 77bd2e922d7545852a460978b23ea015cf3fd721 Mon Sep 17 00:00:00 2001 From: Felipe Santos Date: Fri, 27 Jun 2025 19:41:51 -0300 Subject: [PATCH 1/3] Add support for building with buildkit Signed-off-by: Felipe Santos --- docker/api/build.py | 13 ++++++++++++- tests/integration/api_build_test.py | 21 +++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/docker/api/build.py b/docker/api/build.py index 47216a58fd..59d711f0c2 100644 --- a/docker/api/build.py +++ b/docker/api/build.py @@ -16,7 +16,7 @@ def build(self, path=None, tag=None, quiet=False, fileobj=None, decode=False, buildargs=None, gzip=False, shmsize=None, labels=None, cache_from=None, target=None, network_mode=None, squash=None, extra_hosts=None, platform=None, isolation=None, - use_config_proxy=True): + version=None, use_config_proxy=True): """ Similar to the ``docker build`` command. Either ``path`` or ``fileobj`` needs to be set. ``path`` can be a local path (to a directory @@ -101,6 +101,10 @@ def build(self, path=None, tag=None, quiet=False, fileobj=None, platform (str): Platform in the format ``os[/arch[/variant]]`` isolation (str): Isolation technology used during build. Default: `None`. + version (str): Version of the builder backend to use. + - `1` is the first generation classic (deprecated) builder in the Docker daemon (default) + - `2` is [BuildKit](https://github.com/moby/buildkit) + Default: `None`. use_config_proxy (bool): If ``True``, and if the docker client configuration file (``~/.docker/config.json`` by default) contains a proxy configuration, the corresponding environment @@ -253,6 +257,13 @@ def build(self, path=None, tag=None, quiet=False, fileobj=None, ) params['isolation'] = isolation + if version is not None: + if utils.version_lt(self._version, '1.38'): + raise errors.InvalidVersion( + 'version was only introduced in API version 1.38' + ) + params['version'] = version + if context is not None: headers = {'Content-Type': 'application/tar'} if encoding: diff --git a/tests/integration/api_build_test.py b/tests/integration/api_build_test.py index 0f560159b3..15c86ae1cd 100644 --- a/tests/integration/api_build_test.py +++ b/tests/integration/api_build_test.py @@ -201,6 +201,27 @@ def test_build_isolation(self): for _chunk in stream: pass + @requires_api_version('1.38') + def test_build_with_buildkit(self): + script = io.BytesIO('\n'.join([ + 'FROM scratch', + 'COPY < Date: Mon, 30 Jun 2025 01:39:51 -0300 Subject: [PATCH 2/3] Clarify test intention Signed-off-by: Felipe Santos --- tests/integration/api_build_test.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/integration/api_build_test.py b/tests/integration/api_build_test.py index 15c86ae1cd..e98dac5ca7 100644 --- a/tests/integration/api_build_test.py +++ b/tests/integration/api_build_test.py @@ -202,7 +202,7 @@ def test_build_isolation(self): pass @requires_api_version('1.38') - def test_build_with_buildkit(self): + def test_build_buildkit_heredoc(self): script = io.BytesIO('\n'.join([ 'FROM scratch', 'COPY < Date: Mon, 30 Jun 2025 01:40:32 -0300 Subject: [PATCH 3/3] Clarify version='2' limitations Co-authored-by: Akihiro Suda Signed-off-by: Felipe Santos --- docker/api/build.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker/api/build.py b/docker/api/build.py index 59d711f0c2..1dba760e5f 100644 --- a/docker/api/build.py +++ b/docker/api/build.py @@ -103,7 +103,7 @@ def build(self, path=None, tag=None, quiet=False, fileobj=None, Default: `None`. version (str): Version of the builder backend to use. - `1` is the first generation classic (deprecated) builder in the Docker daemon (default) - - `2` is [BuildKit](https://github.com/moby/buildkit) + - `2` is [BuildKit](https://github.com/moby/buildkit) over the REST API endpoint provided by the Docker daemon. This mode doesn't use the BuildKit gRPC API, and lacks support for advanced features such as secret mounts. Default: `None`. use_config_proxy (bool): If ``True``, and if the docker client configuration file (``~/.docker/config.json`` by default)