@@ -8,7 +8,7 @@ use cb_common::{
88 SIGNER_KEYS , SIGNER_KEYS_ENV , SIGNER_SERVER_ENV ,
99 } ,
1010 loader:: SignerLoader ,
11- utils:: { random_jwt, ENV_ROLLING_DURATION } ,
11+ utils:: { random_jwt, MAX_LOG_FILES_ENV , ROLLING_DURATION_ENV , RUST_LOG_ENV } ,
1212} ;
1313use docker_compose_types:: {
1414 Compose , ComposeVolume , DependsOnOptions , Environment , Labels , LoggingParameters , MapOrEmpty ,
@@ -27,8 +27,6 @@ pub(super) const PROMETHEUS_DATA_VOLUME: &str = "prometheus-data";
2727const METRICS_NETWORK : & str = "monitoring_network" ;
2828const SIGNER_NETWORK : & str = "signer_network" ;
2929
30- const ENV_RUST_LOG : & str = "RUST_LOG" ;
31-
3230/// Builds the docker compose file for the Commit-Boost services
3331
3432// TODO: do more validation for paths, images, etc
@@ -45,15 +43,14 @@ pub fn handle_docker_init(config_path: String, output_dir: String) -> Result<()>
4543 let config_volume = Volumes :: Simple ( format ! ( "./{}:{}:ro" , config_path, CB_CONFIG_NAME ) ) ;
4644 let log_volume = Volumes :: Simple ( format ! (
4745 "{}:{}" ,
48- cb_config. logs. host_path . to_str( ) . unwrap( ) ,
46+ cb_config. logs. log_dir_path . to_str( ) . unwrap( ) ,
4947 CB_BASE_LOG_PATH
5048 ) ) ;
5149
5250 let mut jwts = IndexMap :: new ( ) ;
5351 // envs to write in .env file
5452 let mut envs = IndexMap :: from ( [ ( CB_CONFIG_ENV . into ( ) , CB_CONFIG_NAME . into ( ) ) ] ) ;
55- envs. insert ( ENV_ROLLING_DURATION . into ( ) , cb_config. logs . duration . to_string ( ) ) ;
56- envs. insert ( ENV_RUST_LOG . into ( ) , cb_config. logs . rust_log ) ;
53+
5754 // targets to pass to prometheus
5855 let mut targets = Vec :: new ( ) ;
5956 let metrics_port = 10000 ;
@@ -73,8 +70,14 @@ pub fn handle_docker_init(config_path: String, output_dir: String) -> Result<()>
7370
7471 let mut pbs_envs = IndexMap :: from ( [
7572 get_env_same ( CB_CONFIG_ENV ) ,
76- get_env_val ( METRICS_SERVER_ENV , & metrics_port. to_string ( ) ) ,
73+ get_env_uval ( METRICS_SERVER_ENV , metrics_port as u64 ) ,
74+ get_env_val ( ROLLING_DURATION_ENV , & cb_config. logs . rotation . to_string ( ) ) ,
75+ get_env_val ( RUST_LOG_ENV , & cb_config. logs . log_level ) ,
7776 ] ) ;
77+ if let Some ( max_files) = cb_config. logs . max_log_files {
78+ let ( key, val) = get_env_uval ( MAX_LOG_FILES_ENV , max_files as u64 ) ;
79+ pbs_envs. insert ( key, val) ;
80+ }
7881
7982 let mut needs_signer_module = cb_config. pbs . with_signer ;
8083
@@ -98,13 +101,19 @@ pub fn handle_docker_init(config_path: String, output_dir: String) -> Result<()>
98101 let jwt_name = format ! ( "CB_JWT_{}" , module. id. to_uppercase( ) ) ;
99102
100103 // module ids are assumed unique, so envs dont override each other
101- let module_envs = IndexMap :: from ( [
104+ let mut module_envs = IndexMap :: from ( [
102105 get_env_val ( MODULE_ID_ENV , & module. id ) ,
103106 get_env_same ( CB_CONFIG_ENV ) ,
104107 get_env_interp ( MODULE_JWT_ENV , & jwt_name) ,
105- get_env_val ( METRICS_SERVER_ENV , & metrics_port. to_string ( ) ) ,
108+ get_env_uval ( METRICS_SERVER_ENV , metrics_port as u64 ) ,
106109 get_env_val ( SIGNER_SERVER_ENV , & signer_server) ,
110+ get_env_val ( ROLLING_DURATION_ENV , & cb_config. logs . rotation . to_string ( ) ) ,
111+ get_env_val ( RUST_LOG_ENV , & cb_config. logs . log_level ) ,
107112 ] ) ;
113+ if let Some ( max_files) = cb_config. logs . max_log_files {
114+ let ( key, val) = get_env_uval ( MAX_LOG_FILES_ENV , max_files as u64 ) ;
115+ module_envs. insert ( key, val) ;
116+ }
108117
109118 envs. insert ( jwt_name. clone ( ) , jwt. clone ( ) ) ;
110119 jwts. insert ( module. id . clone ( ) , jwt) ;
@@ -126,12 +135,18 @@ pub fn handle_docker_init(config_path: String, output_dir: String) -> Result<()>
126135 // an event module just needs a port to listen on
127136 ModuleKind :: Events => {
128137 // module ids are assumed unique, so envs dont override each other
129- let module_envs = IndexMap :: from ( [
138+ let mut module_envs = IndexMap :: from ( [
130139 get_env_val ( MODULE_ID_ENV , & module. id ) ,
131140 get_env_same ( CB_CONFIG_ENV ) ,
132- get_env_val ( METRICS_SERVER_ENV , & metrics_port. to_string ( ) ) ,
141+ get_env_uval ( METRICS_SERVER_ENV , metrics_port as u64 ) ,
133142 get_env_val ( BUILDER_SERVER_ENV , & builder_events_port. to_string ( ) ) ,
143+ get_env_val ( ROLLING_DURATION_ENV , & cb_config. logs . rotation . to_string ( ) ) ,
144+ get_env_val ( RUST_LOG_ENV , & cb_config. logs . log_level ) ,
134145 ] ) ;
146+ if let Some ( max_files) = cb_config. logs . max_log_files {
147+ let ( key, val) = get_env_uval ( MAX_LOG_FILES_ENV , max_files as u64 ) ;
148+ module_envs. insert ( key, val) ;
149+ }
135150
136151 builder_events_modules. push ( format ! ( "{module_cid}:{builder_events_port}" ) ) ;
137152
@@ -188,9 +203,15 @@ pub fn handle_docker_init(config_path: String, output_dir: String) -> Result<()>
188203 let mut signer_envs = IndexMap :: from ( [
189204 get_env_same ( CB_CONFIG_ENV ) ,
190205 get_env_same ( JWTS_ENV ) ,
191- get_env_val ( METRICS_SERVER_ENV , & metrics_port. to_string ( ) ) ,
192- get_env_val ( SIGNER_SERVER_ENV , & signer_port. to_string ( ) ) ,
206+ get_env_uval ( METRICS_SERVER_ENV , metrics_port as u64 ) ,
207+ get_env_uval ( SIGNER_SERVER_ENV , signer_port as u64 ) ,
208+ get_env_val ( ROLLING_DURATION_ENV , & cb_config. logs . rotation . to_string ( ) ) ,
209+ get_env_val ( RUST_LOG_ENV , & cb_config. logs . log_level ) ,
193210 ] ) ;
211+ if let Some ( max_files) = cb_config. logs . max_log_files {
212+ let ( key, val) = get_env_uval ( MAX_LOG_FILES_ENV , max_files as u64 ) ;
213+ signer_envs. insert ( key, val) ;
214+ }
194215
195216 // TODO: generalize this, different loaders may not need volumes but eg ports
196217 match signer_config. loader {
@@ -362,6 +383,10 @@ fn get_env_val(k: &str, v: &str) -> (String, Option<SingleValue>) {
362383 ( k. into ( ) , Some ( SingleValue :: String ( v. into ( ) ) ) )
363384}
364385
386+ fn get_env_uval ( k : & str , v : u64 ) -> ( String , Option < SingleValue > ) {
387+ ( k. into ( ) , Some ( SingleValue :: Unsigned ( v) ) )
388+ }
389+
365390/// A prometheus target, use to dynamically add targets to the prometheus config
366391#[ derive( Debug , Serialize ) ]
367392struct PrometheusTargetConfig {
0 commit comments