-
Notifications
You must be signed in to change notification settings - Fork 18
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
Purge Obuilder Docker store when Docker is pruned #242
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -220,7 +220,7 @@ let check_docker_partition t = | |||||||||||||||||||
if max_df_size < gb then Error `Disk_space_low | ||||||||||||||||||||
else Ok () | ||||||||||||||||||||
|
||||||||||||||||||||
let rec maybe_prune t queue = | ||||||||||||||||||||
let rec maybe_prune obuilder t queue = | ||||||||||||||||||||
check_docker_partition t >>= function | ||||||||||||||||||||
| Ok () -> Lwt.return_unit | ||||||||||||||||||||
| Error `Disk_space_low -> | ||||||||||||||||||||
|
@@ -236,6 +236,13 @@ let rec maybe_prune t queue = | |||||||||||||||||||
(fun () -> | ||||||||||||||||||||
Lwt_process.exec ("", [| "docker"; "system"; "prune"; "-af" |]) >>= function | ||||||||||||||||||||
| Unix.WEXITED 0 -> | ||||||||||||||||||||
(match obuilder with | ||||||||||||||||||||
| None -> Lwt.return 0 | ||||||||||||||||||||
| Some obuilder -> | ||||||||||||||||||||
match Obuilder_build.backend obuilder with | ||||||||||||||||||||
| `Native _ -> Lwt.return 0 | ||||||||||||||||||||
| `Docker _ -> Obuilder_build.purge obuilder) >>= fun n -> | ||||||||||||||||||||
Comment on lines
+239
to
+244
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If my suggestion about keeping the sandbox configuration type private makes sense, then this could be something like
Suggested change
|
||||||||||||||||||||
Log.info (fun f -> f "%i items prune from Obuilder" n); | ||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||
Lwt_process.exec ("", [| "docker"; "builder"; "prune"; "-af" |]) | ||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this is out of scope for your changes, but seems worth clarifying any how: According to https://docs.docker.com/reference/cli/docker/builder/prune/, this will
Whereas, according to https://docs.docker.com/reference/cli/docker/system/prune/,
Based on the warning in the docks, this includes all
So I'm wondering whether we actually need this additional step, or if |
||||||||||||||||||||
| e -> Lwt.return e | ||||||||||||||||||||
) | ||||||||||||||||||||
|
@@ -249,12 +256,12 @@ let rec maybe_prune t queue = | |||||||||||||||||||
| Error `Disk_space_low -> | ||||||||||||||||||||
Log.warn (fun f -> f "Disk-space still low after pruning! Will retry in one hour."); | ||||||||||||||||||||
Unix.sleep (60 * 60); | ||||||||||||||||||||
maybe_prune t queue | ||||||||||||||||||||
maybe_prune obuilder t queue | ||||||||||||||||||||
end | ||||||||||||||||||||
| _ -> | ||||||||||||||||||||
Log.warn (fun f -> f "docker prune command failed! Will retry in one hour."); | ||||||||||||||||||||
Unix.sleep (60 * 60); | ||||||||||||||||||||
maybe_prune t queue | ||||||||||||||||||||
maybe_prune obuilder t queue | ||||||||||||||||||||
|
||||||||||||||||||||
let healthcheck obuilder = | ||||||||||||||||||||
let t0 = Unix.gettimeofday () in | ||||||||||||||||||||
|
@@ -306,7 +313,7 @@ let loop ~switch ?obuilder t queue = | |||||||||||||||||||
Log.info (fun f -> f "At capacity. Waiting for a build to finish before requesting more…"); | ||||||||||||||||||||
Lwt_condition.wait t.cond >>= loop | ||||||||||||||||||||
) else ( | ||||||||||||||||||||
maybe_prune t queue >>= fun () -> | ||||||||||||||||||||
maybe_prune obuilder t queue >>= fun () -> | ||||||||||||||||||||
check_health t ~last_healthcheck ~queue obuilder >>= fun () -> | ||||||||||||||||||||
let outcome, set_outcome = Lwt.wait () in | ||||||||||||||||||||
let log = Log_data.create () in | ||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -21,6 +21,8 @@ type t = { | |||||||
prune_threshold : float option; | ||||||||
prune_item_threshold : int64 option; (* Threshold number of items to hold in obuilder store *) | ||||||||
prune_limit : int option; (* Number of items to prune from obuilder when threshold is reached *) | ||||||||
sandbox_config : [ `Native of Obuilder.Native_sandbox.config | ||||||||
| `Docker of Obuilder.Docker_sandbox.config ] | ||||||||
} | ||||||||
|
||||||||
let ( / ) = Filename.concat | ||||||||
|
@@ -65,6 +67,7 @@ let create ?prune_threshold ?prune_item_threshold ?prune_limit config = | |||||||
prune_item_threshold; | ||||||||
prune_limit; | ||||||||
cond = Lwt_condition.create (); | ||||||||
sandbox_config; | ||||||||
} | ||||||||
|
||||||||
(* Prune [t] until free space rises above [prune_threshold] | ||||||||
|
@@ -143,3 +146,13 @@ let healthcheck t = | |||||||
let cache_stats t = | ||||||||
let Builder ((module Builder), builder) = t.builder in | ||||||||
Builder.cache_stats builder | ||||||||
|
||||||||
let purge t = | ||||||||
let Builder ((module Builder), builder) = t.builder in | ||||||||
let before = Unix.gettimeofday () +. prune_margin |> Unix.gmtime in | ||||||||
(* set a future time and a big number to ensure everything is deleted *) | ||||||||
Builder.prune builder ~before Int.max_int >>= fun n -> | ||||||||
Lwt.return n | ||||||||
Comment on lines
+154
to
+155
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
|
||||||||
let backend t = | ||||||||
t.sandbox_config | ||||||||
Comment on lines
+157
to
+158
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. iiuc, the only use of this accessor is at https://github.com/ocurrent/ocluster/pull/242/files#diff-5b7638a06391f25c3c893df03fe8754d5c0702dfc2aa4e12c7881dcf077e106eR244 to classify the kind of configuration being used, which then let's us decide whether to actually call |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,3 +20,7 @@ val build : t -> | |
val healthcheck : t -> (unit, [> `Msg of string]) Lwt_result.t | ||
|
||
val cache_stats : t -> int * int | ||
|
||
val purge : t -> int Lwt.t | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A dock comment explaining what this is meant to be used for would be helpful. |
||
|
||
val backend : t -> [`Native of Obuilder.Native_sandbox.config | `Docker of Obuilder.Docker_sandbox.config ] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given that we are just ignoring the values wrapped in the
Native | Docker
tags here, why do we need to expose them in theBoulder_build
API at all?