Repository: docker/docker-py

Issue:
support cache-from flag



Discussion:
I'm going to try and create a pr for this now.
@thomaschaaf neato

Resolving patch:
diff --git a/docker/api/build.py b/docker/api/build.py
--- a/docker/api/build.py
+++ b/docker/api/build.py
@@ -18,7 +18,7 @@ def build(self, path=None, tag=None, quiet=False, fileobj=None,
               custom_context=False, encoding=None, pull=False,
               forcerm=False, dockerfile=None, container_limits=None,
               decode=False, buildargs=None, gzip=False, shmsize=None,
-              labels=None):
+              labels=None, cachefrom=None):
         """
         Similar to the ``docker build`` command. Either ``path`` or ``fileobj``
         needs to be set. ``path`` can be a local path (to a directory
@@ -92,6 +92,7 @@ def build(self, path=None, tag=None, quiet=False, fileobj=None,
             shmsize (int): Size of `/dev/shm` in bytes. The size must be
                 greater than 0. If omitted the system uses 64MB.
             labels (dict): A dictionary of labels to set on the image.
+            cachefrom (list): A list of images used for build cache resolution.
 
         Returns:
             A generator for the build output.
@@ -188,6 +189,14 @@ def build(self, path=None, tag=None, quiet=False, fileobj=None,
                     'labels was only introduced in API version 1.23'
                 )
 
+        if cachefrom:
+            if utils.version_gte(self._version, '1.25'):
+                params.update({'cachefrom': json.dumps(cachefrom)})
+            else:
+                raise errors.InvalidVersion(
+                    'cachefrom was only introduced in API version 1.25'
+                )
+
         if context is not None:
             headers = {'Content-Type': 'application/tar'}
             if encoding:
diff --git a/docker/models/images.py b/docker/models/images.py
--- a/docker/models/images.py
+++ b/docker/models/images.py
@@ -140,6 +140,7 @@ def build(self, **kwargs):
                     ``"0-3"``, ``"0,1"``
             decode (bool): If set to ``True``, the returned stream will be
                 decoded into dicts on the fly. Default ``False``.
+            cachefrom (list): A list of images used for build cache resolution.
 
         Returns:
             (:py:class:`Image`): The built image.


Test patch:
diff --git a/tests/integration/api_build_test.py b/tests/integration/api_build_test.py
--- a/tests/integration/api_build_test.py
+++ b/tests/integration/api_build_test.py
@@ -153,6 +153,24 @@ def test_build_labels(self):
         info = self.client.inspect_image('labels')
         self.assertEqual(info['Config']['Labels'], labels)
 
+    @requires_api_version('1.25')
+    def test_build_cachefrom(self):
+        script = io.BytesIO('\n'.join([
+            'FROM scratch',
+        ]).encode('ascii'))
+
+        cachefrom = ['build1']
+
+        stream = self.client.build(
+            fileobj=script, tag='cachefrom', cachefrom=cachefrom
+        )
+        self.tmp_imgs.append('cachefrom')
+        for chunk in stream:
+            pass
+
+        info = self.client.inspect_image('cachefrom')
+        self.assertEqual(info['Config']['CacheFrom'], cachefrom)
+
     def test_build_stderr_data(self):
         control_chars = ['\x1b[91m', '\x1b[0m']
         snippet = 'Ancient Temple (Mystic Oriental Dream ~ Ancient Temple)'