Boilerplate FastAPI & Dockerfile + NGINX

This commit is contained in:
2025-09-22 17:58:16 +01:00
parent f3fbed5298
commit bf600b8e42
35 changed files with 650 additions and 0 deletions

35
Dockerfile Normal file
View File

@@ -0,0 +1,35 @@
# syntax=docker/dockerfile:1
############################
# Builder (compile wheels) #
############################
FROM python:3.11-slim AS builder
ENV PIP_NO_CACHE_DIR=1
RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential gcc libffi-dev libssl-dev libpq-dev pkg-config cargo \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /wheels
COPY requirements.txt ./
RUN python -m pip install --upgrade pip setuptools wheel
# Build/download wheels for all deps
RUN pip wheel --wheel-dir /wheels -r requirements.txt
#######################
# Runtime (slim) #
#######################
FROM python:3.11-slim AS runtime
RUN apt-get update && apt-get install -y --no-install-recommends libpq5 \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /app
COPY --from=builder /wheels /wheels
COPY requirements.txt ./
# Tell pip to ONLY use wheels from /wheels for the exact versions you built
RUN python -m pip install --no-index --find-links=/wheels -r requirements.txt
COPY . .
EXPOSE 8000
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"]