diff --git a/.dockerignore b/.dockerignore index f4b035a..1721ef2 100644 --- a/.dockerignore +++ b/.dockerignore @@ -8,6 +8,7 @@ # Useless and heavy folders **/build **/dist +data [...] **/.next **/.vercel @@ -16,4 +17,4 @@ # Other useless files in the image .git/ .github/ -[...] \ No newline at end of file +[...] diff --git a/Dockerfile b/Dockerfile index 29e61a8..0d3ab8a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,29 +1,23 @@ -# Build Stage -FROM node:22-bookworm-slim AS build - -WORKDIR /home/node/app - -COPY package*.json ./ -RUN npm install -COPY . . -RUN npm run build - -# Prod stage FROM node:22-bookworm-slim WORKDIR /home/node/app ENV NODE_ENV=production # Copy only needed files -COPY --chown=node:node --from=build /home/node/app/dist ./dist -COPY --chown=node:node --from=build /home/node/app/public ./public -COPY --chown=node:node --from=build /home/node/app/package*.json ./ +COPY --chown=node:node ./package*.json . RUN npm ci --only=production --ignore-scripts -COPY process.json . +COPY --chown=node:node process.json . RUN mkdir -p /home/node/.pm2 /home/node/app/logs /home/node/app/pids && chown -R node:node /home/node/.pm2 /home/node/app/logs +# db-migrate stuff +COPY --chown=node:node migrations ./migrations +COPY --chown=node:node database.json . + +COPY --chown=node:node ./public ./public +COPY --chown=node:node ./src ./src + USER node EXPOSE 8081 CMD ["./node_modules/pm2/bin/pm2-runtime", "process.json"] diff --git a/docker-compose-production.yml b/docker-compose-production.yml index 39e7787..7b63001 100644 --- a/docker-compose-production.yml +++ b/docker-compose-production.yml @@ -43,4 +43,4 @@ volumes: networks: badgehub_network: name: badgehub_network - external: true \ No newline at end of file + external: true diff --git a/package-lock.json b/package-lock.json index 93904a3..9b0d791 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,13 +11,16 @@ "dependencies": { "db-migrate": "^0.11.14", "db-migrate-pg": "^1.5.2", + "dotenv": "^16.4.5", "express": "^4.21.1", "jose": "^5.9.6", "pg": "^8.11.5", "pino-http": "^10.1.0", "pm2": "^5.4.0", "swagger-ui-express": "^5.0.0", - "tsoa": "^6.2.1" + "tsoa": "^6.2.1", + "tsx": "^4.19.2", + "typescript": "^5.4.5" }, "devDependencies": { "@types/express": "^4.17.21", @@ -27,13 +30,11 @@ "@types/swagger-ui-express": "^4.1.6", "@vitest/coverage-v8": "^2.1.1", "concurrently": "^8.2.2", - "dotenv": "^16.4.5", "husky": "^9.0.11", "prettier": "^3.2.5", "pretty-quick": "^4.0.0", "supertest": "^7.0.0", - "tsx": "^4.11.2", - "typescript": "^5.4.5", + "vite-tsconfig-paths": "^5.1.3", "vitest": "^2.1.1" } }, @@ -129,7 +130,6 @@ "cpu": [ "ppc64" ], - "dev": true, "optional": true, "os": [ "aix" @@ -145,7 +145,6 @@ "cpu": [ "arm" ], - "dev": true, "optional": true, "os": [ "android" @@ -161,7 +160,6 @@ "cpu": [ "arm64" ], - "dev": true, "optional": true, "os": [ "android" @@ -177,7 +175,6 @@ "cpu": [ "x64" ], - "dev": true, "optional": true, "os": [ "android" @@ -193,7 +190,6 @@ "cpu": [ "arm64" ], - "dev": true, "optional": true, "os": [ "darwin" @@ -209,7 +205,6 @@ "cpu": [ "x64" ], - "dev": true, "optional": true, "os": [ "darwin" @@ -225,7 +220,6 @@ "cpu": [ "arm64" ], - "dev": true, "optional": true, "os": [ "freebsd" @@ -241,7 +235,6 @@ "cpu": [ "x64" ], - "dev": true, "optional": true, "os": [ "freebsd" @@ -257,7 +250,6 @@ "cpu": [ "arm" ], - "dev": true, "optional": true, "os": [ "linux" @@ -273,7 +265,6 @@ "cpu": [ "arm64" ], - "dev": true, "optional": true, "os": [ "linux" @@ -289,7 +280,6 @@ "cpu": [ "ia32" ], - "dev": true, "optional": true, "os": [ "linux" @@ -305,7 +295,6 @@ "cpu": [ "loong64" ], - "dev": true, "optional": true, "os": [ "linux" @@ -321,7 +310,6 @@ "cpu": [ "mips64el" ], - "dev": true, "optional": true, "os": [ "linux" @@ -337,7 +325,6 @@ "cpu": [ "ppc64" ], - "dev": true, "optional": true, "os": [ "linux" @@ -353,7 +340,6 @@ "cpu": [ "riscv64" ], - "dev": true, "optional": true, "os": [ "linux" @@ -369,7 +355,6 @@ "cpu": [ "s390x" ], - "dev": true, "optional": true, "os": [ "linux" @@ -385,7 +370,6 @@ "cpu": [ "x64" ], - "dev": true, "optional": true, "os": [ "linux" @@ -401,7 +385,6 @@ "cpu": [ "x64" ], - "dev": true, "optional": true, "os": [ "netbsd" @@ -417,7 +400,6 @@ "cpu": [ "arm64" ], - "dev": true, "optional": true, "os": [ "openbsd" @@ -433,7 +415,6 @@ "cpu": [ "x64" ], - "dev": true, "optional": true, "os": [ "openbsd" @@ -449,7 +430,6 @@ "cpu": [ "x64" ], - "dev": true, "optional": true, "os": [ "sunos" @@ -465,7 +445,6 @@ "cpu": [ "arm64" ], - "dev": true, "optional": true, "os": [ "win32" @@ -481,7 +460,6 @@ "cpu": [ "ia32" ], - "dev": true, "optional": true, "os": [ "win32" @@ -497,7 +475,6 @@ "cpu": [ "x64" ], - "dev": true, "optional": true, "os": [ "win32" @@ -2684,7 +2661,6 @@ "version": "16.4.5", "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.4.5.tgz", "integrity": "sha512-ZmdL2rui+eB2YwhsWzjInR8LldtZHGDoQ1ugH85ppHKwpUHL7j7rN0Ti9NCnGiQbhaZ11FpR+7ao1dNsmduNUg==", - "dev": true, "engines": { "node": ">=12" }, @@ -2755,7 +2731,6 @@ "version": "0.23.1", "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.23.1.tgz", "integrity": "sha512-VVNz/9Sa0bs5SELtn3f7qhJCDPCF5oMEl5cO9/SSinpE9hbPVvxbd572HH5AKiP7WD8INO53GgfDDhRjkylHEg==", - "dev": true, "hasInstallScript": true, "bin": { "esbuild": "bin/esbuild" @@ -3241,7 +3216,6 @@ "version": "4.8.1", "resolved": "https://registry.npmjs.org/get-tsconfig/-/get-tsconfig-4.8.1.tgz", "integrity": "sha512-k9PN+cFBmaLWtVz29SkUoqU5O0slLuHJXt/2P+tMVFT+phsSGXGkp9t3rQIqdz0e+06EHNGs3oM6ZX1s2zHxRg==", - "dev": true, "dependencies": { "resolve-pkg-maps": "^1.0.0" }, @@ -3303,6 +3277,12 @@ "node": ">= 6" } }, + "node_modules/globrex": { + "version": "0.1.2", + "resolved": "https://registry.npmjs.org/globrex/-/globrex-0.1.2.tgz", + "integrity": "sha512-uHJgbwAMwNFf5mLst7IWLNg14x1CkeqglJb/K3doi4dw6q2IvAAmM/Y81kevy83wP+Sst+nutFTYOGg3d1lsxg==", + "dev": true + }, "node_modules/gopd": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/gopd/-/gopd-1.0.1.tgz", @@ -5062,7 +5042,6 @@ "version": "1.0.0", "resolved": "https://registry.npmjs.org/resolve-pkg-maps/-/resolve-pkg-maps-1.0.0.tgz", "integrity": "sha512-seS2Tj26TBVOC2NIc2rOe2y2ZO7efxITtLZcGSOnHHNOQ7CkiUBfw0Iw2ck6xkIhPwLhKNLS8BO+hEpngQlqzw==", - "dev": true, "funding": { "url": "https://github.com/privatenumber/resolve-pkg-maps?sponsor=1" } @@ -5790,6 +5769,26 @@ "node": ">=14.13.1" } }, + "node_modules/tsconfck": { + "version": "3.1.4", + "resolved": "https://registry.npmjs.org/tsconfck/-/tsconfck-3.1.4.tgz", + "integrity": "sha512-kdqWFGVJqe+KGYvlSO9NIaWn9jT1Ny4oKVzAJsKii5eoE9snzTJzL4+MMVOMn+fikWGFmKEylcXL710V/kIPJQ==", + "dev": true, + "bin": { + "tsconfck": "bin/tsconfck.js" + }, + "engines": { + "node": "^18 || >=20" + }, + "peerDependencies": { + "typescript": "^5.0.0" + }, + "peerDependenciesMeta": { + "typescript": { + "optional": true + } + } + }, "node_modules/tslib": { "version": "1.9.3", "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.9.3.tgz", @@ -5815,7 +5814,6 @@ "version": "4.19.2", "resolved": "https://registry.npmjs.org/tsx/-/tsx-4.19.2.tgz", "integrity": "sha512-pOUl6Vo2LUq/bSa8S5q7b91cgNSjctn9ugq/+Mvow99qW6x/UZYwzxy/3NmqoT66eHYfCVvFvACC58UBPFf28g==", - "dev": true, "dependencies": { "esbuild": "~0.23.0", "get-tsconfig": "^4.7.5" @@ -6049,6 +6047,25 @@ "url": "https://opencollective.com/vitest" } }, + "node_modules/vite-tsconfig-paths": { + "version": "5.1.3", + "resolved": "https://registry.npmjs.org/vite-tsconfig-paths/-/vite-tsconfig-paths-5.1.3.tgz", + "integrity": "sha512-0bz+PDlLpGfP2CigeSKL9NFTF1KtXkeHGZSSaGQSuPZH77GhoiQaA8IjYgOaynSuwlDTolSUEU0ErVvju3NURg==", + "dev": true, + "dependencies": { + "debug": "^4.1.1", + "globrex": "^0.1.2", + "tsconfck": "^3.0.3" + }, + "peerDependencies": { + "vite": "*" + }, + "peerDependenciesMeta": { + "vite": { + "optional": true + } + } + }, "node_modules/vite/node_modules/@esbuild/aix-ppc64": { "version": "0.24.0", "resolved": "https://registry.npmjs.org/@esbuild/aix-ppc64/-/aix-ppc64-0.24.0.tgz", diff --git a/package.json b/package.json index 63c66ec..eadd509 100644 --- a/package.json +++ b/package.json @@ -3,10 +3,10 @@ "version": "1.0.0", "description": "Node project for the BadgeHub API", "type": "module", - "main": "dist/index.js", + "main": "src/index.ts", "scripts": { "install:container": "docker exec -it badgehub-api-node-1 npm install", - "start": "node dist/index.js", + "start": "node --import tsx src/index.ts", "monitor": "docker exec -it badgehub-api-node-1 npx pm2 monit", "lint": "pretty-quick --check", "build": "tsc", @@ -23,13 +23,16 @@ "dependencies": { "db-migrate": "^0.11.14", "db-migrate-pg": "^1.5.2", + "dotenv": "^16.4.5", "express": "^4.21.1", "jose": "^5.9.6", "pg": "^8.11.5", "pino-http": "^10.1.0", "pm2": "^5.4.0", "swagger-ui-express": "^5.0.0", - "tsoa": "^6.2.1" + "tsoa": "^6.2.1", + "tsx": "^4.19.2", + "typescript": "^5.4.5" }, "devDependencies": { "@types/express": "^4.17.21", @@ -39,13 +42,10 @@ "@types/swagger-ui-express": "^4.1.6", "@vitest/coverage-v8": "^2.1.1", "concurrently": "^8.2.2", - "dotenv": "^16.4.5", "husky": "^9.0.11", "prettier": "^3.2.5", "pretty-quick": "^4.0.0", "supertest": "^7.0.0", - "tsx": "^4.11.2", - "typescript": "^5.4.5", "vite-tsconfig-paths": "^5.1.3", "vitest": "^2.1.1" } diff --git a/process.json b/process.json index 5f7b5a3..23fd00c 100644 --- a/process.json +++ b/process.json @@ -1,8 +1,10 @@ { - "script": "dist/index.js", + "script": "src/index.ts", + "interpreter": "node", + "interpreter_args": "--import tsx", "name": "badgehub", "exec_mode": "cluster", - "instances": 4, + "instances": 1, "error_file": "./logs/error.log", "out_file": "./logs/access.log", "combine_logs": true diff --git a/tsconfig.json b/tsconfig.json index 277dac7..067379f 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -17,7 +17,7 @@ "module": "esnext", "moduleResolution": "node", "sourceMap": true, - "outDir": "dist", + "noEmit": true, "lib": ["es2022"], "paths": { "@*": ["./src/*"]