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
1 change: 1 addition & 0 deletions newsfragments/mount-image-as-volume.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Support volume.type=image in services, for mounting files from container images.
9 changes: 8 additions & 1 deletion podman_compose.py
Original file line number Diff line number Diff line change
Expand Up @@ -480,13 +480,20 @@ 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)
if mount_type == "image":
image_opts = mount_desc.get("image", {})
subpath = image_opts.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(",")
if mount_type == "volume":
return f"type=volume,source={source},destination={target},{opts_str}".rstrip(",")
if mount_type == "tmpfs":
return f"type=tmpfs,destination={target},{opts_str}".rstrip(",")
if mount_type == "image":
return f"type=image,source={source},destination={target},{opts_str}".rstrip(",")
raise ValueError("unknown mount type:" + mount_type)


Expand Down Expand Up @@ -574,7 +581,7 @@ async def get_mount_args(
srv_name = cnt["_service"]
mount_type = volume["type"]
await assert_volume(compose, volume)
if compose.prefer_volume_over_mount:
if compose.prefer_volume_over_mount and mount_type != "image":
if mount_type == "tmpfs":
# TODO: --tmpfs /tmp:rw,size=787448k,mode=1777
args = volume["target"]
Expand Down
41 changes: 41 additions & 0 deletions tests/unit/test_container_to_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,47 @@ async def test_volumes_bind_mount_source(
],
)

@parameterized.expand([
(
"without_subpath",
{},
"type=image,source=example:latest,destination=/mnt/example",
),
(
"with_subpath",
{"image": {"subpath": "path/to/image/folder"}},
"type=image,source=example:latest,destination=/mnt/example,subpath=path/to/image/folder",
),
])
async def test_volumes_image_mount(
self, test_name: str, image_opts: dict, expected_mount_arg: str
) -> None:
c = create_compose_mock()
cnt = get_minimal_container()
cnt["_service"] = cnt["service_name"]

cnt["volumes"] = [
{
"type": "image",
"source": "example:latest",
"target": "/mnt/example",
**image_opts,
},
]

args = await container_to_args(c, cnt)
self.assertEqual(
args,
[
"--name=project_name_service_name1",
"-d",
"--mount",
expected_mount_arg,
"--network=bridge:alias=service_name",
"busybox",
],
)

@parameterized.expand([
(
"create_host_path_set_to_true",
Expand Down