-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
41 lines (29 loc) · 1.12 KB
/
Dockerfile
File metadata and controls
41 lines (29 loc) · 1.12 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
# syntax=docker/dockerfile:1.4
# ---- Build stage ----
FROM python:3.10-slim AS builder
WORKDIR /app
# System deps for building wheels, psycopg2, etc.
RUN apt-get update && apt-get install -y --no-install-recommends build-essential gcc libpq-dev && rm -rf /var/lib/apt/lists/*
COPY requirements.txt ./
COPY requirements-dev.txt ./
RUN pip install --upgrade pip && pip install -r requirements.txt
# ---- Production image ----
FROM python:3.10-slim
ENV PYTHONUNBUFFERED=1
WORKDIR /app
# System deps for runtime
RUN apt-get update && apt-get install -y --no-install-recommends libpq-dev && rm -rf /var/lib/apt/lists/*
# Copy installed packages from builder
COPY --from=builder /usr/local/lib/python3.10/site-packages /usr/local/lib/python3.10/site-packages
COPY --from=builder /usr/local/bin /usr/local/bin
# Copy app source
COPY . .
# Use non-root user for security
RUN useradd -m appuser && chown -R appuser /app
USER appuser
# Expose FastAPI default port
EXPOSE 8000
# Healthcheck endpoint
HEALTHCHECK CMD curl --fail http://localhost:8000/ || exit 1
# Start with Uvicorn
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]