-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
63 lines (50 loc) · 2.48 KB
/
Dockerfile
File metadata and controls
63 lines (50 loc) · 2.48 KB
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
56
57
58
59
60
61
62
63
# ─────────────────────────────────────────────────────────────────────────────
# Stage 1: Builder
# Installs dependencies and packages the application.
# ─────────────────────────────────────────────────────────────────────────────
FROM python:3.11-slim AS builder
WORKDIR /app
# System dependencies for psycopg2, asyncpg, etc.
RUN apt-get update && apt-get install -y --no-install-recommends \
gcc \
libpq-dev \
&& rm -rf /var/lib/apt/lists/*
# Install pip dependencies into a dedicated prefix so we can copy them cleanly
COPY pyproject.toml ./
RUN pip install --upgrade pip && \
pip install --no-cache-dir ".[dev]" --target /install
# ─────────────────────────────────────────────────────────────────────────────
# Stage 2: Runtime
# ─────────────────────────────────────────────────────────────────────────────
FROM python:3.11-slim AS runtime
ENV PYTHONUNBUFFERED=1 \
PYTHONDONTWRITEBYTECODE=1 \
PYTHONPATH=/app/src
WORKDIR /app
# Runtime system dependencies only
RUN apt-get update && apt-get install -y --no-install-recommends \
libpq5 \
curl \
&& rm -rf /var/lib/apt/lists/*
# Copy installed packages from builder
COPY --from=builder /install /usr/local/lib/python3.11/site-packages
# Copy application source
COPY src/ ./src/
COPY alembic.ini ./
# Create non-root user
RUN useradd -m -u 1001 appuser && chown -R appuser:appuser /app
USER appuser
# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \
CMD curl -f http://localhost:${APP_PORT:-8000}/api/v1/health || exit 1
EXPOSE 8000
# Run with gunicorn + uvicorn workers (async)
CMD ["gunicorn", "app.main:app", \
"--worker-class", "uvicorn.workers.UvicornWorker", \
"--workers", "4", \
"--bind", "0.0.0.0:8000", \
"--timeout", "120", \
"--keep-alive", "5", \
"--log-level", "info", \
"--access-logfile", "-", \
"--error-logfile", "-"]