From 0f1f9ec7d80ac1c085a67a9f935e58d4fe86ff6f Mon Sep 17 00:00:00 2001 From: Riccardo Date: Sun, 6 Aug 2023 20:23:11 +0200 Subject: [PATCH] perf: packages and Docker improvements --- Dockerfile | 28 ++++++++++++++++++---------- package.json | 5 ++--- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/Dockerfile b/Dockerfile index d6aa60c..5a8dfbc 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,19 +1,27 @@ -# Build the Node.js app -FROM node:18 as builder +# Development stage +FROM node:18-alpine3.18 as builder WORKDIR /app -# Copy package.json and package-lock.json (or yarn.lock) to the container COPY package*.json ./ -# Install project dependencies -RUN yarn install - -# Copy the rest of the application code to the container COPY . . -# Expose the port that your Node.js app is running on (change 3000 to your desired port) +RUN yarn build + +# Production stage +FROM node:18-slim + +RUN apt-get update && apt-get install -y openssl + +WORKDIR /app + +COPY --from=builder /app/package*.json ./ +COPY --from=builder /app/yarn.lock ./ +COPY --from=builder /app/build ./build + +RUN yarn install --production + EXPOSE 3000 -# Define the command to start your Node.js application -CMD ["bash", "-c", "yarn db:generate && yarn db:migrate && yarn dev"] +CMD ["bash", "-c", "yarn db:generate && yarn db:migrate && node build/index.js"] diff --git a/package.json b/package.json index 4152750..5ba1065 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "node-with-typescript", "version": "1.0.0", "description": "Backend with NodeJS in TypeScript", - "main": "index.ts", + "main": "src/index.ts", "repository": "https://github.com/RiccardoSenica/node-with-typescript.git", "author": "riccardo.s@hey.com", "license": "MIT", @@ -12,7 +12,7 @@ "lint": "eslint --ext .ts . --fix", "typecheck": "tsc", "format": "prettier --config .prettierrc 'src/**/*.ts' --write", - "test": "jest --runInBand --detectOpenHandles", + "test": "jest --runInBand", "prepare": "husky install", "db:generate": "prisma generate", "db:migrate": "prisma migrate deploy", @@ -30,7 +30,6 @@ "@prisma/client": "5.1.1", "body-parser": "^1.20.2", "cors": "^2.8.5", - "crypto": "^1.0.1", "express": "^4.18.2", "helmet": "^7.0.0", "jsonschema": "^1.4.1",