Skip to content

Commit 7200314

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

File tree

2 files changed

+41
-3
lines changed

2 files changed

+41
-3
lines changed

compose/config.py

+25-3
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,17 @@
5757
'workdir': 'working_dir',
5858
}
5959

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

6172
def load(filename):
6273
working_dir = os.path.dirname(filename)
@@ -356,14 +367,25 @@ def resolve_host_path(volume, working_dir):
356367
def resolve_build_path(build_path, working_dir=None):
357368
if working_dir is None:
358369
raise Exception("No working_dir passed to resolve_build_path")
359-
return expand_path(working_dir, build_path)
370+
if is_git_url(build_path) or is_url(build_path):
371+
return build_path
372+
else:
373+
return expand_path(working_dir, build_path)
360374

361375

362376
def validate_paths(service_dict):
363377
if 'build' in service_dict:
364378
build_path = service_dict['build']
365-
if not os.path.exists(build_path) or not os.access(build_path, os.R_OK):
366-
raise ConfigurationError("build path %s either does not exist or is not accessible." % build_path)
379+
if (not os.path.exists(build_path) or not os.access(build_path, os.R_OK)) and not is_git_url(build_path):
380+
raise ConfigurationError("build path %s either does not exist, is not accessible or is not a valid url." % build_path)
381+
382+
383+
def is_url(build_path):
384+
return build_path.startswith(DOCKER_VALID_URL_PREFIXES)
385+
386+
387+
def is_git_url(build_path):
388+
return build_path.startswith(DOCKER_VALID_GIT_PREFIXES) or is_url(build_path) and build_path.endswith('.git')
367389

368390

369391
def merge_volumes(base, override):

tests/unit/config_test.py

+16
Original file line numberDiff line numberDiff line change
@@ -489,3 +489,19 @@ def test_absolute_path(self):
489489
def test_from_file(self):
490490
service_dict = config.load('tests/fixtures/build-path/docker-compose.yml')
491491
self.assertEquals(service_dict, [{'name': 'foo', 'build': self.abs_context_path}])
492+
493+
def test_valid_url_path(self):
494+
valid_urls = [
495+
'git://github.com/docker/docker',
496+
'git@github.com:docker/docker.git',
497+
'git@bitbucket.org:atlassianlabs/atlassian-docker.git',
498+
'https://github.com/docker/docker.git',
499+
'http://github.com/docker/docker.git',
500+
]
501+
for valid_url in valid_urls:
502+
service_dict = config.make_service_dict(
503+
'validurl',
504+
{'build': valid_url},
505+
working_dir='tests/fixtures/build-path'
506+
)
507+
self.assertEquals(service_dict['build'], valid_url)

0 commit comments

Comments
 (0)