summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoffrey F <joffrey@docker.com>2017-02-15 18:42:49 -0800
committerJoffrey F <joffrey@docker.com>2017-02-16 16:19:31 -0800
commitb1d6e01abe0474ea91d04090fc39e343d877f60d (patch)
tree7eca25c16b584cb4faaf15851ff3f2215ef72acb
parent40290fc99fe31fdb935db70130e4119e15e755f4 (diff)
downloaddocker-py-b1d6e01abe0474ea91d04090fc39e343d877f60d.tar.gz
Rename cachefrom -> cache_from
Fix cache_from integration test Fix image ID detection in ImageCollection.build Signed-off-by: Joffrey F <joffrey@docker.com>
-rw-r--r--docker/api/build.py15
-rw-r--r--docker/models/images.py7
-rw-r--r--tests/integration/api_build_test.py44
3 files changed, 41 insertions, 25 deletions
diff --git a/docker/api/build.py b/docker/api/build.py
index c009f1a..5c34c47 100644
--- a/docker/api/build.py
+++ b/docker/api/build.py
@@ -1,11 +1,11 @@
+import json
import logging
import os
import re
-import json
+from .. import auth
from .. import constants
from .. import errors
-from .. import auth
from .. import utils
@@ -18,7 +18,7 @@ class BuildApiMixin(object):
custom_context=False, encoding=None, pull=False,
forcerm=False, dockerfile=None, container_limits=None,
decode=False, buildargs=None, gzip=False, shmsize=None,
- labels=None, cachefrom=None):
+ labels=None, cache_from=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,7 +92,8 @@ class BuildApiMixin(object):
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.
+ cache_from (list): A list of images used for build cache
+ resolution.
Returns:
A generator for the build output.
@@ -189,12 +190,12 @@ class BuildApiMixin(object):
'labels was only introduced in API version 1.23'
)
- if cachefrom:
+ if cache_from:
if utils.version_gte(self._version, '1.25'):
- params.update({'cachefrom': json.dumps(cachefrom)})
+ params.update({'cachefrom': json.dumps(cache_from)})
else:
raise errors.InvalidVersion(
- 'cachefrom was only introduced in API version 1.25'
+ 'cache_from was only introduced in API version 1.25'
)
if context is not None:
diff --git a/docker/models/images.py b/docker/models/images.py
index a749f63..51ee6f4 100644
--- a/docker/models/images.py
+++ b/docker/models/images.py
@@ -141,7 +141,8 @@ class ImageCollection(Collection):
``"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.
+ cache_from (list): A list of images used for build cache
+ resolution.
Returns:
(:py:class:`Image`): The built image.
@@ -162,10 +163,10 @@ class ImageCollection(Collection):
return BuildError('Unknown')
event = events[-1]
if 'stream' in event:
- match = re.search(r'Successfully built ([0-9a-f]+)',
+ match = re.search(r'(Successfully built |sha256:)([0-9a-f]+)',
event.get('stream', ''))
if match:
- image_id = match.group(1)
+ image_id = match.group(2)
return self.get(image_id)
raise BuildError(event.get('error') or event)
diff --git a/tests/integration/api_build_test.py b/tests/integration/api_build_test.py
index c2fd26c..fe5d994 100644
--- a/tests/integration/api_build_test.py
+++ b/tests/integration/api_build_test.py
@@ -3,13 +3,12 @@ import os
import shutil
import tempfile
-import pytest
-import six
-
from docker import errors
-from ..helpers import requires_api_version
+import six
+
from .base import BaseAPIIntegrationTest
+from ..helpers import requires_api_version
class BuildTest(BaseAPIIntegrationTest):
@@ -155,25 +154,40 @@ class BuildTest(BaseAPIIntegrationTest):
self.assertEqual(info['Config']['Labels'], labels)
@requires_api_version('1.25')
- @pytest.mark.xfail(reason='Bad test')
- def test_build_cachefrom(self):
+ def test_build_with_cache_from(self):
script = io.BytesIO('\n'.join([
- 'FROM scratch',
- 'CMD sh -c "echo \'Hello, World!\'"',
+ 'FROM busybox',
+ 'ENV FOO=bar',
+ 'RUN touch baz',
+ 'RUN touch bax',
]).encode('ascii'))
- cachefrom = ['build1']
+ stream = self.client.build(fileobj=script, tag='build1')
+ self.tmp_imgs.append('build1')
+ for chunk in stream:
+ pass
stream = self.client.build(
- fileobj=script, tag='cachefrom', cachefrom=cachefrom
+ fileobj=script, tag='build2', cache_from=['build1'],
+ decode=True
)
- self.tmp_imgs.append('cachefrom')
+ self.tmp_imgs.append('build2')
+ counter = 0
for chunk in stream:
- pass
+ if 'Using cache' in chunk.get('stream', ''):
+ counter += 1
+ assert counter == 3
+ self.client.remove_image('build2')
- info = self.client.inspect_image('cachefrom')
- # FIXME: Config.CacheFrom is not a real thing
- self.assertEqual(info['Config']['CacheFrom'], cachefrom)
+ counter = 0
+ stream = self.client.build(
+ fileobj=script, tag='build2', cache_from=['nosuchtag'],
+ decode=True
+ )
+ for chunk in stream:
+ if 'Using cache' in chunk.get('stream', ''):
+ counter += 1
+ assert counter == 0
def test_build_stderr_data(self):
control_chars = ['\x1b[91m', '\x1b[0m']