Skip to content

Commit 7a1b2a2

Browse files
authored
Merge pull request #76 from kit-ty-kate/opam-dev
Add opam master (opam-dev + opam-2.2) to the base images
2 parents eeb43a6 + 6cd0ebb commit 7a1b2a2

File tree

2 files changed

+99
-47
lines changed

2 files changed

+99
-47
lines changed

src-opam/dockerfile_opam.ml

Lines changed: 89 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -109,41 +109,95 @@ let header ?win10_revision ?arch ?maintainer ?img ?tag d =
109109
@@ maintainer
110110
@@ shell
111111

112+
type opam_hashes = {
113+
opam_2_0_hash : string;
114+
opam_2_1_hash : string;
115+
opam_master_hash : string;
116+
}
117+
118+
type opam_branch = {
119+
branch : string;
120+
hash : string;
121+
enable_0install_solver : bool;
122+
public_name : string;
123+
aliases : string list;
124+
}
125+
126+
let create_opam_branches opam_hashes =
127+
let {
128+
opam_2_0_hash;
129+
opam_2_1_hash;
130+
opam_master_hash;
131+
} = opam_hashes in
132+
[
133+
{
134+
branch = "2.0";
135+
hash = opam_2_0_hash;
136+
enable_0install_solver = false;
137+
public_name = "opam-2.0";
138+
aliases = ["opam"]; (* Default *)
139+
};
140+
{
141+
branch = "2.1";
142+
hash = opam_2_1_hash;
143+
enable_0install_solver = true;
144+
public_name = "opam-2.1";
145+
aliases = [];
146+
};
147+
{
148+
branch = "master";
149+
hash = opam_master_hash;
150+
enable_0install_solver = true;
151+
public_name = "opam-dev";
152+
aliases = ["opam-2.2"]; (* TODO: Remove/update when opam 2.2 is branched *)
153+
};
154+
]
155+
156+
let install_opams ?prefix f opam_branches =
157+
List.fold_left (fun acc {branch; hash; enable_0install_solver; _} ->
158+
let add_default_link = Some false in
159+
let enable_0install_solver = Some enable_0install_solver in
160+
acc @@ f ?add_default_link ?prefix ?enable_0install_solver ~branch ~hash ()
161+
) empty opam_branches
162+
163+
let copy_opams ~src ~dst opam_branches =
164+
List.fold_left (fun acc {branch; public_name; aliases; _} ->
165+
acc @@
166+
copy ~from:"0" ~src:[src^"/opam-"^branch] ~dst:(dst^"/"^public_name) () @@@
167+
List.map (fun alias -> run "ln %s/%s %s/%s" dst public_name dst alias) aliases
168+
) empty opam_branches
169+
112170
(* Apk based Dockerfile *)
113-
let apk_opam2 ?(labels=[]) ?arch ~hash_opam_2_0 ~hash_opam_2_1 distro () =
171+
let apk_opam2 ?(labels=[]) ?arch ~opam_hashes distro () =
172+
let opam_branches = create_opam_branches opam_hashes in
114173
let img, tag = D.base_distro_tag ?arch distro in
115174
header ?arch distro @@ label (("distro_style", "apk") :: labels)
116175
@@ Linux.Apk.install "build-base bzip2 git tar curl ca-certificates openssl"
117176
@@ Linux.Git.init ()
118-
@@ install_opam_from_source ~add_default_link:false ~branch:"2.0" ~hash:hash_opam_2_0 ()
119-
@@ install_opam_from_source ~add_default_link:false ~enable_0install_solver:true ~branch:"2.1" ~hash:hash_opam_2_1 ()
177+
@@ install_opams install_opam_from_source opam_branches
120178
@@ run "strip /usr/local/bin/opam*"
121179
@@ from ~tag img
122180
@@ Linux.Apk.add_repository ~tag:"edge" "https://dl-cdn.alpinelinux.org/alpine/edge/main"
123181
@@ Linux.Apk.add_repository ~tag:"edgecommunity" "https://dl-cdn.alpinelinux.org/alpine/edge/community"
124182
@@ Linux.Apk.add_repository ~tag:"testing" "https://dl-cdn.alpinelinux.org/alpine/edge/testing"
125-
@@ copy ~from:"0" ~src:["/usr/local/bin/opam-2.0"] ~dst:"/usr/bin/opam-2.0" ()
126-
@@ copy ~from:"0" ~src:["/usr/local/bin/opam-2.1"] ~dst:"/usr/bin/opam-2.1" ()
127-
@@ run "ln /usr/bin/opam-2.0 /usr/bin/opam"
183+
@@ copy_opams ~src:"/usr/local/bin" ~dst:"/usr/bin" opam_branches
128184
@@ Linux.Apk.dev_packages ()
129185
@@ Linux.Apk.add_user ~uid:1000 ~gid:1000 ~sudo:true "opam"
130186
@@ install_bubblewrap_wrappers @@ Linux.Git.init ()
131187

