-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Expand file tree
/
Copy pathDockerfile
More file actions
40 lines (28 loc) · 1.08 KB
/
Copy pathDockerfile
File metadata and controls
40 lines (28 loc) · 1.08 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
FROM ghcr.io/astral-sh/uv:python3.12-bookworm AS base
WORKDIR /app
# Copy configuration files
COPY pyproject.toml uv.lock ./
# UV_COMPILE_BYTECODE for generating .pyc files -> faster application startup.
# UV_LINK_MODE=copy to silence warnings about not being able to use hard links
# since the cache and sync target are on separate file systems.
ENV UV_COMPILE_BYTECODE=1 UV_LINK_MODE=copy
# Install dependencies
RUN --mount=type=cache,target=/root/.cache/uv \
--mount=type=bind,source=uv.lock,target=/app/uv.lock \
--mount=type=bind,source=pyproject.toml,target=/app/pyproject.toml \
uv sync --frozen --no-dev
# Copy source code
COPY src /app/src
FROM python:3.12.8-slim AS final
EXPOSE 8000
# PYTHONUNBUFFERED=1 to disable output buffering
ENV PYTHONUNBUFFERED=1
ARG VERSION=0.1.0
ENV APP_VERSION=$VERSION
WORKDIR /app
# Copy the virtual environment from the base stage
COPY --from=base /app /app
# Add virtual environment to PATH
ENV PATH="/app/.venv/bin:$PATH"
# Run the application
CMD ["uvicorn", "src.main:app", "--host", "0.0.0.0", "--port", "8000", "--workers", "4"]