85 lines
2.0 KiB
Docker
85 lines
2.0 KiB
Docker
# Website Analyzer Backend - Dockerfile
|
|
# Multi-stage build for efficient image size
|
|
|
|
FROM python:3.11-slim as builder
|
|
|
|
# Set environment variables
|
|
ENV PYTHONDONTWRITEBYTECODE=1 \
|
|
PYTHONUNBUFFERED=1 \
|
|
PIP_NO_CACHE_DIR=1 \
|
|
PIP_DISABLE_PIP_VERSION_CHECK=1
|
|
|
|
WORKDIR /app
|
|
|
|
# Install system dependencies
|
|
RUN apt-get update && apt-get install -y --no-install-recommends \
|
|
build-essential \
|
|
libpq-dev \
|
|
curl \
|
|
&& rm -rf /var/lib/apt/lists/*
|
|
|
|
# Install Python dependencies
|
|
COPY requirements.txt .
|
|
RUN pip install --user -r requirements.txt
|
|
|
|
# Install Playwright and its dependencies
|
|
RUN pip install --user playwright && \
|
|
python -m playwright install chromium && \
|
|
python -m playwright install-deps chromium
|
|
|
|
# ==========================================================================
|
|
# Production Stage
|
|
# ==========================================================================
|
|
FROM python:3.11-slim
|
|
|
|
ENV PYTHONDONTWRITEBYTECODE=1 \
|
|
PYTHONUNBUFFERED=1 \
|
|
PATH="/root/.local/bin:$PATH"
|
|
|
|
WORKDIR /app
|
|
|
|
# Install runtime dependencies
|
|
RUN apt-get update && apt-get install -y --no-install-recommends \
|
|
libpq5 \
|
|
curl \
|
|
# Playwright/Chromium dependencies
|
|
libnss3 \
|
|
libnspr4 \
|
|
libatk1.0-0 \
|
|
libatk-bridge2.0-0 \
|
|
libcups2 \
|
|
libdrm2 \
|
|
libdbus-1-3 \
|
|
libxkbcommon0 \
|
|
libxcomposite1 \
|
|
libxdamage1 \
|
|
libxfixes3 \
|
|
libxrandr2 \
|
|
libgbm1 \
|
|
libasound2 \
|
|
libpango-1.0-0 \
|
|
libcairo2 \
|
|
libatspi2.0-0 \
|
|
&& rm -rf /var/lib/apt/lists/*
|
|
|
|
# Copy Python packages from builder
|
|
COPY --from=builder /root/.local /root/.local
|
|
COPY --from=builder /root/.cache/ms-playwright /root/.cache/ms-playwright
|
|
|
|
# Copy application code
|
|
COPY . .
|
|
|
|
# Create logs directory
|
|
RUN mkdir -p logs staticfiles
|
|
|
|
# Create non-root user for security
|
|
RUN useradd -m -u 1000 appuser && \
|
|
chown -R appuser:appuser /app /root/.local /root/.cache
|
|
USER appuser
|
|
|
|
# Expose port
|
|
EXPOSE 8000
|
|
|
|
# Default command
|
|
CMD ["gunicorn", "core.wsgi:application", "--bind", "0.0.0.0:8000", "--workers", "4"]
|