132188

133189
(* Debian based Dockerfile *)
134-
let apt_opam2 ?(labels=[]) ?arch distro ~hash_opam_2_0 ~hash_opam_2_1 () =
190+
let apt_opam2 ?(labels=[]) ?arch distro ~opam_hashes () =
191+
let opam_branches = create_opam_branches opam_hashes in
135192
let img, tag = D.base_distro_tag ?arch distro in
136193
header ?arch distro @@ label (("distro_style", "apt") :: labels)
137194
@@ Linux.Apt.install "build-essential curl git libcap-dev sudo"
138195
@@ Linux.Git.init ()
139196
@@ install_bubblewrap_from_source ()
140-
@@ install_opam_from_source ~add_default_link:false ~branch:"2.0" ~hash:hash_opam_2_0 ()
141-
@@ install_opam_from_source ~add_default_link:false ~enable_0install_solver:true ~branch:"2.1" ~hash:hash_opam_2_1 ()
197+
@@ install_opams install_opam_from_source opam_branches
142198
@@ from ~tag img
143199
@@ copy ~from:"0" ~src:["/usr/local/bin/bwrap"] ~dst:"/usr/bin/bwrap" ()
144-
@@ copy ~from:"0" ~src:["/usr/local/bin/opam-2.0"] ~dst:"/usr/bin/opam-2.0" ()
145-
@@ copy ~from:"0" ~src:["/usr/local/bin/opam-2.1"] ~dst:"/usr/bin/opam-2.1" ()
146-
@@ run "ln /usr/bin/opam-2.0 /usr/bin/opam"
200+
@@ copy_opams ~src:"/usr/local/bin" ~dst:"/usr/bin" opam_branches
147201
@@ run "ln -fs /usr/share/zoneinfo/Europe/London /etc/localtime"
148202
@@ Linux.Apt.dev_packages ()
149203
@@ run "echo 'debconf debconf/frontend select Noninteractive' | debconf-set-selections"
@@ -158,7 +212,8 @@ let apt_opam2 ?(labels=[]) ?arch distro ~hash_opam_2_0 ~hash_opam_2_1 () =
158212
159213
[enable_powertools] enables the PowerTools repository on CentOS 8 and above.
160214
This is needed to get most of *-devel packages frequently used by opam packages. *)
161-
let yum_opam2 ?(labels= []) ?arch ~yum_workaround ~enable_powertools ~hash_opam_2_0 ~hash_opam_2_1 distro () =
215+
let yum_opam2 ?(labels= []) ?arch ~yum_workaround ~enable_powertools ~opam_hashes distro () =
216+
let opam_branches = create_opam_branches opam_hashes in
162217
let img, tag = D.base_distro_tag ?arch distro in
163218
let workaround =
164219
if yum_workaround then
@@ -173,74 +228,65 @@ let yum_opam2 ?(labels= []) ?arch ~yum_workaround ~enable_powertools ~hash_opam_
173228
@@ Linux.RPM.dev_packages ~extra:"which tar curl xz libcap-devel openssl" ()
174229
@@ Linux.Git.init ()
175230
@@ install_bubblewrap_from_source ()
176-
@@ install_opam_from_source ~prefix:"/usr" ~add_default_link:false ~branch:"2.0" ~hash:hash_opam_2_0 ()
177-
@@ install_opam_from_source ~prefix:"/usr" ~add_default_link:false ~enable_0install_solver:true ~branch:"2.1" ~hash:hash_opam_2_1 ()
231+
@@ install_opams ~prefix:"/usr" install_opam_from_source opam_branches
178232
@@ from ~tag img
179233
@@ run "yum --version || dnf install -y yum"
180234
@@ workaround
181235
@@ Linux.RPM.update
182236
@@ Linux.RPM.dev_packages ()
183237
@@ (if enable_powertools then run "yum config-manager --set-enabled powertools" @@ Linux.RPM.update else empty)
184238
@@ copy ~from:"0" ~src:["/usr/local/bin/bwrap"] ~dst:"/usr/bin/bwrap" ()
185-
@@ copy ~from:"0" ~src:["/usr/bin/opam-2.0"] ~dst:"/usr/bin/opam-2.0" ()
186-
@@ copy ~from:"0" ~src:["/usr/bin/opam-2.1"] ~dst:"/usr/bin/opam-2.1" ()
187-
@@ run "ln /usr/bin/opam-2.0 /usr/bin/opam"
239+
@@ copy_opams ~src:"/usr/bin" ~dst:"/usr/bin" opam_branches
188240
@@ run
189241
"sed -i.bak '/LC_TIME LC_ALL LANGUAGE/aDefaults env_keep += \"OPAMYES OPAMJOBS OPAMVERBOSE\"' /etc/sudoers"
190242
@@ Linux.RPM.add_user ~uid:1000 ~sudo:true "opam"
191243
@@ install_bubblewrap_wrappers @@ Linux.Git.init ()
192244

