Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions compose/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@
'workdir': 'working_dir',
}

DOCKER_VALID_URL_PREFIXES = (
'http://',
'https://',
'git://',
'github.com/',
'git@',
)


def load(filename):
working_dir = os.path.dirname(filename)
Expand Down Expand Up @@ -356,14 +364,21 @@ def resolve_host_path(volume, working_dir):
def resolve_build_path(build_path, working_dir=None):
if working_dir is None:
raise Exception("No working_dir passed to resolve_build_path")
return expand_path(working_dir, build_path)
if is_url(build_path):
return build_path
else:
return expand_path(working_dir, build_path)


def validate_paths(service_dict):
if 'build' in service_dict:
build_path = service_dict['build']
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)
if (not os.path.exists(build_path) or not os.access(build_path, os.R_OK)) and not is_url(build_path):
raise ConfigurationError("build path %s either does not exist, is not accessible or is not a valid url." % build_path)


def is_url(build_path):
return build_path.startswith(DOCKER_VALID_URL_PREFIXES)


def merge_volumes(base, override):
Expand Down
16 changes: 16 additions & 0 deletions tests/unit/config_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -489,3 +489,19 @@ def test_absolute_path(self):
def test_from_file(self):
service_dict = config.load('tests/fixtures/build-path/docker-compose.yml')
self.assertEquals(service_dict, [{'name': 'foo', 'build': self.abs_context_path}])

def test_valid_url_path(self):
valid_urls = [
'git://github.com/docker/docker',
'git@github.com:docker/docker.git',
'git@bitbucket.org:atlassianlabs/atlassian-docker.git',
'https://github.com/docker/docker.git',
'http://github.com/docker/docker.git',
]
for valid_url in valid_urls:
service_dict = config.make_service_dict(
'validurl',
{'build': valid_url},
working_dir='tests/fixtures/build-path'
)
self.assertEquals(service_dict['build'], valid_url)