1
0
Fork 0

Compare commits

..

6 commits

Author SHA1 Message Date
4ce53cb20b
example.container: Update example config with volume mount options
Volumes can be mounted with some different flags or no flags at all.
Since converting the string into an object would be overkill, as most of
the time the default options should suffice, and branching in
Volumes.from_json() to handle both strings and objects is also no the
cleanest method, implement it by using what already exists. Mount points
are not checked by the script, so the mount options can just be added to
the CONTAINER-DIR part of the volume config.

Signed-off-by: Enno Tensing <tenno@suij.in>
2025-07-29 09:50:56 +02:00
3616cc9abd
generate: container: Split Secret.command()'s cmd over multiple lines
Neatly sperate the options to one per line.

Signed-off-by: Enno Tensing <tenno@suij.in>
2025-07-29 09:46:01 +02:00
53677fb84e
generate: container: Add missing f to f-strings
Two f-strings where missing their f and thus volume creation and
env-file deletion where broken.

Signed-off-by: Enno Tensing <tenno@suij.in>
2025-07-29 09:42:22 +02:00
ba7827d83b
generate: generate: Add a identifying header to generated scripts
Add a header stating that the script was generated, which version
generated it and where to send bug reports.

Signed-off-by: Enno Tensing <tenno@suij.in>
2025-07-29 09:38:39 +02:00
ff663f7835
generate: generate: Handle empty control scripts
When a given control script is empty, because the current config is
missing a value for said script or is malformed, a script with only
the shebang was written. Change it, so that it now executes true.

Signed-off-by: Enno Tensing <tenno@suij.in>
2025-07-29 09:31:52 +02:00
ef63c0de14
containerrc: Remove optional parts from schema
A container can be created from a name and an image, no other part is
required. Reflect that in the JSON schema, by removing most top-level
required entries. Also remove the hardcoded env-vars from the schema.

Signed-off-by: Enno Tensing <tenno@suij.in>
2025-07-29 09:25:19 +02:00
4 changed files with 28 additions and 37 deletions

View file

@ -101,20 +101,9 @@
]
},
"env": {
"type": "object",
"properties": {
"FOO": {
"type": "string"
},
"MAN_WIDTH": {
"type": "string"
"type": "object"
}
},
"required": [
"FOO",
"MAN_WIDTH"
]
},
"secrets": {
"type": "object"
},
@ -149,18 +138,6 @@
},
"required": [
"name",
"image",
"privileged",
"read_only",
"replace",
"pull_policy",
"restart",
"network",
"dns",
"ports",
"env",
"secrets",
"volumes",
"capabilities"
"image"
]
}
}

View file

@ -42,7 +42,7 @@
}
},
"volumes": {
"etc": "/etc",
"etc": "/etc:ro,noexec",
"var": "/var"
},
"capabilities": {

View file

@ -72,7 +72,7 @@ class Volume:
cmd = f"# Create volume {self.name}\n"
cmd += f"if ! podman volume exists '{self.name}' 2> /dev/null\n"
cmd += "then\n"
cmd += "\tpodman volume create '{self.name}'\n"
cmd += f"\tpodman volume create '{self.name}'\n"
cmd += "fi\n"
return cmd
@ -123,7 +123,9 @@ class Secret:
def command(self) -> str:
"""Option for podman container create."""
cmd = (
f"--secret {self.name},type={self.secret_type},target={self.target}"
f"--secret {self.name},:"
f"type={self.secret_type},"
f"target={self.target}"
)
# Not a password, ruff...
if self.secret_type == "mount" and self.options != "": # noqa: S105
@ -188,7 +190,7 @@ class Environment:
cmd = f"# Remove env-file {self.file}\n"
cmd += f"if [ -e '{self.file}' ]\n"
cmd += "then\n"
cmd += "\trm '{self.file}'\n"
cmd += f"\trm '{self.file}'\n"
cmd += "fi\n"
return cmd

View file

@ -14,6 +14,14 @@ from pathlib import Path
from container import ConfigError, Container
from log import Log
GENERATE_VERSION = "0.0.2"
HEADER = f"""#!/bin/sh
# This script was generated by containerctl v{GENERATE_VERSION}
# Report bugs with _this script_ to <tenno+containerctl@suij.in>
"""
def load_container_config(file: Path, log: Log) -> dict | None:
"""Load a container config."""
@ -98,13 +106,17 @@ def main() -> None:
Path(base).mkdir()
for script, method in scripts.items():
s = Path(f"{base}/{script}")
with s.open("w+", encoding="utf-8") as f:
f.write("#!/bin/sh\n")
script_content = ""
if script == "create":
f.write(ct.create_volumes())
f.write(ct.create_secrets())
f.write(ct.create_environment())
f.write(method())
script_content += ct.create_volumes()
script_content += ct.create_secrets()
script_content += ct.create_environment()
script_content += method()
if script_content == "":
script_content = "true"
with s.open("w+", encoding="utf-8") as f:
f.write(HEADER)
f.write(script_content)
s.chmod(
stat.S_IRWXU
| stat.S_IRGRP