Spaces:
Running
Running
File size: 1,485 Bytes
4cb7ab8 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | # Stage 1: Build Frontend
FROM node:20-slim AS frontend-builder
WORKDIR /app/frontend
COPY frontend/package*.json ./
RUN npm install
COPY frontend/ ./
RUN npm run build
# Stage 2: Final Image
FROM python:3.11-slim
# Create a non-root user
RUN useradd -m -u 1000 user
# Install Node.js
RUN apt-get update && apt-get install -y curl && \
curl -fsSL https://deb.nodesource.com/setup_20.x | bash - && \
apt-get install -y nodejs && \
rm -rf /var/lib/apt/lists/*
WORKDIR /app
# Install Python dependencies
COPY backend/requirements.txt ./backend/
RUN pip install --no-cache-dir -r backend/requirements.txt
# Pre-download rembg models
ENV U2NET_HOME=/app/.u2net
RUN mkdir -p /app/.u2net && \
python3 -c "from rembg import new_session; new_session('u2net')" && \
chown -R user:user /app/.u2net
# Copy backend code
COPY backend/ ./backend/
# Copy built frontend
COPY --from=frontend-builder /app/frontend/.next ./frontend/.next
COPY --from=frontend-builder /app/frontend/public ./frontend/public
COPY --from=frontend-builder /app/frontend/package*.json ./frontend/
COPY --from=frontend-builder /app/frontend/next.config.ts ./frontend/
COPY --from=frontend-builder /app/frontend/node_modules ./frontend/node_modules
# Copy startup script
COPY scripts/start_hf.sh ./scripts/start_hf.sh
RUN chmod +x ./scripts/start_hf.sh && chown user:user ./scripts/start_hf.sh
# Ensure permissions
RUN chown -R user:user /app
USER user
EXPOSE 7860
CMD ["./scripts/start_hf.sh"]
|