mirror of
https://github.com/containers/podman-compose.git
synced 2025-01-09 07:28:13 +01:00
WIP #23: use cmd_quote
This commit is contained in:
parent
2f4da3fddb
commit
e21932e1de
@ -16,6 +16,11 @@ import time
|
|||||||
import re
|
import re
|
||||||
import hashlib
|
import hashlib
|
||||||
|
|
||||||
|
try:
|
||||||
|
from shlex import quote as cmd_quote
|
||||||
|
except ImportError:
|
||||||
|
from pipes import quote as cmd_quote
|
||||||
|
|
||||||
# import fnmatch
|
# import fnmatch
|
||||||
# fnmatch.fnmatchcase(env, "*_HOST")
|
# fnmatch.fnmatchcase(env, "*_HOST")
|
||||||
|
|
||||||
@ -406,6 +411,7 @@ def down(project_name, dirname, pods, containers, dry_run, podman_path):
|
|||||||
run_podman(dry_run, podman_path, ["pod", "rm", pod["name"]], sleep=0)
|
run_podman(dry_run, podman_path, ["pod", "rm", pod["name"]], sleep=0)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def container_to_args(cnt, dirname, podman_path, shared_vols):
|
def container_to_args(cnt, dirname, podman_path, shared_vols):
|
||||||
pod = cnt.get('pod') or ''
|
pod = cnt.get('pod') or ''
|
||||||
args = [
|
args = [
|
||||||
@ -475,43 +481,49 @@ def container_to_args(cnt, dirname, podman_path, shared_vols):
|
|||||||
else:
|
else:
|
||||||
args.extend(['--entrypoint', json.dumps(entrypoint)])
|
args.extend(['--entrypoint', json.dumps(entrypoint)])
|
||||||
|
|
||||||
healthcheck = cnt.get('healthcheck')
|
# WIP: healthchecks are still work in progress
|
||||||
if healthcheck is not None:
|
healthcheck = cnt.get('healthcheck', None) or {}
|
||||||
if is_dict(healthcheck):
|
if not is_dict(healthcheck):
|
||||||
if 'test' in healthcheck:
|
raise ValueError("'healthcheck' must be an key-value mapping")
|
||||||
command = healthcheck['test']
|
healthcheck_test = healthcheck.get('test')
|
||||||
# test must be either a string or a list. If it’s a list,
|
if healthcheck_test:
|
||||||
# the first item must be either NONE, CMD or CMD-SHELL.
|
# If it’s a string, it’s equivalent to specifying CMD-SHELL
|
||||||
# If it’s a string, it’s equivalent to specifying CMD-SHELL
|
if is_str(healthcheck_test):
|
||||||
# followed by that string.
|
# podman does not add shell to handle command with whitespace
|
||||||
if is_str(command):
|
args.extend(['--healthcheck-command', '/bin/sh -c {}'.format(cmd_quote(healthcheck_test))])
|
||||||
if re.search(r'\s', command):
|
elif is_list(healthcheck_test):
|
||||||
# podman does not add shell to handle command with whitespace
|
# If it’s a list, first item is either NONE, CMD or CMD-SHELL.
|
||||||
args.extend(['--healthcheck-command', '"/bin/bash -c \'{}\'"'.format(command)])
|
healthcheck_type = healthcheck_test.pop(0)
|
||||||
else:
|
if healthcheck_type == 'NONE':
|
||||||
args.extend(['--healthcheck-command', command])
|
args.append("--no-healthcheck")
|
||||||
elif command[0] == 'NONE':
|
elif healthcheck_type == 'CMD':
|
||||||
args.extend(['--healthcheck-command', 'none'])
|
args.extend(['--healthcheck-command', '/bin/sh -c {}'.format(
|
||||||
elif command[0] == 'CMD-SHELL':
|
"' '".join([cmd_quote(i) for i in healthcheck_test])
|
||||||
# podman does not add shell to handle command with whitespace
|
)])
|
||||||
args.extend(['--healthcheck-command', '"/bin/bash -c \'{}\'"'.format(command[1])])
|
elif healthcheck_type == 'CMD-SHELL':
|
||||||
else:
|
if len(healthcheck_test)!=1:
|
||||||
# podman splits string on white space
|
raise ValueError("'CMD_SHELL' takes a single string after it")
|
||||||
args.extend(['--healthcheck-command', '"{}"'.format(' '.join(command[1:]))])
|
args.extend(['--healthcheck-command', '/bin/sh -c {}'.format(cmd_quote(healthcheck_test[0])]))
|
||||||
|
else:
|
||||||
# interval, timeout and start_period are specified as durations.
|
raise ValueError(
|
||||||
if 'interval' in healthcheck:
|
"unknown healthcheck test type [{}],\
|
||||||
args.extend(['--healthcheck-interval', healthcheck['interval']])
|
expecting NONE, CMD or CMD-SHELL."
|
||||||
if 'timeout' in healthcheck:
|
.format(healthcheck_type)
|
||||||
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:
|
else:
|
||||||
raise ValueError("'healthcheck' must be an associative array")
|
raise ValueError("'healthcheck.test' either a string or a list")
|
||||||
|
|
||||||
|
# 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'])])
|
||||||
|
|
||||||
args.append(cnt.get('image')) # command, ..etc.
|
args.append(cnt.get('image')) # command, ..etc.
|
||||||
command = cnt.get('command')
|
command = cnt.get('command')
|
||||||
|
Loading…
Reference in New Issue
Block a user