1
- use std:: { path:: Path , vec} ;
1
+ use std:: {
2
+ path:: { Path , PathBuf } ,
3
+ vec,
4
+ } ;
2
5
3
6
use cb_common:: {
4
7
config:: {
5
8
CommitBoostConfig , ModuleKind , BUILDER_SERVER_ENV , CB_BASE_LOG_PATH , CB_CONFIG_ENV ,
6
9
CB_CONFIG_NAME , JWTS_ENV , METRICS_SERVER_ENV , MODULE_ID_ENV , MODULE_JWT_ENV ,
7
- SIGNER_DIR_KEYS , SIGNER_DIR_KEYS_ENV , SIGNER_DIR_SECRETS , SIGNER_DIR_SECRETS_ENV ,
8
- SIGNER_KEYS , SIGNER_KEYS_ENV , SIGNER_SERVER_ENV ,
10
+ PBS_MODULE_NAME , SIGNER_DIR_KEYS , SIGNER_DIR_KEYS_ENV , SIGNER_DIR_SECRETS ,
11
+ SIGNER_DIR_SECRETS_ENV , SIGNER_KEYS , SIGNER_KEYS_ENV , SIGNER_MODULE_NAME ,
12
+ SIGNER_SERVER_ENV ,
9
13
} ,
10
14
loader:: SignerLoader ,
11
15
utils:: { random_jwt, MAX_LOG_FILES_ENV , ROLLING_DURATION_ENV , RUST_LOG_ENV } ,
@@ -42,11 +46,6 @@ pub fn handle_docker_init(config_path: String, output_dir: String) -> Result<()>
42
46
43
47
// config volume to pass to all services
44
48
let config_volume = Volumes :: Simple ( format ! ( "./{}:{}:ro" , config_path, CB_CONFIG_NAME ) ) ;
45
- let log_volume = Volumes :: Simple ( format ! (
46
- "{}:{}" ,
47
- cb_config. logs. log_dir_path. to_str( ) . unwrap( ) ,
48
- CB_BASE_LOG_PATH
49
- ) ) ;
50
49
51
50
let mut jwts = IndexMap :: new ( ) ;
52
51
// envs to write in .env file
@@ -120,7 +119,8 @@ pub fn handle_docker_init(config_path: String, output_dir: String) -> Result<()>
120
119
121
120
envs. insert ( jwt_name. clone ( ) , jwt. clone ( ) ) ;
122
121
jwts. insert ( module. id . clone ( ) , jwt) ;
123
-
122
+ let log_volume =
123
+ get_log_volume ( cb_config. logs . log_dir_path . clone ( ) , & module. id ) ;
124
124
Service {
125
125
container_name : Some ( module_cid. clone ( ) ) ,
126
126
image : Some ( module. docker_image ) ,
@@ -129,7 +129,7 @@ pub fn handle_docker_init(config_path: String, output_dir: String) -> Result<()>
129
129
METRICS_NETWORK . to_owned( ) ,
130
130
SIGNER_NETWORK . to_owned( ) ,
131
131
] ) ,
132
- volumes : vec ! [ config_volume. clone( ) , log_volume. clone ( ) ] ,
132
+ volumes : vec ! [ config_volume. clone( ) , log_volume] ,
133
133
environment : Environment :: KvPair ( module_envs) ,
134
134
depends_on : DependsOnOptions :: Simple ( vec ! [ "cb_signer" . to_owned( ) ] ) ,
135
135
..Service :: default ( )
@@ -152,12 +152,13 @@ pub fn handle_docker_init(config_path: String, output_dir: String) -> Result<()>
152
152
}
153
153
154
154
builder_events_modules. push ( format ! ( "{module_cid}:{builder_events_port}" ) ) ;
155
-
155
+ let log_volume =
156
+ get_log_volume ( cb_config. logs . log_dir_path . clone ( ) , & module. id ) ;
156
157
Service {
157
158
container_name : Some ( module_cid. clone ( ) ) ,
158
159
image : Some ( module. docker_image ) ,
159
160
networks : Networks :: Simple ( vec ! [ METRICS_NETWORK . to_owned( ) ] ) ,
160
- volumes : vec ! [ config_volume. clone( ) , log_volume. clone ( ) ] ,
161
+ volumes : vec ! [ config_volume. clone( ) , log_volume] ,
161
162
environment : Environment :: KvPair ( module_envs) ,
162
163
depends_on : DependsOnOptions :: Simple ( vec ! [ "cb_pbs" . to_owned( ) ] ) ,
163
164
..Service :: default ( )
@@ -174,6 +175,8 @@ pub fn handle_docker_init(config_path: String, output_dir: String) -> Result<()>
174
175
let ( k, v) = get_env_val ( BUILDER_SERVER_ENV , & env) ;
175
176
pbs_envs. insert ( k, v) ;
176
177
}
178
+
179
+ let log_volume = get_log_volume ( cb_config. logs . log_dir_path . clone ( ) , PBS_MODULE_NAME ) ;
177
180
exposed_ports_warn
178
181
. push ( format ! ( "pbs has an exported port on {}" , cb_config. pbs. pbs_config. port) ) ;
179
182
let pbs_service = Service {
@@ -184,7 +187,7 @@ pub fn handle_docker_init(config_path: String, output_dir: String) -> Result<()>
184
187
cb_config. pbs. pbs_config. port, cb_config. pbs. pbs_config. port
185
188
) ] ) ,
186
189
networks : Networks :: Simple ( vec ! [ METRICS_NETWORK . to_owned( ) ] ) ,
187
- volumes : vec ! [ config_volume. clone( ) , log_volume. clone ( ) ] ,
190
+ volumes : vec ! [ config_volume. clone( ) , log_volume] ,
188
191
environment : Environment :: KvPair ( pbs_envs) ,
189
192
..Service :: default ( )
190
193
} ;
@@ -197,7 +200,9 @@ pub fn handle_docker_init(config_path: String, output_dir: String) -> Result<()>
197
200
198
201
if let Some ( signer_config) = cb_config. signer {
199
202
if needs_signer_module {
200
- let mut volumes = vec ! [ config_volume. clone( ) , log_volume. clone( ) ] ;
203
+ let log_volume =
204
+ get_log_volume ( cb_config. logs . log_dir_path . clone ( ) , SIGNER_MODULE_NAME ) ;
205
+ let mut volumes = vec ! [ config_volume. clone( ) , log_volume] ;
201
206
202
207
targets. push ( PrometheusTargetConfig {
203
208
targets : vec ! [ format!( "cb_signer:{metrics_port}" ) ] ,
@@ -445,3 +450,12 @@ struct PrometheusTargetConfig {
445
450
struct PrometheusLabelsConfig {
446
451
job : String ,
447
452
}
453
+
454
+ fn get_log_volume ( host_path : PathBuf , module_id : & str ) -> Volumes {
455
+ let p = host_path. join ( module_id) ;
456
+ Volumes :: Simple ( format ! (
457
+ "{}:{}" ,
458
+ p. to_str( ) . expect( "could not convert pathbuf to str" ) ,
459
+ CB_BASE_LOG_PATH
460
+ ) )
461
+ }
0 commit comments