refactor: optimize multi-stage Dockerfile for improved build efficiency and clarity
This commit is contained in:
28
Dockerfile
28
Dockerfile
@ -1,19 +1,13 @@
|
||||
# Use official Node.js image
|
||||
FROM node:24
|
||||
|
||||
LABEL authors="Ari Yeger"
|
||||
### Client Stage
|
||||
|
||||
# Set working directory
|
||||
WORKDIR /app
|
||||
|
||||
# create client directory
|
||||
RUN mkdir client
|
||||
FROM node:24 AS client-build
|
||||
# Set the working directory for the client
|
||||
WORKDIR /app/client
|
||||
|
||||
# Copy package files and install dependencies
|
||||
COPY /client/package*.json ./
|
||||
RUN npm install
|
||||
RUN npm ci
|
||||
|
||||
# Copy server source code
|
||||
COPY /client .
|
||||
@ -22,13 +16,7 @@ COPY /client .
|
||||
RUN npm run build
|
||||
|
||||
### Server Stage
|
||||
|
||||
# Set working directory
|
||||
WORKDIR /app
|
||||
|
||||
# create server directory
|
||||
RUN mkdir server
|
||||
|
||||
FROM node:24 AS server-build
|
||||
# Set the working directory for the server
|
||||
WORKDIR /app/server
|
||||
|
||||
@ -42,7 +30,13 @@ COPY /server .
|
||||
# no build step for server, its already JavaScript
|
||||
|
||||
# Production stage
|
||||
FROM node:24-slim
|
||||
FROM node:24-slim AS production
|
||||
WORKDIR /app
|
||||
# Copy built client files from client-build stage
|
||||
COPY --from=client-build /app/client/dist ./client/dist
|
||||
# Copy server files from server-build stage
|
||||
COPY --from=server-build /app/server ./server
|
||||
WORKDIR /app/server
|
||||
# Expose the port your server runs on (change if needed)
|
||||
EXPOSE 8000
|
||||
|
||||
|
||||
Reference in New Issue
Block a user