Skip to content

Commit

Permalink
feat: read image blob config
Browse files Browse the repository at this point in the history
  • Loading branch information
frectonz committed Oct 6, 2024
1 parent 5a995e5 commit 5e35212
Show file tree
Hide file tree
Showing 2 changed files with 124 additions and 69 deletions.
104 changes: 52 additions & 52 deletions ui/elm-srcs.nix
Original file line number Diff line number Diff line change
@@ -1,67 +1,67 @@
{

"basti1302/elm-human-readable-filesize" = {
sha256 = "182hjyji8hj5zzn81f676p83fa15dxq5fgqq9li384qk33m5sh05";
version = "1.2.0";
};
"basti1302/elm-human-readable-filesize" = {
sha256 = "182hjyji8hj5zzn81f676p83fa15dxq5fgqq9li384qk33m5sh05";
version = "1.2.0";
};

"elm/browser" = {
sha256 = "0nagb9ajacxbbg985r4k9h0jadqpp0gp84nm94kcgbr5sf8i9x13";
version = "1.0.2";
};
"elm/browser" = {
sha256 = "0nagb9ajacxbbg985r4k9h0jadqpp0gp84nm94kcgbr5sf8i9x13";
version = "1.0.2";
};

"elm/core" = {
sha256 = "19w0iisdd66ywjayyga4kv2p1v9rxzqjaxhckp8ni6n8i0fb2dvf";
version = "1.0.5";
};
"elm/core" = {
sha256 = "19w0iisdd66ywjayyga4kv2p1v9rxzqjaxhckp8ni6n8i0fb2dvf";
version = "1.0.5";
};

"elm/html" = {
sha256 = "1n3gpzmpqqdsldys4ipgyl1zacn0kbpc3g4v3hdpiyfjlgh8bf3k";
version = "1.0.0";
};
"elm/html" = {
sha256 = "1n3gpzmpqqdsldys4ipgyl1zacn0kbpc3g4v3hdpiyfjlgh8bf3k";
version = "1.0.0";
};

"elm/http" = {
sha256 = "008bs76mnp48b4dw8qwjj4fyvzbxvlrl4xpa2qh1gg2kfwyw56v1";
version = "2.0.0";
};
"elm/http" = {
sha256 = "008bs76mnp48b4dw8qwjj4fyvzbxvlrl4xpa2qh1gg2kfwyw56v1";
version = "2.0.0";
};

"elm/json" = {
sha256 = "0kjwrz195z84kwywaxhhlnpl3p251qlbm5iz6byd6jky2crmyqyh";
version = "1.1.3";
};
"elm/json" = {
sha256 = "0kjwrz195z84kwywaxhhlnpl3p251qlbm5iz6byd6jky2crmyqyh";
version = "1.1.3";
};

"elm/url" = {
sha256 = "0av8x5syid40sgpl5vd7pry2rq0q4pga28b4yykn9gd9v12rs3l4";
version = "1.0.0";
};
"elm/url" = {
sha256 = "0av8x5syid40sgpl5vd7pry2rq0q4pga28b4yykn9gd9v12rs3l4";
version = "1.0.0";
};

"elm/bytes" = {
sha256 = "02ywbf52akvxclpxwj9n04jydajcbsbcbsnjs53yjc5lwck3abwj";
version = "1.0.8";
};
"elm/bytes" = {
sha256 = "02ywbf52akvxclpxwj9n04jydajcbsbcbsnjs53yjc5lwck3abwj";
version = "1.0.8";
};

"elm/file" = {
sha256 = "1rljcb41dl97myidyjih2yliyzddkr2m7n74x7gg46rcw4jl0ny8";
version = "1.0.5";
};
"elm/file" = {
sha256 = "1rljcb41dl97myidyjih2yliyzddkr2m7n74x7gg46rcw4jl0ny8";
version = "1.0.5";
};

"elm/regex" = {
sha256 = "0lijsp50w7n1n57mjg6clpn9phly8vvs07h0qh2rqcs0f1jqvsa2";
version = "1.0.0";
};
"elm/regex" = {
sha256 = "0lijsp50w7n1n57mjg6clpn9phly8vvs07h0qh2rqcs0f1jqvsa2";
version = "1.0.0";
};

"elm/time" = {
sha256 = "0vch7i86vn0x8b850w1p69vplll1bnbkp8s383z7pinyg94cm2z1";
version = "1.0.0";
};
"elm/time" = {
sha256 = "0vch7i86vn0x8b850w1p69vplll1bnbkp8s383z7pinyg94cm2z1";
version = "1.0.0";
};

"elm/virtual-dom" = {
sha256 = "1yvb8px2z62xd578ag2q0r5hd1vkz9y7dfkx05355iiy1d7jwq4v";
version = "1.0.3";
};
"elm/virtual-dom" = {
sha256 = "1yvb8px2z62xd578ag2q0r5hd1vkz9y7dfkx05355iiy1d7jwq4v";
version = "1.0.3";
};

"myrho/elm-round" = {
sha256 = "0zv0a60wzkx4xib7h07ijcg72mcyb3vb914hk5pjp6rf4k2lv9kj";
version = "1.0.5";
};
"myrho/elm-round" = {
sha256 = "0zv0a60wzkx4xib7h07ijcg72mcyb3vb914hk5pjp6rf4k2lv9kj";
version = "1.0.5";
};
}
89 changes: 72 additions & 17 deletions ui/src/Main.elm
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ type Route
type Page
= HomePage (RemoteData Catalog)
| SingleRepoPage String (RemoteData Repository)
| ImagePage String (RemoteData Image)
| ImagePage String String (RemoteData Image) (RemoteData ImageBlob)


