feature: add healthcheck

- add express npm to allow creation of health endpoint
- create health end pt as callback to livereload server listening state
- configure healthcheck in container
- allows true 'stack' operation since other services can query status
This commit is contained in:
Asif Bacchus 2021-07-24 03:01:01 -06:00
parent 41dcd6a5bb
commit dfa50ea6b5
2 changed files with 35 additions and 5 deletions

View File

@ -45,13 +45,13 @@ ENV LR_DEBUG=true
ENV LR_HTTPS=true
ENV CERT_HOSTNAME=""
# install node-livereload as node user then switch back to root user
# install node-livereload and express as node user then switch back to root user
USER node
WORKDIR /home/node
RUN mkdir -p .npm-global/bin .npm-global/lib \
&& npm config set fund false \
&& npm config set update-notifier false \
&& npm install livereload --save
&& npm install livereload express --save
# copy scripts and fix-up all permissions
USER root
@ -63,6 +63,13 @@ RUN chown node:node /home/node/livereload.js \
&& chmod 755 /usr/local/bin/entrypoint.sh \
&& chmod 644 /etc/selfsigned.cnf
HEALTHCHECK \
--interval=10s \
--timeout=5s \
--start-period=60s \
--retries=3 \
CMD wget --spider -T 3 -q localhost:3000/api/v1/health || exit 1
# switch to node user, run entrypoint script by default
USER node
WORKDIR /home/node

View File

@ -1,7 +1,30 @@
// implement node-livereload over an HTTPS connection
// healthcheck function
function healthcheck() {
const express = require('express');
const http = require('http');
const app = express();
const router = express.Router();
router.use((req, res, next) =>{
res.header('Access-Control-Allow-Methods', 'GET');
next();
});
router.get('/health', (req, res) =>{
res.status(200).send('Ok');
});
app.use('/api/v1', router);
const hServer = http.createServer(app);
hServer.listen(3000);
}
// load livereload module
let livereload = require('livereload');
const livereload = require('livereload');
// set createServer options
const fs = require('fs');
@ -32,7 +55,7 @@ else {
}
// start server
let server = livereload.createServer(options);
server.watch('/watch')
const lrServer = livereload.createServer(options, healthcheck);
lrServer.watch('/watch')
//#EOF