mirror of
https://github.com/containers/podman-compose.git
synced 2025-06-03 08:55:37 +02:00
Merge pull request #737 from ftyghome/feat_rootfs
Support podman's external rootfs management
This commit is contained in:
commit
0a6c057486
@ -65,3 +65,27 @@ In addition, podman-compose supports the following podman-specific values for `n
|
|||||||
|
|
||||||
The options to the network modes are passed to the `--network` option of the `podman create` command
|
The options to the network modes are passed to the `--network` option of the `podman create` command
|
||||||
as-is.
|
as-is.
|
||||||
|
|
||||||
|
# Service management
|
||||||
|
|
||||||
|
Podman-compose extends the compose specification to support some unique features of Podman. These extensions can be specified in the compose file under the "x-podman" field.
|
||||||
|
|
||||||
|
Currently, podman-compose supports the following extensions:
|
||||||
|
|
||||||
|
* `uidmap` - Run the container in a new user namespace using the supplied UID mapping.
|
||||||
|
|
||||||
|
* `gidmap` - Run the container in a new user namespace using the supplied GID mapping.
|
||||||
|
|
||||||
|
* `rootfs` - Run the container without requiring any image management; the rootfs of the container is assumed to be managed externally.
|
||||||
|
|
||||||
|
For example, the following docker-compose.yml allows running a podman container with externally managed rootfs.
|
||||||
|
```yml
|
||||||
|
version: "3"
|
||||||
|
services:
|
||||||
|
my_service:
|
||||||
|
command: ["/bin/busybox"]
|
||||||
|
x-podman:
|
||||||
|
rootfs: "/path/to/rootfs"
|
||||||
|
```
|
||||||
|
|
||||||
|
For explanations of these extensions, please refer to the [Podman Documentation](https://docs.podman.io/).
|
||||||
|
@ -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))
|
||||||
|
@ -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",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user