193245

194246
(* Zypper based Dockerfile *)
195-
let zypper_opam2 ?(labels=[]) ?arch ~hash_opam_2_0 ~hash_opam_2_1 distro () =
247+
let zypper_opam2 ?(labels=[]) ?arch ~opam_hashes distro () =
248+
let opam_branches = create_opam_branches opam_hashes in
196249
let img, tag = D.base_distro_tag ?arch distro in
197250
header ?arch distro @@ label (("distro_style", "zypper") :: labels)
198251
@@ Linux.Zypper.dev_packages ()
199252
@@ Linux.Git.init ()
200253
@@ install_bubblewrap_from_source ()
201-
@@ install_opam_from_source ~prefix:"/usr" ~add_default_link:false ~branch:"2.0" ~hash:hash_opam_2_0 ()
202-
@@ install_opam_from_source ~prefix:"/usr" ~add_default_link:false ~enable_0install_solver:true ~branch:"2.1" ~hash:hash_opam_2_1 ()
254+
@@ install_opams ~prefix:"/usr" install_opam_from_source opam_branches
203255
@@ from ~tag img
204256
@@ Linux.Zypper.dev_packages ()
205257
@@ copy ~from:"0" ~src:["/usr/local/bin/bwrap"] ~dst:"/usr/bin/bwrap" ()
206-
@@ copy ~from:"0" ~src:["/usr/bin/opam-2.0"] ~dst:"/usr/bin/opam-2.0" ()
207-
@@ copy ~from:"0" ~src:["/usr/bin/opam-2.1"] ~dst:"/usr/bin/opam-2.1" ()
208-
@@ run "ln /usr/bin/opam-2.0 /usr/bin/opam"
258+
@@ copy_opams ~src:"/usr/bin" ~dst:"/usr/bin" opam_branches
209259
@@ Linux.Zypper.add_user ~uid:1000 ~sudo:true "opam"
210260
@@ install_bubblewrap_wrappers @@ Linux.Git.init ()
211261

