Add BUILDER_WEB_DATADIR env, fix bug

The builder-web commands now understand the BUILDER_WEB_DATADIR
environment variable which is used as --datadir.

During a change the transaction when vacuuming was committed twice which
is an error in sqlite. This was found during testing.
This commit is contained in:
Reynir Björnsson 2024-02-13 14:23:25 +01:00
parent 878acf002f
commit e96234488f
3 changed files with 22 additions and 21 deletions

View file

@ -244,23 +244,20 @@ let vacuum datadir (module Db : Caqti_blocking.CONNECTION) platform_opt job_id p
this is too verbose? *) this is too verbose? *)
Logs.info (fun m -> m "Job %s %a; not removing any builds" Logs.info (fun m -> m "Job %s %a; not removing any builds"
jobname pp_reason predicate); jobname pp_reason predicate);
let* () = List.fold_left (fun r (build_id, build) ->
List.fold_left (fun r (build_id, build) -> let* () = r in
let* () = r in let* () = Db.start () in
let* () = Db.start () in let* () = Db.exec defer_foreign_keys () in
let* () = Db.exec defer_foreign_keys () in match
match delete_build datadir (module Db) jobname build_id
delete_build datadir (module Db) jobname build_id build.Builder_db.Build.uuid
build.Builder_db.Build.uuid with
with | Ok () -> Db.commit ()
| Ok () -> Db.commit () | Error _ as e ->
| Error _ as e -> let* () = Db.rollback () in
let* () = Db.rollback () in e)
e) (Ok ())
(Ok ()) builds
builds
in
Db.commit ()
let vacuum () datadir platform_opt jobnames predicate = let vacuum () datadir platform_opt jobnames predicate =
let dbpath = datadir ^ "/builder.sqlite3" in let dbpath = datadir ^ "/builder.sqlite3" in
@ -838,15 +835,17 @@ let dbpath_new =
let datadir = let datadir =
let doc = "Data directory." in let doc = "Data directory." in
let env = Cmdliner.Cmd.Env.info "BUILDER_WEB_DATADIR" in
Cmdliner.Arg.(value & Cmdliner.Arg.(value &
opt dir Builder_system.default_datadir & opt dir Builder_system.default_datadir &
info ~doc ["datadir"; "d"]) info ~doc ~env ["datadir"; "d"])
let cachedir = let cachedir =
let doc = "Cache directory." in let doc = "Cache directory." in
let env = Cmdliner.Cmd.Env.info "BUILDER_WEB_CACHEDIR" in
Cmdliner.Arg.(value & Cmdliner.Arg.(value &
opt (some dir) None & opt (some dir) None &
info ~doc ["cachedir"]) info ~doc ~env ["cachedir"])
let jobname = let jobname =
let doc = "Jobname." in let doc = "Jobname." in

View file

@ -196,10 +196,11 @@ let ip_port : (Ipaddr.V4.t * int) Arg.conv =
let datadir = let datadir =
let doc = "data directory" in let doc = "data directory" in
let docv = "DATA_DIR" in let docv = "DATA_DIR" in
let env = Cmdliner.Cmd.Env.info "BUILDER_WEB_DATADIR" in
Arg.( Arg.(
value & value &
opt dir Builder_system.default_datadir & opt dir Builder_system.default_datadir &
info [ "d"; "datadir" ] ~doc ~docv info ~env [ "d"; "datadir" ] ~doc ~docv
) )
let cachedir = let cachedir =

View file

@ -61,9 +61,10 @@ let help man_format migrations = function
let datadir = let datadir =
let doc = "data directory containing builder.sqlite3 and data files" in let doc = "data directory containing builder.sqlite3 and data files" in
let env = Cmdliner.Cmd.Env.info "BUILDER_WEB_DATADIR" in
Cmdliner.Arg.(value & Cmdliner.Arg.(value &
opt dir Builder_system.default_datadir & opt dir Builder_system.default_datadir &
info ~doc ["datadir"; "d"]) info ~env ~doc ["datadir"; "d"])
let setup_log = let setup_log =
let setup_log level = let setup_log level =