-
Notifications
You must be signed in to change notification settings - Fork 500
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
WIP: proper healthchecks support #23
Comments
Sorry for my bad Pythonese. Your solution using I tested your latest change and it doesn't handle all cases correctly. Please see the latest commit I pushed to my fork. Do you want a PR for it or can you cherry-pick it? |
if my comments in the code should be like if is_str(healthcheck_test):
# podman does not add shell to handle command with whitespace
args.extend(['--healthcheck-command', healthcheck_test])
elif is_list(healthcheck_test):
# If it’s a list, first item is either NONE, CMD or CMD-SHELL.
healthcheck_type = healthcheck_test.pop(0)
if healthcheck_type == 'NONE':
args.append("--no-healthcheck")
elif healthcheck_type == 'CMD':
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")
args.extend(['--healthcheck-command', healthcheck_test]) |
Don't know if that error has anything with this:
on current master (e21932e) |
@chpio I noticed that too and fixed it in my patch stefanb2/podman-compose@d1583d5b |
@chpio I've fixed the typo, please tell me if it fixed the issue @stefanb2 I did not like quoting the whole thing as you did
because when we pass arrays anyway, I'm following it's not compose job to work with shell, compose does not even know which shell to use (bash, sh, or zsh), if I want to inspect the image to know the shell, I might need to pull it first, but I can't pull it every time if it's already pulled. (it's a lot of job to do in compose) on the other hand, podman knows. |
@muayyad-alsadi oops I just looked at the generated command lines and missed the fact that your are not passing them to the shell. Just forget my change then. |
yeah, thank you for that |
I am seeing an error here:
The health check in my compose file:
I was able to get around this by using |
Healthcheck not working on podman-compose (not tested on docker) if /bin/sh not available in container even when using CMD in heathcheck.test (reproduction).
services:
test:
build:
context: .
container_name: healthcheck_test
healthcheck:
test: [
"CMD",
"/healthcheck",
"http://localhost:8080/ping"
]
interval: 5s
timeout: 5s
retries: 5 podman inspect --format "{{json .State.Health }}" healthcheck_test | jq
{
"Status": "unhealthy",
"FailingStreak": 18,
"Log": [
{
"Start": "2024-02-15T10:34:44.046709663+03:00",
"End": "2024-02-15T10:34:44.131872722+03:00",
"ExitCode": 1,
"Output": ""
}, |
Is this still in progress? |
Edit: no, my previous comment was wrong. |
For the problem of podman-compose treating Therefore, it seems like one would only need to modify this branch: podman-compose/podman_compose.py Lines 1204 to 1206 in 84f1fbd
I will send a PR after testing, which is basically equivalent to what was suggested in this thread in 2019. diff --git a/podman_compose.py b/podman_compose.py
index faae0a6..88bcc60 100755
--- a/podman_compose.py
+++ b/podman_compose.py
@@ -28,11 +28,6 @@ import sys
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")
@@ -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()
@@ -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}],\ |
continue on #22
https://docs.docker.com/compose/compose-file/#healthcheck
https://docs.docker.com/engine/reference/builder/#healthcheck
https://docs.docker.com/engine/reference/run/#healthcheck
and
containers/podman#3507
The text was updated successfully, but these errors were encountered: