feat: add Docker support with multi-stage build and compose profiles
Multi-stage Dockerfile (base/dev/prod) using uv for fast installs. Dev stage supports hot-reload via bind-mounted source; prod stage builds an optimised image with 4 uvicorn workers. docker-compose.yml provides 'dev' and 'prod' profiles with named volumes for data.
This commit is contained in:
parent
c381896de4
commit
020e6c6fa0
3 changed files with 98 additions and 0 deletions
47
Dockerfile
Normal file
47
Dockerfile
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
# ---- Base stage: shared dependencies ----
|
||||
FROM python:3.13-slim AS base
|
||||
|
||||
ENV PYTHONDONTWRITEBYTECODE=1 \
|
||||
PYTHONUNBUFFERED=1 \
|
||||
UV_COMPILE_BYTECODE=1 \
|
||||
UV_LINK_MODE=copy
|
||||
|
||||
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# Install production dependencies (cached unless lock changes)
|
||||
COPY pyproject.toml uv.lock ./
|
||||
RUN uv sync --frozen --no-install-project --no-dev
|
||||
|
||||
# ---- Dev stage: hot-reload for local development ----
|
||||
FROM base AS dev
|
||||
|
||||
# Also install dev dependencies
|
||||
RUN uv sync --frozen --no-install-project
|
||||
|
||||
# Source is bind-mounted at runtime via docker-compose
|
||||
ENV OIDC_OP_ISSUER=http://localhost:8000 \
|
||||
OIDC_OP_DEBUG=true
|
||||
|
||||
EXPOSE 8000
|
||||
|
||||
CMD ["uv", "run", "uvicorn", "fastapi_oidc_op.app:create_app", \
|
||||
"--factory", "--host", "0.0.0.0", "--port", "8000", \
|
||||
"--reload", "--reload-dir", "/app/src"]
|
||||
|
||||
# ---- Prod stage: optimised image ----
|
||||
FROM base AS prod
|
||||
|
||||
# Copy source + README (needed by hatchling) and install the project itself
|
||||
COPY README.md ./
|
||||
COPY src/ src/
|
||||
RUN uv sync --frozen --no-dev
|
||||
|
||||
ENV OIDC_OP_ISSUER=http://localhost:8000
|
||||
|
||||
EXPOSE 8000
|
||||
|
||||
CMD ["uv", "run", "uvicorn", "fastapi_oidc_op.app:create_app", \
|
||||
"--factory", "--host", "0.0.0.0", "--port", "8000", \
|
||||
"--workers", "4"]
|
||||
Loading…
Add table
Add a link
Reference in a new issue