212262
(* Pacman based Dockerfile *)
213-
let pacman_opam2 ?(labels=[]) ?arch ~hash_opam_2_0 ~hash_opam_2_1 distro () =
263+
let pacman_opam2 ?(labels=[]) ?arch ~opam_hashes distro () =
264+
let opam_branches = create_opam_branches opam_hashes in
214265
let img, tag = D.base_distro_tag ?arch distro in
215266
header ?arch distro @@ label (("distro_style", "pacman") :: labels)
216267
@@ Linux.Pacman.dev_packages ()
217268
@@ Linux.Git.init ()
218-
@@ install_opam_from_source ~add_default_link:false ~branch:"2.0" ~hash:hash_opam_2_0 ()
219-
@@ install_opam_from_source ~add_default_link:false ~enable_0install_solver:true ~branch:"2.1" ~hash:hash_opam_2_1 ()
269+
@@ install_opams install_opam_from_source opam_branches
220270
@@ run "strip /usr/local/bin/opam*"
221271
@@ from ~tag img
222-
@@ copy ~from:"0" ~src:["/usr/local/bin/opam-2.0"] ~dst:"/usr/bin/opam-2.0" ()
223-
@@ copy ~from:"0" ~src:["/usr/local/bin/opam-2.1"] ~dst:"/usr/bin/opam-2.1" ()
224-
@@ run "ln /usr/bin/opam-2.0 /usr/bin/opam"
272+
@@ copy_opams ~src:"/usr/local/bin" ~dst:"/usr/bin" opam_branches
225273
@@ Linux.Pacman.dev_packages ()
226274
@@ Linux.Pacman.add_user ~uid:1000 ~sudo:true "opam"
227275
@@ install_bubblewrap_wrappers @@ Linux.Git.init ()
228276

229277
(* Cygwin based Dockerfile *)
230-
let cygwin_opam2 ?win10_revision ?(labels=[]) ?arch ~hash_opam_2_0 ~hash_opam_2_1 distro () =
278+
let cygwin_opam2 ?win10_revision ?(labels=[]) ?arch ~opam_hashes distro () =
279+
let opam_branches = create_opam_branches opam_hashes in
231280
let img, tag = D.base_distro_tag ?arch distro in
232281
let cyg = Windows.Cygwin.{ default with args = "--allow-test-packages" :: default.args } in
233282
header ?win10_revision ?arch distro @@ label (("distro_style", "cygwin") :: labels)
234283
@@ user "ContainerAdministrator"
235284
@@ Windows.Cygwin.(setup ~cyg ~extra:(cygwin_packages ()) ())
236285
@@ Windows.Cygwin.Git.init ()
237-
@@ install_opam_from_source_cygwin ~add_default_link:false ~branch:"2.0" ~hash:hash_opam_2_0 ()
238-
@@ install_opam_from_source_cygwin ~add_default_link:false ~enable_0install_solver:true ~branch:"2.1" ~hash:hash_opam_2_1 ()
286+
@@ install_opams install_opam_from_source_cygwin opam_branches
239287
@@ run "strip /usr/local/bin/opam*"
240288
@@ from ~tag img
241-
@@ copy ~from:"0" ~src:["/usr/local/bin/opam-2.0"] ~dst:"/usr/bin/opam-2.0" ()
242-
@@ copy ~from:"0" ~src:["/usr/local/bin/opam-2.1"] ~dst:"/usr/bin/opam-2.1" ()
243-
@@ run "ln /usr/bin/opam-2.0 /usr/bin/opam"
289+
@@ copy_opams ~src:"/usr/local/bin" ~dst:"/usr/bin" opam_branches
244290
@@ Windows.Cygwin.(setup ~cyg ~extra:(cygwin_packages ()) ())
245291
@@ Windows.Cygwin.Git.init ()
246292

@@ -278,17 +324,17 @@ let windows_opam2 ?win10_revision ?winget ?(labels=[]) ?arch distro () =
278324
@@ Windows.Cygwin.Git.init ()
279325
@@ Windows.cleanup ()
280326

