-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #74 from openradx/poetry-to-uv
Switch from poetry to uv
- Loading branch information
Showing
18 changed files
with
2,320 additions
and
3,544 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
3.13 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,92 +1,57 @@ | ||
FROM python:3.12-bullseye AS python-base | ||
# Ideas from https://docs.astral.sh/uv/guides/integration/docker/ | ||
|
||
# python | ||
# ENV variables are also available in the later build stages | ||
ENV PYTHONUNBUFFERED=1 \ | ||
# prevents python creating .pyc files | ||
PYTHONDONTWRITEBYTECODE=1 \ | ||
\ | ||
# pip | ||
PIP_NO_CACHE_DIR=off \ | ||
PIP_DISABLE_PIP_VERSION_CHECK=on \ | ||
PIP_DEFAULT_TIMEOUT=100 \ | ||
\ | ||
# poetry | ||
# https://python-poetry.org/docs/#installing-with-the-official-installer | ||
# https://python-poetry.org/docs/configuration/#using-environment-variables | ||
POETRY_VERSION=2.0.1 \ | ||
# make poetry install to this location | ||
POETRY_HOME="/opt/poetry" \ | ||
# make poetry create the virtual environment in the project's root | ||
# it gets named `.venv` | ||
POETRY_VIRTUALENVS_IN_PROJECT=true \ | ||
# do not ask any interactive question | ||
POETRY_NO_INTERACTION=1 \ | ||
\ | ||
# paths | ||
# this is where our requirements + virtual environment will live | ||
PYSETUP_PATH="/opt/pysetup" \ | ||
VENV_PATH="/opt/pysetup/.venv" \ | ||
# needed for adit-radis-shared to be found | ||
PYTHONPATH="/app" | ||
|
||
# prepend poetry and venv to path | ||
ENV PATH="$POETRY_HOME/bin:$VENV_PATH/bin:$PATH" | ||
|
||
# deps for db management commands | ||
# make sure to match the postgres version to the service in the compose file | ||
FROM python:3.12-bullseye AS builder-base | ||
|
||
# Install dependencies for the `psql` command. | ||
# Must match the version of the postgres service in the compose file! | ||
RUN apt-get update \ | ||
&& apt-get install --no-install-recommends -y postgresql-common \ | ||
&& /usr/share/postgresql-common/pgdg/apt.postgresql.org.sh -y \ | ||
&& apt-get install --no-install-recommends -y \ | ||
postgresql-client-17 \ | ||
&& rm -rf /var/lib/apt/lists/* | ||
|
||
ENV PYTHONUNBUFFERED=1 \ | ||
PYTHONDONTWRITEBYTECODE=1 | ||
|
||
# `builder-base` stage is used to build deps + create our virtual environment | ||
FROM python-base AS builder-base | ||
COPY --from=ghcr.io/astral-sh/uv:0.6.0 /uv /uvx /bin/ | ||
|
||
RUN apt-get update \ | ||
&& apt-get install --no-install-recommends -y \ | ||
# deps for installing poetry | ||
curl \ | ||
# deps for building python deps | ||
build-essential \ | ||
&& rm -rf /var/lib/apt/lists/* | ||
ENV UV_COMPILE_BYTECODE=1 \ | ||
UV_LINK_MODE=copy | ||
|
||
# install poetry - respects $POETRY_VERSION & $POETRY_HOME | ||
RUN curl -sSL https://install.python-poetry.org | python3 - | ||
# There is no git during image build so we need to provide a fake version | ||
ENV UV_DYNAMIC_VERSIONING_BYPASS=0.0.0 | ||
|
||
# copy project requirement files here to ensure they will be cached. | ||
WORKDIR $PYSETUP_PATH | ||
COPY poetry.lock pyproject.toml README.md ./ | ||
ENV PATH="/app/.venv/bin:$PATH" | ||
|
||
# install runtime deps - uses $POETRY_VIRTUALENVS_IN_PROJECT internally | ||
RUN poetry install --without dev --no-root | ||
WORKDIR /app | ||
|
||
|
||
# `development` image is used during development / testing | ||
FROM python-base AS development | ||
# development image | ||
FROM builder-base AS development | ||
|
||
WORKDIR $PYSETUP_PATH | ||
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 | ||
|
||
# copy in our built poetry + venv | ||
COPY --from=builder-base $POETRY_HOME $POETRY_HOME | ||
COPY --from=builder-base $PYSETUP_PATH $PYSETUP_PATH | ||
RUN playwright install --with-deps chromium | ||
|
||
# quicker install as runtime deps are already installed | ||
RUN poetry install --no-root | ||
ADD . /app | ||
|
||
# Install requirements for end-to-end testing | ||
RUN playwright install --with-deps chromium | ||
RUN --mount=type=cache,target=/root/.cache/uv \ | ||
uv sync --frozen | ||
|
||
# will become mountpoint of our code | ||
WORKDIR /app | ||
|
||
# production image | ||
FROM builder-base AS production | ||
|
||
# `production` image used for runtime | ||
FROM python-base AS production | ||
COPY --from=builder-base $PYSETUP_PATH $PYSETUP_PATH | ||
COPY . /app/ | ||
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 | ||
|
||
WORKDIR /app | ||
ADD . /app | ||
|
||
RUN --mount=type=cache,target=/root/.cache/uv \ | ||
uv sync --frozen --no-dev |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.