Skip to content

Commit daf1c28

Browse files
committed
Implement Docker Health Checks
Implements health check server from NeonGeckoCom/neon-utils#551 Adds a CLI option to enable health check server on a specified port Adds a script and updates Dockerfile to enable Docker health checks
1 parent d31a4ac commit daf1c28

File tree

5 files changed

+85
-21
lines changed

5 files changed

+85
-21
lines changed

Dockerfile

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,20 @@ EXPOSE 18181
1111

1212
RUN apt-get update && \
1313
apt-get install -y \
14+
git \
1415
gcc \
1516
g++ \
1617
python3-dev \
1718
swig \
1819
libssl-dev \
1920
libfann-dev
2021

21-
ADD . /neon_gui
22+
COPY . /neon_gui
2223
WORKDIR /neon_gui
2324

24-
RUN pip install wheel \
25-
&& pip install .[docker]
25+
RUN pip install --no-cache-dir wheel \
26+
&& pip install --no-cache-dir .[docker]
2627

2728
COPY docker_overlay/ /
28-
29-
CMD ["neon-gui", "run"]
29+
HEALTHCHECK CMD "/opt/neon/healthcheck.sh"
30+
CMD ["neon-gui", "run", "-p", "8000"]
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/bin/bash
2+
# NEON AI (TM) SOFTWARE, Software Development Kit & Application Development System
3+
# All trademark and other rights reserved by their respective owners
4+
# Copyright 2008-2025 Neongecko.com Inc.
5+
# BSD-3
6+
# Redistribution and use in source and binary forms, with or without
7+
# modification, are permitted provided that the following conditions are met:
8+
# 1. Redistributions of source code must retain the above copyright notice,
9+
# this list of conditions and the following disclaimer.
10+
# 2. Redistributions in binary form must reproduce the above copyright notice,
11+
# this list of conditions and the following disclaimer in the documentation
12+
# and/or other materials provided with the distribution.
13+
# 3. Neither the name of the copyright holder nor the names of its
14+
# contributors may be used to endorse or promote products derived from this
15+
# software without specific prior written permission.
16+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
18+
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19+
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
20+
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21+
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22+
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
23+
# OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
24+
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
25+
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26+
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27+
28+
port=8000
29+
# Perform the health check using curl
30+
resp_content=$(curl -s http://localhost:${port}/status)
31+
if [ "${resp_content}" == "Ready" ]; then
32+
exit 0 # Success
33+
else
34+
echo "Health check failed with response: ${resp_content}" >&2
35+
exit 1 # Failure
36+
fi

neon_gui/__main__.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,24 @@
3030
from ovos_utils.log import LOG
3131
from neon_gui.service import NeonGUIService
3232
from neon_utils.log_utils import init_log
33-
from neon_utils.process_utils import start_malloc, snapshot_malloc, print_malloc
33+
from neon_utils.process_utils import (
34+
start_malloc,
35+
snapshot_malloc,
36+
print_malloc,
37+
)
3438
from ovos_utils.process_utils import reset_sigint_handler
3539

3640

3741
def main(*args, **kwargs):
3842
init_log(log_name="gui")
3943
malloc_running = start_malloc(stack_depth=4)
4044
reset_sigint_handler()
41-
45+
health_check_server_port = kwargs.pop("health_check_server_port", None)
4246
gui = NeonGUIService(*args, **kwargs)
47+
if health_check_server_port is not None:
48+
from neon_utils.process_utils import start_health_check_server
49+
50+
start_health_check_server(gui.status, health_check_server_port)
4351
gui.start()
4452
wait_for_exit_signal()
4553
if malloc_running:
@@ -52,8 +60,10 @@ def main(*args, **kwargs):
5260

5361
def deprecated_entrypoint():
5462
from ovos_utils.log import log_deprecation
55-
log_deprecation("Use `neon-gui run` in place of "
56-
"`neon_gui_service`", "2.0.0")
63+
64+
log_deprecation(
65+
"Use `neon-gui run` in place of `neon_gui_service`", "2.0.0"
66+
)
5767
main()
5868

5969

neon_gui/cli.py

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
import click
3030

31+
from typing import Optional
3132
from os import environ
3233
from click_default_group import DefaultGroup
3334
from neon_utils.packaging_utils import get_package_version_spec
@@ -36,21 +37,36 @@
3637
environ.setdefault("OVOS_CONFIG_FILENAME", "neon.yaml")
3738

3839

39-
@click.group("neon-gui", cls=DefaultGroup,
40-
no_args_is_help=True, invoke_without_command=True,
41-
help="Neon GUI module Commands\n\n"
42-
"See also: neon COMMAND --help")
43-
@click.option("--version", "-v", is_flag=True, required=False,
44-
help="Print the current version")
40+
@click.group(
41+
"neon-gui",
42+
cls=DefaultGroup,
43+
no_args_is_help=True,
44+
invoke_without_command=True,
45+
help="Neon GUI module Commands\n\nSee also: neon COMMAND --help",
46+
)
47+
@click.option(
48+
"--version",
49+
"-v",
50+
is_flag=True,
51+
required=False,
52+
help="Print the current version",
53+
)
4554
def neon_gui_cli(version: bool = False):
4655
if version:
47-
click.echo(f"neon_gui version "
48-
f"{get_package_version_spec('neon_gui')}")
56+
click.echo(f"neon_gui version {get_package_version_spec('neon_gui')}")
4957

5058

5159
@neon_gui_cli.command(help="Start Neon GUI module")
52-
def run():
60+
@click.option(
61+
"--health-check-server-port",
62+
"-p",
63+
type=int,
64+
default=None,
65+
help="Port for health check server to listen on",
66+
)
67+
def run(health_check_server_port: Optional[int] = None):
5368
from neon_gui.__main__ import main
69+
5470
click.echo("Starting GUI Service")
55-
main()
71+
main(health_check_server_port=health_check_server_port)
5672
click.echo("GUI Service Shutdown")

requirements/requirements.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
neon-utils[network]~=1.6
1+
#neon-utils[network]~=1.6
2+
neon-utils[network] @ git+https://github.com/neongeckocom/neon-utils@FEAT_HttpStatusServer#egg=neon-utils
23
ovos-utils~=0.0,>=0.0.34
34
ovos-config~=0.0,>=0.0.10
45
click~=8.0
56
click-default-group~=1.2
67
tornado~=6.0
78
ovos-bus-client~=0.0,>=0.0.6
8-
ovos-gui~=0.2
9+
ovos-gui~=0.2

0 commit comments

Comments
 (0)