Support podman's external rootfs management

Signed-off-by: GnSight <ftyg@live.com>
This commit is contained in:
GnSight 2024-03-16 15:50:49 +08:00 committed by Povilas Kanapickas
parent 12d46ca836
commit 77f2e8e5b0
2 changed files with 36 additions and 2 deletions

View File

@ -1145,13 +1145,23 @@ async def container_to_args(compose, cnt, detached=True):
# handle podman extension # handle podman extension
x_podman = cnt.get("x-podman", None) x_podman = cnt.get("x-podman", None)
rootfs_mode = False
if x_podman is not None: if x_podman is not None:
for uidmap in x_podman.get("uidmaps", []): for uidmap in x_podman.get("uidmaps", []):
podman_args.extend(["--uidmap", uidmap]) podman_args.extend(["--uidmap", uidmap])
for gidmap in x_podman.get("gidmaps", []): for gidmap in x_podman.get("gidmaps", []):
podman_args.extend(["--gidmap", gidmap]) podman_args.extend(["--gidmap", gidmap])
rootfs = x_podman.get("rootfs", None)
if rootfs is not None:
rootfs_mode = True
podman_args.extend(["--rootfs", rootfs])
log.warning(
"WARNING: x-podman.rootfs and image both specified, \
image field ignored"
)
podman_args.append(cnt["image"]) # command, ..etc. if not rootfs_mode:
podman_args.append(cnt["image"]) # command, ..etc.
command = cnt.get("command", None) command = cnt.get("command", None)
if command is not None: if command is not None:
if is_str(command): if is_str(command):
@ -1831,7 +1841,9 @@ class PodmanCompose:
"service_name": service_name, "service_name": service_name,
**service_desc, **service_desc,
} }
if "image" not in cnt: x_podman = service_desc.get("x-podman", None)
rootfs_mode = x_podman is not None and x_podman.get("rootfs", None) is not None
if "image" not in cnt and not rootfs_mode:
cnt["image"] = f"{project_name}_{service_name}" cnt["image"] = f"{project_name}_{service_name}"
labels = norm_as_list(cnt.get("labels", None)) labels = norm_as_list(cnt.get("labels", None))
cnt["ports"] = norm_ports(cnt.get("ports", None)) cnt["ports"] = norm_ports(cnt.get("ports", None))

View File

@ -161,3 +161,25 @@ class TestContainerToArgs(unittest.IsolatedAsyncioTestCase):
"busybox", "busybox",
], ],
) )
async def test_rootfs_extension(self):
c = create_compose_mock()
cnt = get_minimal_container()
del cnt["image"]
cnt["x-podman"] = {
"rootfs": "/path/to/rootfs",
}
args = await container_to_args(c, cnt)
self.assertEqual(
args,
[
"--name=project_name_service_name1",
"-d",
"--network=bridge",
"--network-alias=service_name",
"--rootfs",
"/path/to/rootfs",
],
)