Fix the relative path problem when running quay from non-root
This commit is contained in:
parent
ee67674e5b
commit
3b79955c8c
3 changed files with 12 additions and 9 deletions
|
@ -18,6 +18,7 @@ from buildman.jobutil.workererror import WorkerError
|
||||||
from data import model
|
from data import model
|
||||||
from data.database import BUILD_PHASE
|
from data.database import BUILD_PHASE
|
||||||
from data.model import InvalidRepositoryBuildException
|
from data.model import InvalidRepositoryBuildException
|
||||||
|
from util import slash_join
|
||||||
|
|
||||||
HEARTBEAT_DELTA = datetime.timedelta(seconds=60)
|
HEARTBEAT_DELTA = datetime.timedelta(seconds=60)
|
||||||
BUILD_HEARTBEAT_DELAY = datetime.timedelta(seconds=30)
|
BUILD_HEARTBEAT_DELAY = datetime.timedelta(seconds=30)
|
||||||
|
@ -180,9 +181,10 @@ class BuildComponent(BaseComponent):
|
||||||
context = build_config.get('context', '')
|
context = build_config.get('context', '')
|
||||||
if not (dockerfile_path == '' or context == ''):
|
if not (dockerfile_path == '' or context == ''):
|
||||||
# This should not happen and can be removed when we centralize validating build_config
|
# This should not happen and can be removed when we centralize validating build_config
|
||||||
if ".." in os.path.relpath(dockerfile_path, context):
|
dockerfile_abspath = slash_join('', dockerfile_path)
|
||||||
|
if ".." in os.path.relpath(dockerfile_abspath, context):
|
||||||
return os.path.split(dockerfile_path)
|
return os.path.split(dockerfile_path)
|
||||||
dockerfile_path = os.path.relpath(dockerfile_path, context)
|
dockerfile_path = os.path.relpath(dockerfile_abspath, context)
|
||||||
|
|
||||||
return context, dockerfile_path
|
return context, dockerfile_path
|
||||||
|
|
||||||
|
|
|
@ -23,11 +23,12 @@ def test_path_is_dockerfile(input, expected_path, expected_file):
|
||||||
assert actual_file == expected_file
|
assert actual_file == expected_file
|
||||||
|
|
||||||
@pytest.mark.parametrize('build_config,context,dockerfile_path', [
|
@pytest.mark.parametrize('build_config,context,dockerfile_path', [
|
||||||
({}, "", ""),
|
({}, '', ''),
|
||||||
({'build_subdir': "/builddir/Dockerfile"}, "", "/builddir/Dockerfile"),
|
({'build_subdir': '/builddir/Dockerfile'}, '', '/builddir/Dockerfile'),
|
||||||
({'context': "/builddir"}, "/builddir", ""),
|
({'context': '/builddir'}, '/builddir', ''),
|
||||||
({'context': "/builddir", 'build_subdir': "/builddir/Dockerfile"}, "/builddir", "Dockerfile"),
|
({'context': '/builddir', 'build_subdir': '/builddir/Dockerfile'}, '/builddir', 'Dockerfile'),
|
||||||
({'context': "/some_other_dir/Dockerfile", 'build_subdir': "/builddir/Dockerfile"}, "/builddir", "Dockerfile"),
|
({'context': '/some_other_dir/Dockerfile', 'build_subdir': '/builddir/Dockerfile'}, '/builddir', 'Dockerfile'),
|
||||||
|
({'context': '/', 'build_subdir':'Dockerfile'}, '/', 'Dockerfile')
|
||||||
])
|
])
|
||||||
def test_extract_dockerfile_args(build_config, context, dockerfile_path):
|
def test_extract_dockerfile_args(build_config, context, dockerfile_path):
|
||||||
actual_context, actual_dockerfile_path = BuildComponent.extract_dockerfile_args(build_config)
|
actual_context, actual_dockerfile_path = BuildComponent.extract_dockerfile_args(build_config)
|
||||||
|
|
|
@ -10,8 +10,8 @@ def slash_join(*args):
|
||||||
are not deduplicated.
|
are not deduplicated.
|
||||||
"""
|
"""
|
||||||
def rmslash(path):
|
def rmslash(path):
|
||||||
path = path[1:] if path[0] == '/' else path
|
path = path[1:] if len(path) > 0 and path[0] == '/' else path
|
||||||
path = path[:-1] if path[-1] == '/' else path
|
path = path[:-1] if len(path) > 0 and path[-1] == '/' else path
|
||||||
return path
|
return path
|
||||||
|
|
||||||
args = [rmslash(path) for path in args]
|
args = [rmslash(path) for path in args]
|
||||||
|
|
Reference in a new issue