Converting to multi-stage dockerfile

This commit is contained in:
Aaron Powell 2025-06-04 12:18:43 +10:00
commit 769d045c16

View file

@ -1,24 +1,48 @@
FROM node:22-slim # Build stage
FROM node:24-slim AS builder
# Set working directory # Set working directory
WORKDIR /app WORKDIR /app
# Copy files # Copy package files for installation
COPY . . COPY package*.json ./
COPY .npmrc ./
COPY client/package*.json ./client/
COPY server/package*.json ./server/
COPY cli/package*.json ./cli/
# Install dependencies # Install dependencies
# Working around https://github.com/npm/cli/issues/4828 RUN npm ci --ignore-scripts
# RUN npm ci
RUN npm install --no-package-lock # Copy source files
COPY . .
# Build the application # Build the application
RUN npm run build RUN npm run build
ARG CLIENT_PORT=6274 # Production stage
ARG SERVER_PORT=6277 FROM node:24-slim
EXPOSE ${CLIENT_PORT} ${SERVER_PORT} WORKDIR /app
# Copy package files for production
COPY package*.json ./
COPY .npmrc ./
COPY client/package*.json ./client/
COPY server/package*.json ./server/
COPY cli/package*.json ./cli/
# Install only production dependencies
RUN npm ci --omit=dev --ignore-scripts
# Copy built files from builder stage
COPY --from=builder /app/client/dist ./client/dist
COPY --from=builder /app/client/bin ./client/bin
COPY --from=builder /app/server/build ./server/build
COPY --from=builder /app/cli/build ./cli/build
# Document which ports the application uses internally
EXPOSE 6274 6277
# Use ENTRYPOINT with CMD for arguments # Use ENTRYPOINT with CMD for arguments
ENTRYPOINT ["npm", "start"] ENTRYPOINT ["npm", "start"]
CMD []