finance-news-api / Dockerfile
ayush2917's picture
Update Dockerfile
1fa9651 verified
# Use Python 3.9 slim as the base image
FROM python:3.9-slim
# Set environment variables
ENV PYTHONUNBUFFERED=1 \
PORT=7860 \
HF_HOME=/data/cache \
IS_BUILDING=true
# Install system dependencies
RUN apt-get update && \
apt-get install -y --no-install-recommends \
gcc \
python3-dev \
libffi-dev \
sqlite3 \
&& rm -rf /var/lib/apt/lists/*
# Create persistent data directory and initialize database
RUN mkdir -p /data/cache && \
sqlite3 /data/news.db "VACUUM" && \
chmod -R 777 /data && \
sqlite3 /data/news.db "CREATE TABLE IF NOT EXISTS news (id INTEGER PRIMARY KEY AUTOINCREMENT, title TEXT NOT NULL, source TEXT, published TEXT, url TEXT UNIQUE NOT NULL, summary TEXT, content TEXT, category TEXT, description TEXT, timestamp DATETIME DEFAULT CURRENT_TIMESTAMP); CREATE INDEX IF NOT EXISTS idx_published ON news (published DESC);"
# Set working directory
WORKDIR /app
# Copy requirements file and install dependencies
COPY requirements.txt .
RUN pip install --no-cache-dir -U pip && \
pip install --no-cache-dir -r requirements.txt
# Copy application files
COPY . .
# Expose port
EXPOSE 7860
# Health check to ensure the app is running (increased start period)
HEALTHCHECK --interval=30s --timeout=10s --start-period=120s --retries=3 \
CMD curl -f http://localhost:7860/health || exit 1
# Run with Gunicorn
CMD ["gunicorn", "app:app", \
"--bind", "0.0.0.0:7860", \
"--workers", "2", \
"--threads", "1", \
"--timeout", "600", \
"--worker-class", "gevent"]