Skip to content

Commit

Permalink
Migrate to uv from poetry
Browse files Browse the repository at this point in the history
  • Loading branch information
ulgens committed Jan 19, 2025
1 parent 26c7528 commit 014c079
Show file tree
Hide file tree
Showing 4 changed files with 1,314 additions and 2,023 deletions.
40 changes: 23 additions & 17 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Adapted from https://github.com/astral-sh/uv-docker-example/blob/main/Dockerfile

FROM python:3.13.1-slim-bookworm

RUN --mount=type=cache,target=/var/cache/apt --mount=type=cache,target=/var/lib/apt \
Expand All @@ -14,24 +16,28 @@ RUN --mount=type=cache,target=/var/cache/apt --mount=type=cache,target=/var/lib/
ENV PYTHONFAULTHANDLER=1 \
PYTHONUNBUFFERED=1 \
PYTHONHASHSEED=random \
PYTHONDONTWRITEBYTECODE=True \
PIP_DISABLE_PIP_VERSION_CHECK=on \
PIP_DEFAULT_TIMEOUT=100

# Poetry settings
ENV POETRY_VERSION="2.0.1" \
# # When true, `poetry run` is required to run the commands relating to the venv
POETRY_VIRTUALENVS_CREATE=0 \
POETRY_NO_INTERACTION=1 \
POETRY_NO_ANSI=1
PYTHONDONTWRITEBYTECODE=True

RUN --mount=type=cache,target=/root/.cache/pip \
pip install "poetry==$POETRY_VERSION"
# uv settings
# https://github.com/astral-sh/uv-docker-example/blob/main/pyproject.toml
# https://hynek.me/articles/docker-uv/

RUN mkdir /code
WORKDIR /code
# Enable bytecode compilation
ENV UV_COMPILE_BYTECODE=1
# Silence uv complaining about not being able to use hard links.
ENV UV_LINK_MODE=copy
# https://github.com/astral-sh/uv/pull/6834#issuecomment-2319253359
ENV UV_PROJECT_ENVIRONMENT="/usr/local/"
ENV UV_PYTHON_PREFERENCE=system

COPY poetry.lock pyproject.toml /code/
# https://docs.astral.sh/uv/guides/integration/docker/#installing-uv
# uv version can not be defined in an environment variable,
# because COPY --from doesn't support variable expansion
# https://github.com/moby/moby/issues/34482
COPY --from=ghcr.io/astral-sh/uv:0.5.21 /uv /uvx /bin/

# TODO: Share the venv folder with the host.
RUN poetry install
# https://github.com/astral-sh/uv-docker-example/blob/a14ebc89e3a5e5b33131284968d8969ae054ed0d/Dockerfile#L13
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
Loading

0 comments on commit 014c079

Please sign in to comment.