From 75f058d4fe48363f544c8b84edecc39d04958a9e Mon Sep 17 00:00:00 2001 From: Euan Goddard Date: Mon, 24 Feb 2020 10:38:45 +0000 Subject: [PATCH 1/3] Modified health-check to allow Docker to cycle the process automatically --- lib/server.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/server.js b/lib/server.js index 59e50a44..c5e34809 100644 --- a/lib/server.js +++ b/lib/server.js @@ -92,8 +92,16 @@ app.use(bodyParser.json({ limit: '50mb' })); app.use('/charts', express.static('tmp/')); +var hasHadHealthCheck = false; + app.get('/health', function (req, res) { - res.send('OK'); + if (!hasHadHealthCheck) { + hasHadHealthCheck = true; + res.send('OK'); + } else { + res.status(503); + res.send('Server has been up too long'); + } }); function enableRateLimiting(options) { From f168b7fb6d808b6be004a922e3e667207686afd3 Mon Sep 17 00:00:00 2001 From: Euan Goddard Date: Mon, 24 Feb 2020 11:44:52 +0000 Subject: [PATCH 2/3] Modified health-check only stay healthy for a period of time --- Dockerfile | 2 +- lib/server.js | 20 +++++++++++++++----- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/Dockerfile b/Dockerfile index eda4e03a..ee225d3a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM node:9-alpine +FROM node:12-alpine # Build-time RUN set -ex \ diff --git a/lib/server.js b/lib/server.js index c5e34809..7241dfcf 100644 --- a/lib/server.js +++ b/lib/server.js @@ -92,15 +92,25 @@ app.use(bodyParser.json({ limit: '50mb' })); app.use('/charts', express.static('tmp/')); -var hasHadHealthCheck = false; +var SERVER_CYCLE_MINUTES = parseInt(process.env['SERVER_CYCLE_MINUTES'], 10); + +if (!SERVER_CYCLE_MINUTES || isNaN(SERVER_CYCLE_MINUTES)) { + console.error(`You must specify SERVER_CYCLE_MINUTES in the environment!`); + process.exit(1); +} + +var UPTIME_CUT_OFF = SERVER_CYCLE_MINUTES * 60 * 1000; +var UPTIME_RANDOM_VARIATION_CAP = Math.floor(Math.random() * 10 * 60 * 1000); // 0-10 minutes grace + +var serverStartTime = Date.now(); app.get('/health', function (req, res) { - if (!hasHadHealthCheck) { - hasHadHealthCheck = true; - res.send('OK'); + var uptime = Date.now() - serverStartTime; + if (uptime < UPTIME_RANDOM_VARIATION_CAP + UPTIME_CUT_OFF) { + res.send('OK for ' + uptime + 'ms'); } else { res.status(503); - res.send('Server has been up too long'); + res.send('Server has been up too long (' + uptime + 'ms)'); } }); From 985603bf60c0279cbeb2d8acf4af5c9d4e0aa32c Mon Sep 17 00:00:00 2001 From: Euan Goddard Date: Mon, 2 Mar 2020 16:45:22 +0000 Subject: [PATCH 3/3] Pinned the version of Highcharts --- Dockerfile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index ee225d3a..bc40db43 100644 --- a/Dockerfile +++ b/Dockerfile @@ -13,8 +13,9 @@ RUN chown -R app /usr/charts-server USER app ENV ACCEPT_HIGHCHARTS_LICENSE YES -ENV HIGHCHARTS_VERSION latest ENV HIGHCHARTS_USE_STYLED NO +ENV SERVER_CYCLE_MINUTES 720 +ENV HIGHCHARTS_VERSION "6.2.0" RUN npm install USER root