Skip to content

Commit 8d29a97

Browse files
authored
Prevent uv to download Python and use the one in the image
Extracted from work in PR #2273, but lost in a merge
1 parent 518cc63 commit 8d29a97

File tree

1 file changed

+27
-7
lines changed

1 file changed

+27
-7
lines changed

Dockerfile

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,24 +87,39 @@ FROM alpine/terragrunt:${TERRAFORM_TERRAGRUNT_VERSION} AS terragrunt
8787
# Build wheel for megalinter python package
8888
##################
8989
FROM ghcr.io/astral-sh/uv:0.9.9 AS uv
90-
FROM python:3.13-alpine3.22 AS build-ml-core
90+
# Steps specific to linux/amd64 needed before build-ml-core stage
91+
FROM python:3.13-alpine3.22 AS build-ml-core-linux-amd64--x
92+
# Steps specific to linux/arm64 needed before build-ml-core stage
93+
FROM python:3.13-alpine3.22 AS build-ml-core-linux-arm64--x
94+
# Stage based on platform-specific stage with extra steps
95+
FROM build-ml-core-${TARGETOS}-${TARGETARCH}-${TARGETVARIANT}-x AS build-ml-core
96+
ENV UV_LINK_MODE=copy
97+
# Disable Python downloads, because we want to use the system interpreter
98+
# across images. If using a managed Python version, it needs to be
99+
# copied from the build image into the final image
100+
ENV UV_PYTHON_DOWNLOADS=0
91101
WORKDIR /
92102
COPY --from=uv /uv /uvx /bin/
93103
# Install dependencies
94-
RUN --mount=type=cache,target=/root/.cache/uv \
104+
RUN --mount=type=cache,target=/root/.cache/uv,sharing=locked \
95105
--mount=type=bind,source=uv.lock,target=uv.lock \
96106
--mount=type=bind,source=pyproject.toml,target=pyproject.toml \
97-
uv sync --frozen --no-install-project
107+
uv sync --locked --no-install-project --no-dev
98108
# Copy the project into the image
99109
COPY . .
100110
# Sync the project
101-
RUN --mount=type=cache,target=/root/.cache/uv \
102-
uv sync --frozen
111+
RUN --mount=type=cache,target=/root/.cache/uv,sharing=locked \
112+
uv sync --locked --no-dev
103113

104114
##################
105115
# Get base image #
106116
##################
107-
FROM python:3.13-alpine3.22
117+
FROM python:3.13-alpine3.22 as final
118+
119+
# Disable Python downloads, because we want to use the system interpreter
120+
# across images. If using a managed Python version, it needs to be
121+
# copied from the build image into the final image
122+
ENV UV_PYTHON_DOWNLOADS=0
108123

109124
#############################################################################################
110125
## @generated by .automation/build.py using descriptor files, please do not update manually ##
@@ -1198,7 +1213,12 @@ ENV SWIFT_SWIFTLINT_VERSION=0.62.2
11981213
################################
11991214
COPY --from=build-ml-core pyproject.toml README.md ./
12001215
COPY --from=build-ml-core megalinter /megalinter/
1201-
RUN --mount=type=cache,target=/root/.cache/uv,from=build-ml-core \
1216+
ENV UV_LINK_MODE=copy
1217+
# TODO: technically, our builds should be working without the cache mount being available
1218+
# Since we only install the rust toolchain in the linux/arm64 branch of build-ml-core to
1219+
# build wheels that aren't available for musl linux/arm64, this final stage will fail if
1220+
# the pre-build wheels aren't available anymore in between the two stages.
1221+
RUN --mount=type=cache,target=/root/.cache/uv,sharing=locked \
12021222
--mount=from=uv,source=/uv,target=/bin/uv \
12031223
uv pip install --system -e .
12041224

0 commit comments

Comments
 (0)