Skip to content
Open
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
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Implemented volume subpath mount option.
9 changes: 7 additions & 2 deletions podman_compose.py
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,7 @@ def mount_desc_to_mount_args(mount_desc: dict[str, Any]) -> str:
vol = mount_desc.get("_vol") if mount_type == "volume" else None
source = vol["name"] if vol else mount_desc.get("source")
target = mount_desc["target"]
volume = mount_desc.get("volume") if mount_type == "volume" else None
opts = []
if mount_desc.get(mount_type, None):
# TODO: we might need to add mount_dict[mount_type]["propagation"] = "z"
Expand All @@ -480,6 +481,11 @@ def mount_desc_to_mount_args(mount_desc: dict[str, Any]) -> str:
selinux = bind_opts.get("selinux")
if selinux is not None:
opts.append(selinux)
else:
if volume is not None:
subpath = volume.get("subpath")
if subpath is not None:
opts.append(f"subpath={subpath}")
opts_str = ",".join(opts)
if mount_type == "bind":
return f"type=bind,source={source},destination={target},{opts_str}".rstrip(",")
Expand Down Expand Up @@ -1186,7 +1192,6 @@ async def container_to_args(
podman_args.extend(["--tmpfs", i])
for volume in cnt.get("volumes", []):
podman_args.extend(await get_mount_args(compose, cnt, volume))

await assert_cnt_nets(compose, cnt)
podman_args.extend(get_net_args(compose, cnt))

Expand Down Expand Up @@ -2064,7 +2069,7 @@ def __init__(self) -> None:
self.container_by_name: dict[str, Any]
self.services: dict[str, Any]
self.all_services: set[Any] = set()
self.prefer_volume_over_mount = True
self.prefer_volume_over_mount = False
self.x_podman: dict[PodmanCompose.XPodmanSettingKey, Any] = {}
self.merged_yaml: Any
self.yaml_hash = ""
Expand Down
19 changes: 17 additions & 2 deletions tests/integration/selinux/test_podman_compose_selinux.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,15 @@ def test_selinux(self) -> None:
inspect_out = json.loads(out)
create_command_list = inspect_out[0].get("Config", []).get("CreateCommand", [])
host_path = os.path.join(test_path(), "selinux", "host_test_text.txt")
self.assertIn(f'{host_path}:/test_text.txt:z', create_command_list)
try:
# podman-compose.py: prefer_volume_over_mount set to False
self.assertIn(
f'type=bind,source={host_path},destination=/test_text.txt,z',
create_command_list,
)
except AssertionError:
# podman-compose.py: prefer_volume_over_mount set to True
self.assertIn(f'{host_path}:/test_text.txt:z', create_command_list)

out, _ = self.run_subprocess_assert_returncode([
"podman",
Expand All @@ -48,7 +56,14 @@ def test_selinux(self) -> None:
inspect_out = json.loads(out)
create_command_list = inspect_out[0].get("Config", []).get("CreateCommand", [])
host_path = os.path.join(test_path(), "selinux", "host_test_text.txt")
self.assertIn(f'{host_path}:/test_text.txt', create_command_list)
try:
# podman-compose.py: prefer_volume_over_mount set to False
self.assertIn(
f'type=bind,source={host_path},destination=/test_text.txt', create_command_list
)
except AssertionError:
# podman-compose.py: prefer_volume_over_mount set to True
self.assertIn(f'{host_path}:/test_text.txt', create_command_list)
finally:
out, _ = self.run_subprocess_assert_returncode([
podman_compose_path(),
Expand Down