Skip to content

Commit 97b737e

Browse files
committed
Added support for url buid paths
Signed-off-by: Jonas Eckerström <jonaseck@gmail.com>
1 parent 9532e5a commit 97b737e

File tree

2 files changed

+52
-4
lines changed

2 files changed

+52
-4
lines changed

compose/config.py

+21-4
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,16 @@
5656
'workdir': 'working_dir',
5757
}
5858

59+
DOCKER_VALID_URL_PREFIXES = (
60+
'http://',
61+
'https://',
62+
)
63+
64+
DOCKER_VALID_GIT_PREFIXES = (
65+
'git://',
66+
'github.com/',
67+
'git@',
68+
)
5969

6070
def load(filename):
6171
working_dir = os.path.dirname(filename)
@@ -346,15 +356,22 @@ def resolve_host_path(volume, working_dir):
346356
def resolve_build_path(build_path, working_dir=None):
347357
if working_dir is None:
348358
raise Exception("No working_dir passed to resolve_build_path")
349-
return expand_path(working_dir, build_path)
350-
359+
if is_git_url(build_path) or is_url(build_path):
360+
return build_path
361+
else:
362+
return expand_path(working_dir, build_path)
351363

352364
def validate_paths(service_dict):
353365
if 'build' in service_dict:
354366
build_path = service_dict['build']
355-
if not os.path.exists(build_path) or not os.access(build_path, os.R_OK):
356-
raise ConfigurationError("build path %s either does not exist or is not accessible." % build_path)
367+
if (not os.path.exists(build_path) or not os.access(build_path, os.R_OK)) and not is_git_url(build_path):
368+
raise ConfigurationError("build path %s either does not exist, is not accessible or is not a valid url." % build_path)
369+
370+
def is_url(build_path):
371+
return build_path.startswith(DOCKER_VALID_URL_PREFIXES)
357372

373+
def is_git_url(build_path):
374+
return build_path.startswith(DOCKER_VALID_GIT_PREFIXES) or is_url(build_path) and build_path.endswith('.git')
358375

359376
def merge_volumes(base, override):
360377
d = dict_from_volumes(base)

tests/unit/config_test.py

+31
Original file line numberDiff line numberDiff line change
@@ -448,3 +448,34 @@ def test_absolute_path(self):
448448
def test_from_file(self):
449449
service_dict = config.load('tests/fixtures/build-path/docker-compose.yml')
450450
self.assertEquals(service_dict, [{'name': 'foo', 'build': self.abs_context_path}])
451+
452+
def pytest_generate_tests(metafunc):
453+
if "valid_url" in metafunc.funcargnames:
454+
metafunc.parametrize("valid_url", [
455+
'git://github.com/docker/docker',
456+
'git@github.com:docker/docker.git',
457+
'git@bitbucket.org:atlassianlabs/atlassian-docker.git',
458+
'https://github.com/docker/docker.git',
459+
'http://github.com/docker/docker.git'
460+
])
461+
elif "invalid_url" in metafunc.funcargnames:
462+
metafunc.parametrize("invalid_url", [
463+
'github.com/docker/docker'
464+
])
465+
466+
def test_valid_url_path(self, valid_url):
467+
service_dict = config.make_service_dict(
468+
{'build': valid_url},
469+
working_dir='tests/fixtures/build-path'
470+
)
471+
self.assertEquals(service_dict['build'], valid_url)
472+
473+
def test_invalid_url_path(self, invalid_url):
474+
options = {'build': invalid_url}
475+
self.assertRaises(
476+
config.ConfigurationError,
477+
lambda: config.from_dictionary({
478+
'foo': options,
479+
'working_dir': 'tests/fixtures/build-path'
480+
})
481+
)

0 commit comments

Comments
 (0)