From c93870e5fbbc7df35c69d32e4460d2104e521e33 Mon Sep 17 00:00:00 2001 From: Jack Wills <32690432+mrjackwills@users.noreply.github.com> Date: Sun, 4 Dec 2022 21:42:07 +0000 Subject: [PATCH] feat: -s flag for showing self when conterainerised --- README.md | 1 + containerised/Dockerfile | 3 ++- containerised/Dockerfile_dev | 3 ++- src/docker_data/mod.rs | 24 +++++++++++++----------- src/parse_args/mod.rs | 5 +++++ 5 files changed, 23 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index ab0b38b..80875ea 100644 --- a/README.md +++ b/README.md @@ -73,6 +73,7 @@ Available command line arguments |```-r```| show raw logs, by default oxker will remove ANSI formatting (conflicts with -c) | |```-c```| attempt to color the logs (conflicts with -r) | |```-t```| remove timestamps from each log entry | +|```-s```| if running via docker, will show the oxker container | |```-g```| no tui, basically a pointless debugging mode, for now | ## Build step diff --git a/containerised/Dockerfile b/containerised/Dockerfile index 0d99e80..525ea7d 100644 --- a/containerised/Dockerfile +++ b/containerised/Dockerfile @@ -55,5 +55,6 @@ FROM alpine:latest AS runtime COPY --from=builder /oxker /usr/local/bin COPY ./containerised/start_oxker.sh ./ -# Run the application, this is used in the application itself, to stop itself show when running from a docker container, so DO NOT EDIT +# Run the application +# this is used in the application itself, to stop itself show when running from a docker container, so DO NOT EDIT ENTRYPOINT [ "./start_oxker.sh"] diff --git a/containerised/Dockerfile_dev b/containerised/Dockerfile_dev index cc13dc0..0a844da 100644 --- a/containerised/Dockerfile_dev +++ b/containerised/Dockerfile_dev @@ -8,7 +8,8 @@ FROM alpine:latest AS runtime COPY ./target/x86_64-unknown-linux-musl/release/oxker /usr/local/bin COPY ./containerised/start_oxker.sh ./ -# Run the application, this is used in the application itself, to stop itself show when running from a docker container, so DO NOT EDIT +# Run the application +# this is used in the application itself, to stop itself show when running from a docker container, so DO NOT EDIT ENTRYPOINT [ "./start_oxker.sh"] ## One liner to build musl program, build docker image, then execute the image diff --git a/src/docker_data/mod.rs b/src/docker_data/mod.rs index f80c516..2ef4653 100644 --- a/src/docker_data/mod.rs +++ b/src/docker_data/mod.rs @@ -51,14 +51,14 @@ impl Binate { pub struct DockerData { app_data: Arc>, + args: CliArgs, + binate: Binate, docker: Arc, gui_state: Arc>, initialised: bool, is_running: Arc, receiver: Receiver, spawns: Arc>>>, - timestamps: bool, - binate: Binate, } impl DockerData { @@ -173,7 +173,7 @@ impl DockerData { /// Get all current containers, handle into ContainerItem in the app_data struct rather than here /// Just make sure that items sent are guaranteed to have an id - /// Will ignore any container that contains `oxker` as an entry point + /// Will ignore any container that uses `./start_oxker.sh` as an entry point, unless the `-s` flag is set pub async fn update_all_containers(&mut self) -> Vec<(bool, ContainerId)> { let containers = self .docker @@ -188,7 +188,11 @@ impl DockerData { .into_iter() .filter_map(|f| match f.id { Some(_) => { - if f.command.as_ref().map_or(false, |c| c.contains("oxker")) { + if f.command + .as_ref() + .map_or(false, |c| c.starts_with("./start_oxker.sh")) + && self.args.show_self + { None } else { Some(f) @@ -200,9 +204,6 @@ impl DockerData { self.app_data.lock().update_containers(&mut output); - let current_sort = self.app_data.lock().get_sorted(); - self.app_data.lock().set_sorted(current_sort); - // Just get the containers that are currently running, or being restarted, no point updating info on paused or dead containers output .into_iter() @@ -263,7 +264,7 @@ impl DockerData { tokio::spawn(Self::update_log( docker, id.clone(), - self.timestamps, + self.args.timestamp, 0, app_data, spawns, @@ -288,7 +289,7 @@ impl DockerData { tokio::spawn(Self::update_log( docker, container.id.clone(), - self.timestamps, + self.args.timestamp, container.last_updated, app_data, spawns, @@ -323,6 +324,7 @@ impl DockerData { let loading_spin = self.loading_spin(loading_uuid).await; let all_ids = self.update_all_containers().await; + self.update_all_container_stats(&all_ids); // Maybe only do a single one at first? @@ -410,22 +412,22 @@ impl DockerData { /// Initialise self, and start the message receiving loop pub async fn init( - args: CliArgs, app_data: Arc>, docker: Arc, gui_state: Arc>, receiver: Receiver, is_running: Arc, ) { + let args = app_data.lock().args; if app_data.lock().get_error().is_none() { let mut inner = Self { app_data, + args, docker, gui_state, initialised: false, receiver, spawns: Arc::new(Mutex::new(HashMap::new())), - timestamps: args.timestamp, is_running, binate: Binate::One, }; diff --git a/src/parse_args/mod.rs b/src/parse_args/mod.rs index 5c70ce9..2a881ba 100644 --- a/src/parse_args/mod.rs +++ b/src/parse_args/mod.rs @@ -23,6 +23,10 @@ pub struct CliArgs { #[clap(short = 'r', conflicts_with = "color")] pub raw: bool, + /// Show self when running as a docker container + #[clap(short = 's')] + pub show_self: bool, + /// Don't draw gui - for debugging - mostly pointless #[clap(short = 'g')] pub gui: bool, @@ -43,6 +47,7 @@ impl CliArgs { color: args.color, docker_interval: args.docker_interval, gui: !args.gui, + show_self: !args.show_self, raw: args.raw, timestamp: !args.timestamp, }