ayush2917's picture
Update Dockerfile
f0f5c70 verified
FROM python:3.10-slim-buster
# Set environment variables
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
ENV PORT=7860
ENV DATABASE_PATH=/app/data/news.db
ENV TRANSFORMERS_CACHE=/app/cache
# Explicitly set Hugging Face cache directory
ENV HF_HOME=/app/cache
ENV IS_BUILDING=false
WORKDIR /app
# Install minimal system dependencies
RUN apt-get update && \
apt-get install -y --no-install-recommends \
gcc \
python3-dev \
&& rm -rf /var/lib/apt/lists/*
# Create cache directory with correct permissions (now also used by HF_HOME)
RUN mkdir -p /app/cache && \
chmod -R 777 /app/cache
# Create data directory for database with correct permissions
RUN mkdir -p /app/data && \
chmod -R 777 /app/data
# Install Python dependencies
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt gunicorn uvloop httptools beautifulsoup4 # Added beautifulsoup4
# Copy application
COPY . .
# Verify we can write to database location (now targeting /app/data)
RUN touch /app/data/test_write && rm /app/data/test_write && \
echo "Verified /app/data is writable during build"
# Run as non-root user
USER 65534 # Standard nobody user UID
# Health check
HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 \
CMD curl -f http://localhost:7860/api/health || exit 1
# Start with single worker
CMD ["gunicorn", \
"--bind", "0.0.0.0:7860", \
"--workers", "1", \
"--worker-class", "uvicorn.workers.UvicornWorker", \
"--timeout", "300", \
"main:app"]