Skip to content

Commit 03d33b6

Browse files
committed
refactor: support muting original healthcheck in docker container
Signed-off-by: thxCode <thxcode0824@gmail.com>
1 parent 3879a69 commit 03d33b6

File tree

4 files changed

+66
-16
lines changed

4 files changed

+66
-16
lines changed

gpustack_runtime/cmds/deployer.py

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,7 @@ def register(parser: _SubParsersAction):
110110
deploy_parser.add_argument(
111111
"--port",
112112
type=int,
113-
help="port to expose (default: 80)",
114-
default=80,
113+
help="port to expose",
115114
)
116115

117116
deploy_parser.add_argument(
@@ -210,13 +209,15 @@ def run(self):
210209
)
211210
if self.extra_args:
212211
execution.command = self.extra_args
213-
ports = [
214-
ContainerPort(
215-
internal=self.port,
216-
),
217-
]
212+
ports = None
213+
if self.port:
214+
ports = [
215+
ContainerPort(
216+
internal=self.port,
217+
),
218+
]
218219
checks = None
219-
if self.check:
220+
if self.check and self.port:
220221
checks = [
221222
ContainerCheck(
222223
delay=60,
@@ -318,8 +319,7 @@ def register(parser: _SubParsersAction):
318319
deploy_parser.add_argument(
319320
"--port",
320321
type=int,
321-
help="port to expose (default: 80)",
322-
default=80,
322+
help="port to expose",
323323
)
324324

325325
deploy_parser.add_argument(
@@ -417,13 +417,15 @@ def run(self):
417417
)
418418
if self.extra_args:
419419
execution.command = self.extra_args
420-
ports = [
421-
ContainerPort(
422-
internal=self.port,
423-
),
424-
]
420+
ports = None
421+
if self.port:
422+
ports = [
423+
ContainerPort(
424+
internal=self.port,
425+
),
426+
]
425427
checks = None
426-
if self.check:
428+
if self.check and self.port:
427429
checks = [
428430
ContainerCheck(
429431
delay=60,

gpustack_runtime/deployer/docker.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -958,6 +958,13 @@ def _create_containers(
958958
ephemeral_volume_name_mapping,
959959
)
960960

961+
if envs.GPUSTACK_RUNTIME_DOCKER_MUTE_ORIGINAL_HEALTHCHECK:
962+
create_options["healthcheck"] = {
963+
"test": [
964+
"NONE",
965+
],
966+
}
967+
961968
# Parameterize health checks.
962969
# Since Docker only support one complete check,
963970
# we always pick the first check as target.

gpustack_runtime/envs.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,10 @@
130130
"""
131131
Directory for storing ephemeral files for Docker.
132132
"""
133+
GPUSTACK_RUNTIME_DOCKER_MUTE_ORIGINAL_HEALTHCHECK: bool = True
134+
"""
135+
Mute the original healthcheck of the container.
136+
"""
133137
## Kubernetes
134138
GPUSTACK_RUNTIME_KUBERNETES_NODE_NAME: str | None = None
135139
"""
@@ -266,6 +270,9 @@
266270
expand_path("~/.cache/gpustack-runtime"),
267271
),
268272
),
273+
"GPUSTACK_RUNTIME_DOCKER_MUTE_ORIGINAL_HEALTHCHECK": lambda: to_bool(
274+
getenv("GPUSTACK_RUNTIME_DOCKER_MUTE_ORIGINAL_HEALTHCHECK", "1"),
275+
),
269276
"GPUSTACK_RUNTIME_KUBERNETES_NODE_NAME": lambda: getenv(
270277
"GPUSTACK_RUNTIME_KUBERNETES_NODE_NAME",
271278
None,

pack/Dockerfile.dummy

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Dockerfile to build testing image.
2+
#
3+
FROM nginx:1.29.3-alpine3.22-perl
4+
5+
RUN <<EOF
6+
mkdir -p /etc/nginx/templates/
7+
cat <<EOT > /etc/nginx/templates/default.conf.template
8+
server {
9+
listen \${NGINX_PORT};
10+
server_name \${NGINX_HOST};
11+
12+
location / {
13+
root /usr/share/nginx/html;
14+
index index.html index.htm;
15+
}
16+
17+
error_page 500 502 503 504 /50x.html;
18+
location = /50x.html {
19+
root /usr/share/nginx/html;
20+
}
21+
}
22+
EOT
23+
EOF
24+
ENV NGINX_ENVSUBST_TEMPLATE_DIR=/etc/nginx/templates \
25+
NGINX_ENVSUBST_TEMPLATE_SUFFIX=.template \
26+
NGINX_ENVSUBST_OUTPUT_DIR=/etc/nginx/conf.d \
27+
NGINX_PORT=80 \
28+
NGINX_HOST=localhost
29+
30+
HEALTHCHECK --interval=30s --timeout=30s --start-period=10s --retries=5 \
31+
CMD curl --fail http://${NGINX_HOST}:${NGINX_PORT}/ || exit 1
32+
33+
ENTRYPOINT ["/docker-entrypoint.sh"]
34+
CMD ["nginx", "-g", "daemon off;"]

0 commit comments

Comments
 (0)