Add ability to run multiple "actions" (commit/rm) and even an otherworld command (potentially starting a new container)

This commit is contained in:
Adrian Kuschelyagi Malacoda 2020-08-20 02:44:55 -05:00
parent d0adb3b0ed
commit 71fe46e881

View File

@ -119,6 +119,8 @@ command_user = user
user_volumes = USER_VOLUMES
pull = False
actions = []
command_env = {}
quiet = False
@ -128,16 +130,11 @@ while len(command) > 0:
command = command[1:]
quiet = True
elif arg == "--rm":
if not quiet:
print(f">> Removing container: {container_name}")
docker_rm(container_name)
sys.exit(0)
actions.append("rm")
command = command[1:]
elif arg == "--commit":
image_name = get_generated_image_name(container_name)
if not quiet:
print(f">> Committing container: {container_name} to image: {image_name}")
docker_commit(container_name, image_name)
sys.exit(0)
actions.append("commit")
command = command[1:]
elif arg == "--sudo":
command_user = "root"
command = command[1:]
@ -164,7 +161,22 @@ while len(command) > 0:
else:
break
if len(command) == 0:
if actions:
if "commit" in actions:
target_image_name = get_generated_image_name(container_name)
if not quiet:
print(f">> Committing container: {container_name} to image: {target_image_name}")
docker_commit(container_name, target_image_name)
if "rm" in actions:
if not quiet:
print(f">> Removing container: {container_name}")
docker_rm(container_name)
if not command:
sys.exit(0)
if not command:
command = DEFAULT_COMMAND
container = None