Skip to content

Commit

Permalink
feat: exec mode improvements
Browse files Browse the repository at this point in the history
Use Bollard library to exec in pure Rust.

`--use-cli` cli arg, will then only try to exec into containers using
Docker.

Only try to exec into a container if the state == Running.
  • Loading branch information
mrjackwills committed Nov 18, 2023
1 parent 28b0315 commit 0e5ee14
Show file tree
Hide file tree
Showing 15 changed files with 478 additions and 143 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/create_release_and_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ jobs:
artifacts: |
**/oxker_*.zip
**/oxker_*.tar.gz
#########################
## Publish to crates.io #
#########################
Expand All @@ -106,6 +107,7 @@ jobs:
#########################################
## Build images for Dockerhub & ghcr.io #
#########################################

image_build:
needs: [cargo_publish]
runs-on: ubuntu-latest
Expand Down
15 changes: 8 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,14 @@ In application controls
Available command line arguments
| argument|result|
|--|--|
|```-d [number > 0]```| set the minimum update interval for docker information, in ms, defaults to 1000 (1 second) |
|```--host [hostname]```| connect to Docker with a custom hostname, defaults to `/var/run/docker.sock`, will use `$DOCKER_HOST` env if set |
|```-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 |
|```-d [number > 0]```| Set the minimum update interval for docker information in milliseconds. Defaults to 1000 (1 second).|
|```--host [hostname]```| Connect to Docker with a custom hostname. Defaults to `/var/run/docker.sock`. Will use `$DOCKER_HOST` environment variable if set.|
|```--use-cli```| When executing into a container, use the external Docker CLI application.|
|```-r```| Show raw logs. By default, removes 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 display the oxker container.|
|```-g```| No TUI, essentially a debugging mode with limited functionality, for now.|

## Build step

Expand Down
19 changes: 2 additions & 17 deletions containerised/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -45,32 +45,17 @@ RUN cargo build --release --target $(cat /.platform)

RUN cp /usr/src/oxker/target/$(cat /.platform)/release/oxker /

################
## MUSL SETUP ##
################

FROM alpine:3.18 as MUSL_SETUP

RUN apk add --update --no-cache docker-cli upx

# Compress the docker executable, to reduce final image size
RUN upx -9 /usr/bin/docker

#############
## Runtime ##
#############

FROM alpine:3.18 as RUNTIME
FROM scratch as RUNTIME

# Set an ENV to indicate that we're running in a container
ENV OXKER_RUNTIME=container

COPY --from=BUILDER /oxker /app/
COPY --from=MUSL_SETUP /usr/bin/docker /usr/bin/

# remove sh and busybox, probably pointless
RUN rm /bin/sh /bin/busybox

# Run the application
# this is used in the application itself so DO NOT EDIT
ENTRYPOINT [ "/app/oxker"]
ENTRYPOINT [ "/app/oxker"]
26 changes: 7 additions & 19 deletions containerised/Dockerfile_dev
Original file line number Diff line number Diff line change
@@ -1,28 +1,12 @@
################
## MUSL SETUP ##
################

FROM alpine:3.18 as MUSL_SETUP

RUN apk add --update --no-cache docker-cli upx

# Copy application binary from builder image
RUN upx -9 /usr/bin/docker

#############
## Runtime ##
#############
FROM scratch

FROM alpine:3.18 as RUNTIME

# Set an ENV that we're running in a container, so that the application can sleep for 250ms at start
# Set env that we're running in a container, so that the application can sleep for 250ms at start
ENV OXKER_RUNTIME=container

COPY --from=MUSL_SETUP /usr/bin/docker /usr/bin/


RUN rm /bin/sh /bin/busybox

# Copy application binary from builder image
COPY ./target/x86_64-unknown-linux-musl/release/oxker /app/

# Run the application
Expand All @@ -44,3 +28,7 @@ ENTRYPOINT [ "/app/oxker"]
# 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 .


# Build production version for x86 only, then run
# docker build --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
8 changes: 7 additions & 1 deletion src/app_data/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ impl AppData {

#[cfg(debug_assertions)]
#[allow(unused)]
pub fn set_debug_string(&mut self, x: &str) {
pub fn push_debug_string(&mut self, x: &str) {
self.debug_string.push_str(x);
}

Expand Down Expand Up @@ -506,6 +506,12 @@ impl AppData {
self.get_selected_container().map(|i| i.id.clone())
}

/// Get the Id and State for the currently selected container - used by the exec check method
pub fn get_selected_container_id_state(&self) -> Option<(ContainerId, State)> {
self.get_selected_container()
.map(|i| (i.id.clone(), i.state))
}

/// Update container mem, cpu, & network stats, in single function so only need to call .lock() once
/// Will also, if a sort is set, sort the containers
pub fn update_stats(
Expand Down
2 changes: 1 addition & 1 deletion src/app_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ impl fmt::Display for AppError {
let reason = if *x { "en" } else { "dis" };
write!(f, "Unable to {reason}able mouse capture")
}
Self::Terminal => write!(f, "Unable to draw to terminal"),
Self::Terminal => write!(f, "Unable to fully render to terminal"),
}
}
}
9 changes: 7 additions & 2 deletions src/docker_data/message.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
use std::sync::Arc;

use crate::app_data::ContainerId;
use bollard::Docker;
use tokio::sync::oneshot::Sender;

#[derive(Debug, Clone)]
#[derive(Debug)]
pub enum DockerMessage {
Delete(ContainerId),
ConfirmDelete(ContainerId),
Delete(ContainerId),
Exec(Sender<Arc<Docker>>),
Pause(ContainerId),
Quit,
Restart(ContainerId),
Expand Down
4 changes: 4 additions & 0 deletions src/docker_data/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@ impl DockerData {

/// Handle incoming messages, container controls & all container information update
/// Spawn Docker commands off into own thread
#[allow(clippy::too_many_lines)]
async fn message_handler(&mut self) {
while let Some(message) = self.receiver.recv().await {
let docker = Arc::clone(&self.docker);
Expand All @@ -338,6 +339,9 @@ impl DockerData {
let uuid = Uuid::new_v4();
// TODO need to refactor these
match message {
DockerMessage::Exec(sender) => {
sender.send(Arc::clone(&self.docker)).ok();
}
DockerMessage::Pause(id) => {
tokio::spawn(async move {
let handle = GuiState::start_loading_animation(&gui_state, uuid);
Expand Down
Loading

0 comments on commit 0e5ee14

Please sign in to comment.