Don't add long path prefix to build context URLs

Signed-off-by: Joffrey F <joffrey@docker.com>
This commit is contained in:
Joffrey F 2018-11-26 15:26:27 -08:00
parent c32bc095f3
commit ccc777831c
3 changed files with 30 additions and 1 deletions

View File

@ -6,6 +6,7 @@ from . import environment
from .config import ConfigurationError from .config import ConfigurationError
from .config import DOCKER_CONFIG_KEYS from .config import DOCKER_CONFIG_KEYS
from .config import find from .config import find
from .config import is_url
from .config import load from .config import load
from .config import merge_environment from .config import merge_environment
from .config import merge_labels from .config import merge_labels

View File

@ -27,6 +27,7 @@ from . import __version__
from . import const from . import const
from . import progress_stream from . import progress_stream
from .config import DOCKER_CONFIG_KEYS from .config import DOCKER_CONFIG_KEYS
from .config import is_url
from .config import merge_environment from .config import merge_environment
from .config import merge_labels from .config import merge_labels
from .config.errors import DependencyError from .config.errors import DependencyError
@ -1676,7 +1677,7 @@ def rewrite_build_path(path):
if not six.PY3 and not IS_WINDOWS_PLATFORM: if not six.PY3 and not IS_WINDOWS_PLATFORM:
path = path.encode('utf8') path = path.encode('utf8')
if IS_WINDOWS_PLATFORM and not path.startswith(WINDOWS_LONGPATH_PREFIX): if IS_WINDOWS_PLATFORM and not is_url(path) and not path.startswith(WINDOWS_LONGPATH_PREFIX):
path = WINDOWS_LONGPATH_PREFIX + os.path.normpath(path) path = WINDOWS_LONGPATH_PREFIX + os.path.normpath(path)
return path return path

View File

@ -21,6 +21,7 @@ from compose.const import LABEL_ONE_OFF
from compose.const import LABEL_PROJECT from compose.const import LABEL_PROJECT
from compose.const import LABEL_SERVICE from compose.const import LABEL_SERVICE
from compose.const import SECRETS_PATH from compose.const import SECRETS_PATH
from compose.const import WINDOWS_LONGPATH_PREFIX
from compose.container import Container from compose.container import Container
from compose.errors import OperationFailedError from compose.errors import OperationFailedError
from compose.parallel import ParallelStreamWriter from compose.parallel import ParallelStreamWriter
@ -38,6 +39,7 @@ from compose.service import NeedsBuildError
from compose.service import NetworkMode from compose.service import NetworkMode
from compose.service import NoSuchImageError from compose.service import NoSuchImageError
from compose.service import parse_repository_tag from compose.service import parse_repository_tag
from compose.service import rewrite_build_path
from compose.service import Service from compose.service import Service
from compose.service import ServiceNetworkMode from compose.service import ServiceNetworkMode
from compose.service import warn_on_masked_volume from compose.service import warn_on_masked_volume
@ -1486,3 +1488,28 @@ class ServiceSecretTest(unittest.TestCase):
assert volumes[0].source == secret1['file'] assert volumes[0].source == secret1['file']
assert volumes[0].target == '{}/{}'.format(SECRETS_PATH, secret1['secret'].source) assert volumes[0].target == '{}/{}'.format(SECRETS_PATH, secret1['secret'].source)
class RewriteBuildPathTest(unittest.TestCase):
@mock.patch('compose.service.IS_WINDOWS_PLATFORM', True)
def test_rewrite_url_no_prefix(self):
urls = [
'http://test.com',
'https://test.com',
'git://test.com',
'github.com/test/test',
'git@test.com',
]
for u in urls:
assert rewrite_build_path(u) == u
@mock.patch('compose.service.IS_WINDOWS_PLATFORM', True)
def test_rewrite_windows_path(self):
assert rewrite_build_path('C:\\context') == WINDOWS_LONGPATH_PREFIX + 'C:\\context'
assert rewrite_build_path(
rewrite_build_path('C:\\context')
) == rewrite_build_path('C:\\context')
@mock.patch('compose.service.IS_WINDOWS_PLATFORM', False)
def test_rewrite_unix_path(self):
assert rewrite_build_path('/context') == '/context'