added listing all running containers
All checks were successful
Rust Cross-Platform Build / Detect Rust Project (push) Successful in 5s
Rust Cross-Platform Build / Set Tag Name (push) Successful in 5s
Rust Cross-Platform Build / Run Tests (push) Successful in 1m13s
Rust Cross-Platform Build / Build (x86_64-unknown-linux-gnu) (push) Successful in 3m20s
Rust Cross-Platform Build / Build (x86_64-pc-windows-gnu) (push) Successful in 4m7s
Rust Cross-Platform Build / Build and Push Docker Image (push) Successful in 2m22s
Rust Cross-Platform Build / Workflow Summary (push) Successful in 1s
Rust Cross-Platform Build / Create Tag (push) Successful in 5s
All checks were successful
Rust Cross-Platform Build / Detect Rust Project (push) Successful in 5s
Rust Cross-Platform Build / Set Tag Name (push) Successful in 5s
Rust Cross-Platform Build / Run Tests (push) Successful in 1m13s
Rust Cross-Platform Build / Build (x86_64-unknown-linux-gnu) (push) Successful in 3m20s
Rust Cross-Platform Build / Build (x86_64-pc-windows-gnu) (push) Successful in 4m7s
Rust Cross-Platform Build / Build and Push Docker Image (push) Successful in 2m22s
Rust Cross-Platform Build / Workflow Summary (push) Successful in 1s
Rust Cross-Platform Build / Create Tag (push) Successful in 5s
This commit is contained in:
@@ -2,7 +2,7 @@ use std::time::Duration;
|
||||
|
||||
use crate::hardware::HardwareInfo;
|
||||
use crate::models::{HeartbeatDto, IdResponse, MetricDto, RegistrationDto, ServerMessage, Acknowledgment};
|
||||
use crate::serverclientcomm::handle_server_message;
|
||||
use crate::docker::serverclientcomm::handle_server_message;
|
||||
|
||||
use anyhow::Result;
|
||||
use reqwest::{Client, StatusCode};
|
||||
|
@@ -1,36 +1,69 @@
|
||||
use crate::models::DockerContainer;
|
||||
|
||||
use bollard::query_parameters::{ListContainersOptions};
|
||||
use bollard::Docker;
|
||||
|
||||
|
||||
// Add this function to debug the Docker connection and environment
|
||||
pub async fn get_available_container(docker: &Docker) {
|
||||
println!("=== DOCKER ENVIRONMENT DEBUG ===");
|
||||
|
||||
|
||||
pub async fn get_available_container(docker: &Docker) -> Vec<DockerContainer> {
|
||||
println!("=== DOCKER CONTAINER LIST ===");
|
||||
|
||||
// List containers to see what's available - CORRECTED
|
||||
let options = Some(ListContainersOptions {
|
||||
all: true, // include stopped containers
|
||||
all: true,
|
||||
..Default::default()
|
||||
});
|
||||
|
||||
match docker.list_containers(options).await {
|
||||
let containers_list = match docker.list_containers(options).await {
|
||||
Ok(containers) => {
|
||||
println!("Available containers ({}):", containers.len());
|
||||
for container in containers {
|
||||
if let Some(id) = container.id {
|
||||
let short_id = if id.len() > 12 { &id[..12] } else { &id };
|
||||
println!(" - ID: {}, Image: {:?}", short_id, container.image);
|
||||
containers.into_iter()
|
||||
.filter_map(|container| {
|
||||
container.id.as_ref()?; // Skip if no ID
|
||||
|
||||
// Also print the names for easier identification
|
||||
if let Some(names) = container.names {
|
||||
println!(" Names: {:?}", names);
|
||||
}
|
||||
}
|
||||
}
|
||||
let id = container.id?;
|
||||
let short_id = if id.len() > 12 { &id[..12] } else { &id };
|
||||
|
||||
let name = container.names
|
||||
.and_then(|names| names.into_iter().next())
|
||||
.map(|name| name.trim_start_matches('/').to_string())
|
||||
.unwrap_or_else(|| "unknown".to_string());
|
||||
|
||||
let image = container.image
|
||||
.as_ref()
|
||||
.map(|img| img.to_string())
|
||||
.unwrap_or_else(|| "unknown".to_string());
|
||||
|
||||
let status = container.status
|
||||
.as_ref()
|
||||
.map(|s| match s.to_lowercase().as_str() {
|
||||
s if s.contains("up") || s.contains("running") => "running".to_string(),
|
||||
s if s.contains("exited") || s.contains("stopped") => "stopped".to_string(),
|
||||
_ => s.to_string(),
|
||||
})
|
||||
.unwrap_or_else(|| "unknown".to_string());
|
||||
|
||||
println!(" - ID: {}, Image: {:?}, Name: {}", short_id, container.image, name);
|
||||
|
||||
Some(DockerContainer {
|
||||
ID: short_id.to_string(),
|
||||
image,
|
||||
Name: name,
|
||||
Status: status,
|
||||
_net_in: 0.0,
|
||||
_net_out: 0.0,
|
||||
_cpu_load: 0.0,
|
||||
})
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
Err(e) => {
|
||||
eprintln!("Failed to list containers: {}", e);
|
||||
Vec::new()
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
containers_list
|
||||
}
|
||||
|
||||
pub fn extract_container_id(line: &str) -> Option<String> {
|
||||
|
@@ -1,12 +1,19 @@
|
||||
pub mod container;
|
||||
pub mod serverclientcomm;
|
||||
|
||||
//use std::error::Error;
|
||||
use std::error::Error;
|
||||
use crate::models::DockerContainer;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct DockerInfo {
|
||||
pub number: u16,
|
||||
pub net_in_total: f64,
|
||||
pub net_out_total: f64,
|
||||
pub dockers: Vec<DockerContainer>,
|
||||
pub number: Option<u16>,
|
||||
pub net_in_total: Option<f64>,
|
||||
pub net_out_total: Option<f64>,
|
||||
pub dockers: Option<Vec<DockerContainer>>,
|
||||
}
|
||||
|
||||
impl DockerInfo {
|
||||
pub async fn collect() -> Result<Self, Box<dyn Error + Send + Sync>> {
|
||||
Ok(Self { number: None, net_in_total: None, net_out_total: None, dockers: None })
|
||||
}
|
||||
}
|
@@ -5,7 +5,6 @@ pub mod api;
|
||||
pub mod hardware;
|
||||
pub mod metrics;
|
||||
pub mod models;
|
||||
pub mod serverclientcomm;
|
||||
pub mod docker;
|
||||
|
||||
use std::env;
|
||||
@@ -16,8 +15,6 @@ use std::result::Result;
|
||||
use tokio::task::JoinHandle;
|
||||
use bollard::Docker;
|
||||
|
||||
use crate::serverclientcomm::{get_current_image};
|
||||
|
||||
async fn flatten<T>(
|
||||
handle: JoinHandle<Result<T, Box<dyn Error + Send + Sync>>>,
|
||||
) -> Result<T, Box<dyn Error + Send + Sync>> {
|
||||
@@ -35,7 +32,7 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
|
||||
.map_err(|e| format!("Failed to connect to Docker: {}", e))?;
|
||||
|
||||
// Get current image version
|
||||
let client_version = match get_current_image(&docker).await {
|
||||
let client_version = match docker::serverclientcomm::get_current_image(&docker).await {
|
||||
Ok(Some(version)) => version,
|
||||
Ok(None) => {
|
||||
eprintln!("Warning: No image version found");
|
||||
|
@@ -106,7 +106,7 @@ pub struct DockerContainer {
|
||||
pub image: String,
|
||||
pub Name: String,
|
||||
pub Status: String, // "running";"stopped";others
|
||||
pub net_in: f64,
|
||||
pub net_out: f64,
|
||||
pub cpu_load: f64,
|
||||
pub _net_in: f64,
|
||||
pub _net_out: f64,
|
||||
pub _cpu_load: f64,
|
||||
}
|
Reference in New Issue
Block a user