Skip to content

Commit

Permalink
feat: set log timezone, closes #56
Browse files Browse the repository at this point in the history
Implement a CLI arg, and config file setting, for changing the timezone of the Docker logs timestamp
  • Loading branch information
mrjackwills committed Feb 21, 2025
1 parent 8305e6f commit 17a5e7a
Show file tree
Hide file tree
Showing 27 changed files with 1,121 additions and 162 deletions.
46 changes: 46 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ clap = { version = "4.5", features = ["color", "derive", "unicode"] }
crossterm = "0.28"
directories = "6.0"
futures-util = "0.3"
jiff = { version = "0.2", features = ["tzdb-bundle-always"] }
parking_lot = { version = "0.12" }
ratatui = "0.29"
serde = { version = "1.0", features = ["derive"] }
Expand All @@ -45,6 +46,7 @@ tracing = "0.1"
tracing-subscriber = "0.3"
uuid = { version = "1.12", features = ["fast-rng", "v4"] }


[profile.release]
lto = true
codegen-units = 1
Expand Down
25 changes: 23 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,7 @@ curl https://raw.githubusercontent.com/mrjackwills/oxker/main/install.sh | bash
```shell
oxker
```

In application controls
In application controls, these can be customized with the [config file](#Config-File)
| button| result|
|--|--|
| ```( tab )``` or ```( shift+tab )``` | Change panel, clicking on a panel also changes the selected panel.|
Expand All @@ -118,6 +117,7 @@ In application controls
| ```( esc )``` | Close dialog.|

Available command line arguments

| argument|result|
|--|--|
|```-d [number > 0]```| Set the minimum update interval for docker information in milliseconds. Defaults to 1000 (1 second).|
Expand All @@ -126,11 +126,30 @@ Available command line arguments
|```-t```| Remove timestamps from each log entry.|
|```-s```| If running via Docker, will display the oxker container.|
|```-g```| No TUI, essentially a debugging mode with limited functionality, for now.|
|```--config-file [string]```| Location of a `config.toml`/`config.json`/`config.jsonc`.|
|```--host [string]```| Connect to Docker with a custom hostname. Defaults to `/var/run/docker.sock`. Will use `$DOCKER_HOST` environment variable if set.|
|```--no-stderr```| Do not include stderr output in logs.|
|```--save-dir [string]```| Save exported logs into a custom directory. Defaults to `$HOME`.|
|```--timezone [string]```| Display the Docker logs timestamps in a given [timezone](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones). Defaults to `Etc/UTC`.|
|```--use-cli```| Use the Docker application when exec-ing into a container, instead of the Docker API.|

### Config File


A config file enables the user to persist settings, it also enables the user to create a custom keymap, and set the color scheme used by the application.
<br>
<br>
By default, if not found, `oxker` will create a config file in the user's local config directory. Command line arguments take priority over values from the config file.
<br>
<br>
`oxker` supports `.toml`,`.json`, and `.jsonc` file formats. Examples of each can be found in the [example_config](https://github.com/mrjackwills/oxker/tree/main/example_config) directory.

If running an `oxker` container, the default config location will be `/config.toml` rather than the automatically detected platform-specific local config directory.

```shell
docker run --rm -it -v /var/run/docker.sock:/var/run/docker.sock:ro -v /some/location/config.toml:/config.toml:ro oxker
```

## Build step

### x86_64
Expand Down Expand Up @@ -163,8 +182,10 @@ If no memory information available, try appending either ```/boot/cmdline.txt```

see <a href="https://forums.raspberrypi.com/viewtopic.php?t=203128" target='_blank' rel='noopener noreferrer'>https://forums.raspberrypi.com/viewtopic.php?t=203128</a> and <a href="https://github.com/docker/for-linux/issues/1112" target='_blank' rel='noopener noreferrer'>https://github.com/docker/for-linux/issues/1112</a>


### Untested on other platforms


## Tests

~~As of yet untested, needs work~~
Expand Down
4 changes: 4 additions & 0 deletions containerised/Dockerfile_dev
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,13 @@ COPY ./target/x86_64-unknown-linux-musl/release/oxker /app/
# this is used in the application itself, to stop itself show when running from a docker container, so DO NOT EDIT
ENTRYPOINT [ "/app/oxker"]


# Dev build for testing
# 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

# docker run --rm -it --volume /var/run/docker.sock:/var/run/docker.sock:ro --volume ./example_config/example.config.toml:/config.toml:ro oxker_dev --config-file /config.toml

# docker run --rm -it --volume /etc/timezone:/etc/timezone:ro --volume /etc/localtime:/etc/localtime:ro --volume /var/run/docker.sock:/var/run/docker.sock:ro --volume ./example_config/example.config.toml:/config.toml:ro oxker_dev --config-file /config.toml
# Dev build one liner, x86 host
# docker image prune -a; 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

Expand Down
80 changes: 80 additions & 0 deletions create_release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,40 @@ check_allow_unused() {
fi
}

# build container for amd64 platform
build_container_amd64() {
docker image rm oxker_amd64:latest
docker builder prune -a
echo -e "${YELLOW}docker build --platform linux/amd64 -t oxker_amd64 -f containerised/Dockerfile .; docker save -o /tmp/oxker_amd64.tar oxker_amd64${RESET}"
docker build --platform linux/amd64 -t oxker_amd64 -f containerised/Dockerfile .
docker save -o /tmp/oxker_amd64.tar oxker_amd64
}
# build container for aarm64 platform
build_container_arm64() {
docker image rm oxker_arm64:latest
docker builder prune -a
echo -e "${YELLOW}docker build --platform linux/arm64 -t oxker_arm64 -f containerised/Dockerfile .; docker save -o /tmp/oxker_arm64.tar oxker_arm64${RESET}"
docker build --platform linux/arm64 -t oxker_arm64 -f containerised/Dockerfile .
docker save -o /tmp/oxker_arm64.tar oxker_arm64
}
# build container for armv6 platform
build_container_armv6() {
docker image rm oxker_armv6:latest
docker builder prune -a
echo -e "${YELLOW}docker build --platform linux/arm/v6 -t oxker_armv6 -f containerised/Dockerfile .; docker save -o /tmp/oxker_armv6.tar oxker_armv6${RESET}"
docker build --platform linux/arm/v6 -t oxker_armv6 -f containerised/Dockerfile .
docker save -o /tmp/oxker_armv6.tar oxker_armv6
}

# Build all the containers, this get executed in the github action
build_container_all() {
build_container_amd64
ask_continue
build_container_arm64
ask_continue
build_container_armv6
}

# Full flow to create a new release
release_flow() {
check_allow_unused
Expand All @@ -276,6 +310,7 @@ release_flow() {

cargo_test
cross_build_all
build_container_all
cargo_publish_dry_run

cd "${CWD}" || error_close "Can't find ${CWD}"
Expand Down Expand Up @@ -379,6 +414,45 @@ build_choice() {
;;
esac
done
}

build_container_choice() {
cmd=(dialog --backtitle "Choose option" --radiolist "choose" 14 80 16)
options=(
1 "x86 " off
2 "aarch64" off
3 "armv6" off
4 "all" off
)
choices=$("${cmd[@]}" "${options[@]}" 2>&1 >/dev/tty)
exitStatus=$?
clear
if [ $exitStatus -ne 0 ]; then
exit
fi
for choice in $choices; do
case $choice in
0)
exit
;;
1)
build_container_amd64
exit
;;
2)
build_container_arm64
exit
;;
3)
build_container_armv6
exit
;;
4)
build_container_all
exit
;;
esac
done

}

