-
Notifications
You must be signed in to change notification settings - Fork 18
/
obuilder_pipeline.ml
63 lines (52 loc) · 1.89 KB
/
obuilder_pipeline.ml
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
53
54
55
56
57
58
59
60
61
62
63
let program_name = "obuilder_pipeline"
open Current.Syntax
let () =
Logging.init ()
let repo = { Current_github.Repo_id.owner = "ocurrent"; name = "obuilder" }
let pool = "linux-x86_64"
let timeout = Duration.of_min 60
let example_spec =
let open Obuilder_spec in
stage ~from:"busybox" [
copy ["."] ~dst:"/src";
shell ["sh"; "-c"];
run "ls -l /src"
]
|> Fmt.to_to_string Obuilder_spec.pp
let pipeline ~cluster () =
let src =
let+ src = Current_github.Api.Anonymous.head_of repo (`Ref "refs/heads/master") in
[ src ]
in
let spec = Current.return { Cluster_api.Obuilder_job.Spec.spec = `Contents example_spec } in
let cluster = Current_ocluster.with_timeout (Some timeout) cluster in
let cache_hint = "ocluster-example" in
Current_ocluster.build_obuilder cluster ~cache_hint ~src ~pool spec
let main config mode submission_uri =
let vat = Capnp_rpc_unix.client_only_vat () in
let submission_cap = Capnp_rpc_unix.Vat.import_exn vat submission_uri in
let connection = Current_ocluster.Connection.create submission_cap in
let cluster = Current_ocluster.v connection in
let engine = Current.Engine.create ~config (pipeline ~cluster) in
let site = Current_web.Site.(v ~has_role:allow_all) ~name:program_name (Current_web.routes engine) in
Lwt_main.run begin
Lwt.choose [
Current.Engine.thread engine;
Current_web.run ~mode site;
]
end
(* Command-line parsing *)
open Cmdliner
let submission_service =
Arg.required @@
Arg.opt Arg.(some Capnp_rpc_unix.sturdy_uri) None @@
Arg.info
~doc:"The submission.cap file for the build scheduler service"
~docv:"FILE"
["submission-service"]
let cmd =
let doc = "Run an OBuilder build on a cluster." in
let info = Cmd.info program_name ~doc in
Cmd.v info
Term.(term_result (const main $ Current.Config.cmdliner $ Current_web.cmdliner $ submission_service))
let () = exit @@ Cmd.eval cmd