42 lines
938 B
Docker
42 lines
938 B
Docker
FROM python:3.11-slim
|
|
|
|
# Set environment variables
|
|
ENV PYTHONUNBUFFERED=1 \
|
|
PYTHONDONTWRITEBYTECODE=1 \
|
|
PIP_NO_CACHE_DIR=1 \
|
|
PIP_DISABLE_PIP_VERSION_CHECK=1
|
|
|
|
# Set work directory
|
|
WORKDIR /app
|
|
|
|
# Install system dependencies
|
|
RUN apt-get update && apt-get install -y \
|
|
gcc \
|
|
g++ \
|
|
&& rm -rf /var/lib/apt/lists/*
|
|
|
|
# Install UV for faster Python package management
|
|
RUN pip install uv
|
|
|
|
# Copy pyproject.toml and uv.lock
|
|
COPY pyproject.toml uv.lock ./
|
|
|
|
# Install Python dependencies
|
|
RUN uv sync --frozen --no-dev
|
|
|
|
# Copy application code
|
|
COPY . .
|
|
|
|
# Create non-root user
|
|
RUN useradd --create-home --shell /bin/bash app
|
|
USER app
|
|
|
|
# Expose port
|
|
EXPOSE 8000
|
|
|
|
# Health check
|
|
HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 \
|
|
CMD curl -f http://localhost:8000/api/health || exit 1
|
|
|
|
# Run the application
|
|
CMD ["uv", "run", "python", "-m", "uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"] |