diff options
| author | bozo.kopic <bozo@kopic.xyz> | 2022-03-28 00:37:49 +0200 |
|---|---|---|
| committer | bozo.kopic <bozo@kopic.xyz> | 2022-03-28 00:37:49 +0200 |
| commit | 93828206137278dcdc9e38f7c13181b14f65ed9c (patch) | |
| tree | 759a6ffd338b8d7dd1e335ee83d254d04f2370c2 /src_py | |
| parent | 24fea94665f1c3af45c4e1d3095bce5c15f3b1b2 (diff) | |
docker support
Diffstat (limited to 'src_py')
| -rw-r--r-- | src_py/boxhatter/common.py | 11 | ||||
| -rw-r--r-- | src_py/boxhatter/main.py | 32 | ||||
| -rw-r--r-- | src_py/boxhatter/server.py | 7 |
3 files changed, 36 insertions, 14 deletions
diff --git a/src_py/boxhatter/common.py b/src_py/boxhatter/common.py index ae314a5..15a4d23 100644 --- a/src_py/boxhatter/common.py +++ b/src_py/boxhatter/common.py @@ -30,3 +30,14 @@ class Commit(typing.NamedTuple): change: int status: Status output: str + + +class Settings(typing.NamedTuple): + log_level: str + ssh_key: typing.Optional[Path] + engine: str + + +settings = Settings(log_level='INFO', + ssh_key=None, + engine='podman') diff --git a/src_py/boxhatter/main.py b/src_py/boxhatter/main.py index 2cc30cc..7a16963 100644 --- a/src_py/boxhatter/main.py +++ b/src_py/boxhatter/main.py @@ -25,21 +25,26 @@ user_data_dir: Path = Path(appdirs.user_data_dir('boxhatter')) default_conf_path: Path = user_config_dir / 'server.yaml' default_db_path: Path = user_data_dir / 'boxhatter.db' -ssh_key_path: typing.Optional[Path] = None - @click.group() @click.option('--log-level', - default='INFO', + default=common.settings.log_level, type=click.Choice(['CRITICAL', 'ERROR', 'WARNING', 'INFO', 'DEBUG', 'NOTSET']), - help="log level") -@click.option('--ssh-key', default=None, metavar='PATH', type=Path, + help="log level (default INFO)") +@click.option('--ssh-key', metavar='PATH', type=Path, + default=common.settings.ssh_key, help="private key used for ssh authentication") +@click.option('--engine', + default=common.settings.engine, + help="container engine (default podman)") def main(log_level: str, - ssh_key: typing.Optional[Path]): - global ssh_key_path - ssh_key_path = ssh_key + ssh_key: typing.Optional[Path], + engine: str): + common.settings = common.Settings( + log_level=log_level, + ssh_key=(ssh_key.resolve() if ssh_key else None), + engine=engine) logging.config.dictConfig({ 'version': 1, @@ -97,11 +102,12 @@ def execute(action: str, image = conf['image'] command = conf['command'] - subprocess.run(['podman', 'run', '-i', '--rm', - '-v', f'{repo_dir}:/boxhatter', - *itertools.chain.from_iterable(('--env', i) - for i in env), - image, '/bin/sh'], + + cmd = [common.settings.engine, 'run', '-i', '--rm', + '-v', f'{repo_dir}:/boxhatter', + *itertools.chain.from_iterable(('--env', i) for i in env), + image, '/bin/sh'] + subprocess.run(cmd, input=f'set -e\ncd /boxhatter\n{command}\n', encoding='utf-8', check=True) diff --git a/src_py/boxhatter/server.py b/src_py/boxhatter/server.py index 24e4af0..7fbabde 100644 --- a/src_py/boxhatter/server.py +++ b/src_py/boxhatter/server.py @@ -169,7 +169,12 @@ class Server(aio.Resource): async def _execute(action, env, url, ref): - cmd = [sys.executable, '-m', 'boxhatter', 'execute', + cmd = [sys.executable, '-m', 'boxhatter', + '--log-level', common.settings.log_level, + *(['--ssh-key', common.settings.ssh_key] + if common.settings.ssh_key else []), + '--engine', common.settings.engine, + 'execute', '--action', action, *itertools.chain.from_iterable(('--env', i) for i in env), url, ref] |
