ENH: add timeout option to podman-compose down, as in https://docs.docker.com/compose/reference/down/

This commit is contained in:
Johannes Laurin Hörmann 2020-05-24 16:09:56 +02:00 committed by Muayyad Alsadi
parent 294f8ee37b
commit 3712b545a9

View File

@ -1161,8 +1161,14 @@ def compose_up(compose, args):
@cmd_run(podman_compose, 'down', 'tear down entire stack') @cmd_run(podman_compose, 'down', 'tear down entire stack')
def compose_down(compose, args): def compose_down(compose, args):
podman_args=[]
timeout=getattr(args, 'timeout', None)
if timeout is None:
timeout = 1
podman_args.extend(['-t', "{}".format(timeout)])
for cnt in compose.containers: for cnt in compose.containers:
compose.podman.run(["stop", "-t=1", cnt["name"]], sleep=0) compose.podman.run(["stop", *podman_args, cnt["name"]], sleep=0)
for cnt in compose.containers: for cnt in compose.containers:
compose.podman.run(["rm", cnt["name"]], sleep=0) compose.podman.run(["rm", cnt["name"]], sleep=0)
for pod in compose.pods: for pod in compose.pods:
@ -1331,7 +1337,7 @@ def compose_run_parse(parser):
parser.add_argument('cnt_command', metavar='command', nargs=argparse.REMAINDER, parser.add_argument('cnt_command', metavar='command', nargs=argparse.REMAINDER,
help='command and its arguments') help='command and its arguments')
@cmd_parse(podman_compose, ['stop', 'restart']) @cmd_parse(podman_compose, ['down', 'stop', 'restart'])
def compose_parse_timeout(parser): def compose_parse_timeout(parser):
parser.add_argument("-t", "--timeout", parser.add_argument("-t", "--timeout",
help="Specify a shutdown timeout in seconds. ", help="Specify a shutdown timeout in seconds. ",