mhamzaerol's picture
perms
a8d8373
# Use a Python base image
FROM python:3.9
# Add a user for Hugging Face Spaces requirements
RUN useradd -m -u 1000 user
USER root
# Install Node.js (use a supported version, e.g., Node.js 20)
RUN curl -fsSL https://deb.nodesource.com/setup_20.x | bash - && \
apt-get update && \
apt-get install -y nodejs && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
USER user
# Set environment variables
ENV DATA_PATH=/app/backend/data/all_data_up.pickle
ENV DATA_URL=https://drive.google.com/file/d/1BWlAv2QUMQbKXZ01nby5l0JdtGI8YgNI/view?usp=sharing
ENV PATH="/home/user/.local/bin:$PATH"
# Set working directory
WORKDIR /app
# Create the `data` directory explicitly
RUN mkdir -p /app/backend/data
# Copy and install backend dependencies
COPY ./backend/requirements.txt /app/backend/requirements.txt
RUN pip install --no-cache-dir --upgrade -r /app/backend/requirements.txt
# Install Node.js for the frontend
# RUN curl -fsSL https://deb.nodesource.com/setup_16.x | bash - && \
# apt-get install -y nodejs
# Copy frontend files and install dependencies
COPY ./frontend /app/frontend
# RUN cd /app/frontend && npm install
# RUN cd /app/frontend && npm install --legacy-peer-deps
# Install frontend dependencies as root
USER root
RUN cd /app/frontend && npm install --legacy-peer-deps && npm run build
# Fix permissions so the non-root user can access node_modules
RUN chown -R user:user /app/frontend/node_modules
# Switch back to non-root user
USER user
# Copy backend files
COPY ./backend /app/backend
# Expose the required port (7860)
EXPOSE 7860
# Start both the backend and frontend
CMD ["sh", "-c", "cd /app/backend && uvicorn app:app --host 0.0.0.0 --port 7860 & cd /app/frontend && npm start"]