Merge pull request #22 from stefanb2/topic-support-healthcheck

Support healthcheck associative array
This commit is contained in:
Muayyad Alsadi 2019-07-08 23:01:20 +03:00 committed by GitHub
commit 2f4da3fddb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -474,6 +474,45 @@ def container_to_args(cnt, dirname, podman_path, shared_vols):
args.extend(['--entrypoint', entrypoint]) args.extend(['--entrypoint', entrypoint])
else: else:
args.extend(['--entrypoint', json.dumps(entrypoint)]) 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 its a list,
# the first item must be either NONE, CMD or CMD-SHELL.
# If its a string, its 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. args.append(cnt.get('image')) # command, ..etc.
command = cnt.get('command') command = cnt.get('command')
if command is not None: if command is not None: