Skip to content

Commit 0bc92fd

Browse files
committed
Fix CMD healthchecks running with /bin/sh
Signed-off-by: Ben Krieger <[email protected]>
1 parent 84f1fbd commit 0bc92fd

File tree

1 file changed

+3
-11
lines changed

1 file changed

+3
-11
lines changed

podman_compose.py

+3-11
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,8 @@
2828
from asyncio import Task
2929
from enum import Enum
3030

31-
try:
32-
from shlex import quote as cmd_quote
33-
except ImportError:
34-
from pipes import quote as cmd_quote # pylint: disable=deprecated-module
35-
3631
# import fnmatch
3732
# fnmatch.fnmatchcase(env, "*_HOST")
38-
3933
import yaml
4034
from dotenv import dotenv_values
4135

@@ -1193,7 +1187,7 @@ async def container_to_args(compose, cnt, detached=True):
11931187
# podman does not add shell to handle command with whitespace
11941188
podman_args.extend([
11951189
"--healthcheck-command",
1196-
"/bin/sh -c " + cmd_quote(healthcheck_test),
1190+
json.dumps(["CMD-SHELL", healthcheck_test]),
11971191
])
11981192
elif is_list(healthcheck_test):
11991193
healthcheck_test = healthcheck_test.copy()
@@ -1202,13 +1196,11 @@ async def container_to_args(compose, cnt, detached=True):
12021196
if healthcheck_type == "NONE":
12031197
podman_args.append("--no-healthcheck")
12041198
elif healthcheck_type == "CMD":
1205-
cmd_q = "' '".join([cmd_quote(i) for i in healthcheck_test])
1206-
podman_args.extend(["--healthcheck-command", "/bin/sh -c " + cmd_q])
1199+
podman_args.extend(["--healthcheck-command", json.dumps(healthcheck_test)])
12071200
elif healthcheck_type == "CMD-SHELL":
12081201
if len(healthcheck_test) != 1:
12091202
raise ValueError("'CMD_SHELL' takes a single string after it")
1210-
cmd_q = cmd_quote(healthcheck_test[0])
1211-
podman_args.extend(["--healthcheck-command", "/bin/sh -c " + cmd_q])
1203+
podman_args.extend(["--healthcheck-command", json.dumps(healthcheck_test)])
12121204
else:
12131205
raise ValueError(
12141206
f"unknown healthcheck test type [{healthcheck_type}],\

0 commit comments

Comments
 (0)