Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an obuilder clean command to clean all build results #140

Merged
merged 1 commit into from
Jan 31, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,16 @@ let delete () store conf id =
Builder.delete builder id ~log:(fun id -> Fmt.pr "Removing %s@." id)
end

let clean () store conf =
Lwt_main.run begin
create_builder store conf >>= fun (Builder ((module Builder), builder)) ->
Fun.flip Lwt.finalize (fun () -> Builder.finish builder) @@ begin fun () ->
let now = Unix.(gmtime (gettimeofday ())) in
Builder.prune builder ~before:now max_int ~log:(fun id -> Fmt.pr "Removing %s@." id)
end >|= fun n ->
Fmt.pr "Removed %d items@." n
end

let dockerfile () buildkit escape spec =
Sexplib.Sexp.load_sexp spec
|> Obuilder_spec.t_of_sexp
Expand Down Expand Up @@ -135,6 +145,12 @@ let delete =
Cmd.v info
Term.(const delete $ setup_log $ store $ Obuilder.Sandbox.cmdliner $ id)

let clean =
let doc = "Clean all cached build results." in
let info = Cmd.info "clean" ~doc in
Cmd.v info
Term.(const clean $ setup_log $ store $ Obuilder.Sandbox.cmdliner)

let buildkit =
Arg.value @@
Arg.flag @@
Expand Down Expand Up @@ -163,7 +179,7 @@ let healthcheck =
Cmd.v info
Term.(const healthcheck $ setup_log $ store $ Obuilder.Sandbox.cmdliner)

let cmds = [build; delete; dockerfile; healthcheck]
let cmds = [build; delete; clean; dockerfile; healthcheck]

let () =
let doc = "a command-line interface for OBuilder" in
Expand Down