53 lines
1.2 KiB
Docker
53 lines
1.2 KiB
Docker
# Multi-stage build for Python backend
|
|
# Stage 1: Base with system dependencies and Python packages
|
|
|
|
FROM python:3.11-slim as base
|
|
|
|
# Set working directory
|
|
WORKDIR /app
|
|
|
|
# Install system dependencies
|
|
RUN apt-get update && apt-get install -y \
|
|
gcc \
|
|
postgresql-client \
|
|
&& rm -rf /var/lib/apt/lists/*
|
|
|
|
# Copy requirements files
|
|
COPY requirements.txt .
|
|
|
|
# Install Python dependencies
|
|
RUN pip install --no-cache-dir --upgrade pip && \
|
|
pip install --no-cache-dir -r requirements.txt
|
|
|
|
# Stage 2: Development environment
|
|
FROM base as development
|
|
|
|
# Install development dependencies
|
|
COPY requirements-dev.txt .
|
|
RUN pip install --no-cache-dir -r requirements-dev.txt
|
|
|
|
# Copy application code
|
|
COPY . .
|
|
|
|
# Expose port
|
|
EXPOSE 8048
|
|
|
|
# Development command (with hot reload)
|
|
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8048", "--reload"]
|
|
|
|
# Stage 3: Production environment
|
|
FROM base as production
|
|
|
|
# Copy application code only (no dev dependencies)
|
|
COPY . .
|
|
|
|
# Create non-root user for security
|
|
RUN useradd -m -u 1000 appuser && \
|
|
chown -R appuser:appuser /app
|
|
USER appuser
|
|
|
|
# Expose port
|
|
EXPOSE 8048
|
|
|
|
# Production command with multiple workers
|
|
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8048", "--workers", "4"]
|