Compare commits

...

2 Commits

View File

@ -80,8 +80,9 @@ def docker_create_user (container, user, uid=None):
def docker_start (container):
call(["docker", "start", container])
def docker_exec (container, command, user, env={}, work_dir=None):
call(["docker", "exec", "--user", user, "-ti"] + \
def docker_exec (container, command, user, env={}, tty=True, work_dir=None):
call(["docker", "exec", "--user", user] + \
(["-ti" if tty else "-i"]) + \
(["--workdir", work_dir] if work_dir else []) + \
list(chain.from_iterable([["--env", f"{kv[0]}={kv[1]}"] for kv in env.items()])) + \
[container] + command)
@ -131,13 +132,14 @@ def expand_user_volumes (volumes):
return mappings
def find_config_files (config_name):
def find_config_files (config_names):
config_files = []
directory = os.path.abspath(os.getcwd())
while True:
config_file = os.path.join(directory, config_name)
if os.path.exists(config_file):
config_files.append(config_file)
for config_name in config_names:
config_file = os.path.join(directory, config_name)
if os.path.exists(config_file):
config_files.append(config_file)
if directory == "/" or (not directory):
break
@ -174,6 +176,7 @@ command_env = {}
command_workdir = None
quiet = False
tty = sys.stdout.isatty()
# load config from files
config = load_config_files({
@ -188,8 +191,9 @@ config = load_config_files({
"user_volumes": user_volumes,
"pull": pull,
"command_env": command_env,
"cwd": os.getcwd()
}, find_config_files(OTHERWORLD_CONFIG))
"cwd": os.getcwd(),
"tty": tty
}, find_config_files([OTHERWORLD_CONFIG, "{}{}".format(container_name, OTHERWORLD_CONFIG)]))
locals().update(config)
while len(command) > 0:
@ -197,6 +201,9 @@ while len(command) > 0:
if arg == "--quiet":
command = command[1:]
quiet = True
elif arg == "--notty":
command = command[1:]
tty = False
elif arg == "--rm":
actions.append("rm")
command = command[1:]
@ -313,4 +320,4 @@ except Exception:
if not quiet:
print(f">> Welcome to {container_name} (IP {container['NetworkSettings']['IPAddress']})")
docker_exec(container_name, command, command_user, command_env, command_workdir)
docker_exec(container_name, command, command_user, command_env, tty, command_workdir)