diff --git a/tezt/lib_cloud/docker.ml b/tezt/lib_cloud/docker.ml index f30fa419fc74676c6c5abcb549d6180aebab3f69..4f18d61f637a346f8234275b7531eca465e31920 100644 --- a/tezt/lib_cloud/docker.ml +++ b/tezt/lib_cloud/docker.ml @@ -55,7 +55,8 @@ let pull ?image_name ?alias ?(tag = "latest") ~registry_uri () = let network ~command ~network_name = Process.spawn ~color "docker" (["network"] @ [command] @ [network_name]) -let run ?(rm = false) ?name ?network ?publish_ports image args = +let run ?runner ?(rm = false) ?name ?(detach = false) ?network ?publish_ports + ?volumes image args = let publish_ports = match publish_ports with | None -> [] @@ -67,18 +68,36 @@ let run ?(rm = false) ?name ?network ?publish_ports image args = in let name = match name with None -> [] | Some name -> ["--name"; name] in let rm = if rm then ["--rm"] else [] in + let detach = if detach then ["-d"] else [] in + let volumes = + match volumes with + | None -> [] + | Some volumes -> + let arg_of_volume (host, container) = + ["-v"; Format.asprintf "%s:%s" host container] + in + List.map arg_of_volume volumes |> List.flatten + in (* [init] can be used to ensure signals are forwarded properly to the entrypoint run by the container. *) Process.spawn + ?runner ~color "docker" - (["run"] @ rm @ name @ macos_platform_arg @ network @ publish_ports + (["run"] @ detach @ rm @ name @ macos_platform_arg @ volumes @ network + @ publish_ports @ [Format.asprintf "%s" image] @ args) let kill container_name = Process.spawn ~color "docker" ["kill"; container_name] -let rm container_name = Process.spawn ~color "docker" ["rm"; container_name] +let rm ?runner ?(force = false) container_name = + Log.info "Docker.rm '%s'" container_name ; + Process.spawn + ?runner + ~color + "docker" + (["rm"] @ (if force then ["--force"] else []) @ [container_name]) let cp container_name ~kind ~source ~destination = match kind with diff --git a/tezt/lib_cloud/docker.mli b/tezt/lib_cloud/docker.mli index 0b5cc4970f726dc8a092bf5573dda1c42ce6a9bd..1c48b3fcc8b0573fda4577f7f31229648e1e5c08 100644 --- a/tezt/lib_cloud/docker.mli +++ b/tezt/lib_cloud/docker.mli @@ -49,10 +49,13 @@ val network : command:string -> network_name:string -> Process.t (** [run] is an alias for [docker run]. *) val run : + ?runner:Runner.t -> ?rm:bool -> ?name:string -> + ?detach:bool -> ?network:string -> ?publish_ports:string * string * string * string -> + ?volumes:(string * string) list -> string -> string list -> Process.t @@ -61,7 +64,7 @@ val run : val kill : string -> Process.t (** [rm] is an alias for [docker rm]. *) -val rm : string -> Process.t +val rm : ?runner:Runner.t -> ?force:bool -> string -> Process.t (** [cp] is an alias for [docker cp]. *) val cp :