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:
parent
41dcd6a5bb
commit
dfa50ea6b5
@ -45,13 +45,13 @@ ENV LR_DEBUG=true
|
|||||||
ENV LR_HTTPS=true
|
ENV LR_HTTPS=true
|
||||||
ENV CERT_HOSTNAME=""
|
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
|
USER node
|
||||||
WORKDIR /home/node
|
WORKDIR /home/node
|
||||||
RUN mkdir -p .npm-global/bin .npm-global/lib \
|
RUN mkdir -p .npm-global/bin .npm-global/lib \
|
||||||
&& npm config set fund false \
|
&& npm config set fund false \
|
||||||
&& npm config set update-notifier false \
|
&& npm config set update-notifier false \
|
||||||
&& npm install livereload --save
|
&& npm install livereload express --save
|
||||||
|
|
||||||
# copy scripts and fix-up all permissions
|
# copy scripts and fix-up all permissions
|
||||||
USER root
|
USER root
|
||||||
@ -63,6 +63,13 @@ RUN chown node:node /home/node/livereload.js \
|
|||||||
&& chmod 755 /usr/local/bin/entrypoint.sh \
|
&& chmod 755 /usr/local/bin/entrypoint.sh \
|
||||||
&& chmod 644 /etc/selfsigned.cnf
|
&& 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
|
# switch to node user, run entrypoint script by default
|
||||||
USER node
|
USER node
|
||||||
WORKDIR /home/node
|
WORKDIR /home/node
|
||||||
|
@ -1,7 +1,30 @@
|
|||||||
// implement node-livereload over an HTTPS connection
|
// 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
|
// load livereload module
|
||||||
let livereload = require('livereload');
|
const livereload = require('livereload');
|
||||||
|
|
||||||
// set createServer options
|
// set createServer options
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
@ -32,7 +55,7 @@ else {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// start server
|
// start server
|
||||||
let server = livereload.createServer(options);
|
const lrServer = livereload.createServer(options, healthcheck);
|
||||||
server.watch('/watch')
|
lrServer.watch('/watch')
|
||||||
|
|
||||||
//#EOF
|
//#EOF
|
||||||
|
Loading…
Reference in New Issue
Block a user