Skip to content
Snippets Groups Projects
Commit 606570f3 authored by Martin Mareš's avatar Martin Mareš
Browse files

Implement env_path

parent 77bd0bfa
Branches
No related tags found
No related merge requests found
......@@ -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"
......@@ -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'
......@@ -220,8 +220,7 @@ def create_container(cc: ContainerConfig) -> None:
['podman', 'rm', '-if', cc.name]
)
run_command(
[
cmd = [
'podman', 'create',
'--name', cc.name,
'--conmon-pidfile', cc.pid_file,
......@@ -232,8 +231,12 @@ def create_container(cc: ContainerConfig) -> None:
'--ip', ip,
'--subuidname', cc.user_name,
'--subgidname', cc.user_name,
] + cc.podman_create_options + [cc.image]
)
]
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:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment