Skip to content

Commit

Permalink
container-image: only_rootfs means top layer
Browse files Browse the repository at this point in the history
  • Loading branch information
patricoferris committed Mar 29, 2024
1 parent 7bcbe32 commit c6ea333
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 18 deletions.
16 changes: 10 additions & 6 deletions lib/container_image_extract.ml
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,22 @@ end) = struct
let config =
Ci.Cache.Blob.get_string cache (Descriptor.digest config)
|> Config.of_string ~media_type:Media_type.(Docker Docker.Image_config)
|> Result.get_ok
in
Config.env config
match config with
| Ok config -> Config.env config
| Error (`Msg m) -> failwith m
in
let of_docker_manifest (docker_manifest : Manifest.Docker.t) =
let config = Manifest.Docker.config docker_manifest in
let config =
let config_str =
Ci.Cache.Blob.get_string cache (Descriptor.digest config)
|> Config.of_string ~media_type:Media_type.(Docker Docker.Image_config)
|> Result.get_ok
in
Config.env config
let config =
config_str |> Config.of_string ~media_type:Media_type.(Docker Docker.Image_config)
in
match config with
| Ok config -> Config.env config
| Error (`Msg m) -> failwith (m ^ " : " ^ config_str)
in
match (v : Manifest.t) with
| `Docker_manifest_list _ -> (
Expand Down
21 changes: 12 additions & 9 deletions vendor/container-image/src/checkout.ml
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,14 @@ let checkout_layer ~sw ~cache layer dir =
)
fd ()

let checkout_layers ~sw ~cache ~dir layers =
let checkout_layers ?(top_layer=false) ~sw ~cache ~dir layers =
match layers with
| [ layer ] ->
let d = Descriptor.digest layer in
checkout_layer ~sw ~cache d dir
| layer :: _ when top_layer ->
let d = Descriptor.digest layer in
checkout_layer ~sw ~cache d dir
| layers ->
List.iteri
(fun i layer ->
Expand All @@ -75,13 +78,13 @@ let checkout_layers ~sw ~cache ~dir layers =
checkout_layer ~sw ~cache d dir)
layers

let checkout_docker_manifest ~sw ~cache ~dir m =
checkout_layers ~sw ~cache ~dir (Manifest.Docker.layers m)
let checkout_docker_manifest ?(only_rootfs=false) ~sw ~cache ~dir m =
checkout_layers ~top_layer:only_rootfs ~sw ~cache ~dir (Manifest.Docker.layers m)

let checkout_oci_manifest ~sw ~cache ~dir m =
checkout_layers ~sw ~cache ~dir (Manifest.OCI.layers m)

let checkout_docker_manifests ~sw ~cache ~dir img ds =
let checkout_docker_manifests ?(only_rootfs=false) ~sw ~cache ~dir img ds =
let ms =
List.map
(fun d ->
Expand All @@ -96,7 +99,7 @@ let checkout_docker_manifests ~sw ~cache ~dir img ds =
List.iteri
(fun i m ->
let dir = dir / string_of_int i in
checkout_docker_manifest ~sw ~cache ~dir m)
checkout_docker_manifest ~only_rootfs ~sw ~cache ~dir m)
ms

let checkout_oci_manifests ~sw ~cache ~dir ds =
Expand All @@ -116,8 +119,8 @@ let checkout_oci_manifests ~sw ~cache ~dir ds =
checkout_oci_manifest ~sw ~cache ~dir m)
ms

let checkout_docker_manifest_list ~sw ~cache ~dir img l =
checkout_docker_manifests ~sw ~cache ~dir img (Manifest_list.manifests l)
let checkout_docker_manifest_list ?only_rootfs ~sw ~cache ~dir img l =
checkout_docker_manifests ?only_rootfs ~sw ~cache ~dir img (Manifest_list.manifests l)

let checkout_oci_index ~sw ~cache ~dir i =
checkout_oci_manifests ~sw ~cache ~dir (Index.manifests i)
Expand All @@ -128,8 +131,8 @@ let checkout ?(only_rootfs=false) ~cache ~root i =
in
Eio.Switch.run @@ fun sw ->
match Cache.Manifest.get cache i with
| `Docker_manifest m -> checkout_docker_manifest ~sw ~cache ~dir m
| `Docker_manifest m -> checkout_docker_manifest ~only_rootfs ~sw ~cache ~dir m
| `Docker_manifest_list m ->
checkout_docker_manifest_list ~sw ~cache ~dir (Image.repository i) m
checkout_docker_manifest_list ~only_rootfs ~sw ~cache ~dir (Image.repository i) m
| `OCI_index i -> checkout_oci_index ~sw ~cache ~dir i
| `OCI_manifest m -> checkout_oci_manifest ~sw ~cache ~dir m
6 changes: 3 additions & 3 deletions vendor/container-image/src/spec/config.ml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ module Docker = struct
args_escaped : bool option; [@key "ArgsEscaped"] [@default None]
image : string option; [@key "Image"] [@default None]
volumes : set; [@key "Volumes"] [@default []]
working_dir : string; [@key "WorkingDir"]
working_dir : string option; [@key "WorkingDir"] [@default None]
entrypoint : string list option; [@key "Entrypoint"] [@default None]
network_disabled : bool; [@key "NetworkDisabled"] [@default false]
mac_address : string option; [@key "MacAddress"] [@default None]
Expand All @@ -89,7 +89,7 @@ module Docker = struct
stop_timeout : int option; [@key "StopTimeout"] [@default None]
shell : string list; [@key "Shell"] [@default []]
}
[@@deriving yojson]
[@@deriving yojson { strict = false }]

type rootfs = { type_ : string; [@key "type"] diff_ids : Digest.t list }
[@@deriving yojson]
Expand Down Expand Up @@ -127,7 +127,7 @@ module Docker = struct
rootfs : rootfs;
history : history list; [@default []]
}
[@@deriving yojson]
[@@deriving yojson { strict = false }]

let pp ppf t = pp_json ppf (to_yojson t)

Expand Down

0 comments on commit c6ea333

Please sign in to comment.