Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support healthcheck associative array #22

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions podman-compose.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down