@@ -2,18 +2,25 @@ FROM --platform=$BUILDPLATFORM ubuntu AS build
22ENV HOME="/root"
33WORKDIR $HOME
44
5- RUN apt update \
5+ RUN \
6+ --mount=type=cache,target=/var/cache/apt,sharing=locked \
7+ --mount=type=cache,target=/var/lib/apt,sharing=locked \
8+ # remove the default docker-specific apt config that auto-deletes /var/apt/cache archives
9+ rm -f /etc/apt/apt.conf.d/docker-clean && \
10+ # and configure apt-get to keep downloaded archives in the cache
11+ echo 'Binary::apt::APT::Keep-Downloaded-Packages "true";' >/etc/apt/apt.conf.d/keep-cache && \
12+ apt update \
613 && apt install -y --no-install-recommends \
714 build-essential \
815 curl \
916 python3-venv \
10- cmake \
11- && apt clean \
12- && rm -rf /var/lib/apt/lists/*
17+ cmake
1318
1419# Setup zig as cross compiling linker
1520RUN python3 -m venv $HOME/.venv
16- RUN .venv/bin/pip install cargo-zigbuild
21+ RUN \
22+ --mount=type=cache,target=/root/.cache/pip \
23+ .venv/bin/pip install cargo-zigbuild
1724ENV PATH="$HOME/.venv/bin:$PATH"
1825
1926# Install rust
@@ -32,14 +39,21 @@ ENV PATH="$HOME/.cargo/bin:$PATH"
3239RUN rustup target add $(cat rust_target.txt)
3340
3441# Build
35- COPY crates crates
36- COPY ./Cargo.toml Cargo.toml
37- COPY ./Cargo.lock Cargo.lock
38- RUN case "${TARGETPLATFORM}" in \
42+ RUN \
43+ # bind mounts to access Cargo config, lock, and sources, without having to
44+ # copy them into the build layer and so bloat the docker build cache
45+ --mount=type=bind,source=crates,target=crates \
46+ --mount=type=bind,source=Cargo.toml,target=Cargo.toml \
47+ --mount=type=bind,source=Cargo.lock,target=Cargo.lock \
48+ # Cache mounts to speed up builds
49+ --mount=type=cache,target=/root/target/ \
50+ --mount=type=cache,target=/usr/local/cargo/git/db \
51+ --mount=type=cache,target=/usr/local/cargo/registry/ \
52+ case "${TARGETPLATFORM}" in \
3953 "linux/arm64" ) export JEMALLOC_SYS_WITH_LG_PAGE=16;; \
4054 esac && \
41- cargo zigbuild --bin uv --bin uvx --target $(cat rust_target.txt) --release
42- RUN cp target/$(cat rust_target.txt)/release/uv /uv \
55+ cargo zigbuild --bin uv --bin uvx --target $(cat rust_target.txt) --release \
56+ && cp target/$(cat rust_target.txt)/release/uv /uv \
4357 && cp target/$(cat rust_target.txt)/release/uvx /uvx
4458# TODO(konsti): Optimize binary size, with a version that also works when cross compiling
4559# RUN strip --strip-all /uv
0 commit comments