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: {
PMA_ARBITRARY: 1
}
cmd: [
arg1
arg2
]
}

28
ctl.py
View File

@@ -11,9 +11,9 @@ import sys
import os
import pty
def di_syscall(cmd):
def di_syscall(cmd, workdir='.'):
#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())
@@ -45,8 +45,9 @@ def get_config(path):
# -------------------------- #
class Container:
def __init__(self, conf):
def __init__(self, conf, workdir):
self.conf = conf
self.workdir = workdir
def status(self):
@@ -71,12 +72,15 @@ class Container:
for publish in self.conf['ports']:
cmd.append('--publish')
cmd.append(publish)
if self.conf.get('env', None) is not None:
for env_name in self.conf['env'].keys():
cmd.append('--env')
cmd.append('%s=%s' % (env_name, self.conf['env'][env_name]))
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:
print('ERROR')
print(err)
@@ -142,17 +146,23 @@ class Container:
if len(sys.argv) == 1:
print_help_exit()
begin_index_commands = 2
conf = None
begin_index_commands = None
workdir = None
if os.path.isfile(sys.argv[1]):
conf = get_config(sys.argv[1])
if conf is None:
begin_index_commands = 2
workdir = os.path.dirname(sys.argv[1])
else:
conf = get_config('container.conf')
begin_index_commands = 1
workdir = '.'
if conf is None:
print_help_exit()
else:
begin_index_commands = 1
conf = conf.with_fallback(create_default_config())
container = Container(conf)
container = Container(conf, workdir)
command = sys.argv[begin_index_commands]
if command == 'start':