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"
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"] }
reqwest = { version = "0.11", features = ["json"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"

View file

@ -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
];
};
});

View file

@ -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
@ -70,11 +76,11 @@ async fn root() -> Markup {
ul {
@for tag in &image.tags {
li { (tag.name)
div {
@for arch in &tag.architectures {
span { (arch) }
}
}
// 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!()
}