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(); +})();