A focused Docker Compose management web application.
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

feat: begin work on list_from_filesystem

Brooke c7ecc0f8 e7250b31

+37 -8
+1
.gitignore
··· 1 + .env
+1 -1
packages/macros/src/lib.rs
··· 23 23 24 24 return quote! { 25 25 #visibility #signature { 26 - (#asyncness move || #output #block)()#wait.wrap_err(#attr) 26 + color_eyre::eyre::WrapErr::wrap_err((#asyncness move || #output #block)()#wait, #attr) 27 27 } 28 28 } 29 29 .into();
+1
packages/node/Cargo.toml
··· 14 14 "rt-multi-thread", 15 15 "macros", 16 16 "process", 17 + "fs", 17 18 ] } 18 19 itertools = "0.14.0"
+34 -7
packages/node/src/core/project.rs
··· 1 1 use std::collections::HashMap; 2 2 3 3 use bollard::query_parameters::ListContainersOptionsBuilder; 4 - use color_eyre::eyre::{Ok, Result}; 4 + use color_eyre::eyre::{Ok, Result, WrapErr}; 5 + use luminary_macros::wrap_err; 6 + use tokio::fs; 5 7 6 8 use crate::core::{ 7 9 LuminaryCore, 8 10 model::{LuminaryProject, LuminaryService}, 11 + project, 9 12 }; 10 13 11 14 const COMPOSE_PROJECT_DIR_LABEL: &str = "com.docker.compose.project.working_dir"; 12 15 const COMPOSE_PROJECT_LABEL: &str = "com.docker.compose.project"; 13 16 const COMPOSE_SERVICE_LABEL: &str = "com.docker.compose.service"; 14 17 18 + const ENV_PROJECT_DIRECTORY: &str = "LUMINARY_PROJECT_DIRECTORY"; 19 + 15 20 impl LuminaryCore { 16 - pub async fn get_projects(&self) -> Result<HashMap<String, LuminaryProject>> { 21 + #[wrap_err("Failed to list projects from filesystem")] 22 + async fn list_from_filesystem(&self) -> Result<HashMap<String, LuminaryProject>> { 23 + let dir = std::env::var(ENV_PROJECT_DIRECTORY) 24 + .wrap_err("Failed to read project directory from environment variable")?; 25 + 26 + let mut projects = HashMap::<String, LuminaryProject>::new(); 27 + 28 + let mut entries = fs::read_dir(dir) 29 + .await 30 + .wrap_err("Failed to list project directory contents")?; 31 + while let Some(entry) = entries.next_entry().await? { 32 + let path = entry.path(); 33 + // do something with path 34 + } 35 + 36 + return Ok(projects); 37 + } 38 + 39 + #[wrap_err("Failed to list projects from docker engine")] 40 + async fn list_from_docker(&self) -> Result<HashMap<String, LuminaryProject>> { 17 41 let options = ListContainersOptionsBuilder::default().all(true).build(); 18 - let projects = self.docker.list_containers(Some(options)).await?.iter_mut().fold( 19 - HashMap::<String, LuminaryProject>::new(), 20 - |mut acc, container| { 42 + let projects = self 43 + .docker 44 + .list_containers(Some(options)) 45 + .await 46 + .wrap_err("Failed to fetch containers from docker engine")? 47 + .iter_mut() 48 + .fold(HashMap::<String, LuminaryProject>::new(), |mut acc, container| { 21 49 if let Some(mut labels) = container.labels.take() 22 50 && let Some(service) = labels.remove(COMPOSE_SERVICE_LABEL) 23 51 && let Some(project) = labels.remove(COMPOSE_PROJECT_LABEL) ··· 34 62 } 35 63 36 64 return acc; 37 - }, 38 - ); 65 + }); 39 66 40 67 return Ok(projects); 41 68 }