2020-12-08 10:49:26 +00:00
|
|
|
open Lwt_result.Infix
|
2020-12-02 13:33:15 +00:00
|
|
|
|
2021-01-08 12:47:17 +00:00
|
|
|
let src = Logs.Src.create "builder-web.model" ~doc:"Builder_web model"
|
|
|
|
module Log = (val Logs.src_log src : Logs.LOG)
|
2020-12-14 07:18:13 +00:00
|
|
|
|
2021-01-08 12:47:17 +00:00
|
|
|
module type CONN = Caqti_lwt.CONNECTION
|
|
|
|
|
2021-01-21 16:51:58 +00:00
|
|
|
type error = [ Caqti_error.call_or_retrieve | `Not_found | `File_error of Fpath.t | `Msg of string ]
|
2021-01-08 12:47:17 +00:00
|
|
|
|
|
|
|
let pp_error ppf = function
|
|
|
|
| `Not_found -> Format.fprintf ppf "value not found in database"
|
|
|
|
| `File_error path -> Format.fprintf ppf "error reading file %a" Fpath.pp path
|
2021-01-21 16:51:58 +00:00
|
|
|
| `Msg e -> Format.fprintf ppf "error %s" e
|
2021-01-08 12:47:17 +00:00
|
|
|
| #Caqti_error.call_or_retrieve as e ->
|
|
|
|
Caqti_error.pp ppf e
|
|
|
|
|
|
|
|
let not_found = function
|
|
|
|
| None -> Lwt.return (Error `Not_found :> (_, [> error ]) result)
|
|
|
|
| Some v -> Lwt_result.return v
|
|
|
|
|
2021-03-24 13:49:23 +00:00
|
|
|
let staging datadir = Fpath.(datadir / "_staging")
|
|
|
|
|
2021-06-01 15:43:55 +00:00
|
|
|
let read_file datadir filepath =
|
|
|
|
let filepath = Fpath.(datadir // filepath) in
|
2021-01-08 12:47:17 +00:00
|
|
|
Lwt.try_bind
|
|
|
|
(fun () -> Lwt_io.open_file ~mode:Lwt_io.Input (Fpath.to_string filepath))
|
|
|
|
(fun ic -> Lwt_result.ok (Lwt_io.read ic))
|
|
|
|
(function
|
|
|
|
| Unix.Unix_error (e, _, _) ->
|
|
|
|
Logs.warn (fun m -> m "Error reading local file %a: %s"
|
|
|
|
Fpath.pp filepath (Unix.error_message e));
|
|
|
|
Lwt.return_error (`File_error filepath)
|
|
|
|
| e -> Lwt.fail e)
|
|
|
|
|
2021-06-05 06:13:46 +00:00
|
|
|
let build_artifact build filepath (module Db : CONN) =
|
2021-01-08 12:47:17 +00:00
|
|
|
Db.find_opt Builder_db.Build_artifact.get_by_build_uuid (build, filepath)
|
2021-06-05 06:13:46 +00:00
|
|
|
>>= not_found >|= snd
|
|
|
|
|
|
|
|
let build_artifact_data datadir file =
|
|
|
|
read_file datadir file.Builder_db.localpath
|
2020-12-14 07:18:13 +00:00
|
|
|
|
2021-01-08 12:47:17 +00:00
|
|
|
let build_artifacts build (module Db : CONN) =
|
|
|
|
Db.collect_list Builder_db.Build_artifact.get_all_by_build build >|=
|
|
|
|
List.map snd
|
|
|
|
|
|
|
|
let build uuid (module Db : CONN) =
|
|
|
|
Db.find_opt Builder_db.Build.get_by_uuid uuid >>=
|
|
|
|
not_found
|
2020-12-02 13:33:15 +00:00
|
|
|
|
2021-01-29 13:34:56 +00:00
|
|
|
let build_meta job (module Db : CONN) =
|
|
|
|
Db.find_opt Builder_db.Build.get_latest job >|=
|
|
|
|
Option.map (fun (_id, meta, file) -> (meta, file))
|
|
|
|
|
2021-02-02 08:34:21 +00:00
|
|
|
let build_hash hash (module Db : CONN) =
|
|
|
|
Db.find_opt Builder_db.Build.get_by_hash hash
|
|
|
|
|
2021-01-22 12:13:09 +00:00
|
|
|
let build_exists uuid (module Db : CONN) =
|
|
|
|
Db.find_opt Builder_db.Build.get_by_uuid uuid >|=
|
|
|
|
Option.is_some
|
|
|
|
|
2021-04-23 13:00:12 +00:00
|
|
|
let latest_build_uuid job_id (module Db : CONN) =
|
|
|
|
Db.find_opt Builder_db.Build.get_latest_uuid job_id >>=
|
|
|
|
(* We know there's at least one job when this is called, probably. *)
|
|
|
|
not_found >|= snd
|
|
|
|
|
2021-06-02 13:05:10 +00:00
|
|
|
let latest_successful_build_uuid job_id (module Db : CONN) =
|
|
|
|
Db.find_opt Builder_db.Build.get_latest_successful_uuid job_id
|
2021-06-02 12:23:40 +00:00
|
|
|
|
2021-06-02 13:05:10 +00:00
|
|
|
let previous_successful_build id (module Db : CONN) =
|
|
|
|
Db.find_opt Builder_db.Build.get_previous_successful id >|=
|
2021-04-23 13:00:12 +00:00
|
|
|
Option.map (fun (_id, meta) -> meta)
|
|
|
|
|
2021-07-06 10:23:29 +00:00
|
|
|
let builds_with_same_main_binary id (module Db : CONN) =
|
|
|
|
Db.collect_list Builder_db.Build.get_other_builds_with_same_output id
|
2021-01-27 20:25:51 +00:00
|
|
|
|
2021-06-02 13:05:10 +00:00
|
|
|
let job_id job_name (module Db : CONN) =
|
2021-06-09 09:48:51 +00:00
|
|
|
Db.find_opt Builder_db.Job.get_id_by_name job_name
|
2021-06-02 13:05:10 +00:00
|
|
|
|
2021-06-30 12:47:30 +00:00
|
|
|
let readme job (module Db : CONN) =
|
2021-06-09 09:48:51 +00:00
|
|
|
job_id job (module Db) >>= not_found >>= fun job_id ->
|
2021-06-30 12:47:30 +00:00
|
|
|
Db.find Builder_db.Tag.get_id_by_name "readme.md" >>= fun readme_id ->
|
|
|
|
Db.find_opt Builder_db.Job_tag.get_value (readme_id, job_id)
|
|
|
|
|
|
|
|
let job_and_readme job (module Db : CONN) =
|
|
|
|
job_id job (module Db) >>= not_found >>= fun job_id ->
|
|
|
|
Db.find Builder_db.Tag.get_id_by_name "readme.md" >>= fun readme_id ->
|
|
|
|
Db.find_opt Builder_db.Job_tag.get_value (readme_id, job_id) >>= fun readme ->
|
|
|
|
Db.collect_list Builder_db.Build.get_all_meta job_id >|= fun builds ->
|
|
|
|
readme, List.map (fun (_id, meta, main_binary) -> (meta, main_binary)) builds
|
2021-06-07 13:52:37 +00:00
|
|
|
|
2021-01-08 12:47:17 +00:00
|
|
|
let jobs (module Db : CONN) =
|
2021-01-29 13:34:56 +00:00
|
|
|
Db.collect_list Builder_db.Job.get_all ()
|
2021-01-20 21:50:35 +00:00
|
|
|
|
2021-06-29 14:59:08 +00:00
|
|
|
let jobs_with_section_synopsis (module Db : CONN) =
|
|
|
|
Db.collect_list Builder_db.Job.get_all_with_section_synopsis ()
|
|
|
|
|
2021-02-15 10:48:10 +00:00
|
|
|
let job_name id (module Db : CONN) =
|
|
|
|
Db.find Builder_db.Job.get id
|
|
|
|
|
2021-01-20 21:50:35 +00:00
|
|
|
let user username (module Db : CONN) =
|
2021-06-08 14:54:23 +00:00
|
|
|
Db.find_opt Builder_db.User.get_user username
|
|
|
|
|
|
|
|
let authorized user_id job_name (module Db : CONN) =
|
2021-06-09 09:48:51 +00:00
|
|
|
job_id job_name (module Db) >>=
|
|
|
|
(function None -> Lwt_result.fail (`Msg "No such job") | Some r -> Lwt_result.return r) >>= fun job_id ->
|
2021-06-08 14:54:23 +00:00
|
|
|
Db.find Builder_db.Access_list.get (user_id, job_id) >|= fun _id ->
|
|
|
|
()
|
2021-01-20 21:50:35 +00:00
|
|
|
|
2021-03-24 13:49:23 +00:00
|
|
|
let cleanup_staging datadir (module Db : Caqti_lwt.CONNECTION) =
|
|
|
|
let cleanup_staged staged =
|
|
|
|
match Uuidm.of_string (Fpath.to_string staged) with
|
|
|
|
| None ->
|
|
|
|
Log.warn (fun m -> m "Non-uuid staged files: %a" Fpath.pp
|
|
|
|
Fpath.(staging datadir // staged));
|
|
|
|
Lwt.return (Bos.OS.Path.delete ~recurse:true Fpath.(staging datadir // staged))
|
|
|
|
| Some uuid ->
|
|
|
|
let staged = Fpath.(staging datadir // staged) in
|
|
|
|
Db.find_opt Builder_db.Build.get_by_uuid uuid >>= function
|
|
|
|
| Some (_id, build) ->
|
|
|
|
Db.find Builder_db.Job.get build.job_id >>= fun job_name ->
|
|
|
|
let destdir = Fpath.(datadir / job_name / Uuidm.to_string uuid) in
|
|
|
|
Lwt.return (Bos.OS.Path.move staged destdir)
|
|
|
|
| None ->
|
|
|
|
Lwt.return (Bos.OS.Path.delete ~recurse:true Fpath.(staging datadir // staged))
|
|
|
|
in
|
|
|
|
Lwt.return (Bos.OS.Dir.contents ~rel:true (staging datadir)) >>= fun stageds ->
|
|
|
|
Lwt_result.ok @@
|
|
|
|
Lwt_list.iter_s
|
|
|
|
(fun staged ->
|
|
|
|
Lwt.map (function
|
|
|
|
| Error (_ as e) ->
|
|
|
|
Log.warn (fun m -> m "Failed cleaning up staged files %a in %a: %a"
|
|
|
|
Fpath.pp staged
|
|
|
|
Fpath.pp Fpath.(staging datadir // staged)
|
|
|
|
pp_error e)
|
|
|
|
| Ok () -> ())
|
|
|
|
(cleanup_staged staged))
|
|
|
|
stageds
|
|
|
|
|
2021-01-21 16:51:58 +00:00
|
|
|
let save file data =
|
|
|
|
let open Lwt.Infix in
|
2021-01-21 17:12:26 +00:00
|
|
|
Lwt.catch
|
|
|
|
(fun () ->
|
|
|
|
Lwt_io.open_file ~mode:Lwt_io.Output (Fpath.to_string file) >>= fun oc ->
|
|
|
|
Lwt_io.write oc data >>= fun () ->
|
|
|
|
Lwt_io.close oc
|
|
|
|
|> Lwt_result.ok)
|
|
|
|
(function
|
|
|
|
| Unix.Unix_error (e, _, _) ->
|
|
|
|
Lwt_result.fail (`Msg (Unix.error_message e))
|
|
|
|
| e -> Lwt.fail e)
|
2021-01-21 16:51:58 +00:00
|
|
|
|
|
|
|
let save_exec build_dir exec =
|
|
|
|
let cs = Builder.Asn.exec_to_cs exec in
|
|
|
|
save Fpath.(build_dir / "full") (Cstruct.to_string cs)
|
|
|
|
|
2021-03-24 13:49:23 +00:00
|
|
|
let save_file dir staging (filepath, data) =
|
2021-02-25 14:27:45 +00:00
|
|
|
let size = String.length data in
|
2021-01-20 21:50:35 +00:00
|
|
|
let sha256 = Mirage_crypto.Hash.SHA256.digest (Cstruct.of_string data) in
|
2021-01-21 16:51:58 +00:00
|
|
|
let localpath = Fpath.append dir filepath in
|
2021-03-24 13:49:23 +00:00
|
|
|
let destpath = Fpath.append staging filepath in
|
|
|
|
Lwt_result.lift (Bos.OS.Dir.create (Fpath.parent destpath)) >>= fun _ ->
|
|
|
|
save destpath data >|= fun () ->
|
2021-02-23 14:37:30 +00:00
|
|
|
{ Builder_db.filepath; localpath; sha256; size }
|
2021-01-21 17:12:26 +00:00
|
|
|
|
2021-03-24 13:49:23 +00:00
|
|
|
let save_files dir staging files =
|
2021-01-21 17:12:26 +00:00
|
|
|
List.fold_left
|
|
|
|
(fun r file ->
|
|
|
|
r >>= fun acc ->
|
2021-03-24 13:49:23 +00:00
|
|
|
save_file dir staging file >>= fun file ->
|
2021-01-21 17:12:26 +00:00
|
|
|
Lwt_result.return (file :: acc))
|
|
|
|
(Lwt_result.return [])
|
|
|
|
files
|
2021-01-21 16:51:58 +00:00
|
|
|
|
2021-06-25 16:43:47 +00:00
|
|
|
let save_all staging_dir (((job : Builder.script_job), uuid, _, _, _, _, artifacts) as exec) =
|
2021-06-01 15:43:55 +00:00
|
|
|
let build_dir = Fpath.(v job.Builder.name / Uuidm.to_string uuid) in
|
2021-03-24 13:49:23 +00:00
|
|
|
let output_dir = Fpath.(build_dir / "output")
|
|
|
|
and staging_output_dir = Fpath.(staging_dir / "output") in
|
|
|
|
Lwt.return (Bos.OS.Dir.create staging_dir) >>= (fun created ->
|
2021-01-21 16:51:58 +00:00
|
|
|
if not created
|
|
|
|
then Lwt_result.fail (`Msg "build directory already exists")
|
|
|
|
else Lwt_result.return ()) >>= fun () ->
|
2021-03-24 13:49:23 +00:00
|
|
|
Lwt.return (Bos.OS.Dir.create staging_output_dir) >>= fun _ ->
|
|
|
|
save_exec staging_dir exec >>= fun () ->
|
|
|
|
save_files output_dir staging_output_dir artifacts >>= fun artifacts ->
|
2021-06-25 10:26:03 +00:00
|
|
|
Lwt_result.return artifacts
|
2021-01-20 21:50:35 +00:00
|
|
|
|
2021-06-01 15:43:55 +00:00
|
|
|
let commit_files datadir staging_dir job_name uuid =
|
|
|
|
let job_dir = Fpath.(datadir / job_name) in
|
2021-03-24 13:49:23 +00:00
|
|
|
let dest = Fpath.(job_dir / Uuidm.to_string uuid) in
|
|
|
|
Lwt.return (Bos.OS.Dir.create job_dir) >>= fun _ ->
|
|
|
|
Lwt.return (Bos.OS.Path.move staging_dir dest)
|
|
|
|
|
2021-06-29 14:59:08 +00:00
|
|
|
let infer_section_and_synopsis artifacts =
|
|
|
|
let opam_switch =
|
|
|
|
match List.find_opt (fun (p, _) -> String.equal (Fpath.basename p) "opam-switch") artifacts with
|
|
|
|
| None -> None
|
|
|
|
| Some (_, data) -> Some (OpamFile.SwitchExport.read_from_string data)
|
|
|
|
in
|
2021-06-29 15:15:16 +00:00
|
|
|
let infer_synopsis_and_descr switch =
|
2021-06-29 14:59:08 +00:00
|
|
|
let root = switch.OpamFile.SwitchExport.selections.OpamTypes.sel_roots in
|
|
|
|
if OpamPackage.Set.cardinal root <> 1 then
|
2021-06-29 15:15:16 +00:00
|
|
|
None, None
|
2021-06-29 14:59:08 +00:00
|
|
|
else
|
|
|
|
let root = OpamPackage.Set.choose root in
|
|
|
|
match OpamPackage.Name.Map.find_opt root.OpamPackage.name switch.OpamFile.SwitchExport.overlays with
|
2021-06-29 15:15:16 +00:00
|
|
|
| None -> None, None
|
|
|
|
| Some opam -> OpamFile.OPAM.synopsis opam, OpamFile.OPAM.descr_body opam
|
2021-06-29 14:59:08 +00:00
|
|
|
in
|
|
|
|
let infer_section_from_packages switch =
|
|
|
|
let influx = OpamPackage.Name.of_string "metrics-influx" in
|
|
|
|
if OpamPackage.Set.exists (fun p -> OpamPackage.Name.equal p.OpamPackage.name influx)
|
|
|
|
switch.OpamFile.SwitchExport.selections.OpamTypes.sel_installed
|
|
|
|
then
|
2021-06-30 09:56:47 +00:00
|
|
|
"Unikernel (with metrics reported to Influx)"
|
2021-06-29 14:59:08 +00:00
|
|
|
else
|
|
|
|
"Unikernel"
|
|
|
|
in
|
|
|
|
let infer_section_from_extension =
|
|
|
|
match List.find_opt (fun (p, _) -> Fpath.(is_prefix (v "bin/") p)) artifacts with
|
|
|
|
| None -> None
|
|
|
|
| Some (p, _) ->
|
|
|
|
match Fpath.get_ext p with
|
|
|
|
| ".deb" -> Some "Debian Package"
|
|
|
|
| ".txz" -> Some "FreeBSD Package"
|
|
|
|
| _ -> None
|
|
|
|
in
|
|
|
|
match opam_switch with
|
2021-06-29 15:15:16 +00:00
|
|
|
| None -> None, (None, None)
|
2021-06-29 14:59:08 +00:00
|
|
|
| Some opam_switch ->
|
|
|
|
let section =
|
|
|
|
match infer_section_from_extension with
|
|
|
|
| Some x -> x
|
|
|
|
| None -> infer_section_from_packages opam_switch
|
|
|
|
in
|
2021-06-29 15:15:16 +00:00
|
|
|
Some section, infer_synopsis_and_descr opam_switch
|
2021-06-29 14:59:08 +00:00
|
|
|
|
2021-07-06 13:41:26 +00:00
|
|
|
let compute_input_id artifacts =
|
|
|
|
let get_hash filename =
|
|
|
|
match List.find_opt (fun b -> Fpath.equal b.Builder_db.filepath filename) artifacts with
|
|
|
|
| None -> None
|
|
|
|
| Some x -> Some x.sha256
|
|
|
|
in
|
|
|
|
match
|
|
|
|
get_hash (Fpath.v "opam-switch"),
|
|
|
|
get_hash (Fpath.v "build-environment"),
|
|
|
|
get_hash (Fpath.v "system-packages")
|
|
|
|
with
|
|
|
|
| Some a, Some b, Some c -> Some (Mirage_crypto.Hash.SHA256.digest (Cstruct.concat [a;b;c]))
|
|
|
|
| _ -> None
|
|
|
|
|
2021-01-21 16:51:58 +00:00
|
|
|
let add_build
|
2021-06-01 15:43:55 +00:00
|
|
|
datadir
|
2021-06-09 11:54:24 +00:00
|
|
|
user_id
|
2021-06-29 14:59:08 +00:00
|
|
|
(((job : Builder.script_job), uuid, console, start, finish, result, raw_artifacts) as exec)
|
2021-01-21 16:51:58 +00:00
|
|
|
(module Db : CONN) =
|
2021-01-20 21:50:35 +00:00
|
|
|
let open Builder_db in
|
|
|
|
let job_name = job.Builder.name in
|
2021-06-01 15:43:55 +00:00
|
|
|
let staging_dir = Fpath.(staging datadir / Uuidm.to_string uuid) in
|
2021-03-24 13:49:23 +00:00
|
|
|
let or_cleanup x =
|
|
|
|
Lwt_result.map_err (fun e ->
|
|
|
|
Bos.OS.Dir.delete ~recurse:true staging_dir
|
|
|
|
|> Result.iter_error (fun e ->
|
|
|
|
Log.err (fun m -> m "Failed to remove staging dir %a: %a"
|
|
|
|
Fpath.pp staging_dir
|
|
|
|
pp_error e));
|
|
|
|
e)
|
|
|
|
x
|
|
|
|
in
|
2021-06-25 10:26:03 +00:00
|
|
|
or_cleanup (save_all staging_dir exec) >>= fun artifacts ->
|
2021-03-24 13:49:23 +00:00
|
|
|
let r =
|
|
|
|
Db.start () >>= fun () ->
|
|
|
|
Db.exec Job.try_add job_name >>= fun () ->
|
2021-06-09 09:48:51 +00:00
|
|
|
Db.find_opt Job.get_id_by_name job_name >>= fun job_id ->
|
|
|
|
Lwt.return (Option.to_result ~none:(`Msg "No such job id") job_id) >>= fun job_id ->
|
2021-06-29 14:59:08 +00:00
|
|
|
let section_tag = "section" in
|
|
|
|
Db.exec Tag.try_add section_tag >>= fun () ->
|
|
|
|
Db.find Tag.get_id_by_name section_tag >>= fun section_id ->
|
|
|
|
let synopsis_tag = "synopsis" in
|
|
|
|
Db.exec Tag.try_add synopsis_tag >>= fun () ->
|
|
|
|
Db.find Tag.get_id_by_name synopsis_tag >>= fun synopsis_id ->
|
2021-06-29 15:15:16 +00:00
|
|
|
let descr_tag = "description" in
|
|
|
|
Db.exec Tag.try_add descr_tag >>= fun () ->
|
|
|
|
Db.find Tag.get_id_by_name descr_tag >>= fun descr_id ->
|
2021-06-30 12:47:30 +00:00
|
|
|
let readme_tag = "readme.md" in
|
|
|
|
Db.exec Tag.try_add readme_tag >>= fun () ->
|
|
|
|
Db.find Tag.get_id_by_name readme_tag >>= fun readme_id ->
|
2021-07-06 13:41:26 +00:00
|
|
|
let input_id = compute_input_id artifacts in
|
|
|
|
Db.exec Build.add ({ Build.uuid; start; finish; result;
|
|
|
|
console; script = job.Builder.script;
|
|
|
|
main_binary = None; user_id; job_id }, input_id) >>= fun () ->
|
2021-03-24 13:49:23 +00:00
|
|
|
Db.find last_insert_rowid () >>= fun id ->
|
2021-06-29 14:59:08 +00:00
|
|
|
let sec_syn = infer_section_and_synopsis raw_artifacts in
|
2021-06-30 10:55:00 +00:00
|
|
|
let add_or_update tag_id tag_value =
|
|
|
|
Db.find_opt Job_tag.get_value (tag_id, job_id) >>= function
|
|
|
|
| None -> Db.exec Job_tag.add (tag_id, tag_value, job_id)
|
|
|
|
| Some _ -> Db.exec Job_tag.update (tag_id, tag_value, job_id)
|
|
|
|
in
|
2021-06-29 14:59:08 +00:00
|
|
|
(match fst sec_syn with
|
2021-06-30 12:47:30 +00:00
|
|
|
| None -> Lwt_result.return ()
|
|
|
|
| Some section_v -> add_or_update section_id section_v) >>= fun () ->
|
2021-06-29 14:59:08 +00:00
|
|
|
(match snd sec_syn with
|
2021-06-30 12:47:30 +00:00
|
|
|
| None, _-> Lwt_result.return ()
|
|
|
|
| Some synopsis_v, _ -> add_or_update synopsis_id synopsis_v) >>= fun () ->
|
2021-06-29 15:15:16 +00:00
|
|
|
(match snd sec_syn with
|
2021-06-30 12:47:30 +00:00
|
|
|
| _, None -> Lwt_result.return ()
|
|
|
|
| _, Some descr_v -> add_or_update descr_id descr_v) >>= fun () ->
|
2021-06-30 14:10:02 +00:00
|
|
|
(let readme =
|
|
|
|
List.find_opt (fun (p, _) -> Fpath.(equal (v "README.md") p)) raw_artifacts
|
|
|
|
in
|
|
|
|
let readme_anywhere =
|
|
|
|
List.find_opt (fun (p, _) -> String.equal "README.md" (Fpath.basename p)) raw_artifacts
|
|
|
|
in
|
|
|
|
match readme, readme_anywhere with
|
|
|
|
| None, None -> Lwt_result.return ()
|
|
|
|
| Some (_, data), _ | None, Some (_, data) -> add_or_update readme_id data) >>= fun () ->
|
2021-03-24 13:49:23 +00:00
|
|
|
List.fold_left
|
|
|
|
(fun r file ->
|
|
|
|
r >>= fun () ->
|
|
|
|
Db.exec Build_artifact.add (file, id))
|
|
|
|
(Lwt_result.return ())
|
|
|
|
artifacts >>= fun () ->
|
2021-06-02 10:29:08 +00:00
|
|
|
Db.collect_list Build_artifact.get_all_by_build id >>= fun artifacts ->
|
|
|
|
(match List.filter (fun (_, p) -> Fpath.(is_prefix (v "bin/") p.filepath)) artifacts with
|
|
|
|
| [ (build_artifact_id, _) ] -> Db.exec Build.set_main_binary (id, build_artifact_id)
|
|
|
|
| [] ->
|
|
|
|
Log.debug (fun m -> m "Zero binaries for build %a" Uuidm.pp uuid);
|
|
|
|
Lwt_result.return ()
|
|
|
|
| xs ->
|
|
|
|
Log.warn (fun m -> m "Multiple binaries for build %a: %a" Uuidm.pp uuid
|
|
|
|
Fmt.(list ~sep:(any ",") Fpath.pp)
|
|
|
|
(List.map (fun (_, a) -> a.filepath) xs));
|
|
|
|
Lwt_result.return ()) >>= fun () ->
|
2021-03-24 13:49:23 +00:00
|
|
|
Db.commit () >>= fun () ->
|
2021-06-01 15:43:55 +00:00
|
|
|
commit_files datadir staging_dir job_name uuid
|
2021-03-24 13:49:23 +00:00
|
|
|
in
|
2021-03-25 09:42:04 +00:00
|
|
|
Lwt_result.bind_lwt_err (or_cleanup r)
|
|
|
|
(fun e ->
|
|
|
|
Db.rollback ()
|
|
|
|
|> Lwt.map (fun r ->
|
|
|
|
Result.iter_error
|
|
|
|
(fun e' -> Log.err (fun m -> m "Failed rollback: %a" Caqti_error.pp e'))
|
|
|
|
r;
|
|
|
|
e))
|