From 8fc66b13aa48ba1e95a421da2f7d1db04147860c Mon Sep 17 00:00:00 2001 From: Matthew Lopez <73856503+MatthewL246@users.noreply.github.com> Date: Sun, 2 Jun 2024 15:49:00 -0400 Subject: [PATCH] chore: move the DNS server to a separate container --- dns/.dockerignore | 3 ++ .eslintignore => dns/.eslintignore | 2 +- .eslintrc.json => dns/.eslintrc.json | 2 +- dns/Dockerfile | 42 ++++++++++++++++++++++ package-lock.json => dns/package-lock.json | 4 +-- package.json => dns/package.json | 3 +- {src => dns/src}/server.ts | 2 +- tsconfig.json => dns/tsconfig.json | 2 +- 8 files changed, 52 insertions(+), 8 deletions(-) create mode 100644 dns/.dockerignore rename .eslintignore => dns/.eslintignore (50%) rename .eslintrc.json => dns/.eslintrc.json (99%) create mode 100644 dns/Dockerfile rename package-lock.json => dns/package-lock.json (99%) rename package.json => dns/package.json (87%) rename {src => dns/src}/server.ts (99%) rename tsconfig.json => dns/tsconfig.json (99%) diff --git a/dns/.dockerignore b/dns/.dockerignore new file mode 100644 index 0000000..ecff565 --- /dev/null +++ b/dns/.dockerignore @@ -0,0 +1,3 @@ +.env +node_modules +dist diff --git a/.eslintignore b/dns/.eslintignore similarity index 50% rename from .eslintignore rename to dns/.eslintignore index 7c5c224..ab7762f 100644 --- a/.eslintignore +++ b/dns/.eslintignore @@ -1,2 +1,2 @@ dist -*.js \ No newline at end of file +*.js diff --git a/.eslintrc.json b/dns/.eslintrc.json similarity index 99% rename from .eslintrc.json rename to dns/.eslintrc.json index d66114d..d6e470e 100644 --- a/.eslintrc.json +++ b/dns/.eslintrc.json @@ -51,4 +51,4 @@ "always" ] } -} \ No newline at end of file +} diff --git a/dns/Dockerfile b/dns/Dockerfile new file mode 100644 index 0000000..b8c37fa --- /dev/null +++ b/dns/Dockerfile @@ -0,0 +1,42 @@ +# syntax=docker/dockerfile:1 + +# * Base Node.js image +FROM node:20-alpine AS base +WORKDIR /home/node/app + + +# * Installing production dependencies +FROM base AS dependencies + +RUN --mount=type=bind,source=package.json,target=package.json \ + --mount=type=bind,source=package-lock.json,target=package-lock.json \ + --mount=type=cache,target=/root/.npm \ + npm ci --omit=dev + + +# * Installing development dependencies and building the application +FROM dependencies AS build + +RUN --mount=type=bind,source=package.json,target=package.json \ + --mount=type=bind,source=package-lock.json,target=package-lock.json \ + --mount=type=cache,target=/root/.npm \ + npm ci + +COPY . . +RUN npm run build + + +# * Running the final application +FROM base AS final + +RUN npm install -g pm2 + +ENV NODE_ENV production +USER node + +COPY package.json . + +COPY --from=dependencies /home/node/app/node_modules ./node_modules +COPY --from=build /home/node/app/dist ./dist + +CMD pm2 start . --no-daemon diff --git a/package-lock.json b/dns/package-lock.json similarity index 99% rename from package-lock.json rename to dns/package-lock.json index d4a64c2..2cc7e75 100644 --- a/package-lock.json +++ b/dns/package-lock.json @@ -1,12 +1,12 @@ { "name": "@pretendonetwork/sssl-dns", - "version": "1.0.1", + "version": "1.0.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@pretendonetwork/sssl-dns", - "version": "1.0.1", + "version": "1.0.0", "license": "AGPL-3.0", "dependencies": { "@colors/colors": "^1.6.0", diff --git a/package.json b/dns/package.json similarity index 87% rename from package.json rename to dns/package.json index e6e7f59..038126c 100644 --- a/package.json +++ b/dns/package.json @@ -5,9 +5,8 @@ "main": "dist/server.js", "scripts": { "lint": "npx eslint .", - "build": "npm run lint && npm run clean && npx tsc && npx tsc-alias && npm run copy-files", + "build": "npm run lint && npm run clean && npx tsc && npx tsc-alias", "clean": "npx rimraf ./dist", - "copy-files": "cp package.json dist/package.json && cp README.md dist/README.md", "start": "node --enable-source-maps ." }, "author": "PretendoNetwork", diff --git a/src/server.ts b/dns/src/server.ts similarity index 99% rename from src/server.ts rename to dns/src/server.ts index 4b4ba7a..7b30ec7 100644 --- a/src/server.ts +++ b/dns/src/server.ts @@ -144,4 +144,4 @@ server.on('listening', () => { server.listen({ udp: udpPort !== 0 ? udpPort : undefined, tcp: tcpPort !== 0 ? tcpPort : undefined -}); \ No newline at end of file +}); diff --git a/tsconfig.json b/dns/tsconfig.json similarity index 99% rename from tsconfig.json rename to dns/tsconfig.json index 6594d90..fb6fc0f 100644 --- a/tsconfig.json +++ b/dns/tsconfig.json @@ -18,4 +18,4 @@ } }, "include": ["src"] -} \ No newline at end of file +}