From 13788c553871d1214eae82c6d99507e21bd1cd84 Mon Sep 17 00:00:00 2001 From: clfreville2 Date: Wed, 19 Jun 2024 19:50:02 +0200 Subject: [PATCH] Dockerise --- .dockerignore | 4 ++++ Dockerfile | 14 ++++++++++++++ package.json | 3 ++- src/server.ts | 4 ++-- tsconfig.json | 9 ++++++--- 5 files changed, 28 insertions(+), 6 deletions(-) create mode 100644 .dockerignore create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..4af4093 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,4 @@ +node_modules +Dockerfile +.dockerignore +*.js diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..3567603 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,14 @@ +FROM node:22-bookworm AS runner +WORKDIR /app +ENV NODE_ENV="production" +COPY package.json package-lock.json ./ +RUN npm install --omit=dev + +FROM runner AS builder +COPY . . +RUN npm install && npm run build && npm prune --omit=dev + +FROM runner +COPY --from=builder /app/dist /app +EXPOSE 3000 +ENTRYPOINT ["node", "src/server.js"] diff --git a/package.json b/package.json index d2e192b..d895272 100644 --- a/package.json +++ b/package.json @@ -3,11 +3,12 @@ "module": "src/server.ts", "type": "module", "scripts": { - "build": "tsc", + "build": "tsc && tsc-alias", "start": "tsx src/server.ts" }, "devDependencies": { "@types/bun": "^1.0.4", + "tsc-alias": "^1.8.10", "tsx": "^4.7.0", "typescript": "^5.3.3" }, diff --git a/src/server.ts b/src/server.ts index f859d62..b4798e0 100644 --- a/src/server.ts +++ b/src/server.ts @@ -5,7 +5,7 @@ import { Type, TypeBoxTypeProvider } from "@fastify/type-provider-typebox"; import websocket, { WebSocket } from "@fastify/websocket"; import Fastify, { FastifyReply } from "fastify"; import { nanoid } from "nanoid"; -import { allocateBuffer, getRunner } from "runner"; +import { allocateBuffer, getRunner } from "./runner"; import { Pull, Push } from "zeromq"; import * as db from "./database"; @@ -559,4 +559,4 @@ async function forwardOutput() { } /* Lancer le serveur et la fonction forwardOutput sur le même thread en parallèle */ -await Promise.all([fastify.listen({ port: 3000 }), forwardOutput()]); +await Promise.all([fastify.listen({ port: 3000, host: '0.0.0.0' }), forwardOutput()]); diff --git a/tsconfig.json b/tsconfig.json index 2558e1d..4accc64 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,15 +1,15 @@ { "compilerOptions": { "baseUrl": "./src", + "outDir": "./dist", "types": ["bun-types"], "lib": ["esnext"], "module": "esnext", "target": "esnext", - "moduleResolution": "bundler", - "noEmit": true, - "allowImportingTsExtensions": true, + "moduleResolution": "Node", + "noEmit": false, "moduleDetection": "force", "strict": true, @@ -18,5 +18,8 @@ "composite": true, "downlevelIteration": true, "allowSyntheticDefaultImports": true + }, + "tsc-alias": { + "resolveFullPaths": true } }