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/
|
# http://plugins.drone.io/drone-plugins/drone-github-release/
|
||||||
image: plugins/github-release
|
image: plugins/github-release
|
||||||
files: target/release/reel-moby
|
files: target/release/reel-moby
|
||||||
secrets: [github_release_api_key]
|
secrets: [github_api_key]
|
||||||
when:
|
when:
|
||||||
event: tag
|
event: tag
|
||||||
tag: v*
|
tag: v*
|
||||||
|
28
Cargo.lock
generated
28
Cargo.lock
generated
@ -20,6 +20,12 @@ dependencies = [
|
|||||||
"winapi",
|
"winapi",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "anyhow"
|
||||||
|
version = "1.0.59"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "c91f1f46651137be86f3a2b9a8359f9ab421d04d941c62b5982e1ca21113adf9"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "atty"
|
name = "atty"
|
||||||
version = "0.2.14"
|
version = "0.2.14"
|
||||||
@ -675,6 +681,7 @@ dependencies = [
|
|||||||
name = "reel-moby"
|
name = "reel-moby"
|
||||||
version = "1.2.1"
|
version = "1.2.1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"anyhow",
|
||||||
"chrono",
|
"chrono",
|
||||||
"lazy_static",
|
"lazy_static",
|
||||||
"regex",
|
"regex",
|
||||||
@ -683,6 +690,7 @@ dependencies = [
|
|||||||
"serde_json",
|
"serde_json",
|
||||||
"structopt",
|
"structopt",
|
||||||
"termion",
|
"termion",
|
||||||
|
"thiserror",
|
||||||
"tui",
|
"tui",
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -921,6 +929,26 @@ dependencies = [
|
|||||||
"unicode-width",
|
"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]]
|
[[package]]
|
||||||
name = "time"
|
name = "time"
|
||||||
version = "0.1.44"
|
version = "0.1.44"
|
||||||
|
@ -16,6 +16,8 @@ termion = "1.5"
|
|||||||
regex = "1.5.4"
|
regex = "1.5.4"
|
||||||
lazy_static = "1.4.0"
|
lazy_static = "1.4.0"
|
||||||
structopt = "0.3.23"
|
structopt = "0.3.23"
|
||||||
|
thiserror = "1.0.32"
|
||||||
|
anyhow = "1.0.59"
|
||||||
|
|
||||||
[profile.release]
|
[profile.release]
|
||||||
lto = "yes"
|
lto = "yes"
|
||||||
|
13
src/main.rs
13
src/main.rs
@ -1,12 +1,13 @@
|
|||||||
use std::path::PathBuf;
|
|
||||||
use structopt::StructOpt;
|
|
||||||
|
|
||||||
mod common;
|
mod common;
|
||||||
mod repo;
|
mod repo;
|
||||||
mod repository;
|
mod repository;
|
||||||
mod ui;
|
mod ui;
|
||||||
mod widget;
|
mod widget;
|
||||||
|
|
||||||
|
use anyhow::Result;
|
||||||
|
use std::path::PathBuf;
|
||||||
|
use structopt::StructOpt;
|
||||||
|
|
||||||
/// helps you searching or updating tags of your used docker images
|
/// helps you searching or updating tags of your used docker images
|
||||||
#[derive(StructOpt, Debug)]
|
#[derive(StructOpt, Debug)]
|
||||||
pub struct Opt {
|
pub struct Opt {
|
||||||
@ -19,8 +20,10 @@ pub struct Opt {
|
|||||||
repo: Option<String>,
|
repo: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() -> Result<()> {
|
||||||
//parse parameter
|
//parse parameter
|
||||||
let opt = Opt::from_args();
|
let opt = Opt::from_args();
|
||||||
ui::create_ui(&opt);
|
ui::create_ui(&opt)?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -19,11 +19,11 @@ pub struct Images {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Images {
|
impl Images {
|
||||||
pub fn convert(&self) -> super::Tag {
|
pub fn from_tag(images: &Self) -> super::Tag {
|
||||||
super::Tag {
|
super::Tag {
|
||||||
name: self.tag_name.clone(),
|
name: images.tag_name.clone(),
|
||||||
last_updated: Some(self.last_updated.clone()),
|
last_updated: Some(images.last_updated.clone()),
|
||||||
details: self
|
details: images
|
||||||
.images
|
.images
|
||||||
.iter()
|
.iter()
|
||||||
.map(|d| super::TagDetails {
|
.map(|d| super::TagDetails {
|
||||||
@ -69,7 +69,7 @@ impl DockerHub {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Ok(super::Repo {
|
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,
|
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 dockerhub;
|
||||||
mod ghcr;
|
|
||||||
|
|
||||||
use std::fmt;
|
|
||||||
|
|
||||||
use chrono::DateTime;
|
use chrono::DateTime;
|
||||||
|
use thiserror::Error;
|
||||||
|
|
||||||
use crate::common::display_duration_ext::DisplayDurationExt;
|
use crate::common::display_duration_ext::DisplayDurationExt;
|
||||||
use crate::repo;
|
use crate::repo;
|
||||||
|
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq, Error)]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
/// couldn't fetch json with reqwest
|
/// couldn't fetch json with reqwest
|
||||||
|
#[error("Fetching error: {0}")]
|
||||||
Fetching(String),
|
Fetching(String),
|
||||||
/// a serde error
|
/// a serde error
|
||||||
|
#[error("Converting error: {0}")]
|
||||||
Converting(String),
|
Converting(String),
|
||||||
/// invalid repos show a valid json with 0 tags
|
/// invalid repos show a valid json with 0 tags
|
||||||
|
#[error("Given Repo does not exists or has 0 tags.")]
|
||||||
NoTagsFound,
|
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)]
|
#[derive(Clone, PartialEq)]
|
||||||
pub struct TagDetails {
|
pub struct TagDetails {
|
||||||
pub arch: Option<String>,
|
pub arch: Option<String>,
|
||||||
@ -83,10 +74,10 @@ impl Repo {
|
|||||||
Err(e) => return Err(Error::Converting(format!("{}", e))),
|
Err(e) => return Err(Error::Converting(format!("{}", e))),
|
||||||
};
|
};
|
||||||
|
|
||||||
if registry.unwrap_or_default() == "ghcr.io" {
|
if registry.unwrap_or_default().is_empty() {
|
||||||
ghcr::Ghcr::create_repo(&repo)
|
|
||||||
} else {
|
|
||||||
dockerhub::DockerHub::create_repo(&repo)
|
dockerhub::DockerHub::create_repo(&repo)
|
||||||
|
} else {
|
||||||
|
Err(Error::Converting("This registry is not supported".into()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,17 +1,18 @@
|
|||||||
use std::{io, thread};
|
use anyhow::Result;
|
||||||
|
|
||||||
use crate::Opt;
|
|
||||||
use termion::event::Key;
|
use termion::event::Key;
|
||||||
use termion::raw::IntoRawMode;
|
use termion::raw::IntoRawMode;
|
||||||
use tui::backend::TermionBackend;
|
use tui::backend::TermionBackend;
|
||||||
use tui::layout::{Constraint, Direction, Layout};
|
use tui::layout::{Constraint, Direction, Layout};
|
||||||
use tui::Terminal;
|
use tui::Terminal;
|
||||||
|
|
||||||
|
use std::{io, thread};
|
||||||
|
|
||||||
use crate::repository;
|
use crate::repository;
|
||||||
use crate::widget::info;
|
use crate::widget::info;
|
||||||
use crate::widget::repo_entry;
|
use crate::widget::repo_entry;
|
||||||
use crate::widget::service_switcher;
|
use crate::widget::service_switcher;
|
||||||
use crate::widget::tag_list;
|
use crate::widget::tag_list;
|
||||||
|
use crate::Opt;
|
||||||
|
|
||||||
pub struct Ui {
|
pub struct Ui {
|
||||||
state: State,
|
state: State,
|
||||||
@ -53,14 +54,14 @@ impl std::iter::Iterator for State {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Ui {
|
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 repo_id = opt.repo.as_deref();
|
||||||
|
|
||||||
let mut ui = Ui {
|
let mut ui = Ui {
|
||||||
state: State::SelectService,
|
state: State::SelectService,
|
||||||
repo: repo_entry::RepoEntry::new(repo_id),
|
repo: repo_entry::RepoEntry::new(repo_id),
|
||||||
tags: tag_list::TagList::with_status("Tags are empty"),
|
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(),
|
details: crate::widget::details::Details::new(),
|
||||||
info: info::Info::new("Select image of edit Repository"),
|
info: info::Info::new("Select image of edit Repository"),
|
||||||
};
|
};
|
||||||
@ -70,9 +71,9 @@ impl Ui {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//setup tui
|
//setup tui
|
||||||
let stdout = io::stdout().into_raw_mode().unwrap();
|
let stdout = io::stdout().into_raw_mode()?;
|
||||||
let backend = TermionBackend::new(stdout);
|
let backend = TermionBackend::new(stdout);
|
||||||
let mut terminal = Terminal::new(backend).unwrap();
|
let mut terminal = Terminal::new(backend)?;
|
||||||
|
|
||||||
//setup input thread
|
//setup input thread
|
||||||
let receiver = super::spawn_stdin_channel();
|
let receiver = super::spawn_stdin_channel();
|
||||||
@ -80,8 +81,7 @@ impl Ui {
|
|||||||
//core interaction loop
|
//core interaction loop
|
||||||
'core: loop {
|
'core: loop {
|
||||||
//draw
|
//draw
|
||||||
terminal
|
terminal.draw(|rect| {
|
||||||
.draw(|rect| {
|
|
||||||
let chunks = Layout::default()
|
let chunks = Layout::default()
|
||||||
.direction(Direction::Vertical)
|
.direction(Direction::Vertical)
|
||||||
.constraints(
|
.constraints(
|
||||||
@ -106,8 +106,7 @@ impl Ui {
|
|||||||
rect.render_stateful_widget(list, more_chunks[0], state);
|
rect.render_stateful_widget(list, more_chunks[0], state);
|
||||||
rect.render_widget(ui.details.render(), more_chunks[1]);
|
rect.render_widget(ui.details.render(), more_chunks[1]);
|
||||||
rect.render_widget(ui.info.render(), chunks[3]);
|
rect.render_widget(ui.info.render(), chunks[3]);
|
||||||
})
|
})?;
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
//handle input
|
//handle input
|
||||||
match receiver.try_recv() {
|
match receiver.try_recv() {
|
||||||
@ -219,6 +218,8 @@ impl Ui {
|
|||||||
thread::sleep(std::time::Duration::from_millis(32));
|
thread::sleep(std::time::Duration::from_millis(32));
|
||||||
}
|
}
|
||||||
|
|
||||||
terminal.clear().unwrap();
|
terminal.clear()?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,20 +1,23 @@
|
|||||||
mod default;
|
mod default;
|
||||||
mod no_yaml;
|
mod no_yaml;
|
||||||
|
|
||||||
|
use anyhow::Result;
|
||||||
|
use termion::input::TermRead;
|
||||||
|
|
||||||
|
use crate::widget::service_switcher;
|
||||||
|
use crate::Opt;
|
||||||
|
|
||||||
use std::sync::mpsc;
|
use std::sync::mpsc;
|
||||||
use std::{io, thread};
|
use std::{io, thread};
|
||||||
|
|
||||||
use crate::Opt;
|
pub fn create_ui(opt: &Opt) -> Result<()> {
|
||||||
use termion::input::TermRead;
|
|
||||||
|
|
||||||
use crate::widget::service_switcher;
|
|
||||||
|
|
||||||
pub fn create_ui(opt: &Opt) {
|
|
||||||
let service_result = service_switcher::ServiceSwitcher::new(&opt.file);
|
let service_result = service_switcher::ServiceSwitcher::new(&opt.file);
|
||||||
match service_result {
|
match service_result {
|
||||||
None => no_yaml::NoYaml::run(opt),
|
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
|
/// 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::event::Key;
|
||||||
use termion::raw::IntoRawMode;
|
use termion::raw::IntoRawMode;
|
||||||
use tui::backend::TermionBackend;
|
use tui::backend::TermionBackend;
|
||||||
use tui::layout::{Constraint, Direction, Layout};
|
use tui::layout::{Constraint, Direction, Layout};
|
||||||
use tui::Terminal;
|
use tui::Terminal;
|
||||||
|
|
||||||
|
use std::{io, thread};
|
||||||
|
|
||||||
use crate::widget::details;
|
use crate::widget::details;
|
||||||
use crate::widget::info;
|
use crate::widget::info;
|
||||||
use crate::widget::repo_entry;
|
use crate::widget::repo_entry;
|
||||||
@ -48,7 +49,7 @@ pub struct NoYaml {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl NoYaml {
|
impl NoYaml {
|
||||||
pub fn run(opt: &Opt) {
|
pub fn run(opt: &Opt) -> Result<()> {
|
||||||
let repo_id = opt.repo.as_deref();
|
let repo_id = opt.repo.as_deref();
|
||||||
|
|
||||||
let mut ui = NoYaml {
|
let mut ui = NoYaml {
|
||||||
@ -65,9 +66,9 @@ impl NoYaml {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//setup tui
|
//setup tui
|
||||||
let stdout = io::stdout().into_raw_mode().unwrap();
|
let stdout = io::stdout().into_raw_mode()?;
|
||||||
let backend = TermionBackend::new(stdout);
|
let backend = TermionBackend::new(stdout);
|
||||||
let mut terminal = Terminal::new(backend).unwrap();
|
let mut terminal = Terminal::new(backend)?;
|
||||||
|
|
||||||
//setup input thread
|
//setup input thread
|
||||||
let receiver = super::spawn_stdin_channel();
|
let receiver = super::spawn_stdin_channel();
|
||||||
@ -75,8 +76,7 @@ impl NoYaml {
|
|||||||
//core interaction loop
|
//core interaction loop
|
||||||
'core: loop {
|
'core: loop {
|
||||||
//draw
|
//draw
|
||||||
terminal
|
terminal.draw(|rect| {
|
||||||
.draw(|rect| {
|
|
||||||
let chunks = Layout::default()
|
let chunks = Layout::default()
|
||||||
.direction(Direction::Vertical)
|
.direction(Direction::Vertical)
|
||||||
.constraints(
|
.constraints(
|
||||||
@ -98,8 +98,7 @@ impl NoYaml {
|
|||||||
rect.render_stateful_widget(list, more_chunks[0], state);
|
rect.render_stateful_widget(list, more_chunks[0], state);
|
||||||
rect.render_widget(ui.details.render(), more_chunks[1]);
|
rect.render_widget(ui.details.render(), more_chunks[1]);
|
||||||
rect.render_widget(ui.info.render(), chunks[2]);
|
rect.render_widget(ui.info.render(), chunks[2]);
|
||||||
})
|
})?;
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
//handle input
|
//handle input
|
||||||
match receiver.try_recv() {
|
match receiver.try_recv() {
|
||||||
@ -156,6 +155,7 @@ impl NoYaml {
|
|||||||
thread::sleep(std::time::Duration::from_millis(32));
|
thread::sleep(std::time::Duration::from_millis(32));
|
||||||
}
|
}
|
||||||
|
|
||||||
terminal.clear().unwrap();
|
terminal.clear()?;
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user