From 6b3e708913b66ee037845b98923ce7a64d35f047 Mon Sep 17 00:00:00 2001 From: Stefan Becker Date: Mon, 8 Jul 2019 14:47:27 +0300 Subject: [PATCH] Support healthcheck associative array Map keys to corresponding --healthcheck-XXX option Unfortunately --healthcheck-command only accepts a string, not a list of strings. Furthermore it splits the string on whitespace. Therefore the mapping of all allowed Docker Compose values is not possible. --- podman-compose.py | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/podman-compose.py b/podman-compose.py index 3f3d6ad..1ae8a55 100755 --- a/podman-compose.py +++ b/podman-compose.py @@ -474,6 +474,45 @@ def container_to_args(cnt, dirname, podman_path, shared_vols): args.extend(['--entrypoint', entrypoint]) else: args.extend(['--entrypoint', json.dumps(entrypoint)]) + + healthcheck = cnt.get('healthcheck') + if healthcheck is not None: + if is_dict(healthcheck): + if 'test' in healthcheck: + command = healthcheck['test'] + # test must be either a string or a list. If it’s a list, + # the first item must be either NONE, CMD or CMD-SHELL. + # If it’s a string, it’s equivalent to specifying CMD-SHELL + # followed by that string. + if is_str(command): + if re.search(r'\s', command): + # podman does not add shell to handle command with whitespace + args.extend(['--healthcheck-command', '"/bin/bash -c \'{}\'"'.format(command)]) + else: + args.extend(['--healthcheck-command', command]) + elif command[0] == 'NONE': + args.extend(['--healthcheck-command', 'none']) + elif command[0] == 'CMD-SHELL': + # podman does not add shell to handle command with whitespace + args.extend(['--healthcheck-command', '"/bin/bash -c \'{}\'"'.format(command[1])]) + else: + # podman splits string on white space + args.extend(['--healthcheck-command', '"{}"'.format(' '.join(command[1:]))]) + + # interval, timeout and start_period are specified as durations. + if 'interval' in healthcheck: + args.extend(['--healthcheck-interval', healthcheck['interval']]) + if 'timeout' in healthcheck: + args.extend(['--healthcheck-timeout', healthcheck['timeout']]) + if 'start_period' in healthcheck: + args.extend(['--healthcheck-start-period', healthcheck['start_period']]) + + # convert other parameters to string + if 'retries' in healthcheck: + args.extend(['--healthcheck-retries', '{}'.format(healthcheck['retries'])]) + else: + raise ValueError("'healthcheck' must be an associative array") + args.append(cnt.get('image')) # command, ..etc. command = cnt.get('command') if command is not None: