lifekline / Dockerfile
xiaobo ren
Fix npm dependency conflict: use --legacy-peer-deps for React 19 compatibility
7017101
# Multi-stage build for Life K-Line application
FROM node:18-alpine AS builder
# Install build dependencies for native modules
RUN apk add --no-cache python3 make g++
# Set working directory
WORKDIR /app
# Copy package files
COPY package*.json ./
# Install dependencies
RUN npm ci --legacy-peer-deps
# Copy source code
COPY . .
# Build frontend
RUN npm run build
# Production stage
FROM node:18-alpine
# Install build dependencies for native modules (needed for better-sqlite3)
RUN apk add --no-cache python3 make g++
WORKDIR /app
# Copy package files
COPY package*.json ./
# Install production dependencies only
RUN npm ci --only=production --legacy-peer-deps && npm cache clean --force
# Remove build dependencies to reduce image size (optional, but keeps image smaller)
# Note: Keep them if you need to rebuild native modules at runtime
# RUN apk del python3 make g++
# Copy built frontend from builder
COPY --from=builder /app/dist ./dist
# Copy server files
COPY server ./server
COPY assets ./assets
COPY data ./data
# Create directory for SQLite database
RUN mkdir -p /app/server/data
# Expose port (Hugging Face Spaces uses 7860)
EXPOSE 7860
# Set environment variables
ENV NODE_ENV=production
ENV PORT=7860
# Start the server
CMD ["node", "server/index.js"]