Merge pull request #1376 from aanand/fix-build-non-ascii-filename

Make sure the build path we pass to docker-py is a binary string
This commit is contained in:
Daniel Nephin 2015-04-30 20:54:21 -04:00
commit 4bce388b51
3 changed files with 32 additions and 2 deletions

View File

@ -462,8 +462,10 @@ class Service(object):
def build(self, no_cache=False):
log.info('Building %s...' % self.name)
path = six.binary_type(self.options['build'])
build_output = self.client.build(
self.options['build'],
path=path,
tag=self.full_name,
stream=True,
rm=True,

View File

@ -4,6 +4,10 @@ import os
from os import path
import mock
import tempfile
import shutil
import six
from compose import Service
from compose.service import (
CannotBeScaledError,
@ -404,6 +408,29 @@ class ServiceTest(DockerClientTestCase):
self.assertEqual(list(container['NetworkSettings']['Ports'].keys()), ['8000/tcp'])
self.assertNotEqual(container['NetworkSettings']['Ports']['8000/tcp'][0]['HostPort'], '8000')
def test_build(self):
base_dir = tempfile.mkdtemp()
self.addCleanup(shutil.rmtree, base_dir)
with open(os.path.join(base_dir, 'Dockerfile'), 'w') as f:
f.write("FROM busybox\n")
self.create_service('web', build=base_dir).build()
self.assertEqual(len(self.client.images(name='composetest_web')), 1)
def test_build_non_ascii_filename(self):
base_dir = tempfile.mkdtemp()
self.addCleanup(shutil.rmtree, base_dir)
with open(os.path.join(base_dir, 'Dockerfile'), 'w') as f:
f.write("FROM busybox\n")
with open(os.path.join(base_dir, b'foo\xE2bar'), 'w') as f:
f.write("hello world\n")
self.create_service('web', build=six.text_type(base_dir)).build()
self.assertEqual(len(self.client.images(name='composetest_web')), 1)
def test_start_container_stays_unpriviliged(self):
service = self.create_service('web')
container = create_and_start_container(service).inspect()

View File

@ -22,7 +22,8 @@ class DockerClientTestCase(unittest.TestCase):
self.client.remove_image(i)
def create_service(self, name, **kwargs):
kwargs['image'] = kwargs.pop('image', 'busybox:latest')
if 'image' not in kwargs and 'build' not in kwargs:
kwargs['image'] = 'busybox:latest'
if 'command' not in kwargs:
kwargs['command'] = ["/bin/sleep", "300"]