Source file service.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
open Lwt.Infix

type t = No_context

let id = "docker-service"

module Key = struct
  type t = {
    name : string;
    docker_context : string option;
  } [@@deriving to_yojson]

  let digest t = Yojson.Safe.to_string (to_yojson t)
end

module Value = struct
  type t = {
    image : Image.t;
  }

  let digest { image } =
    Yojson.Safe.to_string @@ `Assoc [
      "image", `String (Image.hash image);
    ]
end

module Outcome = Current.Unit

let cmd { Key.name; docker_context } { Value.image } =
  Cmd.docker ~docker_context ["service"; "update"; "--image"; Image.hash image; name]

let publish No_context job key value =
  Current.Job.start job ~level:Current.Level.Dangerous >>= fun () ->
  Current.Process.exec ~cancellable:true ~job (cmd key value)

let pp f (key, value) =
  Cmd.pp f (cmd key value)

let auto_cancel = false