From 159c46c4cc72c20805ecd477fd4ee4c14e6c2379 Mon Sep 17 00:00:00 2001 From: Fred Boniface Date: Fri, 28 Jul 2023 20:51:43 +0100 Subject: [PATCH] Add support for deploying from TS source Signed-off-by: Fred Boniface --- Dockerfile | 15 ++++++++++++--- app.ts => app.js | 6 +++--- src/controllers/issue.controllers.js | 2 +- src/middlewares/auth.middlewares.js | 2 +- src/middlewares/requireJson.middlewares.js | 2 +- src/services/dbAccess.services.js | 2 +- src/services/find.services.js | 2 +- src/services/issue.services.js | 2 +- src/services/kube.services.js | 2 +- src/services/ldb.services.js | 2 +- src/services/list.services.js | 2 +- src/services/mail.services.js | 2 +- src/services/pis.services.js | 2 +- src/services/registration.services.js | 2 +- src/services/stats.services.js | 2 +- src/services/trainService.services.js | 2 +- src/utils/auth.utils.ts | 4 ++-- src/utils/ldb.utils.js | 2 +- src/utils/{log.utils.ts => logs.utils.ts} | 0 19 files changed, 32 insertions(+), 23 deletions(-) rename app.ts => app.js (96%) rename src/utils/{log.utils.ts => logs.utils.ts} (100%) diff --git a/Dockerfile b/Dockerfile index b6d01b2..30e13c2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,16 @@ -FROM node:19 +FROM node:20 as builder EXPOSE 8460 WORKDIR /usr/src/app COPY ./package*.json ./ -RUN npm ci --omit=dev +RUN npm i COPY . . -CMD [ "node", "app.js" ] +RUN npm run build + +FROM node:20-slim +EXPOSE 8460 +WORKDIR /usr/src/app +COPY ./mail-templates/* ./mail-templates/ +COPY ./package*.json ./ +RUN npm ci --omit=dev +COPY --from=builder /usr/src/app/dist/ ./ +CMD [ "node" , "app.js" ] diff --git a/app.ts b/app.js similarity index 96% rename from app.ts rename to app.js index 0631bc5..8a4fe18 100644 --- a/app.ts +++ b/app.js @@ -18,7 +18,7 @@ const cors = require('cors'); const authenticate= require('./src/middlewares/auth.middlewares'); // Internal Requires -const log = require('./src/utils/log.utils'); +const log = require('./src/utils/logs.utils'); const version = require('./src/configs/version.configs'); const listRtr = require('./src/routes/list.routes'); const ldbRtr = require('./src/routes/ldb.routes'); @@ -54,7 +54,7 @@ log.out(`app: Starting OwlBoard - Backend Version: ${version.app} - ` + `API versions: ${version.api}`, 'init'); // Express Error Handling: -app.use((err: Error, req: Request, res, next) => { +app.use((err, req, res, next) => { const statusCode = err.statuscode || 500; console.error(err.message, err.stack); res.status(statusCode).json({'message': err.message}); @@ -103,7 +103,7 @@ mode === 'development' : null; // Start Express -app.listen(srvPort, srvListen, (error: Error) =>{ +app.listen(srvPort, srvListen, (error) =>{ if(!error) { log.out(`app.listen: Listening on http://${srvListen}:${srvPort}`, 'init'); log.out('app.listen: State - alive', 'init'); diff --git a/src/controllers/issue.controllers.js b/src/controllers/issue.controllers.js index 5986db2..5c1fbd9 100644 --- a/src/controllers/issue.controllers.js +++ b/src/controllers/issue.controllers.js @@ -1,5 +1,5 @@ const issue = require('../services/issue.services'); -const log = require('../utils/log.utils'); +const log = require('../utils/logs.utils'); async function post(req, res, next){ try { diff --git a/src/middlewares/auth.middlewares.js b/src/middlewares/auth.middlewares.js index a37fe94..fabe42c 100644 --- a/src/middlewares/auth.middlewares.js +++ b/src/middlewares/auth.middlewares.js @@ -1,5 +1,5 @@ const utils = require('../utils/auth.utils'); -const log = require('../utils/log.utils'); +const log = require('../utils/logs.utils'); module.exports = async function authCheck(req, res, next) { log.out('authMiddlewares: Checking authentication', 'dbug'); diff --git a/src/middlewares/requireJson.middlewares.js b/src/middlewares/requireJson.middlewares.js index 57f783d..976fc57 100644 --- a/src/middlewares/requireJson.middlewares.js +++ b/src/middlewares/requireJson.middlewares.js @@ -1,4 +1,4 @@ -const log = require('../utils/log.utils'); +const log = require('../utils/logs.utils'); module.exports = async function requireJson(req, res, next) { if (req.headers['content-type'] !== 'application/json') { diff --git a/src/services/dbAccess.services.js b/src/services/dbAccess.services.js index 6c1b0ef..6f31187 100644 --- a/src/services/dbAccess.services.js +++ b/src/services/dbAccess.services.js @@ -1,5 +1,5 @@ /* global process */ -const log = require('../utils/log.utils'); // Log Helper +const log = require('../utils/logs.utils'); // Log Helper const dbUser = process.env.OWL_DB_USER || 'owl'; const dbPass = process.env.OWL_DB_PASS || 'twittwoo'; diff --git a/src/services/find.services.js b/src/services/find.services.js index 4f4a5ce..dd18731 100644 --- a/src/services/find.services.js +++ b/src/services/find.services.js @@ -1,6 +1,6 @@ // Parse and return a find request -const log = require('../utils/log.utils'); // Log Helper +const log = require('../utils/logs.utils'); // Log Helper const db = require('../services/dbAccess.services'); const san = require('../utils/sanitizer.utils'); diff --git a/src/services/issue.services.js b/src/services/issue.services.js index e4843f5..a2d0061 100644 --- a/src/services/issue.services.js +++ b/src/services/issue.services.js @@ -1,6 +1,6 @@ /* eslint-disable no-useless-escape */ const axios = require('axios'); -const log = require('../utils/log.utils'); +const log = require('../utils/logs.utils'); const issueLabels = { bug: 120, diff --git a/src/services/kube.services.js b/src/services/kube.services.js index 1bf77bd..717d8b5 100644 --- a/src/services/kube.services.js +++ b/src/services/kube.services.js @@ -1,5 +1,5 @@ const testing = require('../services/mail.services'); -const log = require('../utils/log.utils'); +const log = require('../utils/logs.utils'); async function getAlive(){ log.out('kubeServices.getAlive: alive hook checked', 'info'); diff --git a/src/services/ldb.services.js b/src/services/ldb.services.js index be8c2d5..a949fa6 100644 --- a/src/services/ldb.services.js +++ b/src/services/ldb.services.js @@ -1,6 +1,6 @@ // Parse and return an LDB Request -const log = require('../utils/log.utils'); // Log Helper +const log = require('../utils/logs.utils'); // Log Helper const ldb = require('ldbs-json'); const util = require('../utils/ldb.utils'); const san = require('../utils/sanitizer.utils'); diff --git a/src/services/list.services.js b/src/services/list.services.js index c80965d..61965a7 100644 --- a/src/services/list.services.js +++ b/src/services/list.services.js @@ -1,4 +1,4 @@ -const log = require('../utils/log.utils'); // Log Helper +const log = require('../utils/logs.utils'); // Log Helper const db = require('../services/dbAccess.services'); async function getStations(){ diff --git a/src/services/mail.services.js b/src/services/mail.services.js index 20d711f..b0c85e6 100644 --- a/src/services/mail.services.js +++ b/src/services/mail.services.js @@ -1,4 +1,4 @@ -const log = require('../utils/log.utils'); +const log = require('../utils/logs.utils'); const mail = require('nodemailer'); //>> Probs wrong const fromAddr = process.env.OWL_EML_FROM; diff --git a/src/services/pis.services.js b/src/services/pis.services.js index 77d11c8..0b50f78 100644 --- a/src/services/pis.services.js +++ b/src/services/pis.services.js @@ -1,7 +1,7 @@ // Finds PIS Codes using DB Lookups const db = require('../services/dbAccess.services'); -const log = require('../utils/log.utils'); +const log = require('../utils/logs.utils'); const clean = require('../utils/sanitizer.utils'); const supported = [ diff --git a/src/services/registration.services.js b/src/services/registration.services.js index 8e4666d..94900cb 100644 --- a/src/services/registration.services.js +++ b/src/services/registration.services.js @@ -1,4 +1,4 @@ -const log = require('../utils/log.utils'); +const log = require('../utils/logs.utils'); const auth = require('../utils/auth.utils'); const db = require('./dbAccess.services'); const mail = require('./mail.services'); diff --git a/src/services/stats.services.js b/src/services/stats.services.js index a147f60..b2c9eab 100644 --- a/src/services/stats.services.js +++ b/src/services/stats.services.js @@ -1,4 +1,4 @@ -const log = require('../utils/log.utils'); // Log Helper +const log = require('../utils/logs.utils'); // Log Helper const db = require('../services/dbAccess.services'); const os = require('os'); const vers = require('../configs/version.configs'); diff --git a/src/services/trainService.services.js b/src/services/trainService.services.js index 25eb641..f82ef7c 100644 --- a/src/services/trainService.services.js +++ b/src/services/trainService.services.js @@ -1,4 +1,4 @@ -const log = require('../utils/log.utils'); +const log = require('../utils/logs.utils'); const db = require('./dbAccess.services'); const clean = require('../utils/sanitizer.utils'); const pis = require('../services/pis.services'); diff --git a/src/utils/auth.utils.ts b/src/utils/auth.utils.ts index 58edf8f..8e8c0db 100644 --- a/src/utils/auth.utils.ts +++ b/src/utils/auth.utils.ts @@ -1,5 +1,5 @@ -const logs = require('../utils/logs.utils'); -const crypt = require('crypt'); +const logs = require('../utils/logs.utils'); +const crypt = require('crypto'); const db = require('../services/dbAccess.services'); const fs = require('fs/promises'); const minify = require('../utils/minify.utils'); diff --git a/src/utils/ldb.utils.js b/src/utils/ldb.utils.js index 1e1d74f..935f1ff 100644 --- a/src/utils/ldb.utils.js +++ b/src/utils/ldb.utils.js @@ -1,4 +1,4 @@ -const log = require('../utils/log.utils'); // Log Helper +const log = require('./logs.utils'); // Log Helper const db = require('../services/dbAccess.services'); // DB Access //const san = require('../utils/sanitizer.utils'); // Sanitiser diff --git a/src/utils/log.utils.ts b/src/utils/logs.utils.ts similarity index 100% rename from src/utils/log.utils.ts rename to src/utils/logs.utils.ts