diff --git a/.github/release-body.md b/.github/release-body.md index 6511fd9..2d3af7b 100644 --- a/.github/release-body.md +++ b/.github/release-body.md @@ -1,11 +1,13 @@ -### 2022-11-13 +### 2022-12-05 ### Chores -+ update dependencies, closes #17, [8a5d0ef8376e3739dda5b0ed4c3e75e565deed45], [eadfc3d6c6896ecc8cff88c6a9e9c8b3e477c0cd] -+ aggressive linting with Rust 1.65.0, [8f3a15137155dc374e6b2822c9155c07d05d5e28] ++ dependencies updated, [e3aa4420cb510df0381e311d37e768937070387a] ++ docker-compose.yml alpine bump, [911c6596684db4ccbe7a55aadd6f595a95f89bb0] ++ github workflow use dtolnay/rust-toolchain, [57c18878690477a05d7330112a65d1d58a07901e] -### Docs -+ README.md improved Download & Install section, and now available on [NixPkg](https://search.nixos.org/packages?channel=unstable&show=oxker&from=0&size=50&sort=relevance&type=packages&query=oxker), thanks [siph](https://github.com/siph), [67a9e183ca04199da758255075ff7e73061eb850] +### 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] see CHANGELOG.md for more details diff --git a/.github/workflows/create_release_and_build.yml b/.github/workflows/create_release_and_build.yml index a398b2c..be50677 100644 --- a/.github/workflows/create_release_and_build.yml +++ b/.github/workflows/create_release_and_build.yml @@ -10,74 +10,64 @@ jobs: - name: Checkout uses: actions/checkout@v3 + ######################### + ## Publish to crates.io # + ######################### - # Publish to crates.io - name: publish to crates.io uses: katyo/publish-crates@v1 with: registry-token: ${{ secrets.CRATES_IO_TOKEN }} + + #################################### + ## Build binaries for release page # + #################################### + # Install stable rust, and associated tools + - name: install rust + uses: dtolnay/rust-toolchain@stable + + # Install cross-rs + - name: install cross + run: cargo install cross --git https://github.com/cross-rs/cross + # Build for linux x86_64 - name: build release linux_x86_64 - uses: actions-rs/cargo@v1 - with: - command: build - args: --release + run: cargo build --release + # Compress ouput into tar - name: compress oxker_linux_x86_64 binary run: tar -C target/release -czf ./oxker_linux_x86_64.tar.gz oxker # Build for linux aarch64, aka 64 bit pi 4 - - name: build release arm64v8 - uses: actions-rs/toolchain@v1 - with: - toolchain: stable - target: aarch64-unknown-linux-musl - override: true - - uses: actions-rs/cargo@v1 - with: - use-cross: true - command: build - args: --target aarch64-unknown-linux-musl --release + - name: build aarch64-unknown-linux-musl + run: cross build --target aarch64-unknown-linux-musl --release + # Compress ouput into tar - name: compress aarch64 binary run: tar -C target/aarch64-unknown-linux-musl/release -czf ./oxker_linux_aarch64.tar.gz oxker # Build for linux armv6, aka 32 bit pi zero w - - name: build release armv6 - uses: actions-rs/toolchain@v1 - with: - toolchain: stable - target: arm-unknown-linux-musleabihf - override: true - - uses: actions-rs/cargo@v1 - with: - use-cross: true - command: build - args: --target arm-unknown-linux-musleabihf --release + - name: build arm-unknown-linux-musleabihf + run: cross build --target arm-unknown-linux-musleabihf --release + # Compress ouput into tar - name: compress armv6 binary run: tar -C target/arm-unknown-linux-musleabihf/release -czf ./oxker_linux_armv6.tar.gz oxker # Build for windows - name: build release windows_x86_64 - uses: actions-rs/toolchain@v1 - with: - toolchain: stable - target: x86_64-pc-windows-gnu - override: true - - uses: actions-rs/cargo@v1 - with: - use-cross: true - command: build - args: --target x86_64-pc-windows-gnu --release + run: cross build --target x86_64-pc-windows-gnu --release + # Compress ouput into zip - name: compress windows_x86_64 binary - run: zip -j ./oxker_windows_x86_64.zip target/x86_64-pc-windows-gnu/release/oxker.exe + run: zip -j ./oxker_windows_x86_64.zip target/x86_64-pc-windows-gnu/release/oxker.exe + + ############################### + ## Build images for Dockerhub # + ############################### - # Build images for Dockerhub - name: Login to DockerHub uses: docker/login-action@v2 with: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - - uses: docker/setup-buildx-action@v2 id: buildx with: @@ -89,6 +79,10 @@ jobs: --push \ -f containerised/Dockerfile . + ################### + ## Create release # + ################### + - name: Release uses: softprops/action-gh-release@v1 with: diff --git a/CHANGELOG.md b/CHANGELOG.md index 5c01623..9846f98 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,15 @@ +# v0.1.8 +### 2022-12-05 + +### Chores ++ dependencies updated, [e3aa4420](https://github.com/mrjackwills/oxker/commit/e3aa4420cb510df0381e311d37e768937070387a) ++ docker-compose.yml alpine bump, [911c6596](https://github.com/mrjackwills/oxker/commit/911c6596684db4ccbe7a55aadd6f595a95f89bb0) ++ 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) ++ `-s` flag for showing the oxker container when executing the docker image, [c93870e5](https://github.com/mrjackwills/oxker/commit/c93870e5fbbc7df35c69d32e4460d2104e521e33) + # v0.1.7 ### 2022-11-13 diff --git a/Cargo.lock b/Cargo.lock index 4ce8dfa..9402487 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8,17 +8,6 @@ version = "1.0.66" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "216261ddc8289130e551ddcd5ce8a064710c0d064a4d2895c67151c92b5443f6" -[[package]] -name = "atty" -version = "0.2.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" -dependencies = [ - "hermit-abi", - "libc", - "winapi", -] - [[package]] name = "autocfg" version = "1.1.0" @@ -77,9 +66,9 @@ dependencies = [ [[package]] name = "bytes" -version = "1.2.1" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec8a7b6a70fde80372154c65702f00a0f56f3e1c36abbc6c440484be248856db" +checksum = "dfb24e866b15a1af2a1b663f10c6b6b8f397a84aadb828f12e5b289ec23a3a3c" [[package]] name = "cansi" @@ -93,6 +82,12 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "df8670b8c7b9dae1793364eafadf7239c40d669904660c5960d74cfd80b46a53" +[[package]] +name = "cc" +version = "1.0.77" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e9f73505338f7d905b19d18738976aae232eb46b8efc15554ffc56deb5d9ebe4" + [[package]] name = "cfg-if" version = "1.0.0" @@ -101,14 +96,14 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "clap" -version = "4.0.23" +version = "4.0.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0eb41c13df48950b20eb4cd0eefa618819469df1bffc49d11e8487c4ba0037e5" +checksum = "4d63b9e9c07271b9957ad22c173bae2a4d9a81127680962039296abcd2f8251d" dependencies = [ - "atty", "bitflags", "clap_derive", "clap_lex", + "is-terminal", "once_cell", "strsim", "termcolor", @@ -198,6 +193,27 @@ dependencies = [ "syn", ] +[[package]] +name = "errno" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f639046355ee4f37944e44f60642c6f3a7efa3cf6b78c78a0d989a8ce6c396a1" +dependencies = [ + "errno-dragonfly", + "libc", + "winapi", +] + +[[package]] +name = "errno-dragonfly" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa68f1b12764fab894d2755d2518754e71b4fd80ecfb822714a1206c2aab39bf" +dependencies = [ + "cc", + "libc", +] + [[package]] name = "fnv" version = "1.0.7" @@ -316,6 +332,15 @@ dependencies = [ "libc", ] +[[package]] +name = "hermit-abi" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee512640fe35acbfb4bb779db6f0d80704c2cacfa2e39b601ef3e3f47d1ae4c7" +dependencies = [ + "libc", +] + [[package]] name = "hex" version = "0.4.3" @@ -411,14 +436,36 @@ dependencies = [ [[package]] name = "indexmap" -version = "1.9.1" +version = "1.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "10a35a97730320ffe8e2d410b5d3b69279b98d2c14bdb8b70ea89ecf7888d41e" +checksum = "1885e79c1fc4b10f0e172c475f458b7f7b93061064d98c3293e98c5ba0c8b399" dependencies = [ "autocfg", "hashbrown", ] +[[package]] +name = "io-lifetimes" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "46112a93252b123d31a119a8d1a1ac19deac4fac6e0e8b0df58f0d4e5870e63c" +dependencies = [ + "libc", + "windows-sys", +] + +[[package]] +name = "is-terminal" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "927609f78c2913a6f6ac3c27a4fe87f43e2a35367c0c4b0f8265e8f49a104330" +dependencies = [ + "hermit-abi 0.2.6", + "io-lifetimes", + "rustix", + "windows-sys", +] + [[package]] name = "itoa" version = "1.0.4" @@ -433,9 +480,15 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.137" +version = "0.2.138" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc7fcc620a3bff7cdd7a365be3376c97191aeaccc2a603e600951e452615bf89" +checksum = "db6d7e329c562c5dfab7a46a2afabc8b987ab9a4834c9d1ca04dc54c1546cef8" + +[[package]] +name = "linux-raw-sys" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f9f08d8963a6c613f4b1a78f4f4a4dbfadf8e6545b2d72861731e4858b8b47f" [[package]] name = "lock_api" @@ -490,7 +543,7 @@ version = "1.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f6058e64324c71e02bc2b150e4f3bc8286db6c83092132ffa3f6b1eab0f9def5" dependencies = [ - "hermit-abi", + "hermit-abi 0.1.19", "libc", ] @@ -502,9 +555,9 @@ checksum = "86f0b0d4bf799edbc74508c1e8bf170ff5f41238e5f8225603ca7caaae2b7860" [[package]] name = "os_str_bytes" -version = "6.4.0" +version = "6.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b5bf27447411e9ee3ff51186bf7a08e16c341efdde93f4d823e8844429bed7e" +checksum = "9b7820b9daea5457c9f21c69448905d723fbd21136ccf521748f23fd49e723ee" [[package]] name = "overload" @@ -514,7 +567,7 @@ checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39" [[package]] name = "oxker" -version = "0.1.7" +version = "0.1.8" dependencies = [ "anyhow", "bollard", @@ -542,9 +595,9 @@ dependencies = [ [[package]] name = "parking_lot_core" -version = "0.9.4" +version = "0.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4dc9e0dc2adc1c69d09143aff38d3d30c5c3f0df0dad82e6d25547af174ebec0" +checksum = "7ff9f3fef3968a3ec5945535ed654cb38ff72d7495a25619e2247fb15a2ed9ba" dependencies = [ "cfg-if", "libc", @@ -678,6 +731,20 @@ dependencies = [ "bitflags", ] +[[package]] +name = "rustix" +version = "0.36.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb93e85278e08bb5788653183213d3a60fc242b10cb9be96586f5a73dcb67c23" +dependencies = [ + "bitflags", + "errno", + "io-lifetimes", + "libc", + "linux-raw-sys", + "windows-sys", +] + [[package]] name = "ryu" version = "1.0.11" @@ -692,18 +759,18 @@ checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" [[package]] name = "serde" -version = "1.0.147" +version = "1.0.148" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d193d69bae983fc11a79df82342761dfbf28a99fc8d203dca4c3c1b590948965" +checksum = "e53f64bb4ba0191d6d0676e1b141ca55047d83b74f5607e6d8eb88126c52c2dc" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.147" +version = "1.0.148" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4f1d362ca8fc9c3e3a7484440752472d68a6caa98f1ab81d99b5dfe517cec852" +checksum = "a55492425aa53521babf6137309e7d34c20bbfbbfcfe2c7f3a047fd1f6b92c0c" dependencies = [ "proc-macro2", "quote", @@ -712,9 +779,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.87" +version = "1.0.89" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ce777b7b150d76b9cf60d28b55f5847135a003f7d7350c6be7a773508ce7d45" +checksum = "020ff22c755c2ed3f8cf162dbb41a7268d934702f3ed3631656ea597e08fc3db" dependencies = [ "itoa", "ryu", @@ -827,9 +894,9 @@ checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" [[package]] name = "syn" -version = "1.0.103" +version = "1.0.105" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a864042229133ada95abf3b54fdc62ef5ccabe9515b64717bcb9a1919e59445d" +checksum = "60b9b43d45702de4c839cb9b51d9f529c5dd26a4aff255b42b1ebc03e88ee908" dependencies = [ "proc-macro2", "quote", @@ -891,9 +958,9 @@ checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" [[package]] name = "tokio" -version = "1.21.2" +version = "1.22.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9e03c497dc955702ba729190dc4aac6f2a0ce97f913e5b1b5912fc5039d9099" +checksum = "d76ce4a75fb488c605c54bf610f221cea8b0dafb53333c1a67e8ee199dcd2ae3" dependencies = [ "autocfg", "bytes", @@ -911,9 +978,9 @@ dependencies = [ [[package]] name = "tokio-macros" -version = "1.8.0" +version = "1.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9724f9a975fb987ef7a3cd9be0350edcbe130698af5b8f7a631e23d42d052484" +checksum = "d266c00fde287f55d3f1c3e96c500c362a2b8c695076ec180f27918820bc6df8" dependencies = [ "proc-macro2", "quote", @@ -1072,9 +1139,9 @@ dependencies = [ [[package]] name = "uuid" -version = "1.2.1" +version = "1.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "feb41e78f93363bb2df8b0e86a2ca30eed7806ea16ea0c790d757cf93f79be83" +checksum = "422ee0de9031b5b948b97a8fc04e3aa35230001a722ddd27943e0be31564ce4c" dependencies = [ "getrandom", "rand", diff --git a/Cargo.toml b/Cargo.toml index f5474de..7e93f5b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "oxker" -version = "0.1.7" +version = "0.1.8" edition = "2021" authors = ["Jack Wills "] description = "A simple tui to view & control docker containers" @@ -19,7 +19,7 @@ clap={version="4.0", features = ["derive", "unicode", "color"] } crossterm = "0.25" futures-util = "0.3" parking_lot = {version= "0.12"} -tokio = {version = "1.21", features=["full"]} +tokio = {version = "1.22", features=["full"]} tracing = "0.1" tracing-subscriber = "0.3" tui = "0.19" 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 18e9953..525ea7d 100644 --- a/containerised/Dockerfile +++ b/containerised/Dockerfile @@ -31,7 +31,7 @@ WORKDIR /usr/src/oxker # Install target platform (Cross-Compilation) RUN rustup target add $(cat /.platform) -# This is a dummy build to get the dependencies cached +# This is a dummy build to get the dependencies cached - probably not needed - as run via a github action RUN cargo build --target $(cat /.platform) --release # Now copy in the rest of the sources @@ -56,4 +56,5 @@ 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 ENTRYPOINT [ "./start_oxker.sh"] diff --git a/containerised/Dockerfile_dev b/containerised/Dockerfile_dev index f6f5148..4a91c38 100644 --- a/containerised/Dockerfile_dev +++ b/containerised/Dockerfile_dev @@ -8,13 +8,16 @@ 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 +# 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 -# cargo build --release --target x86_64-unknown-linux-musl && docker build -t oxker_dev -f containerised/Dockerfile_dev . && docker run --rm -it --volume /var/run/docker.sock:/var/run/docker.sock:ro oxker_dev +# cargo build --release --target x86_64-unknown-linux-musl && docker build -t oxker_dev -f containerised/Dockerfile . && docker run --rm -it --volume /var/run/docker.sock:/var/run/docker.sock:ro oxker_dev +# Build production version +# docker build --platform linux/arm/v6 --platform linux/arm64 --platform linux/amd64 -t oxker_dev -f containerised/Dockerfile . && docker run --rm -it --volume /var/run/docker.sock:/var/run/docker.sock:ro oxker_dev -## Buildx command to build musl version for all three platforms, should probably be executed in create_release +# Buildx command to build musl version for all three platforms, should probably be executed in create_release # docker buildx create --use -# docker buildx build --platform linux/arm/v6,linux/arm64,linux/amd64 -t oxker_dev_all -o type=tar,dest=/tmp/oxker_dev_all.tar -f containerised/Dockerfile . \ No newline at end of file +# docker buildx build --platform linux/arm/v6,linux/arm64,linux/amd64 -t oxker_dev_all -o type=tar,dest=/tmp/oxker_dev_all.tar -f containerised/Dockerfile . diff --git a/create_release.sh b/create_release.sh index e25c211..102c776 100755 --- a/create_release.sh +++ b/create_release.sh @@ -104,12 +104,12 @@ update_release_body_and_changelog () { echo -e "# ${NEW_TAG_WITH_V}\n${DATE_SUBHEADING}${CHANGELOG_ADDITION}$(cat CHANGELOG.md)" > CHANGELOG.md # Update changelog to add links to commits [hex:8](url_with_full_commit) - # "[aaaaaaaaaabbbbbbbbbbccccccccccddddddddd]" -> "[aaaaaaaa](https:/www.../commit/aaaaaaaaaabbbbbbbbbbccccccccccddddddddd)," + # "[aaaaaaaaaabbbbbbbbbbccccccccccddddddddd]" -> "[aaaaaaaa](https:/www.../commit/aaaaaaaaaabbbbbbbbbbccccccccccddddddddd)" sed -i -E "s=(\s)\[([0-9a-f]{8})([0-9a-f]{32})\]= [\2](${GIT_REPO_URL}/commit/\2\3)=g" ./CHANGELOG.md # 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 + # "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 } # update version in cargo.toml, to match selected current version diff --git a/docker-compose.yml b/docker-compose.yml index fd6905e..be077db 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -4,7 +4,7 @@ networks: name: oxker-examaple-net services: postgres: - image: postgres:alpine3.16 + image: postgres:alpine3.17 container_name: postgres environment: - POSTGRES_PASSWORD=never_use_this_password_in_production @@ -18,7 +18,7 @@ services: limits: memory: 128M redis: - image: redis:alpine3.16 + image: redis:alpine3.17 container_name: redis ipc: private restart: always diff --git a/src/app_data/container_state.rs b/src/app_data/container_state.rs index b1a2b64..39a2d6c 100644 --- a/src/app_data/container_state.rs +++ b/src/app_data/container_state.rs @@ -356,6 +356,7 @@ pub type CpuTuple = (Vec<(f64, f64)>, CpuStats, State); /// Info for each container #[derive(Debug, Clone)] pub struct ContainerItem { + pub created: u64, pub cpu_stats: VecDeque, pub docker_controls: StatefulList, pub id: ContainerId, @@ -366,19 +367,27 @@ pub struct ContainerItem { pub mem_stats: VecDeque, pub name: String, pub rx: ByteStats, - pub tx: ByteStats, pub state: State, pub status: String, + pub tx: ByteStats, } impl ContainerItem { /// Create a new container item - pub fn new(id: ContainerId, status: String, image: String, state: State, name: String) -> Self { + pub fn new( + id: ContainerId, + status: String, + image: String, + state: State, + name: String, + created: u64, + ) -> Self { let mut docker_controls = StatefulList::new(DockerControls::gen_vec(state)); docker_controls.start(); let mut logs = StatefulList::new(vec![]); logs.end(); Self { + created, cpu_stats: VecDeque::with_capacity(60), docker_controls, id, @@ -389,9 +398,9 @@ impl ContainerItem { mem_stats: VecDeque::with_capacity(60), name, rx: ByteStats::default(), - tx: ByteStats::default(), state, status, + tx: ByteStats::default(), } } diff --git a/src/app_data/mod.rs b/src/app_data/mod.rs index e429d1c..18fa486 100644 --- a/src/app_data/mod.rs +++ b/src/app_data/mod.rs @@ -11,10 +11,10 @@ pub use container_state::*; /// Global app_state, stored in an Arc #[derive(Debug, Clone)] pub struct AppData { - args: CliArgs, error: Option, logs_parsed: bool, sorted_by: Option<(Header, SortedOrder)>, + pub args: CliArgs, pub containers: StatefulList, } @@ -171,19 +171,20 @@ impl AppData { output } - /// Sort the containers vec, based on a heading, either ascending or descending - pub fn sort_containers(&mut self) { - if let Some((head, ord)) = self.sorted_by.as_ref() { + /// 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) { + if let Some((head, ord)) = self.sorted_by { match head { Header::State => match ord { - SortedOrder::Desc => self - .containers - .items - .sort_by(|a, b| a.state.order().cmp(&b.state.order())), SortedOrder::Asc => self .containers .items .sort_by(|a, b| b.state.order().cmp(&a.state.order())), + SortedOrder::Desc => self + .containers + .items + .sort_by(|a, b| a.state.order().cmp(&b.state.order())), }, Header::Status => match ord { SortedOrder::Asc => self @@ -238,6 +239,10 @@ impl AppData { SortedOrder::Desc => self.containers.items.sort_by(|a, b| b.tx.cmp(&a.tx)), }, } + } else { + self.containers + .items + .sort_by(|a, b| a.created.cmp(&b.created)) } } @@ -428,9 +433,13 @@ 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)); + 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 @@ -472,6 +481,8 @@ impl AppData { .map_or(String::new(), std::clone::Clone::clone); let id = ContainerId::from(id); + + let created = i.created.map_or(now, |i| u64::try_from(i).unwrap_or(now)); // 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 { @@ -496,7 +507,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); + let container = ContainerItem::new(id, status, image, state, name, created); self.containers.items.push(container); } } 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/input_handler/mod.rs b/src/input_handler/mod.rs index 5f61d01..5597eac 100644 --- a/src/input_handler/mod.rs +++ b/src/input_handler/mod.rs @@ -121,13 +121,16 @@ impl InputHandler { self.mouse_capture = !self.mouse_capture; } - /// Sort containers based on a given header, switch asc to desc if already sorted, else always desc - fn sort(&self, header: Header) { - let mut output = Some((header, SortedOrder::Desc)); + /// Sort containers based on a given header, if headings match, and already ascending, remove sorting + fn sort(&self, selected_header: Header) { let mut locked_data = self.app_data.lock(); - if let Some((h, order)) = locked_data.get_sorted().as_ref() { - if &SortedOrder::Desc == order && h == &header { - output = Some((header, SortedOrder::Asc)); + let mut output = Some((selected_header, SortedOrder::Asc)); + if let Some((current_header, order)) = locked_data.get_sorted() { + if current_header == selected_header { + match order { + SortedOrder::Desc => output = None, + SortedOrder::Asc => output = Some((selected_header, SortedOrder::Desc)), + } } } locked_data.set_sorted(output); diff --git a/src/main.rs b/src/main.rs index 6f69c8c..5b4b42a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -50,7 +50,6 @@ async fn main() { let docker = Arc::new(docker); let is_running = Arc::clone(&is_running); tokio::spawn(DockerData::init( - args, docker_app_data, docker, docker_gui_state, 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, }