Skip to content

Commit 50201f0

Browse files
zstadleracalcutt
andauthored
Add Docker Healthcheck (#636)
* Add Docker Healthcheck Fixes #635 * Update Dockerfile_light * Update healthcheck.js fix healthcheck output error: "file:///usr/src/app/src/healthcheck.js:1\nvar http = require(\"http\");\n ^\n\nReferenceError: require is not defined in ES module scope, you can use import instead\nThis file is being treated as an ES module because it has a '.js' file extension and '/usr/src/app/package.json' contains \"type\": \"module\". To treat it as a CommonJS script, rename it to use the '.cjs' file extension.\n at file:///usr/src/app/src/healthcheck.js:1:12\n at ModuleJob.run (node:internal/modules/esm/module_job:193:25)\n at async Promise.all (index 0)\n at async ESMLoader.import (node:internal/modules/esm/loader:526:24)\n at async loadESM (node:internal/process/esm_loader:91:5)\n at async handleMainPromise (node:internal/modules/run_main:65:12)\n" * update version Co-authored-by: acalcutt <acalcutt@techidiots.net>
1 parent d97c217 commit 50201f0

5 files changed

Lines changed: 24 additions & 3 deletions

File tree

Dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,5 @@ EXPOSE 80
8181
USER node:node
8282

8383
ENTRYPOINT ["/usr/src/app/docker-entrypoint.sh"]
84+
85+
HEALTHCHECK CMD node /usr/src/app/src/healthcheck.js

Dockerfile_light

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,4 @@ COPY / /usr/src/app
3232
RUN cd /usr/src/app && npm install --omit=dev
3333
RUN ["chmod", "+x", "/usr/src/app/docker-entrypoint.sh"]
3434
USER node:node
35+
HEALTHCHECK CMD node /usr/src/app/src/healthcheck.js

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "tileserver-gl",
3-
"version": "4.1.2",
3+
"version": "4.1.3",
44
"description": "Map tile server for JSON GL styles - vector and server side generated raster tiles",
55
"main": "src/main.js",
66
"bin": "src/main.js",

src/healthcheck.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import * as http from 'http';
2+
var options = {
3+
timeout: 2000,
4+
};
5+
var url = "http://localhost:80/health";
6+
var request = http.request(url, options, (res) => {
7+
console.log(`STATUS: ${res.statusCode}`);
8+
if (res.statusCode == 200) {
9+
process.exit(0);
10+
} else {
11+
process.exit(1);
12+
}
13+
});
14+
request.on("error", function (err) {
15+
console.log("ERROR");
16+
process.exit(1);
17+
});
18+
request.end();

0 commit comments

Comments
 (0)