From 2818085419a6b8115d9ad05e2923f4b740aa8d29 Mon Sep 17 00:00:00 2001 From: max-im Date: Fri, 4 Aug 2023 18:03:34 +0300 Subject: [PATCH] set 3-th stage Dockerfile --- server/Dockerfile | 30 +++++++++++++++++++++++------- server/package.json | 2 +- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/server/Dockerfile b/server/Dockerfile index 3f5eecc..1263e43 100644 --- a/server/Dockerfile +++ b/server/Dockerfile @@ -1,5 +1,18 @@ -# === Stage 1: Build TypeScript code === -FROM node:14 AS builder +# === Stage 1: Build the client === +FROM node:14 AS client-builder + +WORKDIR /usr/app/client + +COPY ../client/package*.json ./ + +RUN npm install + +COPY ../client ./ + +RUN npm run build + +# === Stage 2: Build the server and create the final Docker image === +FROM node:14 AS server-builder WORKDIR /usr/app @@ -9,19 +22,22 @@ RUN npm install COPY . . -RUN npm run build:prod +RUN npm run build -# === Stage 2: Create the final Docker image === +# === Stage 3: Create the final Docker image === FROM node:14 WORKDIR /usr/app -# Copy only the compiled 'dist' folder and package.json -COPY --from=builder /usr/app/package.json /app/package-lock.json ./ -COPY --from=builder /usr/app/dist ./dist +# Copy only the compiled 'dist' folder from server and 'build' folder from client +COPY --from=client-builder /usr/app/client/build ./dist/build +COPY --from=server-builder /usr/app/dist ./dist + +COPY ./package*.json ./ RUN npm install --production EXPOSE 5000 +# Start the server CMD ["npm", "start"] diff --git a/server/package.json b/server/package.json index 8e40308..61c593c 100644 --- a/server/package.json +++ b/server/package.json @@ -6,7 +6,7 @@ "scripts": { "start": "node ./dist/app.js", "dev": "tsnd --respawn --transpile-only --exit-child src/app.ts", - "build:prod": "rm -rf ./dist && tsc", + "build": "tsc", "lint": "eslint .", "lint:fix": "eslint . --fix", "test": "cross-env NODE_ENV=test jest",