type RemoteData value
Expand Down Expand Up @@ -89,6 +89,13 @@ type alias ImageDigest =
}


type alias ImageBlob =
{ architecture : String
, os : String
, cmd : List String
}


init : Metadata -> Url.Url -> Nav.Key -> ( Model, Cmd Msg )
init meta url key =
let
Expand All @@ -106,7 +113,7 @@ init meta url key =
SingleRepoPage name Loading

Tag (Just repo) (Just tag) ->
ImagePage (repo ++ ":" ++ tag) Loading
ImagePage repo tag Loading Loading

_ ->
HomePage Loading
Expand Down Expand Up @@ -136,6 +143,7 @@ type Msg
| GotCatalog (Result Http.Error Catalog)
| GotRepository (Result Http.Error Repository)
| GotImage (Result Http.Error Image)
| GotImageBlob (Result Http.Error ImageBlob)


update : Msg -> Model -> ( Model, Cmd Msg )
Expand Down Expand Up @@ -166,7 +174,7 @@ update msg model =
( Repo _, SingleRepoPage _ _ ) ->
False

( Tag _ _, ImagePage _ _ ) ->
( Tag _ _, ImagePage _ _ _ _ ) ->
False

_ ->
Expand Down Expand Up @@ -194,13 +202,21 @@ update msg model =
Err _ ->
( { model | page = SingleRepoPage name Failure }, Cmd.none )

( GotImage result, ImagePage name _ ) ->
( GotImage result, ImagePage repo tag _ blob ) ->
case result of
Ok image ->
( { model | page = ImagePage name (Success image) }, Cmd.none )
( { model | page = ImagePage repo tag (Success image) blob }, getImageBlob repo image.config.digest )

Err _ ->
( { model | page = ImagePage repo tag Failure blob }, Cmd.none )

( GotImageBlob result, ImagePage repo tag imageData _ ) ->
case result of
Ok blob ->
( { model | page = ImagePage repo tag imageData (Success blob) }, Cmd.none )

Err _ ->
( { model | page = ImagePage name Failure }, Cmd.none )
( { model | page = ImagePage repo tag imageData Failure }, Cmd.none )

_ ->
( model, Cmd.none )
Expand Down Expand Up @@ -237,7 +253,7 @@ view model =
SingleRepoPage _ (Success repo) ->
"Found " ++ (repo.tags |> List.length |> String.fromInt) ++ pluralize " tag" " tags" (repo.tags |> List.length)

ImagePage _ (Success image) ->
ImagePage _ _ (Success image) _ ->
"Found " ++ (image.layers |> List.length |> String.fromInt) ++ pluralize " layer" " layers" (image.layers |> List.length)

_ ->
Expand All @@ -255,8 +271,8 @@ view model =
SingleRepoPage name data ->
viewSingleRepoPage name data

ImagePage name data ->
viewImagePage name data
ImagePage repo tag data blob ->
viewImagePage (repo ++ ":" ++ tag) data blob
)
}

Expand Down Expand Up @@ -350,14 +366,14 @@ viewRepoDetails data =
)


viewImagePage : String -> RemoteData Image -> List (Html msg)
viewImagePage name data =
viewImagePage : String -> RemoteData Image -> RemoteData ImageBlob -> List (Html msg)
viewImagePage name data blob =
viewPageTitle name
:: viewImageDetail data
:: viewImageDetail data blob


viewImageDetail : RemoteData Image -> List (Html msg)
viewImageDetail data =
viewImageDetail : RemoteData Image -> RemoteData ImageBlob -> List (Html msg)
viewImageDetail data blob =
case data of
Loading ->
[ section [ class "loading__title" ] [ h1 [] [ text "Loading..." ] ] ]
Expand All @@ -384,15 +400,38 @@ viewImageDetail data =
)
)
, div [ class "metadata" ]
[ div []
([ div []
[ h2 [] [ text "Image Digest" ]
, p [] [ text image.config.digest ]
]
, div []
, div []
[ h2 [] [ text "Image Size" ]
, p [] [ size |> Filesize.format |> text ]
]
]
]
++ (case blob of
Loading ->
[]

Failure ->
[]

Success blobData ->
[ div []
[ h2 [] [ text "Architecture" ]
, p [] [ text blobData.architecture ]
]
, div []
[ h2 [] [ text "OS" ]
, p [] [ text blobData.os ]
]
, div []
[ h2 [] [ text "CMD" ]
, p [] [ blobData.cmd |> String.join " " |> text ]
]
]
)
)
]
]

Expand Down Expand Up @@ -455,6 +494,22 @@ decodeImageDigest =
(Decode.field "size" Decode.int)


getImageBlob : String -> String -> Cmd Msg
getImageBlob repo blobDigest =
Http.get
{ url = "/api/v2/" ++ repo ++ "/blobs/" ++ blobDigest
, expect = Http.expectJson GotImageBlob decodeImageBlob
}


decodeImageBlob : Decoder ImageBlob
decodeImageBlob =
Decode.map3 ImageBlob
(Decode.field "architecture" Decode.string)
(Decode.field "os" Decode.string)
(Decode.field "config" (Decode.field "Cmd" (Decode.list Decode.string)))



-- ROUTES

Expand Down

0 comments on commit 5e35212

Please sign in to comment.