Skip to content

Commit ea88f43

Browse files
authored
♻️Maintenance: Improve UV usage (#6566)
1 parent e5dca04 commit ea88f43

File tree

60 files changed

+636
-615
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+636
-615
lines changed

.dockerignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ ops/
88
*.py[cod]
99

1010
# virtualenv
11-
.venv
11+
**/.venv
1212

1313
#python eggs
1414
**/*.egg-info

packages/postgres-database/docker/Dockerfile

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# syntax=docker/dockerfile:1
2-
FROM python:3.6-slim AS base
2+
ARG PYTHON_VERSION="3.11.9"
3+
ARG UV_VERSION="0.4"
4+
FROM ghcr.io/astral-sh/uv:${UV_VERSION} AS uv_build
5+
# we docker image is built based on debian
6+
FROM python:${PYTHON_VERSION}-slim-bookworm AS base
37

48
LABEL maintainer=sanderegg
59

@@ -22,16 +26,14 @@ RUN apt-get update \
2226
&& apt-get clean \
2327
&& rm -rf /var/lib/apt/lists/*
2428

25-
# NOTE: install https://github.com/astral-sh/uv ultra-fast rust-based pip replacement
26-
RUN --mount=type=cache,mode=0755,target=/root/.cache/pip \
27-
pip install uv~=0.2
29+
# install UV https://docs.astral.sh/uv/guides/integration/docker/#installing-uv
30+
COPY --from=uv_build /uv /uvx /bin/
2831

2932
# NOTE: python virtualenv is used here such that installed packages may be moved to production image easily by copying the venv
3033
RUN uv venv "${VIRTUAL_ENV}"
3134

32-
RUN --mount=type=cache,mode=0755,target=/root/.cache/uv \
35+
RUN --mount=type=cache,target=/root/.cache/uv \
3336
uv pip install --upgrade \
34-
pip~=24.0 \
3537
wheel \
3638
setuptools
3739

@@ -44,6 +46,8 @@ RUN git clone --single-branch --branch ${GIT_BRANCH} ${GIT_REPOSITORY} osparc-si
4446
FROM base AS production
4547

4648
ENV PYTHONOPTIMIZE=TRUE
49+
# https://docs.astral.sh/uv/guides/integration/docker/#compiling-bytecode
50+
ENV UV_COMPILE_BYTECODE=1
4751

4852
WORKDIR /home/scu
4953
# ensure home folder is read/writable for user scu

packages/postgres-database/scripts/erd/Dockerfile

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# syntax=docker/dockerfile:1
2+
3+
# Define arguments in the global scope
24
ARG PYTHON_VERSION="3.11.9"
5+
ARG UV_VERSION="0.4"
6+
FROM ghcr.io/astral-sh/uv:${UV_VERSION} AS uv_build
7+
# we docker image is built based on debian
38
FROM python:${PYTHON_VERSION}-slim-bookworm AS base
49

510
RUN apt-get update \
@@ -15,15 +20,14 @@ RUN apt-get update \
1520
&& apt-get clean
1621

1722

18-
RUN --mount=type=cache,mode=0755,target=/root/.cache/pip \
19-
pip install --upgrade \
20-
pip~=24.0 \
23+
RUN --mount=type=cache,target=/root/.cache/uv \
24+
uv pip install --upgrade \
2125
wheel \
2226
setuptools
2327

2428

2529
# devenv
2630
COPY requirements.txt requirements.txt
27-
RUN --mount=type=cache,mode=0755,target=/root/.cache/pip \
28-
pip install \
29-
-r requirements.txt
31+
RUN --mount=type=cache,target=/root/.cache/uv \
32+
uv pip sync \
33+
requirements.txt

packages/service-integration/Dockerfile

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# syntax=docker/dockerfile:1
2+
3+
# Define arguments in the global scope
24
ARG PYTHON_VERSION="3.11.9"
5+
ARG UV_VERSION="0.4"
6+
FROM ghcr.io/astral-sh/uv:${UV_VERSION} AS uv_build
7+
# we docker image is built based on debian
38
FROM python:${PYTHON_VERSION}-slim-bookworm AS base
49

510
LABEL maintainer=pcrespov
@@ -38,12 +43,13 @@ ENV LANG=C.UTF-8
3843
# Turns off writing .pyc files; superfluous on an ephemeral container.
3944
ENV PYTHONDONTWRITEBYTECODE=1 \
4045
VIRTUAL_ENV=/home/scu/.venv
46+
# https://docs.astral.sh/uv/guides/integration/docker/#compiling-bytecode
47+
ENV UV_COMPILE_BYTECODE=1
4148

4249
# Ensures that the python and pip executables used
4350
# in the image will be those from our virtualenv.
4451
ENV PATH="${VIRTUAL_ENV}/bin:$PATH"
4552

46-
4753
# -------------------------- Build stage -------------------
4854

4955
FROM base AS build
@@ -55,15 +61,14 @@ RUN --mount=type=cache,target=/var/cache/apt,mode=0755,sharing=private \
5561
&& apt-get install -y --no-install-recommends \
5662
build-essential
5763

58-
# NOTE: install https://github.com/astral-sh/uv ultra-fast rust-based pip replacement
59-
RUN --mount=type=cache,mode=0755,target=/root/.cache/pip \
60-
pip install uv~=0.2
64+
# install UV https://docs.astral.sh/uv/guides/integration/docker/#installing-uv
65+
COPY --from=uv_build /uv /uvx /bin/
6166

6267
# NOTE: python virtualenv is used here such that installed
6368
# packages may be moved to production image easily by copying the venv
6469
RUN uv venv "${VIRTUAL_ENV}"
6570

66-
RUN --mount=type=cache,mode=0755,target=/root/.cache/uv \
71+
RUN --mount=type=cache,target=/root/.cache/uv \
6772
uv pip install --upgrade \
6873
pip~=24.0 \
6974
wheel \
@@ -74,7 +79,7 @@ WORKDIR /build/packages/service-integration
7479
RUN \
7580
--mount=type=bind,source=packages,target=/build/packages,rw \
7681
--mount=type=bind,source=packages/service-integration,target=/build/packages/service-integration,rw \
77-
--mount=type=cache,mode=0755,target=/root/.cache/uv \
82+
--mount=type=cache,target=/root/.cache/uv \
7883
uv pip install \
7984
--requirement requirements/prod.txt \
8085
&& uv pip list
@@ -86,8 +91,6 @@ FROM base AS development
8691
# NOTE: this is necessary to allow to build development images but is the same as production here
8792
FROM base AS production
8893

89-
ENV PYTHONOPTIMIZE=TRUE
90-
9194
WORKDIR /home/scu
9295
# ensure home folder is read/writable for user scu
9396
RUN chown -R scu /home/scu

requirements/tools/Dockerfile

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
#
1010
#
1111
ARG PYTHON_VERSION="3.11.9"
12+
ARG UV_VERSION="0.4"
13+
FROM ghcr.io/astral-sh/uv:${UV_VERSION} AS uv_build
14+
# we docker image is built based on debian
1215
FROM python:${PYTHON_VERSION}-slim-bookworm AS base
1316

1417
ENV VIRTUAL_ENV=/home/scu/.venv
@@ -24,24 +27,21 @@ RUN --mount=type=cache,target=/var/cache/apt,mode=0755,sharing=private \
2427
&& apt-get clean -y
2528

2629

27-
# NOTE: install https://github.com/astral-sh/uv ultra-fast rust-based pip replacement
28-
RUN --mount=type=cache,mode=0755,target=/root/.cache/pip \
29-
pip install uv~=0.2
30+
# install UV https://docs.astral.sh/uv/guides/integration/docker/#installing-uv
31+
COPY --from=uv_build /uv /uvx /bin/
3032

3133
RUN uv venv "${VIRTUAL_ENV}"
3234

33-
RUN --mount=type=cache,mode=0755,target=/root/.cache/uv \
35+
RUN --mount=type=cache,target=/root/.cache/uv \
3436
uv pip install --upgrade \
35-
pip~=24.0 \
3637
wheel \
3738
setuptools
3839

3940

4041

4142
# devenv
42-
RUN --mount=type=cache,mode=0755,target=/root/.cache/uv \
43+
RUN --mount=type=cache,target=/root/.cache/uv \
4344
uv pip install \
44-
pip-tools \
4545
pipreqs \
4646
pipdeptree && \
4747
uv pip list -vv

scripts/erd/Dockerfile

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
#
99

1010
ARG PYTHON_VERSION="3.11.9"
11+
ARG UV_VERSION="0.4"
12+
FROM ghcr.io/astral-sh/uv:${UV_VERSION} AS uv_build
13+
# we docker image is built based on debian
1114
FROM python:${PYTHON_VERSION}-slim-bookworm AS base
1215

1316
RUN apt-get update \
@@ -22,13 +25,14 @@ RUN apt-get update \
2225
&& rm -rf /var/lib/apt/lists/* \
2326
&& apt-get clean
2427

28+
# install UV https://docs.astral.sh/uv/guides/integration/docker/#installing-uv
29+
COPY --from=uv_build /uv /uvx /bin/
2530

26-
RUN --mount=type=cache,mode=0755,target=/root/.cache/pip \
27-
pip install --upgrade \
28-
pip~=24.0 \
31+
RUN --mount=type=cache,target=/root/.cache/uv \
32+
uv pip install --upgrade \
2933
wheel \
3034
setuptools
3135

3236
COPY requirements.txt .
33-
RUN --mount=type=cache,mode=0755,target=/root/.cache/pip \
34-
pip install -r requirements.txt
37+
RUN --mount=type=cache,target=/root/.cache/uv \
38+
uv pip install -r requirements.txt
Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,27 @@
11
# syntax=docker/dockerfile:1
2+
ARG UV_VERSION="0.4"
3+
FROM ghcr.io/astral-sh/uv:${UV_VERSION} AS uv_build
4+
# we docker image is built based on debian
25
FROM python:3.11.9-buster
36

47
RUN curl https://rclone.org/install.sh | bash && \
58
rclone --version
69

10+
# install UV https://docs.astral.sh/uv/guides/integration/docker/#installing-uv
11+
COPY --from=uv_build /uv /uvx /bin/
12+
713
WORKDIR /scripts
814

915
COPY packages/postgres-database postgres-database
10-
RUN --mount=type=cache,mode=0755,target=/root/.cache/pip \
11-
cd postgres-database && pip install .
16+
RUN --mount=type=cache,target=/root/.cache/uv \
17+
cd postgres-database && uv pip install .
1218

1319
COPY packages/settings-library settings-library
14-
RUN --mount=type=cache,mode=0755,target=/root/.cache/pip \
15-
cd settings-library && pip install .
20+
RUN --mount=type=cache,target=/root/.cache/uv \
21+
cd settings-library && uv pip install .
1622

1723
COPY scripts/maintenance/migrate_project/requirements.txt /scripts/requirements.txt
18-
RUN --mount=type=cache,mode=0755,target=/root/.cache/pip \
19-
pip install -r /scripts/requirements.txt
24+
RUN --mount=type=cache,target=/root/.cache/uv \
25+
uv pip install -r /scripts/requirements.txt
2026

2127
COPY scripts/maintenance/migrate_project/src/*.py /scripts/

scripts/openapi/oas_resolver/Dockerfile

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
# Usage:
33
# docker build . -t oas_resolver
44
# docker run -v /path/to/api:/input -v /path/to/compiled/file:/output oas_resolver /input/path/to/openapi.yaml /output/output_file.yaml
5+
ARG UV_VERSION="0.4"
6+
FROM ghcr.io/astral-sh/uv:${UV_VERSION} AS uv_build
7+
# we docker image is built based on debian
58
FROM python:3.6-alpine
69

710
LABEL maintainer=sanderegg
@@ -11,16 +14,16 @@ VOLUME [ "/output" ]
1114

1215
WORKDIR /src
1316

17+
# install UV https://docs.astral.sh/uv/guides/integration/docker/#installing-uv
18+
COPY --from=uv_build /uv /uvx /bin/
19+
1420
# update pip
15-
RUN --mount=type=cache,mode=0755,target=/root/.cache/pip \
16-
pip install --upgrade \
17-
pip~=24.0 \
21+
RUN --mount=type=cache,target=/root/.cache/uv \
22+
uv pip install --upgrade \
1823
wheel \
1924
setuptools
2025

21-
RUN --mount=type=cache,mode=0755,target=/root/.cache/pip \
22-
pip install prance && \
23-
pip install click &&\
24-
pip install openapi_spec_validator
26+
RUN --mount=type=cache,target=/root/.cache/uv \
27+
uv pip install prance click openapi_spec_validator
2528

2629
ENTRYPOINT [ "prance", "compile" , "--backend=openapi-spec-validator"]

scripts/pydeps-docker/Dockerfile

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
#
1010
#
1111
ARG PYTHON_VERSION="3.11.9"
12+
ARG UV_VERSION="0.4"
13+
FROM ghcr.io/astral-sh/uv:${UV_VERSION} AS uv_build
14+
# we docker image is built based on debian
1215
FROM python:${PYTHON_VERSION}-slim-bookworm AS base
1316

1417

@@ -23,18 +26,20 @@ RUN apt-get update \
2326
&& rm -rf /var/lib/apt/lists/* \
2427
&& apt-get clean
2528

29+
# install UV https://docs.astral.sh/uv/guides/integration/docker/#installing-uv
30+
COPY --from=uv_build /uv /uvx /bin/
31+
2632
ARG HOME_DIR
2733
RUN mkdir -p ${HOME_DIR}
2834
COPY .pydeps ${HOME_DIR}/.pydeps
2935

30-
RUN --mount=type=cache,mode=0755,target=/root/.cache/pip \
31-
pip install --upgrade \
32-
pip~=24.0 \
36+
RUN --mount=type=cache,target=/root/.cache/uv \
37+
uv pip install --upgrade \
3338
wheel \
3439
setuptools
3540

3641

3742
# devenv
38-
RUN --mount=type=cache,mode=0755,target=/root/.cache/pip \
39-
pip install \
43+
RUN --mount=type=cache,target=/root/.cache/uv \
44+
uv pip install \
4045
pydeps

services/agent/Dockerfile

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# syntax=docker/dockerfile:1
2+
3+
# Define arguments in the global scope
24
ARG PYTHON_VERSION="3.11.9"
5+
ARG UV_VERSION="0.4"
6+
FROM ghcr.io/astral-sh/uv:${UV_VERSION} AS uv_build
7+
# we docker image is built based on debian
38
FROM python:${PYTHON_VERSION}-slim-bookworm AS base
49

510
#
@@ -73,29 +78,22 @@ RUN --mount=type=cache,target=/var/cache/apt,mode=0755,sharing=private \
7378
&& apt-get install -y --no-install-recommends \
7479
build-essential
7580

76-
# NOTE: install https://github.com/astral-sh/uv ultra-fast rust-based pip replacement
77-
RUN --mount=type=cache,mode=0755,target=/root/.cache/pip \
78-
pip install uv~=0.2
81+
# install UV https://docs.astral.sh/uv/guides/integration/docker/#installing-uv
82+
COPY --from=uv_build /uv /uvx /bin/
7983

8084
# NOTE: python virtualenv is used here such that installed
8185
# packages may be moved to production image easily by copying the venv
8286
RUN uv venv "${VIRTUAL_ENV}"
8387

84-
RUN --mount=type=cache,mode=0755,target=/root/.cache/uv \
88+
RUN --mount=type=cache,target=/root/.cache/uv \
8589
uv pip install --upgrade \
86-
pip~=24.0 \
8790
wheel \
8891
setuptools
8992

9093
WORKDIR /build
9194

9295
# install base 3rd party dependencies
93-
# NOTE: copies to /build to avoid overwriting later which would invalidate this layer
94-
RUN \
95-
--mount=type=bind,source=services/agent/requirements/_base.txt,target=_base.txt \
96-
--mount=type=cache,mode=0755,target=/root/.cache/uv \
97-
uv pip install \
98-
--requirement _base.txt
96+
9997

10098

10199
# --------------------------Prod-depends-only stage -------------------
@@ -113,9 +111,9 @@ WORKDIR /build/services/agent
113111
RUN \
114112
--mount=type=bind,source=packages,target=/build/packages,rw \
115113
--mount=type=bind,source=services/agent,target=/build/services/agent,rw \
116-
--mount=type=cache,mode=0755,target=/root/.cache/uv \
117-
uv pip install \
118-
--requirement requirements/prod.txt \
114+
--mount=type=cache,target=/root/.cache/uv \
115+
uv pip sync \
116+
requirements/prod.txt \
119117
&& uv pip list
120118

121119

@@ -132,6 +130,8 @@ ENV SC_BUILD_TARGET=production \
132130
SC_BOOT_MODE=production
133131

134132
ENV PYTHONOPTIMIZE=TRUE
133+
# https://docs.astral.sh/uv/guides/integration/docker/#compiling-bytecode
134+
ENV UV_COMPILE_BYTECODE=1
135135

136136
WORKDIR /home/scu
137137

0 commit comments

Comments
 (0)