From f54cf636621cabf905693f6b937008a34a262069 Mon Sep 17 00:00:00 2001 From: Araozu Date: Thu, 29 Feb 2024 09:14:57 -0500 Subject: [PATCH] Docker & Jenkins --- .dockerignore | 15 +++++++++++++++ Dockerfile | 14 ++++++++++++++ Jenkinsfile | 25 +++++++++++++++++++++++++ srv/index.ts | 25 +++---------------------- 4 files changed, 57 insertions(+), 22 deletions(-) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100644 Jenkinsfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..f965aed --- /dev/null +++ b/.dockerignore @@ -0,0 +1,15 @@ +node_modules +Dockerfile* +docker-compose* +.dockerignore +.git +.gitignore +README.md +LICENSE +.vscode +Makefile +helm-charts +.env +.editorconfig +.idea +coverage* diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..e475fa0 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,14 @@ +FROM oven/bun:latest as base +WORKDIR /usr/src/app + +# Copy the dist folder from here +COPY . . + +ENV NODE_ENV=production +# Install deps +RUN bun install --frozen-lockfile --production + +# run the app +USER bun +EXPOSE 3485/tcp +ENTRYPOINT [ "bun", "run", "srv/index.ts" ] diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..d20d8e8 --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,25 @@ +pipeline { + agent any + environment { + PATH = "/var/lib/jenkins/.nvm/versions/node/v20.9.0/bin:/var/lib/jenkins/bin:${env.PATH}" + } + stages { + stage('Install') { + steps { + sh 'pnpm i' + } + } + stage('Build frontend') { + steps { + sh 'pnpm build-only' + } + } + stage('Deploy') { + steps { + sh 'docker build -t bun-pseudosubs-v1:latest .' + sh 'docker stop bun-pseudosubs-v1 && docker rm bun-pseudosubs-v1' + sh 'docker run -d --name bun-pseudosubs-v1 -p 3485:3485 bun-pseudosubs-v1:latest' + } + } + } +} diff --git a/srv/index.ts b/srv/index.ts index 7bfc2ab..062d860 100644 --- a/srv/index.ts +++ b/srv/index.ts @@ -20,14 +20,15 @@ import {estadisticas} from './Admin/Eps/estadisticas'; console.log("express??"); const app = express(); -const port = 3000; +const port = 3485; const expressApp = (app: core.Express) => { app.use(express.json()); app.use(express.urlencoded()); - app.get("/"); + // Serve the frontend + app.use(express.static("dist")); app.post('/links', require('./LinksAnimes/obtenerLinks').obtenerLinks); app.put('/links', require('./LinksAnimes/modificarLink').modificarLink); @@ -65,26 +66,6 @@ export const sqliteConnection = { }, }; -const conexion = (() => { - const con = mysql.createConnection({ - host: 'localhost', - user: 'root', - password: '123456789', - database: 'pseudo', - }); - - con.connect((err) => { - if (!err) { - console.log("MySQL iniciado c:"); - } else { - throw err; - } - }); - - return con; -})(); - - expressApp(app); app.listen(port, () => {