Skip to content

Commit ec3cdcf

Browse files
committed
Cache Apt package downloads with BuildKit cache mounts
1 parent 16b50df commit ec3cdcf

File tree

3 files changed

+23
-4
lines changed

3 files changed

+23
-4
lines changed

CHANGES.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
unreleased
2+
----------
3+
4+
- Cache packages downloads for Apt-based distributions using BuildKit
5+
cache mounts. (@MisterDA, #???)
6+
17
v8.2.3 2024-10-30 Rochester
28
---------------------------
39

src-opam/linux.ml

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,27 @@ end
7676

7777
(** Debian rules *)
7878
module Apt = struct
79+
(* https://docs.docker.com/reference/dockerfile/#example-cache-apt-packages *)
80+
let mounts =
81+
[
82+
mount_cache ~target:"/var/cache/apt" ~sharing:`Locked ();
83+
mount_cache ~target:"/var/lib/apt" ~sharing:`Locked ();
84+
]
85+
7986
let update =
80-
run "apt-get -y update"
81-
@@ run "DEBIAN_FRONTEND=noninteractive apt-get -y upgrade"
87+
run
88+
{|rm -f /etc/apt/apt.conf.d/docker-clean; echo 'Binary::apt::APT::Keep-Downloaded-Packages "true";' > /etc/apt/apt.conf.d/keep-cache|}
89+
@@ run ~mounts
90+
"apt update && DEBIAN_FRONTEND=noninteractive apt-get -y upgrade"
8291

8392
let install fmt =
8493
ksprintf
8594
(fun s ->
86-
update @@ run "DEBIAN_FRONTEND=noninteractive apt-get -y install %s" s)
95+
update
96+
@@ run ~mounts
97+
"DEBIAN_FRONTEND=noninteractive apt-get --no-install-recommends \
98+
install -y %s"
99+
s)
87100
fmt
88101

89102
let dev_packages ?extra () =

src-opam/linux.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ end
5959
(** Rules for Apt-based distributions *)
6060
module Apt : sig
6161
val update : t
62-
(** [update] will run [apt-get update && apt-get upgrade] non-interactively. *)
62+
(** [update] will run [apt-get update && apt-get upgrade] non-interactively. Requires [syntax=docker/dockerfile:1]. *)
6363

6464
val install : ('a, unit, string, t) format4 -> 'a
6565
(** [install fmt] will [apt-get update && apt-get install] the packages specified by the [fmt] format string. *)

0 commit comments

Comments
 (0)