1
0
Fork 0

generate: container: Allow one volume to be mounted multiple times

Signed-off-by: Enno Tensing <tenno@suij.in>
This commit is contained in:
Enno Tensing 2025-08-08 15:58:53 +02:00
parent 8b7221363c
commit 7a794197f4
Signed by: tenno
GPG key ID: 95265603BD36E66C

View file

@ -244,7 +244,7 @@ class Volume:
"""Container Volume."""
name: str
path: str
path: list
@classmethod
def from_json(cls, val: ConfigValue, logger: Log) -> list:
@ -254,7 +254,16 @@ class Volume:
if not isinstance(val, dict):
logger.log_warning("Volume key is present, but malformed.")
return []
return [cls(key, value) for key, value in val.items()]
return [
Volume.from_json_entry(key, value) for key, value in val.items()
]
@classmethod
def from_json_entry(cls, key: str, value: str | list) -> Self:
"""Create from JSON entry."""
if isinstance(value, str):
return cls(key, [value])
return cls(key, value)
def is_host_volume(self) -> bool:
"""Check if this Volume is a named or a host volume."""
@ -262,7 +271,10 @@ class Volume:
def command(self) -> str:
"""Option for podman container create."""
return f"--volume {self.name}:{self.path}"
cmd = ""
for path in self.path:
cmd += f"\t--volume {self.name}:{path} \\\n"
return cmd
def create(self) -> str:
"""Create volume, if it does not exist."""
@ -324,9 +336,7 @@ class Secret:
options = maybe_or(val[key], "options", "")
if options is None:
options = ""
secrets.append(
cls(name, str(secret_type), target, str(options))
)
secrets.append(cls(name, str(secret_type), target, str(options)))
return secrets
@ -708,7 +718,7 @@ class Container:
for secret in self.secrets:
cmd += f"{secret.command()}"
for volume in self.volumes:
cmd += f"\t{volume.command()} \\\n"
cmd += f"{volume.command()}"
for capability in self.capabilities:
cmd += f"\t{capability.command()} \\\n"
cmd += f"{self.accounting.command()}"