Skip to content

Commit

Permalink
Dev - Healthcheck (#8)
Browse files Browse the repository at this point in the history
* Update dockstatapi.js

* Update logger.js

* Update Dockerfile

* Create build-dev.yaml

* Update dockstatapi.js

* Update dockstatapi.js
  • Loading branch information
Its4Nik authored Sep 18, 2024
1 parent 814b303 commit 8ff26ac
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 6 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/build-dev.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Docker Image CI (dev)

on:
push:
branches: [ "dev" ]

permissions:
packages: write
contents: read

jobs:
build-main:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
name: Checkout repository

- uses: pmorelli92/[email protected]
name: Build and Publish latest service image
with:
github-push-secret: ${{secrets.GITHUB_TOKEN}}
docker-image-name: dockstatapi
docker-image-tag: dev # optional
dockerfile-path: Dockerfile # optional
build-context: . # optional
build-only: false # optional
4 changes: 3 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@ FROM node:alpine

WORKDIR /api

RUN apk add --no-cache bash
RUN apk add --no-cache bash curl

# Copy the production dependencies from the builder stage
COPY --from=builder /api .

EXPOSE 7070

HEALTHCHECK CMD curl --fail http://localhost:7070/ || exit 1

ENTRYPOINT [ "bash", "entrypoint.sh" ]
11 changes: 8 additions & 3 deletions dockstatapi.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ const logger = require('./logger');
const app = express();
const port = 7070;
const key = process.env.SECRET || 'CHANGE-ME';
const jsonLogging = process.env.JSON_LOGGING || 'False'
const skipAuth = process.env.SKIP_AUTH || 'True'
const jsonLogging = process.env.JSON_LOGGING || 'True'
const skipAuth = process.env.SKIP_AUTH || 'False'

let config = yaml.load('./config/hosts.yaml');
let hosts = config.hosts;
Expand Down Expand Up @@ -199,6 +199,11 @@ app.get('/', (req, res) => {
res.redirect(301, '/stats');
});

app.get('/status', (req, res) => {
logger.info("Healthcheck requested");
return res.status(200).send('UP');
});

// Start the server and log the startup message
app.listen(port, () => {
logger.info('=============================== DockStat ===============================')
Expand All @@ -212,4 +217,4 @@ app.listen(port, () => {
logger.info('========================================================================')
});

initializeHostQueues();
initializeHostQueues();
4 changes: 2 additions & 2 deletions logger.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const winston = require('winston');
const yaml = require('yamljs');
const config = yaml.load('./config/hosts.yaml');
const jsonLogging = process.env.JSON_LOGGING || 'False'
const jsonLogging = process.env.JSON_LOGGING || 'True'

const maxlogsize = config.log.logsize || 1;
const LogAmount = config.log.LogCount || 5;
Expand Down Expand Up @@ -43,4 +43,4 @@ if (jsonLogging === 'True') {
});

module.exports = logger;
}
}

0 comments on commit 8ff26ac

Please sign in to comment.