Skip to content

Commit

Permalink
Merge branch 'sergi0g:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
steveiliop56 authored Sep 3, 2024
2 parents 2926bc0 + b0eff24 commit b8f86be
Show file tree
Hide file tree
Showing 41 changed files with 724 additions and 562 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
/docs/.next
/docs/node_modules
/docs/out
/src/static

# In case I accidentally commit mine...
cup.json
152 changes: 0 additions & 152 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ tokio = {version = "1.38.0", features = ["rt", "rt-multi-thread", "macros"]}
ureq = { version = "2.9.7", features = ["tls"] }
rayon = "1.10.0"
xitca-web = { version = "0.5.0", optional = true, features = ["logger"] }
liquid = { version = "0.26.6", optional = true }
bollard = "0.16.1"
once_cell = "1.19.0"
http-auth = { version = "0.1.9", features = [] }
Expand All @@ -21,7 +20,7 @@ json = "0.12.4"

[features]
default = ["server", "cli"]
server = ["dep:xitca-web", "dep:liquid", "dep:chrono"]
server = ["dep:xitca-web", "dep:chrono"]
cli = ["dep:indicatif", "dep:termsize"]

[profile.release]
Expand Down
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ Here are some ideas to get you started:

To contribute, fork the repository, make your changes and the submit a pull request.

Note: If you update the UI, please make sure to recompile the CSS with `tailwindcss -mo src/static/index.css`. You need to have the Tailwind CSS CLI installed ([instructions here](https://tailwindcss.com/docs/installation))

## Support

If you have any questions about Cup, feel free to ask in the [discussions](https://github.com/sergi0g/cup/discussions)!
Expand Down
7 changes: 7 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/sh

rm -rf src/static
cd web/
bun run build
cp -r dist/ ../src/static
cargo build $@
31 changes: 24 additions & 7 deletions src/check.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
use std::{collections::{HashMap, HashSet}, sync::Mutex};
use std::{
collections::{HashMap, HashSet},
sync::Mutex,
};

use rayon::iter::{IntoParallelRefIterator, ParallelIterator};
use json::JsonValue;
use rayon::iter::{IntoParallelRefIterator, ParallelIterator};

use crate::{docker::get_images_from_docker_daemon, image::Image, registry::{check_auth, get_token, get_latest_digests}, utils::unsplit_image};
use crate::{
docker::get_images_from_docker_daemon,
image::Image,
registry::{check_auth, get_latest_digests, get_token},
utils::unsplit_image,
};

#[cfg(feature = "cli")]
use crate::docker::get_image_from_docker_daemon;
Expand All @@ -25,7 +33,10 @@ where
}
}

pub async fn get_all_updates(socket: Option<String>, config: &JsonValue) -> Vec<(String, Option<bool>)> {
pub async fn get_all_updates(
socket: Option<String>,
config: &JsonValue,
) -> Vec<(String, Option<bool>)> {
let image_map_mutex: Mutex<HashMap<String, &Option<String>>> = Mutex::new(HashMap::new());
let local_images = get_images_from_docker_daemon(socket).await;
local_images.par_iter().for_each(|image| {
Expand All @@ -44,7 +55,10 @@ pub async fn get_all_updates(socket: Option<String>, config: &JsonValue) -> Vec<
.par_iter()
.filter(|image| &image.registry == registry)
.collect();
let credentials = config["authentication"][registry].clone().take_string().or(None);
let credentials = config["authentication"][registry]
.clone()
.take_string()
.or(None);
let mut latest_images = match check_auth(registry, config) {
Some(auth_url) => {
let token = get_token(images.clone(), &auth_url, &credentials);
Expand Down Expand Up @@ -72,7 +86,10 @@ pub async fn get_all_updates(socket: Option<String>, config: &JsonValue) -> Vec<
#[cfg(feature = "cli")]
pub async fn get_update(image: &str, socket: Option<String>, config: &JsonValue) -> Option<bool> {
let local_image = get_image_from_docker_daemon(socket, image).await;
let credentials = config["authentication"][&local_image.registry].clone().take_string().or(None);
let credentials = config["authentication"][&local_image.registry]
.clone()
.take_string()
.or(None);
let token = match check_auth(&local_image.registry, config) {
Some(auth_url) => get_token(vec![&local_image], &auth_url, &credentials),
None => String::new(),
Expand All @@ -85,4 +102,4 @@ pub async fn get_update(image: &str, socket: Option<String>, config: &JsonValue)
Some(d) => Some(d != &local_image.digest.unwrap()),
None => None,
}
}
}
5 changes: 1 addition & 4 deletions src/docker.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
use bollard::{
secret::ImageSummary,
ClientVersion, Docker,
};
use bollard::{secret::ImageSummary, ClientVersion, Docker};

#[cfg(feature = "cli")]
use bollard::secret::ImageInspect;
Expand Down
2 changes: 1 addition & 1 deletion src/formatting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ pub fn print_update(name: &str, has_update: &Option<bool>) {
}

pub fn print_raw_update(name: &str, has_update: &Option<bool>) {
let result = object! {images: {[name]: *has_update}} ;
let result = object! {images: {[name]: *has_update}};
println!("{}", result);
}

Expand Down
10 changes: 5 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
#[cfg(feature = "cli")]
use check::{get_all_updates, get_update};
use clap::{Parser, Subcommand};
#[cfg(feature = "cli")]
use formatting::{print_raw_update, print_raw_updates, print_update, print_updates, Spinner};
#[cfg(feature = "cli")]
use check::{get_all_updates, get_update};
#[cfg(feature = "server")]
use server::serve;
use std::path::PathBuf;
use utils::load_config;

pub mod check;
pub mod docker;
pub mod image;
pub mod registry;
pub mod utils;
#[cfg(feature = "cli")]
pub mod formatting;
pub mod image;
pub mod registry;
#[cfg(feature = "server")]
pub mod server;
pub mod utils;

#[derive(Parser)]
#[command(version, about, long_about = None)]
Expand Down
Loading

0 comments on commit b8f86be

Please sign in to comment.