@@ -87,24 +87,39 @@ FROM alpine/terragrunt:${TERRAFORM_TERRAGRUNT_VERSION} AS terragrunt
8787# Build wheel for megalinter python package
8888# #################
8989FROM 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
91101WORKDIR /
92102COPY --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
99109COPY . .
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# ###############################
11991214COPY --from=build-ml-core pyproject.toml README.md ./
12001215COPY --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