NovelCrafter2 / Dockerfile
NoLev's picture
Update Dockerfile
d6ebe14 verified
# Use official Python 3.10 slim image as base
FROM python:3.10-slim
# Set working directory
WORKDIR /app
# Set environment variables for NLTK and Hugging Face cache
ENV NLTK_DATA=/app/nltk_data
ENV TRANSFORMERS_CACHE=/app/hf_cache
ENV PYTHONUNBUFFERED=1
# Install system dependencies
RUN apt-get update && apt-get install -y \
gcc \
g++ \
libmariadb-dev-compat \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
# Copy requirements.txt
COPY requirements.txt .
# Install Python dependencies
RUN pip install --no-cache-dir -r requirements.txt
# Pre-download NLTK punkt data to avoid runtime permission issues
RUN python -m nltk.downloader -d /app/nltk_data punkt
# Copy application code
COPY app/main.py ./app/main.py
COPY static/index.html ./static/index.html
# Create cache directories and set permissions
RUN mkdir -p /app/nltk_data /app/hf_cache \
&& chmod -R 777 /app/nltk_data /app/hf_cache
# Create a non-root user and switch to it
RUN useradd -m -u 1000 appuser \
&& chown -R appuser:appuser /app
USER appuser
# Expose port 7860 for Hugging Face Spaces
EXPOSE 7860
# Run the FastAPI app with Uvicorn
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "7860"]