Skip to content

Commit

Permalink
chore: merge release-v0.0.5 into main
Browse files Browse the repository at this point in the history
  • Loading branch information
mrjackwills committed May 30, 2022
2 parents 7bdbb1e + 643e6e8 commit 7364597
Show file tree
Hide file tree
Showing 15 changed files with 181 additions and 145 deletions.
2 changes: 1 addition & 1 deletion .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ FROM mcr.microsoft.com/vscode/devcontainers/rust:0-${VARIANT}

RUN printf "alias cls='clear'\nalias ll='ls -l --human-readable --color=auto --group-directories-first --classify --time-style=long-iso -all'" >> /etc/bash.bashrc

RUN apt-get update && apt-get -y install upx-ucl
# RUN apt-get update && apt-get -y install upx-ucl
4 changes: 2 additions & 2 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
],

"mounts": [
"source=/etc/timezone,target=/etc/timezone,type=bind,readonly",
"source=/ramdrive,target=/ramdrive,type=bind",
// //"source=/etc/timezone,target=/etc/timezone,type=bind,readonly",
"source=/dev/shm,target=/ramdrive,type=bind",
"source=${localEnv:HOME}/.cargo/bin/cargo-watch,target=/usr/local/cargo/bin/cargo-watch,type=bind,readonly",
"source=${localEnv:HOME}/.cargo/bin/cross,target=/usr/local/cargo/bin/cross,type=bind,readonly",
],
Expand Down
10 changes: 8 additions & 2 deletions .github/release-body.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
### 2022-05-08
### 2022-05-30

### Docs
+ Readme one-liner to download & install latest version, [11d5ba361ee4c11d080f1c3c14d8bb677cbfd1fc]
+ Example docker-compose.yml bump alpine version to 3.16, [98c83f2f68f59e78f0c78270c59886630d98913c]

