Migrate x-podman dictionary to x-podman.* fields in container root

Signed-off-by: Povilas Kanapickas <povilas@radix.lt>
This commit is contained in:
Povilas Kanapickas 2024-04-28 18:23:19 +03:00
parent 0a6c057486
commit 9599cc039e
3 changed files with 50 additions and 42 deletions

View File

@ -1,6 +1,30 @@
# Podman specific extensions to the docker-compose format # Podman specific extensions to the docker-compose format
Podman-compose supports the following extension to the docker-compose format. Podman-compose supports the following extension to the docker-compose format. These extensions
are generally specified under fields with "x-podman" prefix in the compose file.
## Container management
The following extension keys are available under container configuration:
* `x-podman.uidmap` - Run the container in a new user namespace using the supplied UID mapping.
* `x-podman.gidmap` - Run the container in a new user namespace using the supplied GID mapping.
* `x-podman.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/).
## Per-network MAC-addresses ## Per-network MAC-addresses
@ -65,27 +89,3 @@ 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/).

View File

@ -1144,21 +1144,22 @@ async def container_to_args(compose, cnt, detached=True):
podman_args.extend(["--healthcheck-retries", str(healthcheck["retries"])]) podman_args.extend(["--healthcheck-retries", str(healthcheck["retries"])])
# handle podman extension # handle podman extension
x_podman = cnt.get("x-podman", None) if 'x-podman' in cnt:
raise ValueError(
'Configuration under x-podman has been migrated to x-podman.uidmap and '
'x-podman.gidman fields'
)
rootfs_mode = False rootfs_mode = False
if x_podman is not None: for uidmap in cnt.get('x-podman.uidmaps', []):
for uidmap in x_podman.get("uidmaps", []): podman_args.extend(["--uidmap", uidmap])
podman_args.extend(["--uidmap", uidmap]) for gidmap in cnt.get('x-podman.gidmaps', []):
for gidmap in x_podman.get("gidmaps", []): podman_args.extend(["--gidmap", gidmap])
podman_args.extend(["--gidmap", gidmap]) rootfs = cnt.get('x-podman.rootfs', None)
rootfs = x_podman.get("rootfs", None) if rootfs is not None:
if rootfs is not None: rootfs_mode = True
rootfs_mode = True podman_args.extend(["--rootfs", rootfs])
podman_args.extend(["--rootfs", rootfs]) log.warning("WARNING: x-podman.rootfs and image both specified, image field ignored")
log.warning(
"WARNING: x-podman.rootfs and image both specified, \
image field ignored"
)
if not rootfs_mode: if not rootfs_mode:
podman_args.append(cnt["image"]) # command, ..etc. podman_args.append(cnt["image"]) # command, ..etc.

View File

@ -162,14 +162,21 @@ class TestContainerToArgs(unittest.IsolatedAsyncioTestCase):
], ],
) )
async def test_uidmaps_extension_old_path(self):
c = create_compose_mock()
cnt = get_minimal_container()
cnt['x-podman'] = {'uidmaps': ['1000:1000:1']}
with self.assertRaises(ValueError):
await container_to_args(c, cnt)
async def test_rootfs_extension(self): async def test_rootfs_extension(self):
c = create_compose_mock() c = create_compose_mock()
cnt = get_minimal_container() cnt = get_minimal_container()
del cnt["image"] del cnt["image"]
cnt["x-podman"] = { cnt["x-podman.rootfs"] = "/path/to/rootfs"
"rootfs": "/path/to/rootfs",
}
args = await container_to_args(c, cnt) args = await container_to_args(c, cnt)
self.assertEqual( self.assertEqual(