Compare commits
6 commits
64b797d18d
...
4ce53cb20b
Author | SHA1 | Date | |
---|---|---|---|
4ce53cb20b | |||
3616cc9abd | |||
53677fb84e | |||
ba7827d83b | |||
ff663f7835 | |||
ef63c0de14 |
4 changed files with 28 additions and 37 deletions
|
@ -101,19 +101,8 @@
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"env": {
|
"env": {
|
||||||
"type": "object",
|
"type": "object"
|
||||||
"properties": {
|
}
|
||||||
"FOO": {
|
|
||||||
"type": "string"
|
|
||||||
},
|
|
||||||
"MAN_WIDTH": {
|
|
||||||
"type": "string"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"required": [
|
|
||||||
"FOO",
|
|
||||||
"MAN_WIDTH"
|
|
||||||
]
|
|
||||||
},
|
},
|
||||||
"secrets": {
|
"secrets": {
|
||||||
"type": "object"
|
"type": "object"
|
||||||
|
@ -149,18 +138,6 @@
|
||||||
},
|
},
|
||||||
"required": [
|
"required": [
|
||||||
"name",
|
"name",
|
||||||
"image",
|
"image"
|
||||||
"privileged",
|
|
||||||
"read_only",
|
|
||||||
"replace",
|
|
||||||
"pull_policy",
|
|
||||||
"restart",
|
|
||||||
"network",
|
|
||||||
"dns",
|
|
||||||
"ports",
|
|
||||||
"env",
|
|
||||||
"secrets",
|
|
||||||
"volumes",
|
|
||||||
"capabilities"
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,7 +42,7 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"volumes": {
|
"volumes": {
|
||||||
"etc": "/etc",
|
"etc": "/etc:ro,noexec",
|
||||||
"var": "/var"
|
"var": "/var"
|
||||||
},
|
},
|
||||||
"capabilities": {
|
"capabilities": {
|
||||||
|
|
|
@ -72,7 +72,7 @@ class Volume:
|
||||||
cmd = f"# Create volume {self.name}\n"
|
cmd = f"# Create volume {self.name}\n"
|
||||||
cmd += f"if ! podman volume exists '{self.name}' 2> /dev/null\n"
|
cmd += f"if ! podman volume exists '{self.name}' 2> /dev/null\n"
|
||||||
cmd += "then\n"
|
cmd += "then\n"
|
||||||
cmd += "\tpodman volume create '{self.name}'\n"
|
cmd += f"\tpodman volume create '{self.name}'\n"
|
||||||
cmd += "fi\n"
|
cmd += "fi\n"
|
||||||
return cmd
|
return cmd
|
||||||
|
|
||||||
|
@ -123,7 +123,9 @@ class Secret:
|
||||||
def command(self) -> str:
|
def command(self) -> str:
|
||||||
"""Option for podman container create."""
|
"""Option for podman container create."""
|
||||||
cmd = (
|
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...
|
# Not a password, ruff...
|
||||||
if self.secret_type == "mount" and self.options != "": # noqa: S105
|
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"# Remove env-file {self.file}\n"
|
||||||
cmd += f"if [ -e '{self.file}' ]\n"
|
cmd += f"if [ -e '{self.file}' ]\n"
|
||||||
cmd += "then\n"
|
cmd += "then\n"
|
||||||
cmd += "\trm '{self.file}'\n"
|
cmd += f"\trm '{self.file}'\n"
|
||||||
cmd += "fi\n"
|
cmd += "fi\n"
|
||||||
return cmd
|
return cmd
|
||||||
|
|
||||||
|
|
|
@ -14,6 +14,14 @@ from pathlib import Path
|
||||||
from container import ConfigError, Container
|
from container import ConfigError, Container
|
||||||
from log import Log
|
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:
|
def load_container_config(file: Path, log: Log) -> dict | None:
|
||||||
"""Load a container config."""
|
"""Load a container config."""
|
||||||
|
@ -98,13 +106,17 @@ def main() -> None:
|
||||||
Path(base).mkdir()
|
Path(base).mkdir()
|
||||||
for script, method in scripts.items():
|
for script, method in scripts.items():
|
||||||
s = Path(f"{base}/{script}")
|
s = Path(f"{base}/{script}")
|
||||||
|
script_content = ""
|
||||||
|
if script == "create":
|
||||||
|
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:
|
with s.open("w+", encoding="utf-8") as f:
|
||||||
f.write("#!/bin/sh\n")
|
f.write(HEADER)
|
||||||
if script == "create":
|
f.write(script_content)
|
||||||
f.write(ct.create_volumes())
|
|
||||||
f.write(ct.create_secrets())
|
|
||||||
f.write(ct.create_environment())
|
|
||||||
f.write(method())
|
|
||||||
s.chmod(
|
s.chmod(
|
||||||
stat.S_IRWXU
|
stat.S_IRWXU
|
||||||
| stat.S_IRGRP
|
| stat.S_IRGRP
|
||||||
|
|
Loading…
Add table
Reference in a new issue