@@ -8,7 +8,7 @@ use cb_common::{
8
8
SIGNER_KEYS , SIGNER_KEYS_ENV , SIGNER_SERVER_ENV ,
9
9
} ,
10
10
loader:: SignerLoader ,
11
- utils:: { random_jwt, ENV_ROLLING_DURATION } ,
11
+ utils:: { random_jwt, MAX_LOG_FILES_ENV , ROLLING_DURATION_ENV , RUST_LOG_ENV } ,
12
12
} ;
13
13
use docker_compose_types:: {
14
14
Compose , ComposeVolume , DependsOnOptions , Environment , Labels , LoggingParameters , MapOrEmpty ,
@@ -27,8 +27,6 @@ pub(super) const PROMETHEUS_DATA_VOLUME: &str = "prometheus-data";
27
27
const METRICS_NETWORK : & str = "monitoring_network" ;
28
28
const SIGNER_NETWORK : & str = "signer_network" ;
29
29
30
- const ENV_RUST_LOG : & str = "RUST_LOG" ;
31
-
32
30
/// Builds the docker compose file for the Commit-Boost services
33
31
34
32
// TODO: do more validation for paths, images, etc
@@ -45,15 +43,14 @@ pub fn handle_docker_init(config_path: String, output_dir: String) -> Result<()>
45
43
let config_volume = Volumes :: Simple ( format ! ( "./{}:{}:ro" , config_path, CB_CONFIG_NAME ) ) ;
46
44
let log_volume = Volumes :: Simple ( format ! (
47
45
"{}:{}" ,
48
- cb_config. logs. host_path . to_str( ) . unwrap( ) ,
46
+ cb_config. logs. log_dir_path . to_str( ) . unwrap( ) ,
49
47
CB_BASE_LOG_PATH
50
48
) ) ;
51
49
52
50
let mut jwts = IndexMap :: new ( ) ;
53
51
// envs to write in .env file
54
52
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
+
57
54
// targets to pass to prometheus
58
55
let mut targets = Vec :: new ( ) ;
59
56
let metrics_port = 10000 ;
@@ -73,8 +70,14 @@ pub fn handle_docker_init(config_path: String, output_dir: String) -> Result<()>
73
70
74
71
let mut pbs_envs = IndexMap :: from ( [
75
72
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 ) ,
77
76
] ) ;
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
+ }
78
81
79
82
let mut needs_signer_module = cb_config. pbs . with_signer ;
80
83
@@ -98,13 +101,19 @@ pub fn handle_docker_init(config_path: String, output_dir: String) -> Result<()>
98
101
let jwt_name = format ! ( "CB_JWT_{}" , module. id. to_uppercase( ) ) ;
99
102
100
103
// module ids are assumed unique, so envs dont override each other
101
- let module_envs = IndexMap :: from ( [
104
+ let mut module_envs = IndexMap :: from ( [
102
105
get_env_val ( MODULE_ID_ENV , & module. id ) ,
103
106
get_env_same ( CB_CONFIG_ENV ) ,
104
107
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 ) ,
106
109
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 ) ,
107
112
] ) ;
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
+ }
108
117
109
118
envs. insert ( jwt_name. clone ( ) , jwt. clone ( ) ) ;
110
119
jwts. insert ( module. id . clone ( ) , jwt) ;
@@ -126,12 +135,18 @@ pub fn handle_docker_init(config_path: String, output_dir: String) -> Result<()>
126
135
// an event module just needs a port to listen on
127
136
ModuleKind :: Events => {
128
137
// module ids are assumed unique, so envs dont override each other
129
- let module_envs = IndexMap :: from ( [
138
+ let mut module_envs = IndexMap :: from ( [
130
139
get_env_val ( MODULE_ID_ENV , & module. id ) ,
131
140
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 ) ,
133
142
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 ) ,
134
145
] ) ;
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
+ }
135
150
136
151
builder_events_modules. push ( format ! ( "{module_cid}:{builder_events_port}" ) ) ;
137
152
@@ -188,9 +203,15 @@ pub fn handle_docker_init(config_path: String, output_dir: String) -> Result<()>
188
203
let mut signer_envs = IndexMap :: from ( [
189
204
get_env_same ( CB_CONFIG_ENV ) ,
190
205
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 ) ,
193
210
] ) ;
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
+ }
194
215
195
216
// TODO: generalize this, different loaders may not need volumes but eg ports
196
217
match signer_config. loader {
@@ -362,6 +383,10 @@ fn get_env_val(k: &str, v: &str) -> (String, Option<SingleValue>) {
362
383
( k. into ( ) , Some ( SingleValue :: String ( v. into ( ) ) ) )
363
384
}
364
385
386
+ fn get_env_uval ( k : & str , v : u64 ) -> ( String , Option < SingleValue > ) {
387
+ ( k. into ( ) , Some ( SingleValue :: Unsigned ( v) ) )
388
+ }
389
+
365
390
/// A prometheus target, use to dynamically add targets to the prometheus config
366
391
#[ derive( Debug , Serialize ) ]
367
392
struct PrometheusTargetConfig {
0 commit comments