Expand All @@ -388,6 +462,7 @@ main() {
1 "test" off
2 "release" off
3 "build" off
4 "docker builds" off
)
choices=$("${cmd[@]}" "${options[@]}" 2>&1 >/dev/tty)
exitStatus=$?
Expand All @@ -414,6 +489,11 @@ main() {
main
break
;;
4)
build_container_choice
main
break
;;
esac
done
}
Expand Down
6 changes: 6 additions & 0 deletions example_config/example.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
"show_self": false,
"show_std_err": false,
"show_timestamp": true,
"timezone": "Etc/UTC",
"timestamp_format":"%Y-%m-%dT%H:%M:%S.%8f",
"use_cli": false,
"colors": {
"borders": {
Expand Down Expand Up @@ -68,6 +70,10 @@
"text": "black",
"text_selected": "gray"
},
"logs": {
"background": "reset",
"text": "reset"
},
"popup_delete": {
"background": "white",
"text": "black",
Expand Down
14 changes: 13 additions & 1 deletion example_config/example.config.jsonc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
// Example JSONC config file
// This needs to be renamed to "config.jsonc" ("config.json" will also work, even if the file is actually a jsonc) in order for oxker to automatically load
// oxker will also read .jsonc and .json files which use the same key/value structure & format as this file
// oxker will also read .toml and .json files which use the same key/value structure & format as this file
// Every key is optional, with defaults that oxker will choose if missing or invalid
// The `--config-file` cli argument can be used to load configuration files from any readable location
// Docker update interval in ms, minimum effectively 1000
Expand All @@ -20,6 +20,11 @@
"gui": true,
// Docker host location
"host": "/var/run/docker.sock",
// Display the timestamp in a custom format, if given option is invalid, it will default to %Y-%m-%dT%H:%M:%S.%8f -> 2025-02-18T12:34:56.01234567
// *Should* accept any valid strftime string up to 32 chars
"timestamp_format":"%Y-%m-%dT%H:%M:%S.%8f",
// Display the container logs timestamp with a given timezone, if timezone is unknown, defaults to UTC
"timezone": "Etc/UTC",
// Directory for saving exported logs, defaults to `$HOME`, this is automatically *correctly* calculated for Linux, Mac, and Windows
// "save_dir": "$HOME",
// Force use of docker cli when execing into containers, honestly mostly pointless
Expand Down Expand Up @@ -246,6 +251,13 @@
// Ports & IP listing text
"text": "white"
},
// The logs panel, will only be applied if color_logs is false
"logs": {
// Background color of panel
"background": "reset",
// text color
"text": "reset"
},
// The help popup
"popup_help": {
// Background color
Expand Down
19 changes: 15 additions & 4 deletions example_config/example.config.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
# Example toml config file

# This needs to be renamed to "config.toml" in order for oxker to automatically load
# oxker config file
# oxker will also read .jsonc and .json files which use the same key/value structure & format as this file

# Every key is optional, with defaults that oxker will choose if missing or invalid
# The `--config-file` cli argument can be used to load configuration files from any readable location

Expand Down Expand Up @@ -30,6 +27,13 @@ gui = true
# Docker host location
host = "/var/run/docker.sock"

# Display the container logs timestamp with a given timezone, if timezone is unknown, defaults to UTC
timezone = "Etc/UTC"

# Display the timestamp in a custom format, if given option is invalid, it will default to %Y-%m-%dT%H:%M:%S.%8f -> 2025-02-18T12:34:56.012345678Z
# *Should* accept any valid strftime string up to 32 chars
timestamp_format="%Y-%m-%dT%H:%M:%S.%8f"

# Directory for saving exported logs, defaults to `$HOME`, this is automatically *correctly* calculated for Linux, Mac, and Windows
# save_dir = "$HOME"

Expand Down Expand Up @@ -141,6 +145,13 @@ text_rx="#FFE9C1"
# Text color of the TX column
text_tx="#CD8C8C"

# The logs panel, will only be applied if color_logs is false
[colors.logs]
# Background color of panel
background = "reset"
# text color
text="reset"

# Each state of a container has a color, which is used in multiple places, i.e. chart titles, state/status/cpu/memory columns in the container section
[colors.container_state]
dead="red"
Expand Down
Loading

0 comments on commit 17a5e7a

Please # to comment.