Compare commits
3 commits
6d9f63abb5
...
34b0d6f4ea
Author | SHA1 | Date | |
---|---|---|---|
34b0d6f4ea | |||
31d94b5266 | |||
260a0dcc52 |
3 changed files with 46 additions and 29 deletions
12
Makefile
12
Makefile
|
@ -7,12 +7,12 @@ CONTAINERDIR ?= $(VARDIR)/containers
|
||||||
|
|
||||||
install:
|
install:
|
||||||
mkdir -p \
|
mkdir -p \
|
||||||
$(PREFIX)/$(GENERATEDIR) \
|
$(PREFIX)$(GENERATEDIR) \
|
||||||
$(PREFIX)/$(CONFIGDIR) \
|
$(PREFIX)$(CONFIGDIR) \
|
||||||
$(PREFIX)/$(CONTAINERDIR) \
|
$(PREFIX)$(CONTAINERDIR) \
|
||||||
$(PREFIX)/$(BINDIR)
|
$(PREFIX)$(BINDIR)
|
||||||
install -m755 containerctl $(PREFIX)/$(BINDIR)
|
install -m755 containerctl $(PREFIX)$(BINDIR)
|
||||||
cp -t $(PREFIX)/$(GENERATEDIR) \
|
cp -t $(PREFIX)$(GENERATEDIR) \
|
||||||
generate/container.py \
|
generate/container.py \
|
||||||
generate/log.py \
|
generate/log.py \
|
||||||
generate/generate.py
|
generate/generate.py
|
||||||
|
|
|
@ -384,12 +384,17 @@ class Environment:
|
||||||
|
|
||||||
def create(self) -> str:
|
def create(self) -> str:
|
||||||
"""Create env file."""
|
"""Create env file."""
|
||||||
cmd = f"# Create env-file {self.file}\n"
|
cmd = ""
|
||||||
|
header = f"# Create env-file {self.file}\n"
|
||||||
|
|
||||||
for var in self.variables:
|
for var in self.variables:
|
||||||
escaped_var = var.replace("'", "%b")
|
escaped_var = var.replace("'", "%b")
|
||||||
cmd += f"printf '{escaped_var}\\n' \"'\" \"'\" >> '{self.file}'\n"
|
cmd += f"printf '{escaped_var}\\n' \"'\" \"'\" >> '{self.file}'\n"
|
||||||
|
|
||||||
return cmd
|
if cmd == "":
|
||||||
|
return ""
|
||||||
|
|
||||||
|
return header + cmd
|
||||||
|
|
||||||
def remove(self) -> str:
|
def remove(self) -> str:
|
||||||
"""Remove env file."""
|
"""Remove env file."""
|
||||||
|
@ -418,27 +423,41 @@ class Ports:
|
||||||
return cls([], [])
|
return cls([], [])
|
||||||
tcp_ports = maybe(val, "tcp")
|
tcp_ports = maybe(val, "tcp")
|
||||||
udp_ports = maybe(val, "udp")
|
udp_ports = maybe(val, "udp")
|
||||||
|
if tcp_ports is None:
|
||||||
|
tcp_ports = []
|
||||||
|
if udp_ports is None:
|
||||||
|
udp_ports = []
|
||||||
|
if not isinstance(tcp_ports, list) and not isinstance(udp_ports, list):
|
||||||
|
logger.log_warning("Port configuration is malformed!")
|
||||||
|
return cls([], [])
|
||||||
if not isinstance(tcp_ports, list):
|
if not isinstance(tcp_ports, list):
|
||||||
logger.log_warning("Key tcp_ports is not an array!")
|
logger.log_warning("tcp_ports configuration is malformed!")
|
||||||
return cls([], [])
|
return cls([], udp_ports)
|
||||||
if not isinstance(udp_ports, list):
|
if not isinstance(udp_ports, list):
|
||||||
logger.log_warning("Key udp_ports is not an array!")
|
logger.log_warning("udp_ports configuration is malformed!")
|
||||||
return cls([], [])
|
return cls(tcp_ports, [])
|
||||||
return cls(tcp_ports, udp_ports)
|
return cls(tcp_ports, udp_ports)
|
||||||
|
|
||||||
def command(self) -> str:
|
def command(self) -> str:
|
||||||
"""Option for podman container create."""
|
"""Option for podman container create."""
|
||||||
ports = ""
|
|
||||||
seperator = " \\\n"
|
seperator = " \\\n"
|
||||||
ports += seperator.join(
|
tcp_ports = seperator.join(
|
||||||
[f"\t--publish {port}/tcp" for port in self.tcp_ports]
|
[f"\t--publish {port}/tcp" for port in self.tcp_ports]
|
||||||
)
|
)
|
||||||
ports += seperator
|
udp_ports = seperator.join(
|
||||||
ports += seperator.join(
|
|
||||||
[f"\t--publish {port}/udp" for port in self.udp_ports]
|
[f"\t--publish {port}/udp" for port in self.udp_ports]
|
||||||
)
|
)
|
||||||
ports += seperator
|
|
||||||
return ports
|
if tcp_ports == "" and udp_ports == "":
|
||||||
|
return ""
|
||||||
|
|
||||||
|
if tcp_ports == "":
|
||||||
|
return udp_ports + seperator
|
||||||
|
|
||||||
|
if udp_ports == "":
|
||||||
|
return tcp_ports + seperator
|
||||||
|
|
||||||
|
return tcp_ports + seperator + udp_ports + seperator
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
|
@ -469,11 +488,11 @@ class Network:
|
||||||
"""Option for podman container create."""
|
"""Option for podman container create."""
|
||||||
if self.mode == "":
|
if self.mode == "":
|
||||||
return ""
|
return ""
|
||||||
cmd = f"--network={self.mode}"
|
cmd = f"\t--network={self.mode}"
|
||||||
opts = ",".join(self.options)
|
opts = ",".join(self.options)
|
||||||
if opts != "":
|
if opts != "":
|
||||||
cmd += f":{opts}"
|
cmd += f":{opts}"
|
||||||
return cmd
|
return cmd + " \\\n"
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
|
@ -513,9 +532,7 @@ class Capability:
|
||||||
if val is None:
|
if val is None:
|
||||||
return []
|
return []
|
||||||
if not isinstance(val, dict):
|
if not isinstance(val, dict):
|
||||||
logger.log_warning(
|
logger.log_warning("Capabilities key is malformed!")
|
||||||
"Capabilities key is malformed!"
|
|
||||||
)
|
|
||||||
return []
|
return []
|
||||||
add = [cls(value, "add") for value in val["add"]]
|
add = [cls(value, "add") for value in val["add"]]
|
||||||
drop = [cls(value, "drop") for value in val["drop"]]
|
drop = [cls(value, "drop") for value in val["drop"]]
|
||||||
|
@ -554,11 +571,11 @@ class Dns:
|
||||||
if len(self.servers) == 0 and self.search == "":
|
if len(self.servers) == 0 and self.search == "":
|
||||||
return ""
|
return ""
|
||||||
if len(self.servers) == 0:
|
if len(self.servers) == 0:
|
||||||
return f"--dns-search={self.search}"
|
return f"\t--dns-search={self.search} \\\n"
|
||||||
if self.search == "":
|
if self.search == "":
|
||||||
return f"--dns={','.join(self.servers)}"
|
return f"\t--dns={','.join(self.servers)} \\\n"
|
||||||
|
|
||||||
cmd = f"--dns-search={self.search} \\\n\t--dns="
|
cmd = f"\t--dns-search={self.search} \\\n\t--dns="
|
||||||
cmd += ",".join(self.servers)
|
cmd += ",".join(self.servers)
|
||||||
|
|
||||||
return cmd
|
return cmd
|
||||||
|
@ -667,8 +684,8 @@ class Container:
|
||||||
cmd += f"\t--restart={self.restart} \\\n"
|
cmd += f"\t--restart={self.restart} \\\n"
|
||||||
cmd += f"\t--pull={self.pull_policy} \\\n"
|
cmd += f"\t--pull={self.pull_policy} \\\n"
|
||||||
cmd += f"\t--tz={self.timezone} \\\n"
|
cmd += f"\t--tz={self.timezone} \\\n"
|
||||||
cmd += f"\t{self.network.command()} \\\n"
|
cmd += f"{self.network.command()}"
|
||||||
cmd += f"\t{self.dns.command()} \\\n"
|
cmd += f"{self.dns.command()}"
|
||||||
cmd += f"{self.ports.command()}"
|
cmd += f"{self.ports.command()}"
|
||||||
if self.env is not None:
|
if self.env is not None:
|
||||||
cmd += f"\t{self.env.command()} \\\n"
|
cmd += f"\t{self.env.command()} \\\n"
|
||||||
|
|
|
@ -14,7 +14,7 @@ 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.5"
|
GENERATE_VERSION = "0.0.6"
|
||||||
HEADER = f"""#!/bin/sh
|
HEADER = f"""#!/bin/sh
|
||||||
# This script was generated by containerctl v{GENERATE_VERSION}
|
# This script was generated by containerctl v{GENERATE_VERSION}
|
||||||
# Report bugs with _this script_ to <tenno+containerctl@suij.in>
|
# Report bugs with _this script_ to <tenno+containerctl@suij.in>
|
||||||
|
|
Loading…
Add table
Reference in a new issue