Kaydet (Commit) 0a97df1a authored tarafından Joffrey F's avatar Joffrey F

Rename cachefrom -> cache_from

Fix cache_from integration test
Fix image ID detection in ImageCollection.build
Signed-off-by: 's avatarJoffrey F <joffrey@docker.com>
üst 4a50784a
import json
import logging import logging
import os import os
import re import re
import json
from .. import auth
from .. import constants from .. import constants
from .. import errors from .. import errors
from .. import auth
from .. import utils from .. import utils
...@@ -18,7 +18,7 @@ class BuildApiMixin(object): ...@@ -18,7 +18,7 @@ class BuildApiMixin(object):
custom_context=False, encoding=None, pull=False, custom_context=False, encoding=None, pull=False,
forcerm=False, dockerfile=None, container_limits=None, forcerm=False, dockerfile=None, container_limits=None,
decode=False, buildargs=None, gzip=False, shmsize=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`` Similar to the ``docker build`` command. Either ``path`` or ``fileobj``
needs to be set. ``path`` can be a local path (to a directory needs to be set. ``path`` can be a local path (to a directory
...@@ -92,7 +92,8 @@ class BuildApiMixin(object): ...@@ -92,7 +92,8 @@ class BuildApiMixin(object):
shmsize (int): Size of `/dev/shm` in bytes. The size must be shmsize (int): Size of `/dev/shm` in bytes. The size must be
greater than 0. If omitted the system uses 64MB. greater than 0. If omitted the system uses 64MB.
labels (dict): A dictionary of labels to set on the image. 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: Returns:
A generator for the build output. A generator for the build output.
...@@ -189,12 +190,12 @@ class BuildApiMixin(object): ...@@ -189,12 +190,12 @@ class BuildApiMixin(object):
'labels was only introduced in API version 1.23' 'labels was only introduced in API version 1.23'
) )
if cachefrom: if cache_from:
if utils.version_gte(self._version, '1.25'): if utils.version_gte(self._version, '1.25'):
params.update({'cachefrom': json.dumps(cachefrom)}) params.update({'cachefrom': json.dumps(cache_from)})
else: else:
raise errors.InvalidVersion( 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: if context is not None:
......
...@@ -141,7 +141,8 @@ class ImageCollection(Collection): ...@@ -141,7 +141,8 @@ class ImageCollection(Collection):
``"0-3"``, ``"0,1"`` ``"0-3"``, ``"0,1"``
decode (bool): If set to ``True``, the returned stream will be decode (bool): If set to ``True``, the returned stream will be
decoded into dicts on the fly. Default ``False``. 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: Returns:
(:py:class:`Image`): The built image. (:py:class:`Image`): The built image.
...@@ -162,10 +163,10 @@ class ImageCollection(Collection): ...@@ -162,10 +163,10 @@ class ImageCollection(Collection):
return BuildError('Unknown') return BuildError('Unknown')
event = events[-1] event = events[-1]
if 'stream' in event: 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', '')) event.get('stream', ''))
if match: if match:
image_id = match.group(1) image_id = match.group(2)
return self.get(image_id) return self.get(image_id)
raise BuildError(event.get('error') or event) raise BuildError(event.get('error') or event)
......
...@@ -3,13 +3,12 @@ import os ...@@ -3,13 +3,12 @@ import os
import shutil import shutil
import tempfile import tempfile
import pytest
import six
from docker import errors from docker import errors
from ..helpers import requires_api_version import six
from .base import BaseAPIIntegrationTest from .base import BaseAPIIntegrationTest
from ..helpers import requires_api_version
class BuildTest(BaseAPIIntegrationTest): class BuildTest(BaseAPIIntegrationTest):
...@@ -155,25 +154,40 @@ class BuildTest(BaseAPIIntegrationTest): ...@@ -155,25 +154,40 @@ class BuildTest(BaseAPIIntegrationTest):
self.assertEqual(info['Config']['Labels'], labels) self.assertEqual(info['Config']['Labels'], labels)
@requires_api_version('1.25') @requires_api_version('1.25')
@pytest.mark.xfail(reason='Bad test') def test_build_with_cache_from(self):
def test_build_cachefrom(self):
script = io.BytesIO('\n'.join([ script = io.BytesIO('\n'.join([
'FROM scratch', 'FROM busybox',
'CMD sh -c "echo \'Hello, World!\'"', 'ENV FOO=bar',
'RUN touch baz',
'RUN touch bax',
]).encode('ascii')) ]).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( 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: 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') counter = 0
# FIXME: Config.CacheFrom is not a real thing stream = self.client.build(
self.assertEqual(info['Config']['CacheFrom'], cachefrom) 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): def test_build_stderr_data(self):
control_chars = ['\x1b[91m', '\x1b[0m'] control_chars = ['\x1b[91m', '\x1b[0m']
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment