Update Dockerfile
This commit is contained in:
24
Dockerfile
24
Dockerfile
@@ -1,30 +1,32 @@
|
|||||||
# Stage 1: Build the React Application
|
# Stage 1: Build the React Application
|
||||||
FROM node:20-slim AS builder
|
# Using standard node:20 (not slim/alpine) to ensure build tools like python/make/g++ are present
|
||||||
|
FROM node:20 AS builder
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
# Copy package.json (and lock file if it exists) to install dependencies first
|
# Copy package.json (and lock file if it exists)
|
||||||
COPY package*.json ./
|
COPY package*.json ./
|
||||||
|
|
||||||
# Install all dependencies (including devDependencies for the build process)
|
# Install dependencies using legacy-peer-deps to avoid version conflicts
|
||||||
RUN npm install
|
RUN npm install --legacy-peer-deps
|
||||||
|
|
||||||
# Copy the rest of the application source code
|
# Copy the rest of the application source code
|
||||||
COPY . .
|
COPY . .
|
||||||
|
|
||||||
# Build the frontend assets (Vite will output to /app/dist)
|
# Build the frontend assets
|
||||||
RUN npm run build
|
RUN npm run build
|
||||||
|
|
||||||
# Stage 2: Setup the Production Server (Node.js)
|
# Stage 2: Setup the Production Server
|
||||||
FROM node:20-slim
|
# Using standard node:20 to ensure native modules (like pg/mysql drivers) install correctly
|
||||||
|
FROM node:20
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
# Copy package.json again for production dependencies
|
# Copy package.json again for production dependencies
|
||||||
COPY package*.json ./
|
COPY package*.json ./
|
||||||
|
|
||||||
# Install ONLY production dependencies (skips devDependencies like Vite/Typescript)
|
# Install ONLY production dependencies
|
||||||
RUN npm install --omit=dev
|
RUN npm install --omit=dev --legacy-peer-deps
|
||||||
|
|
||||||
# Copy the built frontend assets from the 'builder' stage
|
# Copy the built frontend assets from the 'builder' stage
|
||||||
COPY --from=builder /app/dist ./dist
|
COPY --from=builder /app/dist ./dist
|
||||||
@@ -32,11 +34,11 @@ COPY --from=builder /app/dist ./dist
|
|||||||
# Copy the server entry point
|
# Copy the server entry point
|
||||||
COPY server.js ./
|
COPY server.js ./
|
||||||
|
|
||||||
# Set environment variables (defaults)
|
# Set environment variables
|
||||||
ENV NODE_ENV=production
|
ENV NODE_ENV=production
|
||||||
ENV PORT=3000
|
ENV PORT=3000
|
||||||
|
|
||||||
# Expose the port the app runs on
|
# Expose the port
|
||||||
EXPOSE 3000
|
EXPOSE 3000
|
||||||
|
|
||||||
# Start the Node.js server
|
# Start the Node.js server
|
||||||
|
|||||||
Reference in New Issue
Block a user