Skip to content

Commit

Permalink
set 3-th stage Dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
Max-im committed Aug 4, 2023
1 parent b03a480 commit 2818085
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
30 changes: 23 additions & 7 deletions server/Dockerfile
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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"]
2 changes: 1 addition & 1 deletion server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 2818085

Please sign in to comment.