-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
37 lines (27 loc) · 1.15 KB
/
Dockerfile
File metadata and controls
37 lines (27 loc) · 1.15 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
FROM python:3.11.9
WORKDIR /src
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
# Enable bytecode compilation
ENV UV_COMPILE_BYTECODE=1
# Copy from the cache instead of linking since it's a mounted volume
ENV UV_LINK_MODE=copy
COPY uv.lock uv.lock
COPY pyproject.toml pyproject.toml
RUN apt-get update \
&& apt-get install --no-install-recommends -y build-essential libpq-dev gcc python3-dev musl-dev
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/
# Install the project's dependencies using the lockfile and settings
RUN --mount=type=cache,target=/root/.cache/uv \
--mount=type=bind,source=uv.lock,target=uv.lock \
--mount=type=bind,source=pyproject.toml,target=pyproject.toml \
uv sync --frozen --no-install-project --no-dev
# Then, add the rest of the project source code and install it
# Installing separately from its dependencies allows optimal layer caching
ADD ./app /src/app
RUN --mount=type=cache,target=/root/.cache/uv \
uv sync --frozen --no-dev
ENV PATH="/src/app/.venv/bin:$PATH"
ENV PYTHONPATH=/src/app
# Run the application.
CMD ["/src/.venv/bin/fastapi", "run", "app/main.py", "--port", "80", "--host", "0.0.0.0"]