From 1adb61ce3b029d4fcf51961958d483b2fae8825a Mon Sep 17 00:00:00 2001 From: Jack Wills <32690432+mrjackwills@users.noreply.github.com> Date: Mon, 5 Dec 2022 03:22:08 +0000 Subject: [PATCH 01/11] fix: if no container created time, use 0 instead of system time --- src/app_data/mod.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/app_data/mod.rs b/src/app_data/mod.rs index 18fa486..557c136 100644 --- a/src/app_data/mod.rs +++ b/src/app_data/mod.rs @@ -439,7 +439,6 @@ impl AppData { if !all_containers.is_empty() && self.containers.state.selected().is_none() { self.containers.start(); } - let now = Self::get_systemtime(); for (index, id) in all_ids.iter().enumerate() { if !all_containers @@ -482,7 +481,7 @@ impl AppData { let id = ContainerId::from(id); - let created = i.created.map_or(now, |i| u64::try_from(i).unwrap_or(now)); + let created = i.created.map_or(0, |i| u64::try_from(i).unwrap_or(0)); // If container info already in containers Vec, then just update details if let Some(item) = self.get_container_by_id(&id) { if item.name != name { From 43fe902bae50ba756c337c543c0c05032c52108e Mon Sep 17 00:00:00 2001 From: Jack Wills <32690432+mrjackwills@users.noreply.github.com> Date: Mon, 5 Dec 2022 03:22:33 +0000 Subject: [PATCH 02/11] docs: readme docker instructions add name to docker run one-liner --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 80875ea..71b4f1e 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ Published on Docker Hub, with images built for `linux/amd64`, `linux/arm64`, and `linux/arm/v6` -`docker run --rm -it -v /var/run/docker.sock:/var/run/docker.sock:ro --pull=always mrjackwills/oxker` +`docker run --rm -it -v /var/run/docker.sock:/var/run/docker.sock:ro --name oxker --pull=always mrjackwills/oxker` ### Nix Using nix flakes, oxker can be ran directly with From 160b8021b1de898064756b53c127d49b8096ce4d Mon Sep 17 00:00:00 2001 From: Jack Wills <32690432+mrjackwills@users.noreply.github.com> Date: Mon, 5 Dec 2022 03:52:41 +0000 Subject: [PATCH 03/11] fix: disallow commands to be sent so an oxker container, closes #19 --- src/app_data/container_state.rs | 9 ++++++--- src/app_data/mod.rs | 20 +++++++++++++++++--- src/docker_data/mod.rs | 4 ++-- src/input_handler/mod.rs | 4 ++++ src/main.rs | 2 ++ 5 files changed, 31 insertions(+), 8 deletions(-) diff --git a/src/app_data/container_state.rs b/src/app_data/container_state.rs index 39a2d6c..bde1e4f 100644 --- a/src/app_data/container_state.rs +++ b/src/app_data/container_state.rs @@ -370,17 +370,19 @@ pub struct ContainerItem { pub state: State, pub status: String, pub tx: ByteStats, + pub is_oxker: bool } impl ContainerItem { /// Create a new container item pub fn new( + created: u64, id: ContainerId, - status: String, image: String, - state: State, + is_oxker: bool, name: String, - created: u64, + state: State, + status: String, ) -> Self { let mut docker_controls = StatefulList::new(DockerControls::gen_vec(state)); docker_controls.start(); @@ -392,6 +394,7 @@ impl ContainerItem { docker_controls, id, image, + is_oxker, last_updated: 0, logs, mem_limit: ByteStats::default(), diff --git a/src/app_data/mod.rs b/src/app_data/mod.rs index 557c136..d56a792 100644 --- a/src/app_data/mod.rs +++ b/src/app_data/mod.rs @@ -5,7 +5,7 @@ use tui::widgets::ListItem; mod container_state; -use crate::{app_error::AppError, parse_args::CliArgs, ui::log_sanitizer}; +use crate::{app_error::AppError, parse_args::CliArgs, ui::log_sanitizer, ENTRY_POINT}; pub use container_state::*; /// Global app_state, stored in an Arc @@ -171,6 +171,18 @@ impl AppData { output } + /// Check if the selected container is a dockerised version of oxker + /// So that can disallow commands to be send + /// Is a poor way of implementing this + pub fn selected_container_is_oxker(&self) -> bool { + if let Some(index) = self.containers.state.selected() { + if let Some(x) = self.containers.items.get(index) { + return x.is_oxker + } + } + false + } + /// Sort the containers vec, based on a heading, either ascending or descending, /// If not sort set, then sort by created time fn sort_containers(&mut self) { @@ -242,7 +254,7 @@ impl AppData { } else { self.containers .items - .sort_by(|a, b| a.created.cmp(&b.created)) + .sort_by(|a, b| a.created.cmp(&b.created)); } } @@ -471,6 +483,8 @@ impl AppData { }) }); + let is_oxker = i.command.as_ref().map_or(false, |i|i.starts_with(ENTRY_POINT)); + let state = State::from(i.state.as_ref().map_or("dead".to_owned(), trim_owned)); let status = i.status.as_ref().map_or(String::new(), trim_owned); @@ -506,7 +520,7 @@ impl AppData { }; // else container not known, so make new ContainerItem and push into containers Vec } else { - let container = ContainerItem::new(id, status, image, state, name, created); + let container = ContainerItem::new(created, id, image, is_oxker, name, state, status); self.containers.items.push(container); } } diff --git a/src/docker_data/mod.rs b/src/docker_data/mod.rs index 2ef4653..535b230 100644 --- a/src/docker_data/mod.rs +++ b/src/docker_data/mod.rs @@ -19,7 +19,7 @@ use crate::{ app_data::{AppData, ContainerId, DockerControls}, app_error::AppError, parse_args::CliArgs, - ui::{GuiState, Status}, + ui::{GuiState, Status}, ENTRY_POINT, }; mod message; pub use message::DockerMessage; @@ -190,7 +190,7 @@ impl DockerData { Some(_) => { if f.command .as_ref() - .map_or(false, |c| c.starts_with("./start_oxker.sh")) + .map_or(false, |c| c.starts_with(ENTRY_POINT)) && self.args.show_self { None diff --git a/src/input_handler/mod.rs b/src/input_handler/mod.rs index 5597eac..0c3f461 100644 --- a/src/input_handler/mod.rs +++ b/src/input_handler/mod.rs @@ -250,6 +250,10 @@ impl InputHandler { if let Some(command) = option_command { let option_id = self.app_data.lock().get_selected_container_id(); + // Poor way of disallowing commands to be sent to a containerised okxer + if self.app_data.lock().selected_container_is_oxker() { + return + }; if let Some(id) = option_id { match command { DockerControls::Pause => self diff --git a/src/main.rs b/src/main.rs index 5b4b42a..e3845ef 100644 --- a/src/main.rs +++ b/src/main.rs @@ -26,6 +26,8 @@ mod ui; use ui::{create_ui, GuiState, Status}; +const ENTRY_POINT: &str = "./start_oxker.sh"; + fn setup_tracing() { tracing_subscriber::fmt().with_max_level(Level::INFO).init(); // TODO write to file? From c5ad2b31c11dc5137df81251a475817904e8f8ae Mon Sep 17 00:00:00 2001 From: Jack Wills <32690432+mrjackwills@users.noreply.github.com> Date: Mon, 5 Dec 2022 03:55:09 +0000 Subject: [PATCH 04/11] docs: changelog --- CHANGELOG.md | 6 ++++++ README.md | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9846f98..8de83f9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +### Fixes ++ disallow commands to be sent so an oxker container, closes #19, [160b8021b1de898064756b53c127d49b8096ce4d] ++ if no container created time, use 0 instead of system time, [1adb61ce3b029d4fcf51961958d483b2fae8825a] + +### Fixes + # v0.1.8 ### 2022-12-05 diff --git a/README.md b/README.md index 71b4f1e..80875ea 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ Published on Docker Hub, with images built for `linux/amd64`, `linux/arm64`, and `linux/arm/v6` -`docker run --rm -it -v /var/run/docker.sock:/var/run/docker.sock:ro --name oxker --pull=always mrjackwills/oxker` +`docker run --rm -it -v /var/run/docker.sock:/var/run/docker.sock:ro --pull=always mrjackwills/oxker` ### Nix Using nix flakes, oxker can be ran directly with From 3d84b48fdd855aa4f4319beff5da481315af81e0 Mon Sep 17 00:00:00 2001 From: Jack Wills <32690432+mrjackwills@users.noreply.github.com> Date: Mon, 5 Dec 2022 04:02:20 +0000 Subject: [PATCH 05/11] docs: changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8de83f9..d0fb275 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,5 @@ ### Fixes -+ disallow commands to be sent so an oxker container, closes #19, [160b8021b1de898064756b53c127d49b8096ce4d] ++ disallow commands to be sent to an oxker container, closes #19, [160b8021b1de898064756b53c127d49b8096ce4d] + if no container created time, use 0 instead of system time, [1adb61ce3b029d4fcf51961958d483b2fae8825a] ### Fixes From e25de4d8438532621b1f0b13672437aa54bb97e8 Mon Sep 17 00:00:00 2001 From: Jack Wills <32690432+mrjackwills@users.noreply.github.com> Date: Mon, 5 Dec 2022 04:02:48 +0000 Subject: [PATCH 06/11] docs: changelog --- CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d0fb275..7a3344b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ ### Fixes -+ disallow commands to be sent to an oxker container, closes #19, [160b8021b1de898064756b53c127d49b8096ce4d] -+ if no container created time, use 0 instead of system time, [1adb61ce3b029d4fcf51961958d483b2fae8825a] ++ disallow commands to be sent to an dockerised oxker container, closes #19, [160b8021b1de898064756b53c127d49b8096ce4d] ++ if no container created time, use 0, instead of system_time(), [1adb61ce3b029d4fcf51961958d483b2fae8825a] ### Fixes From 0d58bd7864cdc7710f58b22b8ccdf868a9d6eda7 Mon Sep 17 00:00:00 2001 From: Jack Wills <32690432+mrjackwills@users.noreply.github.com> Date: Mon, 5 Dec 2022 04:07:16 +0000 Subject: [PATCH 07/11] docs: changelog --- CHANGELOG.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7a3344b..e3040e3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,8 +2,6 @@ + disallow commands to be sent to an dockerised oxker container, closes #19, [160b8021b1de898064756b53c127d49b8096ce4d] + if no container created time, use 0, instead of system_time(), [1adb61ce3b029d4fcf51961958d483b2fae8825a] -### Fixes - # v0.1.8 ### 2022-12-05 From 6a0b5659753f5b5737f7c4381830256aabf51203 Mon Sep 17 00:00:00 2001 From: Jack Wills <32690432+mrjackwills@users.noreply.github.com> Date: Mon, 5 Dec 2022 04:16:10 +0000 Subject: [PATCH 08/11] docs: changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e3040e3..757d73e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,5 @@ ### Fixes -+ disallow commands to be sent to an dockerised oxker container, closes #19, [160b8021b1de898064756b53c127d49b8096ce4d] ++ disallow commands to be sent to a dockerised oxker container, closes #19, [160b8021b1de898064756b53c127d49b8096ce4d] + if no container created time, use 0, instead of system_time(), [1adb61ce3b029d4fcf51961958d483b2fae8825a] # v0.1.8 From bfb3b826300cda5672ef6d4a230f83e4111cd542 Mon Sep 17 00:00:00 2001 From: Jack Wills <32690432+mrjackwills@users.noreply.github.com> Date: Mon, 5 Dec 2022 04:27:53 +0000 Subject: [PATCH 09/11] fix: create_release.sh sed --- create_release.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/create_release.sh b/create_release.sh index 102c776..2a0a409 100755 --- a/create_release.sh +++ b/create_release.sh @@ -109,7 +109,7 @@ update_release_body_and_changelog () { # Update changelog to add links to closed issues - comma included! # "closes #1" -> "closes [#1](https:/www.../issues/1),"" - sed -i -r -E "s=closes \#([0-9]+)\=closes [#\1](${GIT_REPO_URL}/issues/\1)=g" ./CHANGELOG.md + sed -i -r -E "s=closes \#([0-9]+)=closes [#\1](${GIT_REPO_URL}/issues/\1)=g" ./CHANGELOG.md } # update version in cargo.toml, to match selected current version From 552c26bc5c13b3895370884b217b1fbe73630c9c Mon Sep 17 00:00:00 2001 From: Jack Wills <32690432+mrjackwills@users.noreply.github.com> Date: Mon, 5 Dec 2022 13:50:14 +0000 Subject: [PATCH 10/11] fix: only sort if no containers currently set, i.e. on first attempt --- src/app_data/mod.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/app_data/mod.rs b/src/app_data/mod.rs index d56a792..eb14a91 100644 --- a/src/app_data/mod.rs +++ b/src/app_data/mod.rs @@ -445,8 +445,10 @@ impl AppData { pub fn update_containers(&mut self, all_containers: &mut [ContainerSummary]) { let all_ids = self.get_all_ids(); - // Sort the containes by created, that have a constant order - all_containers.sort_by(|a, b| a.created.cmp(&b.created)); + // Only sort it no containers currently set, as afterwards the order is fixed + if self.containers.items.is_empty() { + all_containers.sort_by(|a, b| a.created.cmp(&b.created)); + } if !all_containers.is_empty() && self.containers.state.selected().is_none() { self.containers.start(); From e71802fe21132a68e74ec581d57466b45c8cef3a Mon Sep 17 00:00:00 2001 From: Jack Wills <32690432+mrjackwills@users.noreply.github.com> Date: Mon, 5 Dec 2022 14:06:22 +0000 Subject: [PATCH 11/11] chore: release v0.1.9 --- .github/release-body.md | 11 +++-------- CHANGELOG.md | 9 ++++++--- Cargo.lock | 2 +- Cargo.toml | 2 +- src/app_data/container_state.rs | 8 ++++---- src/app_data/mod.rs | 26 +++++++++++++++----------- src/docker_data/mod.rs | 3 ++- src/input_handler/mod.rs | 8 ++++---- 8 files changed, 36 insertions(+), 33 deletions(-) diff --git a/.github/release-body.md b/.github/release-body.md index 2d3af7b..da6e282 100644 --- a/.github/release-body.md +++ b/.github/release-body.md @@ -1,13 +1,8 @@ ### 2022-12-05 -### Chores -+ dependencies updated, [e3aa4420cb510df0381e311d37e768937070387a] -+ docker-compose.yml alpine bump, [911c6596684db4ccbe7a55aadd6f595a95f89bb0] -+ github workflow use dtolnay/rust-toolchain, [57c18878690477a05d7330112a65d1d58a07901e] - -### Features -+ Clicking a header now toggles between Ascending -> Descending -> Default. Use the containers created_time as the default order - maybe add created column in future version, closes #18, [cf14ba498987db587c0f5bef8a67cf4113ffcb1e], [d1de291473d8a1028f1936429832d3820d75df54] -+ `-s` flag for showing the oxker container when executing the docker image, [c93870e5fbbc7df35c69d32e4460d2104e521e33] +### Fixes ++ disallow commands to be sent to a dockerised oxker container, closes #19, [160b8021b1de898064756b53c127d49b8096ce4d] ++ if no container created time, use 0, instead of system_time(), [1adb61ce3b029d4fcf51961958d483b2fae8825a] see CHANGELOG.md for more details diff --git a/CHANGELOG.md b/CHANGELOG.md index 757d73e..93e0776 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,9 @@ +# v0.1.9 +### 2022-12-05 + ### Fixes -+ disallow commands to be sent to a dockerised oxker container, closes #19, [160b8021b1de898064756b53c127d49b8096ce4d] -+ if no container created time, use 0, instead of system_time(), [1adb61ce3b029d4fcf51961958d483b2fae8825a] ++ disallow commands to be sent to a dockerised oxker container, closes [#19](https://github.com/mrjackwills/oxker/issues/19), [160b8021](https://github.com/mrjackwills/oxker/commit/160b8021b1de898064756b53c127d49b8096ce4d) ++ if no container created time, use 0, instead of system_time(), [1adb61ce](https://github.com/mrjackwills/oxker/commit/1adb61ce3b029d4fcf51961958d483b2fae8825a) # v0.1.8 ### 2022-12-05 @@ -11,7 +14,7 @@ + github workflow use dtolnay/rust-toolchain, [57c18878](https://github.com/mrjackwills/oxker/commit/57c18878690477a05d7330112a65d1d58a07901e) ### Features -+ Clicking a header now toggles between Ascending -> Descending -> Default. Use the containers created_time as the default order - maybe add created column in future version, closes #18, [cf14ba49](https://github.com/mrjackwills/oxker/commit/cf14ba498987db587c0f5bef8a67cf4113ffcb1e), [d1de2914](https://github.com/mrjackwills/oxker/commit/d1de291473d8a1028f1936429832d3820d75df54) ++ Clicking a header now toggles between Ascending -> Descending -> Default. Use the containers created_time as the default order - maybe add created column in future version, closes [#18](https://github.com/mrjackwills/oxker/issues/18), [cf14ba49](https://github.com/mrjackwills/oxker/commit/cf14ba498987db587c0f5bef8a67cf4113ffcb1e), [d1de2914](https://github.com/mrjackwills/oxker/commit/d1de291473d8a1028f1936429832d3820d75df54) + `-s` flag for showing the oxker container when executing the docker image, [c93870e5](https://github.com/mrjackwills/oxker/commit/c93870e5fbbc7df35c69d32e4460d2104e521e33) # v0.1.7 diff --git a/Cargo.lock b/Cargo.lock index 9402487..4a21bd8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -567,7 +567,7 @@ checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39" [[package]] name = "oxker" -version = "0.1.8" +version = "0.1.9" dependencies = [ "anyhow", "bollard", diff --git a/Cargo.toml b/Cargo.toml index 7e93f5b..269778d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "oxker" -version = "0.1.8" +version = "0.1.9" edition = "2021" authors = ["Jack Wills "] description = "A simple tui to view & control docker containers" diff --git a/src/app_data/container_state.rs b/src/app_data/container_state.rs index bde1e4f..a6ff466 100644 --- a/src/app_data/container_state.rs +++ b/src/app_data/container_state.rs @@ -370,16 +370,16 @@ pub struct ContainerItem { pub state: State, pub status: String, pub tx: ByteStats, - pub is_oxker: bool + pub is_oxker: bool, } impl ContainerItem { /// Create a new container item pub fn new( - created: u64, + created: u64, id: ContainerId, image: String, - is_oxker: bool, + is_oxker: bool, name: String, state: State, status: String, @@ -394,7 +394,7 @@ impl ContainerItem { docker_controls, id, image, - is_oxker, + is_oxker, last_updated: 0, logs, mem_limit: ByteStats::default(), diff --git a/src/app_data/mod.rs b/src/app_data/mod.rs index eb14a91..0fa8092 100644 --- a/src/app_data/mod.rs +++ b/src/app_data/mod.rs @@ -171,13 +171,13 @@ impl AppData { output } - /// Check if the selected container is a dockerised version of oxker - /// So that can disallow commands to be send - /// Is a poor way of implementing this - pub fn selected_container_is_oxker(&self) -> bool { + /// Check if the selected container is a dockerised version of oxker + /// So that can disallow commands to be send + /// Is a poor way of implementing this + pub fn selected_container_is_oxker(&self) -> bool { if let Some(index) = self.containers.state.selected() { if let Some(x) = self.containers.items.get(index) { - return x.is_oxker + return x.is_oxker; } } false @@ -445,10 +445,10 @@ impl AppData { pub fn update_containers(&mut self, all_containers: &mut [ContainerSummary]) { let all_ids = self.get_all_ids(); - // Only sort it no containers currently set, as afterwards the order is fixed - if self.containers.items.is_empty() { - all_containers.sort_by(|a, b| a.created.cmp(&b.created)); - } + // Only sort it no containers currently set, as afterwards the order is fixed + if self.containers.items.is_empty() { + all_containers.sort_by(|a, b| a.created.cmp(&b.created)); + } if !all_containers.is_empty() && self.containers.state.selected().is_none() { self.containers.start(); @@ -485,7 +485,10 @@ impl AppData { }) }); - let is_oxker = i.command.as_ref().map_or(false, |i|i.starts_with(ENTRY_POINT)); + let is_oxker = i + .command + .as_ref() + .map_or(false, |i| i.starts_with(ENTRY_POINT)); let state = State::from(i.state.as_ref().map_or("dead".to_owned(), trim_owned)); let status = i.status.as_ref().map_or(String::new(), trim_owned); @@ -522,7 +525,8 @@ impl AppData { }; // else container not known, so make new ContainerItem and push into containers Vec } else { - let container = ContainerItem::new(created, id, image, is_oxker, name, state, status); + let container = + ContainerItem::new(created, id, image, is_oxker, name, state, status); self.containers.items.push(container); } } diff --git a/src/docker_data/mod.rs b/src/docker_data/mod.rs index 535b230..af53655 100644 --- a/src/docker_data/mod.rs +++ b/src/docker_data/mod.rs @@ -19,7 +19,8 @@ use crate::{ app_data::{AppData, ContainerId, DockerControls}, app_error::AppError, parse_args::CliArgs, - ui::{GuiState, Status}, ENTRY_POINT, + ui::{GuiState, Status}, + ENTRY_POINT, }; mod message; pub use message::DockerMessage; diff --git a/src/input_handler/mod.rs b/src/input_handler/mod.rs index 0c3f461..77f4204 100644 --- a/src/input_handler/mod.rs +++ b/src/input_handler/mod.rs @@ -250,10 +250,10 @@ impl InputHandler { if let Some(command) = option_command { let option_id = self.app_data.lock().get_selected_container_id(); - // Poor way of disallowing commands to be sent to a containerised okxer - if self.app_data.lock().selected_container_is_oxker() { - return - }; + // Poor way of disallowing commands to be sent to a containerised okxer + if self.app_data.lock().selected_container_is_oxker() { + return; + }; if let Some(id) = option_id { match command { DockerControls::Pause => self