Skip to content

Commit 06b23aa

Browse files
committed
Add support for building with buildkit
1 parent 6e6a273 commit 06b23aa

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

docker/api/build.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def build(self, path=None, tag=None, quiet=False, fileobj=None,
1616
decode=False, buildargs=None, gzip=False, shmsize=None,
1717
labels=None, cache_from=None, target=None, network_mode=None,
1818
squash=None, extra_hosts=None, platform=None, isolation=None,
19-
use_config_proxy=True):
19+
version=None, use_config_proxy=True):
2020
"""
2121
Similar to the ``docker build`` command. Either ``path`` or ``fileobj``
2222
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,
101101
platform (str): Platform in the format ``os[/arch[/variant]]``
102102
isolation (str): Isolation technology used during build.
103103
Default: `None`.
104+
version (str): Version of the builder backend to use.
105+
- `1` is the first generation classic (deprecated) builder in the Docker daemon (default)
106+
- `2` is [BuildKit](https://github.com/moby/buildkit)
107+
Default: `None`.
104108
use_config_proxy (bool): If ``True``, and if the docker client
105109
configuration file (``~/.docker/config.json`` by default)
106110
contains a proxy configuration, the corresponding environment
@@ -253,6 +257,13 @@ def build(self, path=None, tag=None, quiet=False, fileobj=None,
253257
)
254258
params['isolation'] = isolation
255259

260+
if version is not None:
261+
if utils.version_lt(self._version, '1.38'):
262+
raise errors.InvalidVersion(
263+
'version was only introduced in API version 1.38'
264+
)
265+
params['version'] = version
266+
256267
if context is not None:
257268
headers = {'Content-Type': 'application/tar'}
258269
if encoding:

tests/integration/api_build_test.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,27 @@ def test_build_isolation(self):
201201
for _chunk in stream:
202202
pass
203203

204+
@requires_api_version('1.38')
205+
def test_build_with_buildkit(self):
206+
script = io.BytesIO('\n'.join([
207+
'FROM scratch',
208+
'COPY <<EOF greeting.txt',
209+
'hello world',
210+
'EOF'
211+
]).encode('ascii'))
212+
213+
self.tmp_imgs.append('buildkit')
214+
215+
stream = self.client.build(
216+
fileobj=script, tag='buildkit',
217+
version='2'
218+
)
219+
220+
for _chunk in stream:
221+
pass
222+
223+
assert self.client.inspect_image('buildkit')
224+
204225
@requires_api_version('1.23')
205226
def test_build_labels(self):
206227
script = io.BytesIO('\n'.join([

0 commit comments

Comments
 (0)