diff --git a/etc/container.toml.example b/etc/container.toml.example index 60403f06b17b76d0c483963e354ec46f7e48ff34..47d659c4ba11564123e6874a2efa7f1c81fdc314 100644 --- a/etc/container.toml.example +++ b/etc/container.toml.example @@ -19,3 +19,7 @@ create_on_start = false # Extra options passed to "podman create" (default=none) podman_create_options = [] + +# Environment file (relative to root_dir, default=none) +# Contains lines of format "KEY=VALUE" +# env_file = "environment" diff --git a/shipcat/config.py b/shipcat/config.py index 3cfe988ba581727b973b3ff9a6dadf0d15d7cbc2..f4989c5fb6068000dc21c8c5f002f25450c0c259 100644 --- a/shipcat/config.py +++ b/shipcat/config.py @@ -6,7 +6,7 @@ from grp import getgrnam from pathlib import Path import re import tomllib -from typing import Set, List +from typing import Set, List, Optional from .json_walker import Walker, WalkerError @@ -62,6 +62,7 @@ class ContainerConfig: create_on_start: bool global_config: GlobalConfig podman_create_options: List[str] + env_path: Optional[Path] # Automatically generated pid_file: str @@ -125,6 +126,12 @@ class ContainerConfig: self.create_on_start = w['create_on_start'].as_bool(self.global_config.default_create_on_start) self.podman_create_options = [o.as_str() for o in w['podman_create_options'].default_to([]).array_values()] + env_file = w['env_file'].as_optional_str() + if env_file is None: + self.env_path = None + else: + self.env_path = self.root_path / env_file + self.pid_file = f'/run/shc/{self.name}.pid' self.user_name = self.name self.service_name = f'shc@{self.name}.service' diff --git a/shipcat/main.py b/shipcat/main.py index 9e315ebf0f65e6908d2731708d8c0b7c9af4c214..1bbee1952711b2ec9d2c332de973d7bd425f548b 100755 --- a/shipcat/main.py +++ b/shipcat/main.py @@ -220,20 +220,23 @@ def create_container(cc: ContainerConfig) -> None: ['podman', 'rm', '-if', cc.name] ) - run_command( - [ - 'podman', 'create', - '--name', cc.name, - '--conmon-pidfile', cc.pid_file, - '--log-driver', 'journald', - '--hostname', cc.name, - '--volume', f'{cc.data_path}:/data', - '--network', 'static', - '--ip', ip, - '--subuidname', cc.user_name, - '--subgidname', cc.user_name, - ] + cc.podman_create_options + [cc.image] - ) + cmd = [ + 'podman', 'create', + '--name', cc.name, + '--conmon-pidfile', cc.pid_file, + '--log-driver', 'journald', + '--hostname', cc.name, + '--volume', f'{cc.data_path}:/data', + '--network', 'static', + '--ip', ip, + '--subuidname', cc.user_name, + '--subgidname', cc.user_name, + ] + if cc.env_path is not None: + cmd.extend(['--env-file', str(cc.env_path)]) + cmd.extend(cc.podman_create_options) + cmd.append(cc.image) + run_command(cmd) def cmd_start(args: argparse.Namespace) -> None: