A focused Docker Compose management web application.
0
fork

Configure Feed

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

feat: luminary node-wide config

Brooke 8bedb831 78f689a9

+40 -17
+3 -1
.env.example
··· 1 - LUMINARY_PROJECT_DIRECTORY=/opt/stacks # Directory where Luminary will look for projects. 1 + LUMINARY_PROJECT_DIRECTORY=/opt/stacks # Directory where Luminary will look for projects. 2 + LUMINARY_ADDRESS=0.0.0.0:9000 # Address and port that the Luminary Node will listen on. 3 + RUST_LOG=info # Set the log level for the Luminary Node
+1 -3
packages/node/src/api/mod.rs
··· 22 22 23 23 /// Sets up the app router and all dependencies. 24 24 #[wrap_err("Crashed while setting up")] 25 - pub async fn setup(pool: SqlitePool, logs: BroadcastLayer) -> Result<Router> { 26 - let engine = LuminaryEngine::setup().await?; 27 - 25 + pub async fn setup(engine: LuminaryEngine, pool: SqlitePool, logs: BroadcastLayer) -> Result<Router> { 28 26 // Set up the affix state with all dependencies 29 27 let affix = affix_state::inject(LuminaryAuthentication::new(pool.clone())) 30 28 .inject(engine)
+17
packages/node/src/configuration.rs
··· 1 + use serde::Deserialize; 2 + 3 + /// A struct containing Luminary configuration, to be loaded from environment variables. 4 + #[derive(Deserialize, Debug)] 5 + pub struct LuminaryConfiguration { 6 + /// The directory where Luminary will look to find projects. 7 + pub project_directory: String, 8 + 9 + /// The address and port that the Luminary Node will listen on. 10 + #[serde(default = "default_address")] 11 + pub address: String, 12 + } 13 + 14 + // Provides a default address for the Luminary Node. 15 + fn default_address() -> String { 16 + return "0.0.0.0:9000".to_string(); 17 + }
-7
packages/node/src/core/configuration.rs
··· 1 - use serde::Deserialize; 2 - 3 - /// A struct containing Luminary configuration, to be loaded from environment variables. 4 - #[derive(Deserialize, Debug)] 5 - pub struct LuminaryConfiguration { 6 - pub project_directory: String, 7 - }
+5 -3
packages/node/src/core/engine.rs
··· 14 14 sync::{Mutex, RwLock, broadcast}, 15 15 }; 16 16 17 - use crate::core::{LuminaryStateList, ProjectLogChannel, configuration::LuminaryConfiguration}; 17 + use crate::{ 18 + configuration::LuminaryConfiguration, 19 + core::{LuminaryStateList, ProjectLogChannel}, 20 + }; 18 21 19 22 /// The core engine of the Luminary application, containing shared state and configuration. 20 23 #[derive(Debug, Clone)] ··· 38 41 impl LuminaryEngine { 39 42 /// Initializes a new instance of the Engine struct, loading configuration from environment variables and connecting to the Docker engine. 40 43 #[wrap_err("Failed to create LuminaryEngine")] 41 - pub async fn setup() -> Result<Self> { 44 + pub async fn setup(configuration: Arc<LuminaryConfiguration>) -> Result<Self> { 42 45 let docker = Docker::connect_with_defaults().wrap_err("Failed to connect to docker engine.")?; 43 - let configuration = Arc::new(envy::prefixed("LUMINARY_").from_env::<LuminaryConfiguration>()?); 44 46 45 47 let instance = Self { 46 48 state: Arc::new(RwLock::new(LuminaryStateList::new())),
-1
packages/node/src/core/mod.rs
··· 4 4 5 5 mod action; 6 6 mod compose; 7 - mod configuration; 8 7 mod engine; 9 8 mod logs; 10 9 mod model;
+14 -2
packages/node/src/main.rs
··· 1 1 //! The main entry point for the Luminary Node, which serves as the backend for the Luminary Panel. 2 2 3 + use std::sync::Arc; 4 + 3 5 use eyre::{Context, Result}; 4 6 use log::debug; 5 7 use salvo::prelude::*; ··· 8 10 EnvFilter, Layer, filter::LevelFilter, layer::SubscriberExt, util::SubscriberInitExt, 9 11 }; 10 12 13 + use crate::{configuration::LuminaryConfiguration, core::LuminaryEngine}; 14 + 11 15 const DATABASE: &str = "luminary.db"; 12 16 13 17 mod api; 18 + mod configuration; 14 19 mod core; 15 20 mod logging; 16 21 mod util; ··· 32 37 .with(fmt_layer) 33 38 .init(); 34 39 40 + // Load configuration 41 + #[cfg(debug_assertions)] 42 + let configuration = Arc::new(envy::prefixed("LUMINARY_").from_env::<LuminaryConfiguration>()?); 43 + 35 44 // Set up the app and dependencies 36 - let listener = TcpListener::new("0.0.0.0:9000").bind().await; 37 - let router = api::setup(setup_database().await?, broadcast_layer).await?; 45 + let listener = TcpListener::new(configuration.address.clone()).bind().await; 46 + let engine = LuminaryEngine::setup(configuration).await?; 47 + let pool = setup_database().await?; 48 + 49 + let router = api::setup(engine, pool, broadcast_layer).await?; 38 50 39 51 // Log router structure for debugging 40 52 debug!("Router structure: {router:?}");