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