45 lines
1.0 KiB
Docker
45 lines
1.0 KiB
Docker
# Stage 1: Build React frontend
|
|
FROM node:20-alpine AS frontend-builder
|
|
WORKDIR /app/frontend
|
|
|
|
# Install yarn for faster package management
|
|
RUN npm install -g yarn
|
|
|
|
# Copy package files
|
|
COPY frontend/package*.json ./
|
|
COPY frontend/yarn.lock* ./
|
|
|
|
# Install dependencies with yarn (faster than npm)
|
|
RUN yarn install --frozen-lockfile --network-timeout 300000
|
|
|
|
# Copy source code
|
|
COPY frontend/ .
|
|
|
|
# Build the application
|
|
RUN yarn build
|
|
|
|
# Stage 2: Setup Node.js backend and serve everything
|
|
FROM node:20-alpine
|
|
WORKDIR /app
|
|
|
|
# Install yarn for faster package management
|
|
RUN npm install -g yarn
|
|
|
|
# Copy package files
|
|
COPY backend/package*.json ./
|
|
COPY backend/yarn.lock* ./
|
|
|
|
# Install production dependencies only
|
|
RUN yarn install --frozen-lockfile --production --network-timeout 300000
|
|
|
|
# Copy backend source code
|
|
COPY backend/ .
|
|
|
|
# Copy built frontend assets from the previous stage
|
|
COPY --from=frontend-builder /app/frontend/dist ./public
|
|
|
|
# The port the backend runs on
|
|
EXPOSE 3001
|
|
|
|
# Start the server
|
|
CMD ["node", "server.js"] |