File size: 1,464 Bytes
6e6e8a8 a172bd0 58837e7 6e6e8a8 a172bd0 6e6e8a8 9af05cb 6e6e8a8 58837e7 6e6e8a8 9af05cb 6e6e8a8 58837e7 6e6e8a8 8f236a7 6e6e8a8 a172bd0 6e6e8a8 58837e7 6e6e8a8 9af05cb 6e6e8a8 84f5589 6e6e8a8 58837e7 6e6e8a8 a172bd0 58837e7 6e6e8a8 276ae2a a172bd0 6e6e8a8 84f5589 6e6e8a8 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# Use Python 3.9 slim-buster for stability and smaller footprint
FROM python:3.9-slim-buster AS builder
# Install system dependencies
RUN apt-get update && \
apt-get install -y --no-install-recommends \
gcc \
python3-dev \
libssl-dev \
curl \
&& rm -rf /var/lib/apt/lists/*
# Create and activate virtual environment
RUN python -m venv /opt/venv
ENV PATH="/opt/venv/bin:$PATH"
# Install Python dependencies
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
# ========== Runtime Stage ========== #
FROM python:3.9-slim-buster
# Install runtime dependencies
RUN apt-get update && \
apt-get install -y --no-install-recommends \
libssl1.1 \
curl \
&& rm -rf /var/lib/apt/lists/*
# Copy virtual environment from builder
COPY --from=builder /opt/venv /opt/venv
ENV PATH="/opt/venv/bin:$PATH"
# Create non-root user
RUN useradd -m -u 1001 krishna
USER krishna
WORKDIR /home/krishna/app
# Copy application code (with proper ownership)
COPY --chown=krishna:krishna . .
# Environment variables
ENV PORT=7860 \
PYTHONUNBUFFERED=1 \
PYTHONPATH=/home/krishna/app \
GUNICORN_CMD_ARGS="--bind=0.0.0.0:7860 --workers=1 --threads=2 --timeout=120 --worker-class=gthread --log-level=info"
# Expose port and health check
EXPOSE 7860
HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \
CMD curl -f http://localhost:7860/ || exit 1
# Run Gunicorn
CMD ["gunicorn", "app:app"] |