Skip to content

Commit

Permalink
Support podman's external rootfs management
Browse files Browse the repository at this point in the history
Signed-off-by: GnSight <[email protected]>
  • Loading branch information
ftyghome committed Mar 16, 2024
1 parent d704622 commit bb857aa
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 3 deletions.
17 changes: 14 additions & 3 deletions podman_compose.py
Original file line number Diff line number Diff line change
Expand Up @@ -1060,13 +1060,22 @@ async def container_to_args(compose, cnt, detached=True):

# handle podman extension
x_podman = cnt.get("x-podman", None)
rootfs_mode = False
if x_podman is not None:
for uidmap in x_podman.get("uidmaps", []):
podman_args.extend(["--uidmap", uidmap])
for gidmap in x_podman.get("gidmaps", []):
podman_args.extend(["--gidmap", gidmap])

podman_args.append(cnt["image"]) # command, ..etc.

rootfs = x_podman.get("rootfs", None)
if rootfs is not None:
rootfs_mode = True
podman_args.extend(["--rootfs", rootfs])
if "image" in cnt.keys():
log.warning("WARNING: x-podman.rootfs and image both specified, image field ignored")

if not rootfs_mode:
podman_args.append(cnt["image"]) # command, ..etc.
command = cnt.get("command", None)
if command is not None:
if is_str(command):
Expand Down Expand Up @@ -1746,7 +1755,9 @@ def _parse_compose_file(self):
"service_name": service_name,
**service_desc,
}
if "image" not in cnt:

x_podman = service_desc.get("x-podman", None)
if "image" not in cnt and (x_podman is None or x_podman.get("rootfs", None) is None):
cnt["image"] = f"{project_name}_{service_name}"
labels = norm_as_list(cnt.get("labels", None))
cnt["ports"] = norm_ports(cnt.get("ports", None))
Expand Down
24 changes: 24 additions & 0 deletions pytests/test_container_to_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,3 +173,27 @@ async def test_http_proxy(self):
"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",
"--net",
"",
"--network-alias",
"service_name",
"--rootfs",
"/path/to/rootfs",
],
)

0 comments on commit bb857aa

Please sign in to comment.