281-
let gen_opam2_distro ?win10_revision ?winget ?(clone_opam_repo=true) ?arch ?labels ~hash_opam_2_0 ~hash_opam_2_1 d =
327+
let gen_opam2_distro ?win10_revision ?winget ?(clone_opam_repo=true) ?arch ?labels ~opam_hashes d =
282328
let fn = match D.package_manager d with
283-
| `Apk -> apk_opam2 ?labels ?arch ~hash_opam_2_0 ~hash_opam_2_1 d ()
284-
| `Apt -> apt_opam2 ?labels ?arch ~hash_opam_2_0 ~hash_opam_2_1 d ()
329+
| `Apk -> apk_opam2 ?labels ?arch ~opam_hashes d ()
330+
| `Apt -> apt_opam2 ?labels ?arch ~opam_hashes d ()
285331
| `Yum ->
286332
let yum_workaround = match d with `CentOS `V7 -> true | _ -> false in
287333
let enable_powertools = match d with `CentOS (`V6 | `V7) -> false | `CentOS _ -> true | _ -> false in
288-
yum_opam2 ?labels ?arch ~yum_workaround ~enable_powertools ~hash_opam_2_0 ~hash_opam_2_1 d ()
289-
| `Zypper -> zypper_opam2 ?labels ?arch ~hash_opam_2_0 ~hash_opam_2_1 d ()
290-
| `Pacman -> pacman_opam2 ?labels ?arch ~hash_opam_2_0 ~hash_opam_2_1 d ()
291-
| `Cygwin -> cygwin_opam2 ?win10_revision ?labels ?arch ~hash_opam_2_0 ~hash_opam_2_1 d ()
334+
yum_opam2 ?labels ?arch ~yum_workaround ~enable_powertools ~opam_hashes d ()
335+
| `Zypper -> zypper_opam2 ?labels ?arch ~opam_hashes d ()
336+
| `Pacman -> pacman_opam2 ?labels ?arch ~opam_hashes d ()
337+
| `Cygwin -> cygwin_opam2 ?win10_revision ?labels ?arch ~opam_hashes d ()
292338
| `Windows -> windows_opam2 ?win10_revision ?winget ?labels ?arch d ()
293339
in
294340
let clone = if clone_opam_repo then

src-opam/dockerfile_opam.mli

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,24 @@ val install_opam_from_source : ?add_default_link:bool ->
3939
If [enable_0install_solver] is true (false by default), then the [builtin-0install]
4040
solver should be accessible in the resulting opam binary. *)
4141

42+
type opam_hashes = {
43+
opam_2_0_hash : string;
44+
opam_2_1_hash : string;
45+
opam_master_hash : string;
46+
}
47+
4248
val gen_opam2_distro :
4349
?win10_revision:Dockerfile_distro.win10_lcu ->
4450
?winget:string ->
4551
?clone_opam_repo:bool ->
4652
?arch:Ocaml_version.arch ->
4753
?labels:(string * string) list ->
48-
hash_opam_2_0:string ->
49-
hash_opam_2_1:string ->
54+
opam_hashes:opam_hashes ->
5055
Dockerfile_distro.t
5156
-> string * Dockerfile.t
52-
(** [gen_opam2_distro ~hash_opam_2_0 ~hash_opam_2_1 d] will generate a Dockerfile
53-
for Linux distribution [d] with opam 2.0 and opam 2.1, per hash given in parameter.
57+
(** [gen_opam2_distro ~opam_hashes d] will generate a Dockerfile
58+
for Linux distribution [d] with opam 2.0, opam 2.1, opam 2.2 and opam master,
59+
per hash given in parameter.
5460
@return a tuple of the Docker tag and the Dockerfile.
5561
If [clone_opam_repo] is true (the default) then the Dockerfile will also git
5662
clone the official opam-repository into [/home/opam/opam-repository].

0 commit comments

Comments
 (0)