mirror of
https://github.com/docker/compose.git
synced 2025-07-23 13:45:00 +02:00
Merge pull request #1357 from turtlemonvh/1350-extends_parent_build_directory_dne_error
Fix for #1350, nonexisting build path in parent section causes extending section to fail
This commit is contained in:
commit
a631c1eddb
@ -69,6 +69,7 @@ def from_dictionary(dictionary, working_dir=None, filename=None):
|
|||||||
raise ConfigurationError('Service "%s" doesn\'t have any configuration options. All top level keys in your docker-compose.yml must map to a dictionary of configuration options.' % service_name)
|
raise ConfigurationError('Service "%s" doesn\'t have any configuration options. All top level keys in your docker-compose.yml must map to a dictionary of configuration options.' % service_name)
|
||||||
loader = ServiceLoader(working_dir=working_dir, filename=filename)
|
loader = ServiceLoader(working_dir=working_dir, filename=filename)
|
||||||
service_dict = loader.make_service_dict(service_name, service_dict)
|
service_dict = loader.make_service_dict(service_name, service_dict)
|
||||||
|
validate_paths(service_dict)
|
||||||
service_dicts.append(service_dict)
|
service_dicts.append(service_dict)
|
||||||
|
|
||||||
return service_dicts
|
return service_dicts
|
||||||
@ -344,12 +345,14 @@ def resolve_host_path(volume, working_dir):
|
|||||||
def resolve_build_path(build_path, working_dir=None):
|
def resolve_build_path(build_path, working_dir=None):
|
||||||
if working_dir is None:
|
if working_dir is None:
|
||||||
raise Exception("No working_dir passed to resolve_build_path")
|
raise Exception("No working_dir passed to resolve_build_path")
|
||||||
|
return expand_path(working_dir, build_path)
|
||||||
|
|
||||||
_path = expand_path(working_dir, build_path)
|
|
||||||
if not os.path.exists(_path) or not os.access(_path, os.R_OK):
|
def validate_paths(service_dict):
|
||||||
raise ConfigurationError("build path %s either does not exist or is not accessible." % _path)
|
if 'build' in service_dict:
|
||||||
else:
|
build_path = service_dict['build']
|
||||||
return _path
|
if not os.path.exists(build_path) or not os.access(build_path, os.R_OK):
|
||||||
|
raise ConfigurationError("build path %s either does not exist or is not accessible." % build_path)
|
||||||
|
|
||||||
|
|
||||||
def merge_volumes(base, override):
|
def merge_volumes(base, override):
|
||||||
|
6
tests/fixtures/extends/nonexistent-path-base.yml
vendored
Normal file
6
tests/fixtures/extends/nonexistent-path-base.yml
vendored
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
dnebase:
|
||||||
|
build: nonexistent.path
|
||||||
|
command: /bin/true
|
||||||
|
environment:
|
||||||
|
- FOO=1
|
||||||
|
- BAR=1
|
8
tests/fixtures/extends/nonexistent-path-child.yml
vendored
Normal file
8
tests/fixtures/extends/nonexistent-path-child.yml
vendored
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
dnechild:
|
||||||
|
extends:
|
||||||
|
file: nonexistent-path-base.yml
|
||||||
|
service: dnebase
|
||||||
|
image: busybox
|
||||||
|
command: /bin/true
|
||||||
|
environment:
|
||||||
|
- BAR=2
|
@ -398,6 +398,21 @@ class ExtendsTest(unittest.TestCase):
|
|||||||
|
|
||||||
self.assertEqual(set(dicts[0]['volumes']), set(paths))
|
self.assertEqual(set(dicts[0]['volumes']), set(paths))
|
||||||
|
|
||||||
|
def test_parent_build_path_dne(self):
|
||||||
|
child = config.load('tests/fixtures/extends/nonexistent-path-child.yml')
|
||||||
|
|
||||||
|
self.assertEqual(child, [
|
||||||
|
{
|
||||||
|
'name': 'dnechild',
|
||||||
|
'image': 'busybox',
|
||||||
|
'command': '/bin/true',
|
||||||
|
'environment': {
|
||||||
|
"FOO": "1",
|
||||||
|
"BAR": "2",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
])
|
||||||
|
|
||||||
|
|
||||||
class BuildPathTest(unittest.TestCase):
|
class BuildPathTest(unittest.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
@ -407,7 +422,10 @@ class BuildPathTest(unittest.TestCase):
|
|||||||
options = {'build': 'nonexistent.path'}
|
options = {'build': 'nonexistent.path'}
|
||||||
self.assertRaises(
|
self.assertRaises(
|
||||||
config.ConfigurationError,
|
config.ConfigurationError,
|
||||||
lambda: config.make_service_dict('foo', options, 'tests/fixtures/build-path'),
|
lambda: config.from_dictionary({
|
||||||
|
'foo': options,
|
||||||
|
'working_dir': 'tests/fixtures/build-path'
|
||||||
|
})
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_relative_path(self):
|
def test_relative_path(self):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user