### Fixes
+ Help menu logo corrected, [2f5452027e86f714729b804d4bf65306e755df7f]
+ use Some() checks to make sure that container item indexes are still valid, else can create out-of-bounds errors, closes [#8], [4cf02e3f04426ef44ec5a7421687f2104ac5102f]
+ Remove + replace as many unwrap()'s as possible, [d8e22d7444965f1874d7367259310440a889432b]
+ Help panel typo, [e497f3f2d9e1dca99469860c2e728c99e29353ad]


see <a href='https://github.com/mrjackwills/oxker/blob/main/CHANGELOG.md'>CHANGELOG.md</a> for more details
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
# <a href='https://github.com/mrjackwills/oxker/releases/tag/v0.0.5'>v0.0.5</a>
### 2022-05-30

### Docs
+ Readme one-liner to download & install latest version, [11d5ba36](https://github.com/mrjackwills/oxker/commit/11d5ba361ee4c11d080f1c3c14d8bb677cbfd1fc),
+ Example docker-compose.yml bump alpine version to 3.16, [98c83f2f](https://github.com/mrjackwills/oxker/commit/98c83f2f68f59e78f0c78270c59886630d98913c),

### Fixes
+ use Some() checks to make sure that container item indexes are still valid, else can create out-of-bounds errors, closes [#8](https://github.com/mrjackwills/oxker/issues/8), [4cf02e3f](https://github.com/mrjackwills/oxker/commit/4cf02e3f04426ef44ec5a7421687f2104ac5102f),
+ Remove + replace as many unwrap()'s as possible, [d8e22d74](https://github.com/mrjackwills/oxker/commit/d8e22d7444965f1874d7367259310440a889432b),
+ Help panel typo, [e497f3f2](https://github.com/mrjackwills/oxker/commit/e497f3f2d9e1dca99469860c2e728c99e29353ad),

# <a href='https://github.com/mrjackwills/oxker/releases/tag/v0.0.4'>v0.0.4</a>
### 2022-05-08

Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "oxker"
version = "0.0.4"
version = "0.0.5"
edition = "2021"
authors = ["Jack Wills <[email protected]>"]
description = "a simple tui to view & control docker containers"
Expand Down
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,15 @@

See <a href="https://github.com/mrjackwills/oxker/releases" target='_blank' rel='noopener noreferrer'>releases</a>

install
download & install (x86_64 one liner)

```bash
tar xzvf oxker_linux_x86_64.tar.gz oxker
install -Dm 755 oxker -t "${HOME}/.local/bin"
wget https://www.github.com/mrjackwills/oxker/releases/latest/download/oxker_linux_x86_64.tar.gz &&
tar xzvf oxker_linux_x86_64.tar.gz oxker &&
install -Dm 755 oxker -t "${HOME}/.local/bin" &&
rm oxker_linux_x86_64.tar.gz oxker
```

## Run

```oxker```
Expand Down Expand Up @@ -88,7 +90,7 @@ using docker-compose.yml;
or individually


```docker run --name redis -d redis:alpine3.15```
```docker run --name redis -d redis:alpine3.16```

```docker run --name postgres -e POSTGRES_PASSWORD=never_use_this_password_in_production -d postgres:alpine```

Expand Down
4 changes: 2 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ networks:
name: oxker-examaple-net
services:
postgres:
image: postgres:alpine
image: postgres:alpine3.16
container_name: postgres
environment:
- POSTGRES_PASSWORD=never_use_this_password_in_production
Expand All @@ -18,7 +18,7 @@ services:
limits:
memory: 128M
redis:
image: redis:alpine
image: redis:alpine3.16
container_name: redis
ipc: private
restart: always
Expand Down
3 changes: 2 additions & 1 deletion src/app_data/container_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ impl DockerControls {
match state {
State::Dead | State::Exited => vec![Self::Start, Self::Restart],
State::Paused => vec![Self::Unpause, Self::Stop],
State::Restarting => vec![Self::Stop],
State::Running => vec![Self::Pause, Self::Restart, Self::Stop],
_ => vec![],
}
Expand Down Expand Up @@ -276,7 +277,7 @@ impl Stats for ByteStats {
}
}

// convert from bytes to kb, mb, gb etc
// convert from bytes to kB, MB, GB etc
impl fmt::Display for ByteStats {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let one_kb = 1000.0;
Expand Down
108 changes: 56 additions & 52 deletions src/app_data/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,9 @@ impl AppData {
self.error = Some(error);
}

/// Find the if of the currently selected container
/// If any containers on system, will always return
/// Only returns None when no containers found
/// Find the if of the currently selected container.
/// If any containers on system, will always return a string.
/// Only returns None when no containers found.
pub fn get_selected_container_id(&self) -> Option<String> {
let mut output = None;
if let Some(index) = self.containers.state.selected() {
Expand Down Expand Up @@ -296,68 +296,72 @@ impl AppData {
for (index, id) in all_ids.iter().enumerate() {
if !containers
.iter()
.map(|i| i.id.as_ref().unwrap())
.filter_map(|i| i.id.as_ref())
.any(|x| x == id)
{
// If removed container is currently selected, then change selected to previous
// This will default to 0 in any edge cases
if self.containers.state.selected().is_some() {
self.containers.previous();
}
// docker rm -f $(docker ps -aq) will cause this to crash
self.containers.items.remove(index);
// Check is some, else can cause out of bounds error, if containers get removed before a docker update
if self.containers.items.get(index).is_some() {
self.containers.items.remove(index);
}
}
}

for i in containers.iter() {
let id = i.id.as_ref().unwrap().to_owned();
let mut name = i
.names
.as_ref()
.unwrap_or(&vec!["".to_owned()])
.get(0)
.unwrap()
.to_owned();
if let Some(c) = name.chars().next() {
if c == '/' {
name.remove(0);
if let Some(id) = i.id.as_ref() {
let mut name = i
.names
.as_ref()
.unwrap_or(&vec!["".to_owned()])
.get(0)
.unwrap()
.to_owned();
if let Some(c) = name.chars().next() {
if c == '/' {
name.remove(0);
}
}
}

let state = State::from(i.state.as_ref().unwrap_or(&"dead".to_owned()).trim());
let status = i
.status
.as_ref()
.unwrap_or(&"".to_owned())
.trim()
.to_owned();
let image = i.image.as_ref().unwrap_or(&"".to_owned()).trim().to_owned();
if let Some(current_container) = self.get_container_by_id(&id) {
if current_container.name != name {
current_container.name = name
};
if current_container.status != status {
current_container.status = status
};
if current_container.state != state {
current_container.docker_controls.items = DockerControls::gen_vec(&state);

// Update the list state, needs to be None if the gen_vec returns an empty vec
match state {
State::Removing | State::Restarting | State::Unknown => {
current_container.docker_controls.state.select(None)
}
_ => current_container.docker_controls.start(),
let state = State::from(i.state.as_ref().unwrap_or(&"dead".to_owned()).trim());
let status = i
.status
.as_ref()
.unwrap_or(&"".to_owned())
.trim()
.to_owned();
let image = i.image.as_ref().unwrap_or(&"".to_owned()).trim().to_owned();
if let Some(current_container) = self.get_container_by_id(id) {
if current_container.name != name {
current_container.name = name
};
current_container.state = state;
};
if current_container.image != image {
current_container.image = image
};
} else {
let mut container = ContainerItem::new(id, status, image, state, name);
container.logs.end();
self.containers.items.push(container);
if current_container.status != status {
current_container.status = status
};
if current_container.state != state {
current_container.docker_controls.items = DockerControls::gen_vec(&state);

// Update the list state, needs to be None if the gen_vec returns an empty vec
match state {
State::Removing | State::Restarting | State::Unknown => {
current_container.docker_controls.state.select(None)
}
_ => current_container.docker_controls.start(),
};
current_container.state = state;
};
if current_container.image != image {
current_container.image = image
};
} else {
let mut container =
ContainerItem::new(id.to_owned(), status, image, state, name);
container.logs.end();
self.containers.items.push(container);
}
}
}
}
Expand All @@ -379,7 +383,7 @@ impl AppData {
container.logs.items.push(ListItem::new(lines));
});
if container.logs.state.selected().is_none()
|| container.logs.state.selected().unwrap() + 1 == current_len
|| container.logs.state.selected().unwrap_or_default() + 1 == current_len
{
container.logs.end();
}
Expand Down
2 changes: 1 addition & 1 deletion src/app_error.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::app_data::DockerControls;
use core::fmt;
use std::fmt;

/// app errors to set in global state
#[allow(unused)]
Expand Down
32 changes: 18 additions & 14 deletions src/docker_data/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ impl DockerData {
if stats.cpu_stats.system_cpu_usage.is_some()
&& stats.precpu_stats.system_cpu_usage.is_some()
{
let system_delta = (stats.cpu_stats.system_cpu_usage.unwrap()
- stats.precpu_stats.system_cpu_usage.unwrap())
let system_delta = (stats.cpu_stats.system_cpu_usage.unwrap_or(0)
- stats.precpu_stats.system_cpu_usage.unwrap_or(0))
as f64;
let online_cpus = stats.cpu_stats.online_cpus.unwrap_or_else(|| {
stats
Expand Down Expand Up @@ -75,20 +75,22 @@ impl DockerData {
let mem_stat = stats.memory_stats.usage.unwrap_or(0);
let mem_limit = stats.memory_stats.limit.unwrap_or(0);

let key = if let Some(networks) = &stats.networks {
let some_key = if let Some(networks) = &stats.networks {
networks.keys().next().map(|x| x.to_owned())
} else {
None
};

let cpu_stats = Self::calculate_usage(&stats);

let (rx, tx) = if let Some(k) = key {
let ii = stats.networks.unwrap();
let v = ii.get(&k).unwrap();
(v.rx_bytes.to_owned(), v.tx_bytes.to_owned())
let no_bytes = (0, 0);
let (rx, tx) = if let Some(key) = some_key {
match stats.networks.unwrap_or_default().get(&key) {
Some(data) => (data.rx_bytes.to_owned(), data.tx_bytes.to_owned()),
None => no_bytes,
}
} else {
(0, 0)
no_bytes
};

if is_running {
Expand Down Expand Up @@ -131,7 +133,7 @@ impl DockerData {
..Default::default()
}))
.await
.unwrap();
.unwrap_or_default();

let mut output = vec![];
// iter over containers, to only send ones which have an id, as use ID for extensivley!
Expand All @@ -143,11 +145,13 @@ impl DockerData {
self.app_data.lock().update_containers(&output);
output
.iter()
.map(|i| {
(
i.state.as_ref().unwrap() == "running",
i.id.as_ref().unwrap().to_owned(),
)
.filter_map(|i| {
i.id.as_ref().map(|id| {
(
i.state.as_ref().unwrap_or(&String::new()) == "running",
id.to_owned(),
)
})
})
.collect::<Vec<_>>()
}
Expand Down
Loading

0 comments on commit 7364597

Please sign in to comment.