merimandi / Dockerfile
datamk's picture
Upload 59 files
a5ef51c verified
# Stage 1: Build the frontend
FROM node:20 AS builder
WORKDIR /build
# Install build tools for native dependencies
RUN apt-get update && apt-get install -y \
python3 \
make \
g++ \
python-is-python3 \
&& rm -rf /var/lib/apt/lists/*
COPY package*.json ./
# Install ALL dependencies (including dev for building)
RUN npm install
COPY . .
RUN npm run build
# Stage 2: Production server
FROM node:20
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update && apt-get install -y \
python3 \
make \
g++ \
python-is-python3 \
&& rm -rf /var/lib/apt/lists/*
# Set environment for node-gyp
ENV PYTHON=python3
# Set up user 1000 for Hugging Face (default user name 'user')
RUN useradd -m -u 1000 user
USER user
ENV HOME=/home/user \
PATH=/home/user/.local/bin:$PATH
WORKDIR $HOME/app
# Copy production package files
COPY --chown=user package*.json ./
# Install only production dependencies
# This will build better-sqlite3 for the production environment
RUN npm install --omit=dev
# Copy the built frontend from the builder stage
COPY --chown=user --from=builder /build/dist ./dist
# Copy the server source and database
COPY --chown=user server ./server
COPY --chown=user mandi.db ./mandi.db
# Ensure the database and uploads directory are writable
# mkdir -p as user 'user' in the workdir is safe
RUN mkdir -p server/uploads && chmod -R 777 server/uploads
EXPOSE 7860
CMD ["node", "server/index.js"]