Skip to content

Commit

Permalink
Cache Apt package downloads with BuildKit cache mounts
Browse files Browse the repository at this point in the history
  • Loading branch information
MisterDA committed Nov 6, 2024
1 parent 16b50df commit ec3cdcf
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
6 changes: 6 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
unreleased
----------

- Cache packages downloads for Apt-based distributions using BuildKit
cache mounts. (@MisterDA, #???)

v8.2.3 2024-10-30 Rochester
---------------------------

Expand Down
19 changes: 16 additions & 3 deletions src-opam/linux.ml
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,27 @@ end

(** Debian rules *)
module Apt = struct
(* https://docs.docker.com/reference/dockerfile/#example-cache-apt-packages *)
let mounts =
[
mount_cache ~target:"/var/cache/apt" ~sharing:`Locked ();
mount_cache ~target:"/var/lib/apt" ~sharing:`Locked ();
]

let update =
run "apt-get -y update"
@@ run "DEBIAN_FRONTEND=noninteractive apt-get -y upgrade"
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|}
@@ run ~mounts
"apt update && DEBIAN_FRONTEND=noninteractive apt-get -y upgrade"

let install fmt =
ksprintf
(fun s ->
update @@ run "DEBIAN_FRONTEND=noninteractive apt-get -y install %s" s)
update
@@ run ~mounts
"DEBIAN_FRONTEND=noninteractive apt-get --no-install-recommends \
install -y %s"
s)
fmt

let dev_packages ?extra () =
Expand Down
2 changes: 1 addition & 1 deletion src-opam/linux.mli
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ end
(** Rules for Apt-based distributions *)
module Apt : sig
val update : t
(** [update] will run [apt-get update && apt-get upgrade] non-interactively. *)
(** [update] will run [apt-get update && apt-get upgrade] non-interactively. Requires [syntax=docker/dockerfile:1]. *)

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

0 comments on commit ec3cdcf

Please sign in to comment.