AlanYky's picture
Update Dockerfile
8aaec83 verified
# # Use a Python base image with Node.js installed for npx
# FROM python:3.10.18-slim
# # Install Node.js 20.x and npm for npx
# RUN apt-get update && apt-get install -y \
# curl \
# && curl -fsSL https://deb.nodesource.com/setup_20.x | bash - \
# && apt-get install -y nodejs \
# && apt-get clean \
# && rm -rf /var/lib/apt/lists/*
# # Install uv
# RUN pip install --no-cache-dir uv==0.4.18
# # Create a non-root user and set up npm cache directory
# RUN useradd -m -u 1000 appuser \
# && mkdir -p /home/appuser/.npm \
# && chown -R appuser:appuser /home/appuser/.npm
# # Set npm cache directory to avoid permission issues
# ENV NPM_CONFIG_CACHE=/home/appuser/.npm
# # Set npm registry to public to avoid authentication issues
# RUN npm config set registry https://registry.npmjs.org/
# # Set working directory
# WORKDIR /app
# # Copy requirements.txt and install Python dependencies using uv
# COPY requirements.txt .
# RUN uv pip install --system -r requirements.txt
# # Copy the application code
# COPY . .
# # Switch to non-root user
# USER appuser
# # Expose the port (Hugging Face Spaces typically uses 7860)
# EXPOSE 7860
# # Run the FastAPI application with uvicorn
# CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
# Use a Python base image with Node.js installed for npx
FROM python:3.10.18-slim
# Install Node.js 20.x and npm for npx
RUN apt-get update && apt-get install -y \
curl \
&& curl -fsSL https://deb.nodesource.com/setup_20.x | bash - \
&& apt-get install -y nodejs \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
# Install uv
RUN pip install --no-cache-dir uv==0.4.18
# Create a non-root user and set up npm cache directory
RUN useradd -m -u 1000 appuser \
&& mkdir -p /home/appuser/.npm \
&& chown -R appuser:appuser /home/appuser/.npm
# Set npm cache directory to avoid permission issues
ENV NPM_CONFIG_CACHE=/home/appuser/.npm
# Set npm registry to public to avoid authentication issues
RUN npm config set registry https://registry.npmjs.org/
# Set working directory
WORKDIR /app
# Copy requirements.txt and install Python dependencies using uv
COPY requirements.txt .
RUN uv pip install --system -r requirements.txt
# Copy the application code
COPY . .
# Switch to non-root user
USER appuser
# Expose the port (Hugging Face Spaces typically uses 7860)
EXPOSE 7860
# Run the FastAPI application with uvicorn
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860", "--no-server-header"]