#1 - Control de Signals y Cambios en Dockerfile

This commit is contained in:
Luciano Giacchetta 2025-07-03 15:11:15 -03:00
parent e846a8293d
commit ee371b82d0
3 changed files with 26 additions and 3 deletions

6
Dockerfile Normal file
View File

@ -0,0 +1,6 @@
FROM docker.io/library/node:22-alpine
LABEL org.opencontainers.image.source https://gianet.us/codyops/nucleus
COPY . /opt
WORKDIR /opt
RUN npm run build
CMD npm run start

View File

@ -4,7 +4,7 @@
"description": "CodyOps Nucleus",
"main": "dist/index.js",
"scripts": {
"build": "npx tsc",
"build": "npm i && npx tsc",
"start": "node dist/main.js",
"dev": "tsc-watch --noClear --onSuccess 'node ./dist/main.js'"
},

View File

@ -35,6 +35,23 @@ app.post(`/${processor}`, jsonParser, async (req: Request, res: Response) => {
res.sendStatus(201);
})
app.listen(port, () => {
const server = app.listen(port, () => {
console.log('Serving function...');
});
});
function shutdown(signal: string) {
console.log(`Received ${signal}. Shutting down gracefully...`);
server.close(() => {
console.log('HTTP server closed.');
process.exit(0);
});
setTimeout(() => {
console.error('Forced shutdown due to timeout.');
process.exit(1);
}, 10000);
}
process.on('SIGTERM', () => shutdown('SIGTERM'));
process.on('SIGINT', () => shutdown('SIGINT')); // Handles Ctrl+C