# Build stage FROM node:20 AS builder WORKDIR /app # Use a faster npm registry mirror RUN npm config set registry https://registry.npmmirror.com # Copy package files first for better caching COPY package*.json ./ RUN npm install # Copy the rest of the code and build COPY . . RUN npm run build # Production stage FROM node:20-slim WORKDIR /app # Use a faster npm registry mirror RUN npm config set registry https://registry.npmmirror.com # Install only production dependencies # Copy package files again for production layer caching COPY package*.json ./ # Install build tools temporarily for native modules if needed, # though many have pre-built binaries on standard Node images RUN apt-get update && apt-get install -y python3 make g++ \ && npm install --omit=dev \ && apt-get purge -y python3 make g++ \ && apt-get autoremove -y \ && rm -rf /var/lib/apt/lists/* # Copy built app and static files from builder COPY --from=builder /app/build ./build COPY --from=builder /app/static ./static # App configuration ENV PORT=1995 ENV NODE_ENV=production EXPOSE 1995 # The database data.db will be created at /app/data.db or mounted via volume CMD ["node", "build"]