From 0d142c1dd8786e2be4b77bb942a2cd8d30678349 Mon Sep 17 00:00:00 2001 From: Kurbanov Bulat Date: Sun, 2 Jan 2022 15:11:10 +0300 Subject: [PATCH] Add healthcheck script --- docker/build.dockerfile | 1 + scripts/healthcheck.js | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 scripts/healthcheck.js diff --git a/docker/build.dockerfile b/docker/build.dockerfile index f220339..ec87a30 100644 --- a/docker/build.dockerfile +++ b/docker/build.dockerfile @@ -14,6 +14,7 @@ FROM node:lts-alpine as runtime-image WORKDIR /root/app COPY ./package.json ./ +COPY ./scripts/healthcheck.js ./ RUN npm i --only=production diff --git a/scripts/healthcheck.js b/scripts/healthcheck.js new file mode 100644 index 0000000..b93d7f3 --- /dev/null +++ b/scripts/healthcheck.js @@ -0,0 +1,20 @@ +(async () => { + const http = await import('http'); + + const healthCheck = http.request("http://localhost:8080/healthcheck", (res) => { + console.log(`HEALTHCHECK STATUS: ${res.statusCode}`); + if (res.statusCode == 200) { + process.exit(0); + } + else { + process.exit(1); + } + }); + + healthCheck.on('error', function (err) { + console.error('ERROR'); + process.exit(1); + }); + + healthCheck.end(); +})();