Skip to content

Commit

Permalink
Fix CMD healthchecks running with /bin/sh
Browse files Browse the repository at this point in the history
  • Loading branch information
ben-krieger committed Jan 13, 2025
1 parent 84f1fbd commit fbe8cb8
Showing 1 changed file with 3 additions and 10 deletions.
13 changes: 3 additions & 10 deletions podman_compose.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,6 @@
from asyncio import Task
from enum import Enum

try:
from shlex import quote as cmd_quote
except ImportError:
from pipes import quote as cmd_quote # pylint: disable=deprecated-module

# import fnmatch
# fnmatch.fnmatchcase(env, "*_HOST")

Expand Down Expand Up @@ -1193,7 +1188,7 @@ async def container_to_args(compose, cnt, detached=True):
# podman does not add shell to handle command with whitespace
podman_args.extend([
"--healthcheck-command",
"/bin/sh -c " + cmd_quote(healthcheck_test),
json.dumps(["CMD-SHELL", healthcheck_test]),
])
elif is_list(healthcheck_test):
healthcheck_test = healthcheck_test.copy()
Expand All @@ -1202,13 +1197,11 @@ async def container_to_args(compose, cnt, detached=True):
if healthcheck_type == "NONE":
podman_args.append("--no-healthcheck")
elif healthcheck_type == "CMD":
cmd_q = "' '".join([cmd_quote(i) for i in healthcheck_test])
podman_args.extend(["--healthcheck-command", "/bin/sh -c " + cmd_q])
podman_args.extend(["--healthcheck-command", json.dumps(healthcheck_test)])
elif healthcheck_type == "CMD-SHELL":
if len(healthcheck_test) != 1:
raise ValueError("'CMD_SHELL' takes a single string after it")
cmd_q = cmd_quote(healthcheck_test[0])
podman_args.extend(["--healthcheck-command", "/bin/sh -c " + cmd_q])
podman_args.extend(["--healthcheck-command", json.dumps(healthcheck_test)])
else:
raise ValueError(
f"unknown healthcheck test type [{healthcheck_type}],\
Expand Down

0 comments on commit fbe8cb8

Please sign in to comment.