Skip to content
Merged
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
9 changes: 5 additions & 4 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ the run step:
# A map specifying files that should be injected into the container.
# The map key is the alias referencing a given file (as configured in
# the "local-files" section of the global configuration file) or a
# relative path to a file/directory in the build directory. The value
# relative path to a file/directory in the build directory. The value
# is the path the given file should be mounted at within the container.
files:
namespaced.file.alias1: "/path/to/readonly/file/or/dir"
Expand Down Expand Up @@ -829,12 +829,13 @@ within service container configuration:

# A map specifying files that should be injected into the container.
# The map key is the alias referencing a given file (as configured in
# the "local-files" section of the global configuration file) and the
# value is the path the given file should be mounted at within the
# container.
# the "local-files" section of the global configuration file) or a
# relative path to a file/directory in the build directory. The value
# is the path the given file should be mounted at within the container.
files:
namespaced.file.alias1: "/path/to/readonly/file/or/dir"
namespaced.file.alias2: "/path/to/readwrite/file/or/dir:rw"
build/dir/file: "/path/to/build/dir/file"

# A list specifying other service containers whose exposed volumes
# should be mapped into this service container's file system. Any
Expand Down
62 changes: 34 additions & 28 deletions buildrunner/steprunner/tasks/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,38 @@ def _archive_file(
properties,
)

def _get_local_file(
self, buildrunner_config: BuildRunnerConfig, file_alias: str
) -> str:
"""
Lookup file alias from global config or as a local file.
:param buildrunner_config: buildrunner global configuration
:param file_alias: the file alias
:return: the local file to use (if available)
:raises BuildRunnerConfigurationError: the file alias is not found and is not a valid local file
"""
f_local = buildrunner_config.get_local_files_from_alias(file_alias)
if not f_local:
f_local = os.path.realpath(
os.path.join(self.step_runner.build_runner.build_dir, file_alias)
)
if (
f_local != self.step_runner.build_runner.build_dir
and not f_local.startswith(
self.step_runner.build_runner.build_dir + os.path.sep
)
):
raise BuildRunnerConfigurationError(
f'Mount path of "{file_alias}" attempts to step out of '
f'source directory "{self.step_runner.build_runner.build_dir}"'
)

if not os.path.exists(f_local):
raise BuildRunnerConfigurationError(
f"Cannot find valid alias for files entry '{file_alias}' nor path at '{f_local}'"
)
return f_local

# pylint: disable=too-many-statements,too-many-branches,too-many-locals
def _start_service_container(self, name, service: Service):
"""
Expand Down Expand Up @@ -603,11 +635,7 @@ def _start_service_container(self, name, service: Service):
if service.files:
for f_alias, f_path in service.files.items():
# lookup file from alias
f_local = buildrunner_config.get_local_files_from_alias(f_alias)
if not f_local or not os.path.exists(f_local):
raise BuildRunnerConfigurationError(
f"Cannot find valid local file for alias '{f_alias}'"
)
f_local = self._get_local_file(buildrunner_config, f_alias)

if f_path[-3:] not in [":ro", ":rw"]:
f_path = f_path + ":ro"
Expand Down Expand Up @@ -980,29 +1008,7 @@ def run(self, context: dict): # pylint: disable=too-many-statements,too-many-br
# see if we need to inject any files
if self.step.files:
for f_alias, f_path in self.step.files.items():
# lookup file from alias
f_local = buildrunner_config.get_local_files_from_alias(
f_alias,
)
if not f_local:
f_local = os.path.realpath(
os.path.join(self.step_runner.build_runner.build_dir, f_alias)
)
if (
f_local != self.step_runner.build_runner.build_dir
and not f_local.startswith(
self.step_runner.build_runner.build_dir + os.path.sep
)
):
raise BuildRunnerConfigurationError(
f'Mount path of "{f_alias}" attempts to step out of '
f'source directory "{self.step_runner.build_runner.build_dir}"'
)

if not os.path.exists(f_local):
raise BuildRunnerConfigurationError(
f"Cannot find valid alias for files entry '{f_alias}' nor path at '{f_local}'"
)
f_local = self._get_local_file(buildrunner_config, f_alias)

if f_path[-3:] not in [":ro", ":rw"]:
f_path = f_path + ":ro"
Expand Down
10 changes: 9 additions & 1 deletion tests/test-files/test-build_dir_mount.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,17 @@
steps:
test-build_dir_mount:
run:
services:
service1:
image: {{ DOCKER_REGISTRY }}/ubuntu:latest
files:
# Obvious directory that should succeed
.: /test_services_dir
cmd: |
set -eux
[ -d /test_services_dir ]
image: {{ DOCKER_REGISTRY }}/ubuntu:latest
files:
# Obvious directory that should succeed
.: /test_dir
cmds:
- |
Expand Down
Loading