forked from ocurrent/obuilder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.spec
52 lines (51 loc) · 2.04 KB
/
example.spec
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
; This script builds OBuilder itself using a snapshot of the ocaml/opam:debian-11-ocaml-4.14 base image.
;
; Run it from the top-level of the OBuilder source tree, e.g.
;
; dune exec -- obuilder build --store=zfs:tank -f example.spec .
;
; The result can then be found in /tank/HASH/rootfs/ (where HASH is displayed at the end of the build).
((build dev
((from ocaml/opam@sha256:4bfe3c0814b4220417d6ccbbed7eb5486a35d900024745c1f299973e9584e0e5)
(workdir /src)
(user (uid 1000) (gid 1000)) ; Build as the "opam" user
(run (shell "sudo chown opam /src"))
(env OPAM_HASH "f44d347b2119b4bdfddfb2a8ec55ae25c396c0d7")
(run
(network host)
(shell "sudo apt-get --allow-releaseinfo-change update"))
(run
(network host)
(shell
"cd ~/opam-repository \
&& (git cat-file -e $OPAM_HASH || git fetch origin master) \
&& git reset -q --hard $OPAM_HASH \
&& git --no-pager log --no-decorate -n1 --oneline \
&& opam update -u"))
; Copy just the opam file first (helps caching) + container image whilst vendored
(copy (src obuilder-spec.opam obuilder.opam vendor) (dst ./))
(run (shell "opam pin add -yn ."))
; Install OS package dependencies
(run
(network host)
(cache (opam-archives (target /home/opam/.opam/download-cache)))
(shell "opam depext -yu obuilder"))
; Install OCaml dependencies
(run
(network host)
(cache (opam-archives (target /home/opam/.opam/download-cache)))
(shell "opam install --deps-only -t obuilder"))
(copy ; Copy the rest of the source code
(src .)
(dst /src/)
(exclude .git _build _opam))
(run (shell "opam exec -- dune build @install @runtest")))) ; Build and test
; Now generate a small runtime image with just the resulting binary:
(from debian:11)
(run
(network host)
(shell "apt-get update && apt-get install -y libsqlite3-0 --no-install-recommends"))
(copy (from (build dev))
(src /src/_build/default/main.exe)
(dst /usr/local/bin/obuilder))
(run (shell "obuilder --help")))