Skip to content

Commit 7eee437

Browse files
committed
CI: Fix OCI image builds with cache mounts
Apt needs exclusive access to its data, so the caches use the option `sharing=locked`, which will make sure multiple parallel builds using the same cache mount will wait for each other and not access the same cache files at the same time. You could also use `sharing=private` if you prefer to have each build create another cache directory in this case. -- moby/buildkit@a577b86201
1 parent bdb468f commit 7eee437

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

Dockerfile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ FROM python:3.11-slim-bullseye
1313

1414
# Install build prerequisites.
1515
RUN rm -f /etc/apt/apt.conf.d/docker-clean; echo 'Binary::apt::APT::Keep-Downloaded-Packages "true";' > /etc/apt/apt.conf.d/keep-cache
16-
RUN --mount=type=cache,id=apt-cache,target=/var/cache/apt --mount=type=cache,id=apt-lib,target=/var/lib/apt \
16+
RUN \
17+
--mount=type=cache,id=apt,sharing=locked,target=/var/cache/apt \
18+
--mount=type=cache,id=apt,sharing=locked,target=/var/lib/apt \
1719
true \
1820
&& apt-get update \
1921
&& apt-get install --no-install-recommends --no-install-suggests --yes git build-essential librrd-dev

Dockerfile.full

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ FROM python:3.11-slim-bullseye
1313

1414
# Install build prerequisites.
1515
RUN rm -f /etc/apt/apt.conf.d/docker-clean; echo 'Binary::apt::APT::Keep-Downloaded-Packages "true";' > /etc/apt/apt.conf.d/keep-cache
16-
RUN --mount=type=cache,id=apt-cache,target=/var/cache/apt --mount=type=cache,id=apt-lib,target=/var/lib/apt \
16+
RUN \
17+
--mount=type=cache,id=apt,sharing=locked,target=/var/cache/apt \
18+
--mount=type=cache,id=apt,sharing=locked,target=/var/lib/apt \
1719
true \
1820
&& apt-get update \
1921
&& apt-get install --no-install-recommends --no-install-suggests --yes git build-essential librrd-dev

0 commit comments

Comments
 (0)