-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
separate sandboxing from base image fetching
- Loading branch information
1 parent
9ea4466
commit be83721
Showing
13 changed files
with
78 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
open Lwt.Infix | ||
|
||
let export_env base : Config.env Lwt.t = | ||
Os.pread ["docker"; "image"; "inspect"; | ||
"--format"; {|{{range .Config.Env}}{{print . "\x00"}}{{end}}|}; | ||
"--"; base] >|= fun env -> | ||
String.split_on_char '\x00' env | ||
|> List.filter_map (function | ||
| "\n" -> None | ||
| kv -> | ||
match Astring.String.cut ~sep:"=" kv with | ||
| None -> Fmt.failwith "Invalid environment in Docker image %S (should be 'K=V')" kv | ||
| Some _ as pair -> pair | ||
) | ||
|
||
let with_container ~log base fn = | ||
Os.with_pipe_from_child (fun ~r ~w -> | ||
(* We might need to do a pull here, so log the output to show progress. *) | ||
let copy = Build_log.copy ~src:r ~dst:log in | ||
Os.pread ~stderr:(`FD_move_safely w) ["docker"; "create"; "--"; base] >>= fun cid -> | ||
copy >|= fun () -> | ||
String.trim cid | ||
) >>= fun cid -> | ||
Lwt.finalize | ||
(fun () -> fn cid) | ||
(fun () -> Os.exec ~stdout:`Dev_null ["docker"; "rm"; "--"; cid]) | ||
|
||
|
||
let fetch ~log ~rootfs base = | ||
with_container ~log base (fun cid -> | ||
Os.with_pipe_between_children @@ fun ~r ~w -> | ||
let exporter = Os.exec ~stdout:(`FD_move_safely w) ["docker"; "export"; "--"; cid] in | ||
let tar = Os.sudo ~stdin:(`FD_move_safely r) ["tar"; "-C"; rootfs; "-xf"; "-"] in | ||
exporter >>= fun () -> | ||
tar | ||
) >>= fun () -> | ||
export_env base |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
(** Fetching of base images using Docker *) | ||
|
||
include S.FETCHER |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters