From fd9d5ea805240ab04fe0cabab95eca8706c0d68f Mon Sep 17 00:00:00 2001 From: rare-magma Date: Sat, 27 Jul 2024 11:19:22 +0200 Subject: [PATCH] ci: add healthcheck script Signed-off-by: rare-magma --- Dockerfile | 2 ++ docker/healthcheck.js | 25 +++++++++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 docker/healthcheck.js diff --git a/Dockerfile b/Dockerfile index 37c61ca41..57921f88c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -61,6 +61,8 @@ RUN apt update && apt install -y \ COPY --from=builder /ghostfolio/dist/apps /ghostfolio/apps COPY ./docker/entrypoint.sh /ghostfolio/entrypoint.sh +COPY ./docker/healthcheck.js /ghostfolio/healthcheck.js WORKDIR /ghostfolio/apps/api EXPOSE ${PORT:-3333} CMD [ "/ghostfolio/entrypoint.sh" ] +HEALTHCHECK --interval=15s --timeout=5s --start-period=2s --retries=3 CMD [ "node", "/ghostfolio/healthcheck.js" ] \ No newline at end of file diff --git a/docker/healthcheck.js b/docker/healthcheck.js new file mode 100644 index 000000000..3e920a34e --- /dev/null +++ b/docker/healthcheck.js @@ -0,0 +1,25 @@ +import { request } from "node:http"; + +const options = { + host : "localhost", + path: "/api/v1/health", + port : "3333", + timeout : 2000 +}; + +const healthCheck = request(options, (res) => { + if (res.statusCode === 200) { + process.exit(0); + } + else { + console.error(res.statusMessage) + process.exit(1); + } +}); + +healthCheck.on('error', (err) => { + console.error(err); + process.exit(1); +}); + +healthCheck.end(); \ No newline at end of file