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