diff --git a/docker/api/build.py b/docker/api/build.py index 47216a58fd..1dba760e5f 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) 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) 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..e98dac5ca7 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_buildkit_heredoc(self): + script = io.BytesIO('\n'.join([ + 'FROM scratch', + 'COPY <