mirror of
https://github.com/ets-cfuhrman-pfe/EvalueTonSavoir.git
synced 2025-08-11 21:23:54 -04:00
Adds basic health checks
This commit is contained in:
parent
8eab2d3a05
commit
5c75347887
7 changed files with 71 additions and 6 deletions
|
|
@ -14,4 +14,7 @@ RUN npm run build
|
||||||
|
|
||||||
EXPOSE 5173
|
EXPOSE 5173
|
||||||
|
|
||||||
|
HEALTHCHECK --interval=30s --timeout=10s --start-period=30s --retries=3 \
|
||||||
|
CMD curl -f http://localhost:5173 || exit 1
|
||||||
|
|
||||||
CMD [ "npm", "run", "preview" ]
|
CMD [ "npm", "run", "preview" ]
|
||||||
|
|
@ -33,7 +33,8 @@ services:
|
||||||
FRONTEND_URL: "http://localhost:5173"
|
FRONTEND_URL: "http://localhost:5173"
|
||||||
#QUIZROOM_IMAGE: ghcr.io/ets-cfuhrman-pfe/evaluetonsavoir-quizroom:latest
|
#QUIZROOM_IMAGE: ghcr.io/ets-cfuhrman-pfe/evaluetonsavoir-quizroom:latest
|
||||||
depends_on:
|
depends_on:
|
||||||
- mongo
|
mongo:
|
||||||
|
condition: service_healthy
|
||||||
networks:
|
networks:
|
||||||
- quiz_network
|
- quiz_network
|
||||||
restart: always
|
restart: always
|
||||||
|
|
@ -45,8 +46,6 @@ services:
|
||||||
container_name: quizroom
|
container_name: quizroom
|
||||||
ports:
|
ports:
|
||||||
- "4500:4500"
|
- "4500:4500"
|
||||||
depends_on:
|
|
||||||
- backend
|
|
||||||
networks:
|
networks:
|
||||||
- quiz_network
|
- quiz_network
|
||||||
restart: always
|
restart: always
|
||||||
|
|
@ -59,8 +58,10 @@ services:
|
||||||
ports:
|
ports:
|
||||||
- "80:80"
|
- "80:80"
|
||||||
depends_on:
|
depends_on:
|
||||||
- backend
|
frontend:
|
||||||
- frontend
|
condition: service_healthy
|
||||||
|
backend:
|
||||||
|
condition: service_healthy
|
||||||
networks:
|
networks:
|
||||||
- quiz_network
|
- quiz_network
|
||||||
restart: always
|
restart: always
|
||||||
|
|
@ -70,6 +71,12 @@ services:
|
||||||
# - FRONTEND_PORT=5173
|
# - FRONTEND_PORT=5173
|
||||||
# - BACKEND_HOST=backend
|
# - BACKEND_HOST=backend
|
||||||
# - BACKEND_PORT=3000
|
# - BACKEND_PORT=3000
|
||||||
|
healthcheck:
|
||||||
|
test: ["CMD-SHELL", "wget --spider http://0.0.0.0:${PORT}/health || exit 1"]
|
||||||
|
interval: 5s
|
||||||
|
timeout: 10s
|
||||||
|
start_period: 5s
|
||||||
|
retries: 6
|
||||||
|
|
||||||
mongo:
|
mongo:
|
||||||
image: mongo
|
image: mongo
|
||||||
|
|
@ -82,6 +89,12 @@ services:
|
||||||
networks:
|
networks:
|
||||||
- quiz_network
|
- quiz_network
|
||||||
restart: always
|
restart: always
|
||||||
|
healthcheck:
|
||||||
|
test: ["CMD", "mongosh", "--eval", "db.adminCommand('ping')"]
|
||||||
|
interval: 10s
|
||||||
|
timeout: 5s
|
||||||
|
retries: 3
|
||||||
|
start_period: 20s
|
||||||
|
|
||||||
watchtower:
|
watchtower:
|
||||||
image: containrrr/watchtower
|
image: containrrr/watchtower
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ FROM alpine:3.19
|
||||||
# Install gettext for envsubst and other dependencies
|
# Install gettext for envsubst and other dependencies
|
||||||
RUN apk add --no-cache \
|
RUN apk add --no-cache \
|
||||||
gettext \
|
gettext \
|
||||||
|
curl \
|
||||||
nginx-mod-http-js \
|
nginx-mod-http-js \
|
||||||
nginx-mod-http-keyval \
|
nginx-mod-http-keyval \
|
||||||
pcre2 \
|
pcre2 \
|
||||||
|
|
@ -80,5 +81,8 @@ RUN chmod +x /entrypoint.sh && \
|
||||||
# Switch to nginx user
|
# Switch to nginx user
|
||||||
USER nginx
|
USER nginx
|
||||||
|
|
||||||
|
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
|
||||||
|
CMD wget -q --spider http://0.0.0.0:${PORT}/health || exit 1
|
||||||
|
|
||||||
# Start Nginx using entrypoint script
|
# Start Nginx using entrypoint script
|
||||||
ENTRYPOINT ["/entrypoint.sh"]
|
ENTRYPOINT ["/entrypoint.sh"]
|
||||||
|
|
@ -20,6 +20,26 @@ server {
|
||||||
|
|
||||||
set $proxy_target "";
|
set $proxy_target "";
|
||||||
|
|
||||||
|
location /health {
|
||||||
|
access_log off;
|
||||||
|
add_header Content-Type text/plain;
|
||||||
|
return 200 'healthy';
|
||||||
|
}
|
||||||
|
|
||||||
|
location /backend-health {
|
||||||
|
proxy_pass http://backend/health;
|
||||||
|
proxy_http_version 1.1;
|
||||||
|
proxy_set_header Host $host;
|
||||||
|
access_log off;
|
||||||
|
}
|
||||||
|
|
||||||
|
location /frontend-health {
|
||||||
|
proxy_pass http://frontend;
|
||||||
|
proxy_http_version 1.1;
|
||||||
|
proxy_set_header Host $host;
|
||||||
|
access_log off;
|
||||||
|
}
|
||||||
|
|
||||||
location /api {
|
location /api {
|
||||||
proxy_pass http://backend;
|
proxy_pass http://backend;
|
||||||
proxy_http_version 1.1;
|
proxy_http_version 1.1;
|
||||||
|
|
|
||||||
|
|
@ -10,4 +10,7 @@ COPY ./ .
|
||||||
|
|
||||||
EXPOSE 4400
|
EXPOSE 4400
|
||||||
|
|
||||||
|
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
|
||||||
|
CMD curl -f http://localhost:${PORT}/health || exit 1
|
||||||
|
|
||||||
CMD ["npm", "run", "start"]
|
CMD ["npm", "run", "start"]
|
||||||
|
|
@ -47,6 +47,7 @@ const folderRouter = require('./routers/folders.js');
|
||||||
const quizRouter = require('./routers/quiz.js');
|
const quizRouter = require('./routers/quiz.js');
|
||||||
const imagesRouter = require('./routers/images.js');
|
const imagesRouter = require('./routers/images.js');
|
||||||
const roomRouter = require('./routers/rooms.js');
|
const roomRouter = require('./routers/rooms.js');
|
||||||
|
const healthRouter = require('./routers/health.js');
|
||||||
|
|
||||||
// Setup environment
|
// Setup environment
|
||||||
dotenv.config();
|
dotenv.config();
|
||||||
|
|
@ -71,6 +72,7 @@ app.use('/api/folder', folderRouter);
|
||||||
app.use('/api/quiz', quizRouter);
|
app.use('/api/quiz', quizRouter);
|
||||||
app.use('/api/image', imagesRouter);
|
app.use('/api/image', imagesRouter);
|
||||||
app.use('/api/room', roomRouter);
|
app.use('/api/room', roomRouter);
|
||||||
|
app.use('/health', healthRouter);
|
||||||
|
|
||||||
app.use(errorHandler);
|
app.use(errorHandler);
|
||||||
|
|
||||||
|
|
|
||||||
20
server/routers/health.js
Normal file
20
server/routers/health.js
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
const express = require('express');
|
||||||
|
const router = express.Router();
|
||||||
|
|
||||||
|
router.get('/', async (req, res) => {
|
||||||
|
try {
|
||||||
|
const dbStatus = await require('../config/db.js').getConnection() ? 'connected' : 'disconnected';
|
||||||
|
res.json({
|
||||||
|
status: 'healthy',
|
||||||
|
timestamp: new Date(),
|
||||||
|
db: dbStatus
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({
|
||||||
|
status: 'unhealthy',
|
||||||
|
error: error.message
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
module.exports = router;
|
||||||
Loading…
Reference in a new issue