Skip to content

Commit

Permalink
Merge pull request #1 from AlanCoding/mount_full_dir
Browse files Browse the repository at this point in the history
Depending on command, either mount subfolders or the full private_data_dir
  • Loading branch information
shanemcd committed Sep 21, 2020
2 parents f51ec11 + 9d266cf commit a43a41f
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 21 deletions.
37 changes: 18 additions & 19 deletions ansible_runner/runner_config.py
Expand Up @@ -728,26 +728,25 @@ def _parse_cli_execenv_cmd_playbook_args():
new_args.extend(["--userns=keep-id"])
new_args.extend(["--ipc=host"])

# the playbook / adhoc cases (cli_execenv_cmd) are handled separately
# because they have pre-existing mounts already in new_args
if self.cli_execenv_cmd:
# Relative paths are mounted relative to /runner/project
for subdir in ('project', 'artifacts'):
subdir_path = os.path.join(self.private_data_dir, subdir)
if not os.path.exists(subdir_path):
os.mkdir(subdir_path, 0o700)

# playbook / adhoc commands need artifacts mounted to output data
new_args.extend(["-v", "{}/artifacts:/runner/artifacts:Z".format(self.private_data_dir)])
else:
subdir_path = os.path.join(self.private_data_dir, 'artifacts')
if not os.path.exists(subdir_path):
os.mkdir(subdir_path, 0o700)

# These directories need to exist before they are mounted in the container,
# or they will be owned by root.
private_subdirs = [
d for d in os.listdir(self.private_data_dir) if os.path.isdir(
os.path.join(self.private_data_dir, d)
)
]

if 'artifacts' not in private_subdirs:
private_subdirs += ['artifacts']

for d in private_subdirs:
if not os.path.exists(os.path.join(self.private_data_dir, d)):
if d == 'artifacts':
os.mkdir(os.path.join(self.private_data_dir, d), 0o700)
else:
continue

new_args.extend(["-v", "{}:/runner/{}:Z".format(os.path.join(self.private_data_dir, d), d)])
# Mount the entire private_data_dir
# custom show paths inside private_data_dir do not make sense
new_args.extend(["-v", "{}:/runner:Z".format(self.private_data_dir)])

container_volume_mounts = self.container_volume_mounts
if container_volume_mounts:
Expand Down
16 changes: 15 additions & 1 deletion test/integration/containerized/test_cli_containerized.py
Expand Up @@ -47,12 +47,26 @@ def test_adhoc_localhost_setup(cli, skip_if_no_podman, container_runtime_install

@pytest.mark.serial
def test_playbook_with_private_data_dir(cli, skip_if_no_podman, container_runtime_installed):
# tests using a private_data_dir in conjunction with an absolute path
r = cli(
[
'playbook',
'--private-data-dir', os.path.join(HERE,'priv_data'),
'--container-runtime', container_runtime_installed,
'test/integration/containerized/priv_data/project/test-container.yml' # FIXME: this may be a bug
os.path.join(HERE, 'priv_data/project/test-container.yml')
]
)
assert 'PLAY RECAP *******' in r.stdout
assert 'failed=0' in r.stdout


@pytest.mark.serial
def test_playbook_with_relative_path(cli, skip_if_no_podman, container_runtime_installed):
r = cli(
[
'playbook',
'--container-runtime', container_runtime_installed,
'test/integration/containerized/priv_data/project/test-container.yml'
]
)
assert 'PLAY RECAP *******' in r.stdout
Expand Down
2 changes: 1 addition & 1 deletion test/unit/test_runner_config.py
Expand Up @@ -627,7 +627,7 @@ def test_containerization_settings(tmpdir, container_runtime):
extra_container_args = ['--user={os.getuid()}']

expected_command_start = [container_runtime, 'run', '--rm', '--tty', '--interactive', '--workdir', '/runner/project'] + \
['-v', '{}/artifacts:/runner/artifacts:Z'.format(rc.private_data_dir)] + \
['-v', '{}:/runner:Z'.format(rc.private_data_dir)] + \
['-v', '/host1:/container1', '-v', 'host2:/container2'] + \
['--env-file', '{}/env.list'.format(rc.artifact_dir)] + \
extra_container_args + \
Expand Down

0 comments on commit a43a41f

Please sign in to comment.