Skip to content

Commit

Permalink
fix: add healthcheck to docker image (#536)
Browse files Browse the repository at this point in the history
build: use docker node-alpine image
  • Loading branch information
hugo-vrijswijk authored Mar 11, 2024
1 parent 679afa7 commit 813f564
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 11 deletions.
7 changes: 5 additions & 2 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
FROM node:20.11.1
FROM node:20-alpine
ARG version=latest
ENV NODE_ENV production
USER node

RUN mkdir /app
WORKDIR /app
RUN npm init --yes
RUN npm install @stryker-mutator/dashboard-backend@$version

HEALTHCHECK CMD npx dashboard-healthcheck
EXPOSE 1337
ENTRYPOINT [ "npx", "dashboard-backend" ]
3 changes: 2 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/badge-api/.npmignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
**/*
!/badge/*.mjs
!/dist/badge/**/*.js
!/dist/badge/**/*.+(js|d.ts)
!README.md
!host.json
!bin
4 changes: 2 additions & 2 deletions packages/data-access/.npmignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
**/*
!dist/src/**/*.+(js|.d.ts)
!README.md
!dist/src/**/*.+(js|d.ts)
!README.md
4 changes: 2 additions & 2 deletions packages/website-backend/.npmignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
**/*
!/dist/src/**/*.js
!/dist/src/**/*.+(js|d.ts)
!README.md
!bin
!bin
19 changes: 19 additions & 0 deletions packages/website-backend/bin/healthcheck.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env node

const response = await fetch(`http://localhost:1337/api/version`);

if (!response.ok) {
console.error(
`Health check failed: ${response.status}: ${response.statusText}`,
);
process.exit(1);
}

const json = await response.json();
if (!json.dashboard || !json.frontend) {
console.error(`Health check failed: invalid response`, json);
process.exit(1);
}
console.log(
`Health check passed. dashboard: ${json.dashboard}, frontend: ${json.frontend}`,
);
4 changes: 3 additions & 1 deletion packages/website-backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
"description": "The package which contains the stryker dashboard website backend.",
"type": "module",
"bin": {
"dashboard-backend": "bin/dashboard-backend.js"
"dashboard-backend": "bin/dashboard-backend.js",
"dashboard-healthcheck": "bin/healthcheck.js"
},
"main": "dist/src/index.js",
"scripts": {
"start": "node dist/src/index.js",
"start:watch": "node --watch dist/src/index.js",
Expand Down
1 change: 1 addition & 0 deletions packages/website-backend/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import { dist } from '@stryker-mutator/dashboard-frontend';
ConfigModule.forRoot(),
ServeStaticModule.forRoot({
rootPath: dist,
exclude: ['/api/(.*)'],
serveStaticOptions: {
immutable: true,
maxAge: '1y',
Expand Down
2 changes: 1 addition & 1 deletion start-server.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ DEBUG=*,-express:* \
JWT_SECRET="123" \
PGUSER=stryker \
PORT=1337 \
node packages/website-backend/src/index.js
node packages/website-backend/bin/dashboard-backend.js
2 changes: 1 addition & 1 deletion tasks/download-badge-api-package.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ fi

tar -xzf dashboard-badge-api-${NPM_PACKAGE_VERSION}.tgz
cd package
npm install --production
npm install --omit=dev

0 comments on commit 813f564

Please sign in to comment.