Source file compose_cli.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
open Lwt.Infix
type t = {
pull: bool ;
}
let id = "docker-compose-cli"
module Key = struct
type t = {
name: string;
docker_context: string option;
detach: bool;
up_args: string list;
} [@@deriving to_yojson]
let digest t = Yojson.Safe.to_string (to_yojson t)
end
module Value = struct
type t = {
contents: string;
}
let digest { contents } =
Yojson.Safe.to_string @@ `Assoc [
"contents", `String contents
]
end
module Outcome = Current.Unit
let cmd args { Key.docker_context; name; detach=_; up_args=_ } =
Cmd.docker ~docker_context (["compose"; "-f"; "/dev/stdin"; "-p"; name ] @ args)
let cmd_pull = cmd ["pull"]
let cmd_update ({ Key.detach; up_args; _ } as key) =
let args = (if detach then ["-d"] else []) @ up_args in
cmd ("up" :: args) key
let publish { pull } job key {Value.contents} =
Current.Job.start job ~level:Current.Level.Dangerous >>= fun () ->
let p =
if pull then Current.Process.exec ~stdin:contents ~cancellable:true ~job (cmd_pull key)
else Lwt.return (Ok ())
in
p >>= function
| Error _ as e -> Lwt.return e
| Ok () -> Current.Process.exec ~stdin:contents ~cancellable:true ~job (cmd_update key)
let pp f (key, { Value.contents }) =
Fmt.pf f "%a@.@[%a@]" Cmd.pp (cmd_update key) Fmt.string contents
let auto_cancel = false