Remove dkregistry crate
This commit is contained in:
parent
527d6f8fbf
commit
51ee4e5638
953
Cargo.lock
generated
953
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
@ -9,6 +9,8 @@ edition = "2021"
|
|||
axum = "0.6.1"
|
||||
maud = { git = "https://github.com/mhutter/maud", branch = "axum-0.6", features = ["axum"] }
|
||||
tokio = {version = "1.23.0", features = ["full"]}
|
||||
dkregistry = { git = "https://github.com/camallo/dkregistry-rs", features = ["reqwest-rustls"], default-features = false}
|
||||
futures = "0.3"
|
||||
axum-extra = { version = "0.4.2", features = ["spa"] }
|
||||
axum-extra = { version = "0.4.2", features = ["spa"] }
|
||||
reqwest = { version = "0.11", features = ["json"] }
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
serde_json = "1.0"
|
|
@ -27,6 +27,8 @@
|
|||
|
||||
buildInputs = [
|
||||
# Add additional build inputs here
|
||||
pkgs.openssl
|
||||
pkgs.pkg-config
|
||||
] ++ pkgs.lib.optionals pkgs.stdenv.isDarwin [
|
||||
# Additional darwin specific inputs can be set here
|
||||
pkgs.libiconv
|
||||
|
@ -71,6 +73,8 @@
|
|||
cargo
|
||||
rustc
|
||||
rust-analyzer
|
||||
openssl
|
||||
pkg-config
|
||||
];
|
||||
};
|
||||
});
|
||||
|
|
90
src/main.rs
90
src/main.rs
|
@ -1,23 +1,29 @@
|
|||
mod css;
|
||||
|
||||
use std::{boxed, error, env};
|
||||
use dkregistry::v2::Client;
|
||||
use std::{boxed, error, env, collections::{HashMap, self}};
|
||||
use maud::{html, Markup, DOCTYPE};
|
||||
use axum::{Router, routing::get, response::IntoResponse};
|
||||
use futures::{stream::StreamExt, future::join_all};
|
||||
use serde::{Serialize, Deserialize};
|
||||
|
||||
// To be expanded upon.
|
||||
#[derive(Debug)]
|
||||
struct Image {
|
||||
name: String,
|
||||
tags: Vec<Tag>,
|
||||
tags: Vec<RichTag>,
|
||||
}
|
||||
#[derive(Debug)]
|
||||
struct Tag {
|
||||
struct RichTag {
|
||||
name: String,
|
||||
architectures: Vec<String>
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
struct Tags {
|
||||
name: String,
|
||||
tags: Vec<String>
|
||||
}
|
||||
|
||||
#[tokio::main(flavor = "multi_thread", worker_threads = 10)]
|
||||
async fn main() {
|
||||
// build our application with a single route
|
||||
|
@ -68,16 +74,16 @@ async fn root() -> Markup {
|
|||
details {
|
||||
summary { (image.name) }
|
||||
ul {
|
||||
@for tag in &image.tags {
|
||||
li { (tag.name)
|
||||
div {
|
||||
@for arch in &tag.architectures {
|
||||
span { (arch) }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@for tag in &image.tags {
|
||||
li { (tag.name)
|
||||
// div {
|
||||
// @for arch in &tag.architectures {
|
||||
// span { (arch) }
|
||||
// }
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -89,41 +95,37 @@ async fn root() -> Markup {
|
|||
|
||||
async fn get_images() -> Result<Vec<Image>, boxed::Box<dyn error::Error>> {
|
||||
let host = env::var("DREF_REGISTRY").unwrap();
|
||||
let insecure_registry = env::var("DREF_REGISTRY_USE_SSL").unwrap() == "false";
|
||||
let dclient = Client::configure()
|
||||
.insecure_registry(insecure_registry)
|
||||
.registry(&host)
|
||||
.build()?;
|
||||
let catalog = dclient.get_catalog(None).collect::<Vec<_>>().await
|
||||
.into_iter()
|
||||
.map(Result::unwrap).collect::<Vec<String>>();
|
||||
let images: Vec<Image> = join_all(catalog.into_iter()
|
||||
.map(|img| async { Image{name: String::from(&img), tags: get_tags(img).await.unwrap() } })
|
||||
).await;
|
||||
let resp = reqwest::get(host + "/v2/_catalog")
|
||||
.await?
|
||||
.json::<HashMap<String, Vec<String>>>()
|
||||
.await?;
|
||||
let i = resp.get("repositories").unwrap().into_iter().map(|i| async {
|
||||
let tags = get_tags(i.to_string()).await;
|
||||
Image{
|
||||
name: i.to_string(),
|
||||
tags: tags.unwrap(),
|
||||
}
|
||||
});
|
||||
let images: Vec<Image> = futures::future::join_all(i).await;
|
||||
Ok(images)
|
||||
}
|
||||
|
||||
async fn get_tags(image: String) -> Result<Vec<Tag>, boxed::Box<dyn error::Error>> {
|
||||
async fn get_tags(image: String) -> Result<Vec<RichTag>, boxed::Box<dyn error::Error>> {
|
||||
let host = env::var("DREF_REGISTRY").unwrap();
|
||||
let insecure_registry = env::var("DREF_REGISTRY_USE_SSL").unwrap() == "false";
|
||||
let dclient = Client::configure()
|
||||
.insecure_registry(insecure_registry)
|
||||
.registry(&host)
|
||||
.build()?;
|
||||
let tags = dclient.get_tags(image.as_str(), None).collect::<Vec<_>>().await
|
||||
.into_iter()
|
||||
.map(Result::unwrap).collect::<Vec<String>>();
|
||||
let tags_complete: Vec<Tag> = join_all(tags.into_iter().map(|t| async { Tag{name: String::from(&t), architectures: get_platforms(&image, t).await.unwrap() }})).await;
|
||||
Ok(tags_complete)
|
||||
let resp: Tags = reqwest::get(host + "/v2/" + &image + "/tags/list")
|
||||
.await?
|
||||
.json::<Tags>()
|
||||
.await?;
|
||||
let i = resp.tags.into_iter().map(|i| async move {
|
||||
RichTag{
|
||||
name: i.to_string(),
|
||||
architectures: Vec::new(),
|
||||
}
|
||||
});
|
||||
let tags: Vec<RichTag> = futures::future::join_all(i).await;
|
||||
Ok(tags)
|
||||
}
|
||||
|
||||
async fn get_platforms(image: &String, tag: String) -> Result<Vec<String>, boxed::Box<dyn error::Error>> {
|
||||
let host = env::var("DREF_REGISTRY").unwrap();
|
||||
let insecure_registry = env::var("DREF_REGISTRY_USE_SSL").unwrap() == "false";
|
||||
let dclient = Client::configure()
|
||||
.insecure_registry(insecure_registry)
|
||||
.registry(&host)
|
||||
.build()?;
|
||||
let manifest = dclient.get_manifest(image.as_str(), tag.as_str()).await.unwrap();
|
||||
Ok(manifest.architectures().unwrap())
|
||||
todo!()
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue