Compare commits
4 Commits
13350f872a
...
8ab2690d17
Author | SHA1 | Date | |
---|---|---|---|
|
8ab2690d17 | ||
|
8363896052 | ||
|
22429ac74b | ||
|
8f0eb3db4f |
@ -20,7 +20,7 @@ pipeline:
|
||||
# http://plugins.drone.io/drone-plugins/drone-github-release/
|
||||
image: plugins/github-release
|
||||
files: target/release/reel-moby
|
||||
secrets: [github_release_api_key]
|
||||
secrets: [github_api_key]
|
||||
when:
|
||||
event: tag
|
||||
tag: v*
|
||||
|
28
Cargo.lock
generated
28
Cargo.lock
generated
@ -20,6 +20,12 @@ dependencies = [
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "anyhow"
|
||||
version = "1.0.59"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c91f1f46651137be86f3a2b9a8359f9ab421d04d941c62b5982e1ca21113adf9"
|
||||
|
||||
[[package]]
|
||||
name = "atty"
|
||||
version = "0.2.14"
|
||||
@ -675,6 +681,7 @@ dependencies = [
|
||||
name = "reel-moby"
|
||||
version = "1.2.1"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"chrono",
|
||||
"lazy_static",
|
||||
"regex",
|
||||
@ -683,6 +690,7 @@ dependencies = [
|
||||
"serde_json",
|
||||
"structopt",
|
||||
"termion",
|
||||
"thiserror",
|
||||
"tui",
|
||||
]
|
||||
|
||||
@ -921,6 +929,26 @@ dependencies = [
|
||||
"unicode-width",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thiserror"
|
||||
version = "1.0.32"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f5f6586b7f764adc0231f4c79be7b920e766bb2f3e51b3661cdb263828f19994"
|
||||
dependencies = [
|
||||
"thiserror-impl",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thiserror-impl"
|
||||
version = "1.0.32"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "12bafc5b54507e0149cdf1b145a5d80ab80a90bcd9275df43d4fff68460f6c21"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "time"
|
||||
version = "0.1.44"
|
||||
|
@ -16,6 +16,8 @@ termion = "1.5"
|
||||
regex = "1.5.4"
|
||||
lazy_static = "1.4.0"
|
||||
structopt = "0.3.23"
|
||||
thiserror = "1.0.32"
|
||||
anyhow = "1.0.59"
|
||||
|
||||
[profile.release]
|
||||
lto = "yes"
|
||||
|
13
src/main.rs
13
src/main.rs
@ -1,12 +1,13 @@
|
||||
use std::path::PathBuf;
|
||||
use structopt::StructOpt;
|
||||
|
||||
mod common;
|
||||
mod repo;
|
||||
mod repository;
|
||||
mod ui;
|
||||
mod widget;
|
||||
|
||||
use anyhow::Result;
|
||||
use std::path::PathBuf;
|
||||
use structopt::StructOpt;
|
||||
|
||||
/// helps you searching or updating tags of your used docker images
|
||||
#[derive(StructOpt, Debug)]
|
||||
pub struct Opt {
|
||||
@ -19,8 +20,10 @@ pub struct Opt {
|
||||
repo: Option<String>,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
fn main() -> Result<()> {
|
||||
//parse parameter
|
||||
let opt = Opt::from_args();
|
||||
ui::create_ui(&opt);
|
||||
ui::create_ui(&opt)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -19,11 +19,11 @@ pub struct Images {
|
||||
}
|
||||
|
||||
impl Images {
|
||||
pub fn convert(&self) -> super::Tag {
|
||||
pub fn from_tag(images: &Self) -> super::Tag {
|
||||
super::Tag {
|
||||
name: self.tag_name.clone(),
|
||||
last_updated: Some(self.last_updated.clone()),
|
||||
details: self
|
||||
name: images.tag_name.clone(),
|
||||
last_updated: Some(images.last_updated.clone()),
|
||||
details: images
|
||||
.images
|
||||
.iter()
|
||||
.map(|d| super::TagDetails {
|
||||
@ -69,7 +69,7 @@ impl DockerHub {
|
||||
}
|
||||
|
||||
Ok(super::Repo {
|
||||
tags: tags.results.iter().map(|t| t.convert()).collect(),
|
||||
tags: tags.results.iter().map(Images::from_tag).collect(),
|
||||
next_page: tags.next_page,
|
||||
})
|
||||
}
|
||||
|
@ -1,72 +0,0 @@
|
||||
use serde::Deserialize;
|
||||
|
||||
use crate::repository::Error;
|
||||
|
||||
#[derive(Deserialize)]
|
||||
struct Token {
|
||||
token: String,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct Ghcr {
|
||||
tags: Vec<String>,
|
||||
}
|
||||
|
||||
impl Ghcr {
|
||||
/// fetches tag information with a repository name in the form of organization/repository or library/repository in the case of official images from docker
|
||||
pub fn create_repo(repo: &str) -> Result<super::Repo, Error> {
|
||||
let request_token = format!("https://ghcr.io/token?scope=repository:{}:pull", repo);
|
||||
let response = match reqwest::blocking::get(request_token) {
|
||||
Err(e) => return Err(Error::Fetching(format!("reqwest error: {}", e))),
|
||||
Ok(response) => response,
|
||||
};
|
||||
|
||||
let token = match response.json::<Token>() {
|
||||
Err(e) => return Err(Error::Converting(format!("invalid token json: {}", e))),
|
||||
Ok(token) => token.token,
|
||||
};
|
||||
|
||||
let request = format!("https://ghcr.io/v2/{}/tags/list?n=100", repo);
|
||||
let client = reqwest::blocking::Client::new();
|
||||
let response = match client
|
||||
.get(request)
|
||||
.header(reqwest::header::AUTHORIZATION, format!("Bearer {}", token))
|
||||
.send()
|
||||
{
|
||||
Ok(result) => result,
|
||||
Err(e) => return Err(Error::Fetching(format!("reqwest error: {}", e))),
|
||||
};
|
||||
|
||||
//convert it to json
|
||||
let tags = match response.json::<Self>() {
|
||||
Ok(result) => result,
|
||||
Err(e) => return Err(Error::Converting(format!("invalid json: {}", e))),
|
||||
};
|
||||
|
||||
if tags.tags.is_empty() {
|
||||
return Err(Error::NoTagsFound);
|
||||
}
|
||||
|
||||
Ok(super::Repo {
|
||||
tags: tags
|
||||
.tags
|
||||
.iter()
|
||||
.map(|t| super::Tag {
|
||||
name: t.clone(),
|
||||
details: vec![],
|
||||
last_updated: None,
|
||||
})
|
||||
.collect(),
|
||||
next_page: None,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::Ghcr;
|
||||
#[test]
|
||||
fn test_ghcr() {
|
||||
Ghcr::create_repo("ghcr.io/linuxserver/beets").unwrap();
|
||||
}
|
||||
}
|
@ -1,33 +1,24 @@
|
||||
mod dockerhub;
|
||||
mod ghcr;
|
||||
|
||||
use std::fmt;
|
||||
|
||||
use chrono::DateTime;
|
||||
use thiserror::Error;
|
||||
|
||||
use crate::common::display_duration_ext::DisplayDurationExt;
|
||||
use crate::repo;
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
#[derive(Debug, PartialEq, Error)]
|
||||
pub enum Error {
|
||||
/// couldn't fetch json with reqwest
|
||||
#[error("Fetching error: {0}")]
|
||||
Fetching(String),
|
||||
/// a serde error
|
||||
#[error("Converting error: {0}")]
|
||||
Converting(String),
|
||||
/// invalid repos show a valid json with 0 tags
|
||||
#[error("Given Repo does not exists or has 0 tags.")]
|
||||
NoTagsFound,
|
||||
}
|
||||
|
||||
impl fmt::Display for Error {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
Error::Fetching(s) => write!(f, "Fetching error: {}", s),
|
||||
Error::Converting(s) => write!(f, "Converting error: {}", s),
|
||||
Error::NoTagsFound => write!(f, "Given Repo has 0 tags. Is it valid?"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq)]
|
||||
pub struct TagDetails {
|
||||
pub arch: Option<String>,
|
||||
@ -83,10 +74,10 @@ impl Repo {
|
||||
Err(e) => return Err(Error::Converting(format!("{}", e))),
|
||||
};
|
||||
|
||||
if registry.unwrap_or_default() == "ghcr.io" {
|
||||
ghcr::Ghcr::create_repo(&repo)
|
||||
} else {
|
||||
if registry.unwrap_or_default().is_empty() {
|
||||
dockerhub::DockerHub::create_repo(&repo)
|
||||
} else {
|
||||
Err(Error::Converting("This registry is not supported".into()))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,17 +1,18 @@
|
||||
use std::{io, thread};
|
||||
|
||||
use crate::Opt;
|
||||
use anyhow::Result;
|
||||
use termion::event::Key;
|
||||
use termion::raw::IntoRawMode;
|
||||
use tui::backend::TermionBackend;
|
||||
use tui::layout::{Constraint, Direction, Layout};
|
||||
use tui::Terminal;
|
||||
|
||||
use std::{io, thread};
|
||||
|
||||
use crate::repository;
|
||||
use crate::widget::info;
|
||||
use crate::widget::repo_entry;
|
||||
use crate::widget::service_switcher;
|
||||
use crate::widget::tag_list;
|
||||
use crate::Opt;
|
||||
|
||||
pub struct Ui {
|
||||
state: State,
|
||||
@ -53,14 +54,14 @@ impl std::iter::Iterator for State {
|
||||
}
|
||||
|
||||
impl Ui {
|
||||
pub fn run(opt: &Opt) {
|
||||
pub fn run(opt: &Opt, switcher: service_switcher::ServiceSwitcher) -> Result<()> {
|
||||
let repo_id = opt.repo.as_deref();
|
||||
|
||||
let mut ui = Ui {
|
||||
state: State::SelectService,
|
||||
repo: repo_entry::RepoEntry::new(repo_id),
|
||||
tags: tag_list::TagList::with_status("Tags are empty"),
|
||||
services: service_switcher::ServiceSwitcher::new(&opt.file).unwrap(),
|
||||
services: switcher,
|
||||
details: crate::widget::details::Details::new(),
|
||||
info: info::Info::new("Select image of edit Repository"),
|
||||
};
|
||||
@ -70,9 +71,9 @@ impl Ui {
|
||||
}
|
||||
|
||||
//setup tui
|
||||
let stdout = io::stdout().into_raw_mode().unwrap();
|
||||
let stdout = io::stdout().into_raw_mode()?;
|
||||
let backend = TermionBackend::new(stdout);
|
||||
let mut terminal = Terminal::new(backend).unwrap();
|
||||
let mut terminal = Terminal::new(backend)?;
|
||||
|
||||
//setup input thread
|
||||
let receiver = super::spawn_stdin_channel();
|
||||
@ -80,34 +81,32 @@ impl Ui {
|
||||
//core interaction loop
|
||||
'core: loop {
|
||||
//draw
|
||||
terminal
|
||||
.draw(|rect| {
|
||||
let chunks = Layout::default()
|
||||
.direction(Direction::Vertical)
|
||||
.constraints(
|
||||
[
|
||||
Constraint::Length(10),
|
||||
Constraint::Length(3),
|
||||
Constraint::Min(7),
|
||||
Constraint::Length(2),
|
||||
]
|
||||
.as_ref(),
|
||||
)
|
||||
.split(rect.size());
|
||||
terminal.draw(|rect| {
|
||||
let chunks = Layout::default()
|
||||
.direction(Direction::Vertical)
|
||||
.constraints(
|
||||
[
|
||||
Constraint::Length(10),
|
||||
Constraint::Length(3),
|
||||
Constraint::Min(7),
|
||||
Constraint::Length(2),
|
||||
]
|
||||
.as_ref(),
|
||||
)
|
||||
.split(rect.size());
|
||||
|
||||
let (list, state) = ui.services.render(ui.state == State::SelectService);
|
||||
rect.render_stateful_widget(list, chunks[0], state);
|
||||
rect.render_widget(ui.repo.render(ui.state == State::EditRepo), chunks[1]);
|
||||
let (list, state) = ui.tags.render(ui.state == State::SelectTag);
|
||||
let more_chunks = Layout::default()
|
||||
.direction(Direction::Horizontal)
|
||||
.constraints([Constraint::Min(15), Constraint::Length(28)].as_ref())
|
||||
.split(chunks[2]);
|
||||
rect.render_stateful_widget(list, more_chunks[0], state);
|
||||
rect.render_widget(ui.details.render(), more_chunks[1]);
|
||||
rect.render_widget(ui.info.render(), chunks[3]);
|
||||
})
|
||||
.unwrap();
|
||||
let (list, state) = ui.services.render(ui.state == State::SelectService);
|
||||
rect.render_stateful_widget(list, chunks[0], state);
|
||||
rect.render_widget(ui.repo.render(ui.state == State::EditRepo), chunks[1]);
|
||||
let (list, state) = ui.tags.render(ui.state == State::SelectTag);
|
||||
let more_chunks = Layout::default()
|
||||
.direction(Direction::Horizontal)
|
||||
.constraints([Constraint::Min(15), Constraint::Length(28)].as_ref())
|
||||
.split(chunks[2]);
|
||||
rect.render_stateful_widget(list, more_chunks[0], state);
|
||||
rect.render_widget(ui.details.render(), more_chunks[1]);
|
||||
rect.render_widget(ui.info.render(), chunks[3]);
|
||||
})?;
|
||||
|
||||
//handle input
|
||||
match receiver.try_recv() {
|
||||
@ -219,6 +218,8 @@ impl Ui {
|
||||
thread::sleep(std::time::Duration::from_millis(32));
|
||||
}
|
||||
|
||||
terminal.clear().unwrap();
|
||||
terminal.clear()?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
@ -1,20 +1,23 @@
|
||||
mod default;
|
||||
mod no_yaml;
|
||||
|
||||
use anyhow::Result;
|
||||
use termion::input::TermRead;
|
||||
|
||||
use crate::widget::service_switcher;
|
||||
use crate::Opt;
|
||||
|
||||
use std::sync::mpsc;
|
||||
use std::{io, thread};
|
||||
|
||||
use crate::Opt;
|
||||
use termion::input::TermRead;
|
||||
|
||||
use crate::widget::service_switcher;
|
||||
|
||||
pub fn create_ui(opt: &Opt) {
|
||||
pub fn create_ui(opt: &Opt) -> Result<()> {
|
||||
let service_result = service_switcher::ServiceSwitcher::new(&opt.file);
|
||||
match service_result {
|
||||
None => no_yaml::NoYaml::run(opt),
|
||||
Some(_) => default::Ui::run(opt),
|
||||
}
|
||||
Some(switcher) => default::Ui::run(opt, switcher),
|
||||
}?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// create a thread for catching input and send them to core loop
|
||||
|
@ -1,11 +1,12 @@
|
||||
use std::{io, thread};
|
||||
|
||||
use anyhow::Result;
|
||||
use termion::event::Key;
|
||||
use termion::raw::IntoRawMode;
|
||||
use tui::backend::TermionBackend;
|
||||
use tui::layout::{Constraint, Direction, Layout};
|
||||
use tui::Terminal;
|
||||
|
||||
use std::{io, thread};
|
||||
|
||||
use crate::widget::details;
|
||||
use crate::widget::info;
|
||||
use crate::widget::repo_entry;
|
||||
@ -48,7 +49,7 @@ pub struct NoYaml {
|
||||
}
|
||||
|
||||
impl NoYaml {
|
||||
pub fn run(opt: &Opt) {
|
||||
pub fn run(opt: &Opt) -> Result<()> {
|
||||
let repo_id = opt.repo.as_deref();
|
||||
|
||||
let mut ui = NoYaml {
|
||||
@ -65,9 +66,9 @@ impl NoYaml {
|
||||
}
|
||||
|
||||
//setup tui
|
||||
let stdout = io::stdout().into_raw_mode().unwrap();
|
||||
let stdout = io::stdout().into_raw_mode()?;
|
||||
let backend = TermionBackend::new(stdout);
|
||||
let mut terminal = Terminal::new(backend).unwrap();
|
||||
let mut terminal = Terminal::new(backend)?;
|
||||
|
||||
//setup input thread
|
||||
let receiver = super::spawn_stdin_channel();
|
||||
@ -75,31 +76,29 @@ impl NoYaml {
|
||||
//core interaction loop
|
||||
'core: loop {
|
||||
//draw
|
||||
terminal
|
||||
.draw(|rect| {
|
||||
let chunks = Layout::default()
|
||||
.direction(Direction::Vertical)
|
||||
.constraints(
|
||||
[
|
||||
Constraint::Length(3),
|
||||
Constraint::Min(7),
|
||||
Constraint::Length(2),
|
||||
]
|
||||
.as_ref(),
|
||||
)
|
||||
.split(rect.size());
|
||||
terminal.draw(|rect| {
|
||||
let chunks = Layout::default()
|
||||
.direction(Direction::Vertical)
|
||||
.constraints(
|
||||
[
|
||||
Constraint::Length(3),
|
||||
Constraint::Min(7),
|
||||
Constraint::Length(2),
|
||||
]
|
||||
.as_ref(),
|
||||
)
|
||||
.split(rect.size());
|
||||
|
||||
rect.render_widget(ui.repo.render(ui.state == State::EditRepo), chunks[0]);
|
||||
let (list, state) = ui.tags.render(ui.state == State::SelectTag);
|
||||
let more_chunks = Layout::default()
|
||||
.direction(Direction::Horizontal)
|
||||
.constraints([Constraint::Min(15), Constraint::Length(28)].as_ref())
|
||||
.split(chunks[1]);
|
||||
rect.render_stateful_widget(list, more_chunks[0], state);
|
||||
rect.render_widget(ui.details.render(), more_chunks[1]);
|
||||
rect.render_widget(ui.info.render(), chunks[2]);
|
||||
})
|
||||
.unwrap();
|
||||
rect.render_widget(ui.repo.render(ui.state == State::EditRepo), chunks[0]);
|
||||
let (list, state) = ui.tags.render(ui.state == State::SelectTag);
|
||||
let more_chunks = Layout::default()
|
||||
.direction(Direction::Horizontal)
|
||||
.constraints([Constraint::Min(15), Constraint::Length(28)].as_ref())
|
||||
.split(chunks[1]);
|
||||
rect.render_stateful_widget(list, more_chunks[0], state);
|
||||
rect.render_widget(ui.details.render(), more_chunks[1]);
|
||||
rect.render_widget(ui.info.render(), chunks[2]);
|
||||
})?;
|
||||
|
||||
//handle input
|
||||
match receiver.try_recv() {
|
||||
@ -156,6 +155,7 @@ impl NoYaml {
|
||||
thread::sleep(std::time::Duration::from_millis(32));
|
||||
}
|
||||
|
||||
terminal.clear().unwrap();
|
||||
terminal.clear()?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user