Remove dkregistry crate

This commit is contained in:
Gabriel Simmer 2023-07-16 10:48:40 +01:00
parent 527d6f8fbf
commit 51ee4e5638
Signed by: arch
GPG key ID: C81B106D46C5B875
4 changed files with 502 additions and 551 deletions

953
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -9,6 +9,8 @@ edition = "2021"
axum = "0.6.1" axum = "0.6.1"
maud = { git = "https://github.com/mhutter/maud", branch = "axum-0.6", features = ["axum"] } maud = { git = "https://github.com/mhutter/maud", branch = "axum-0.6", features = ["axum"] }
tokio = {version = "1.23.0", features = ["full"]} tokio = {version = "1.23.0", features = ["full"]}
dkregistry = { git = "https://github.com/camallo/dkregistry-rs", features = ["reqwest-rustls"], default-features = false}
futures = "0.3" 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"

View file

@ -27,6 +27,8 @@
buildInputs = [ buildInputs = [
# Add additional build inputs here # Add additional build inputs here
pkgs.openssl
pkgs.pkg-config
] ++ pkgs.lib.optionals pkgs.stdenv.isDarwin [ ] ++ pkgs.lib.optionals pkgs.stdenv.isDarwin [
# Additional darwin specific inputs can be set here # Additional darwin specific inputs can be set here
pkgs.libiconv pkgs.libiconv
@ -71,6 +73,8 @@
cargo cargo
rustc rustc
rust-analyzer rust-analyzer
openssl
pkg-config
]; ];
}; };
}); });

View file

@ -1,23 +1,29 @@
mod css; mod css;
use std::{boxed, error, env}; use std::{boxed, error, env, collections::{HashMap, self}};
use dkregistry::v2::Client;
use maud::{html, Markup, DOCTYPE}; use maud::{html, Markup, DOCTYPE};
use axum::{Router, routing::get, response::IntoResponse}; use axum::{Router, routing::get, response::IntoResponse};
use futures::{stream::StreamExt, future::join_all}; use futures::{stream::StreamExt, future::join_all};
use serde::{Serialize, Deserialize};
// To be expanded upon. // To be expanded upon.
#[derive(Debug)] #[derive(Debug)]
struct Image { struct Image {
name: String, name: String,
tags: Vec<Tag>, tags: Vec<RichTag>,
} }
#[derive(Debug)] #[derive(Debug)]
struct Tag { struct RichTag {
name: String, name: String,
architectures: Vec<String> architectures: Vec<String>
} }
#[derive(Deserialize)]
struct Tags {
name: String,
tags: Vec<String>
}
#[tokio::main(flavor = "multi_thread", worker_threads = 10)] #[tokio::main(flavor = "multi_thread", worker_threads = 10)]
async fn main() { async fn main() {
// build our application with a single route // build our application with a single route
@ -68,16 +74,16 @@ async fn root() -> Markup {
details { details {
summary { (image.name) } summary { (image.name) }
ul { ul {
@for tag in &image.tags { @for tag in &image.tags {
li { (tag.name) li { (tag.name)
div { // div {
@for arch in &tag.architectures { // @for arch in &tag.architectures {
span { (arch) } // span { (arch) }
} // }
} // }
} }
} }
} }
} }
} }
} }
@ -89,41 +95,37 @@ async fn root() -> Markup {
async fn get_images() -> Result<Vec<Image>, boxed::Box<dyn error::Error>> { async fn get_images() -> Result<Vec<Image>, boxed::Box<dyn error::Error>> {
let host = env::var("DREF_REGISTRY").unwrap(); let host = env::var("DREF_REGISTRY").unwrap();
let insecure_registry = env::var("DREF_REGISTRY_USE_SSL").unwrap() == "false"; let resp = reqwest::get(host + "/v2/_catalog")
let dclient = Client::configure() .await?
.insecure_registry(insecure_registry) .json::<HashMap<String, Vec<String>>>()
.registry(&host) .await?;
.build()?; let i = resp.get("repositories").unwrap().into_iter().map(|i| async {
let catalog = dclient.get_catalog(None).collect::<Vec<_>>().await let tags = get_tags(i.to_string()).await;
.into_iter() Image{
.map(Result::unwrap).collect::<Vec<String>>(); name: i.to_string(),
let images: Vec<Image> = join_all(catalog.into_iter() tags: tags.unwrap(),
.map(|img| async { Image{name: String::from(&img), tags: get_tags(img).await.unwrap() } }) }
).await; });
let images: Vec<Image> = futures::future::join_all(i).await;
Ok(images) 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 host = env::var("DREF_REGISTRY").unwrap();
let insecure_registry = env::var("DREF_REGISTRY_USE_SSL").unwrap() == "false"; let resp: Tags = reqwest::get(host + "/v2/" + &image + "/tags/list")
let dclient = Client::configure() .await?
.insecure_registry(insecure_registry) .json::<Tags>()
.registry(&host) .await?;
.build()?; let i = resp.tags.into_iter().map(|i| async move {
let tags = dclient.get_tags(image.as_str(), None).collect::<Vec<_>>().await RichTag{
.into_iter() name: i.to_string(),
.map(Result::unwrap).collect::<Vec<String>>(); architectures: Vec::new(),
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 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>> { async fn get_platforms(image: &String, tag: String) -> Result<Vec<String>, boxed::Box<dyn error::Error>> {
let host = env::var("DREF_REGISTRY").unwrap(); todo!()
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())
} }