mz_chatbot / Dockerfile
Shurem's picture
added chatbot
41f012a
Raw
History Blame Contribute Delete
1.3 kB
# Dockerfile for HuggingFace Spaces deployment with UV package manager
FROM python:3.11-slim
# Set working directory
WORKDIR /app
# Set environment variables
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
ENV PORT=7860
ENV UV_SYSTEM_PYTHON=1
# Install system dependencies and UV
RUN apt-get update && apt-get install -y \
gcc \
curl \
&& rm -rf /var/lib/apt/lists/* \
&& curl -LsSf https://astral.sh/uv/install.sh | sh
# Add UV to PATH
ENV PATH="/root/.local/bin:$PATH"
# Copy requirements first for better caching
COPY requirements.txt .
# Create virtual environment with UV and install dependencies
RUN uv venv .venv && \
. .venv/bin/activate && \
uv pip install -r requirements.txt
# Copy application code
COPY . .
# Create non-root user for security
RUN useradd -m -u 1000 user && \
chown -R user:user /app
USER user
# Add venv to PATH for the user
ENV PATH="/app/.venv/bin:$PATH"
ENV VIRTUAL_ENV="/app/.venv"
# Expose the port HuggingFace Spaces expects
EXPOSE 7860
# Health check
HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 \
CMD python -c "import urllib.request; urllib.request.urlopen('http://localhost:7860/health')" || exit 1
# Run the application
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]