Archived
0

add container arguments

This commit is contained in:
dedic-one
2022-02-17 14:24:36 +03:00
parent 5e561d2531
commit 1013f44d40
2 changed files with 29 additions and 15 deletions

View File

@@ -12,5 +12,9 @@
env: { env: {
PMA_ARBITRARY: 1 PMA_ARBITRARY: 1
} }
cmd: [
arg1
arg2
]
} }

40
ctl.py
View File

@@ -11,9 +11,9 @@ import sys
import os import os
import pty import pty
def di_syscall(cmd): def di_syscall(cmd, workdir='.'):
#print('[dbg] CMD: %s' % (cmd)) #print('[dbg] CMD: %s' % (cmd))
process = subprocess.run(cmd, capture_output=True) process = subprocess.run(cmd, capture_output=True, cwd=workdir)
return (process.stdout.decode("utf-8").strip(), process.stderr.decode("utf-8").strip()) return (process.stdout.decode("utf-8").strip(), process.stderr.decode("utf-8").strip())
@@ -45,8 +45,9 @@ def get_config(path):
# -------------------------- # # -------------------------- #
class Container: class Container:
def __init__(self, conf): def __init__(self, conf, workdir):
self.conf = conf self.conf = conf
self.workdir = workdir
def status(self): def status(self):
@@ -71,12 +72,15 @@ class Container:
for publish in self.conf['ports']: for publish in self.conf['ports']:
cmd.append('--publish') cmd.append('--publish')
cmd.append(publish) cmd.append(publish)
for env_name in self.conf['env'].keys(): if self.conf.get('env', None) is not None:
cmd.append('--env') for env_name in self.conf['env'].keys():
cmd.append('%s=%s' % (env_name, self.conf['env'][env_name])) cmd.append('--env')
cmd.append('%s=%s' % (env_name, self.conf['env'][env_name]))
cmd.append(self.conf['image']) cmd.append(self.conf['image'])
for arg in self.conf['cmd']:
cmd.append('%s' % arg)
container_id, err = di_syscall(cmd) container_id, err = di_syscall(cmd, self.workdir)
if err: if err:
print('ERROR') print('ERROR')
print(err) print(err)
@@ -142,17 +146,23 @@ class Container:
if len(sys.argv) == 1: if len(sys.argv) == 1:
print_help_exit() print_help_exit()
begin_index_commands = 2 conf = None
conf = get_config(sys.argv[1]) begin_index_commands = None
if conf is None: workdir = None
if os.path.isfile(sys.argv[1]):
conf = get_config(sys.argv[1])
begin_index_commands = 2
workdir = os.path.dirname(sys.argv[1])
else:
conf = get_config('container.conf') conf = get_config('container.conf')
if conf is None: begin_index_commands = 1
print_help_exit() workdir = '.'
else:
begin_index_commands = 1 if conf is None:
print_help_exit()
conf = conf.with_fallback(create_default_config()) conf = conf.with_fallback(create_default_config())
container = Container(conf) container = Container(conf, workdir)
command = sys.argv[begin_index_commands] command = sys.argv[begin_index_commands]
if command == 'start': if command == 'start':