diff --git a/crates/cli/src/docker_init.rs b/crates/cli/src/docker_init.rs index 4b70c092..6ea0f82c 100644 --- a/crates/cli/src/docker_init.rs +++ b/crates/cli/src/docker_init.rs @@ -1,11 +1,15 @@ -use std::{path::Path, vec}; +use std::{ + path::{Path, PathBuf}, + vec, +}; use cb_common::{ config::{ CommitBoostConfig, ModuleKind, BUILDER_SERVER_ENV, CB_BASE_LOG_PATH, CB_CONFIG_ENV, CB_CONFIG_NAME, JWTS_ENV, METRICS_SERVER_ENV, MODULE_ID_ENV, MODULE_JWT_ENV, - SIGNER_DIR_KEYS, SIGNER_DIR_KEYS_ENV, SIGNER_DIR_SECRETS, SIGNER_DIR_SECRETS_ENV, - SIGNER_KEYS, SIGNER_KEYS_ENV, SIGNER_SERVER_ENV, + PBS_MODULE_NAME, SIGNER_DIR_KEYS, SIGNER_DIR_KEYS_ENV, SIGNER_DIR_SECRETS, + SIGNER_DIR_SECRETS_ENV, SIGNER_KEYS, SIGNER_KEYS_ENV, SIGNER_MODULE_NAME, + SIGNER_SERVER_ENV, }, loader::SignerLoader, 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<()> // config volume to pass to all services let config_volume = Volumes::Simple(format!("./{}:{}:ro", config_path, CB_CONFIG_NAME)); - let log_volume = Volumes::Simple(format!( - "{}:{}", - cb_config.logs.log_dir_path.to_str().unwrap(), - CB_BASE_LOG_PATH - )); let mut jwts = IndexMap::new(); // envs to write in .env file @@ -120,7 +119,8 @@ pub fn handle_docker_init(config_path: String, output_dir: String) -> Result<()> envs.insert(jwt_name.clone(), jwt.clone()); jwts.insert(module.id.clone(), jwt); - + let log_volume = + get_log_volume(cb_config.logs.log_dir_path.clone(), &module.id); Service { container_name: Some(module_cid.clone()), image: Some(module.docker_image), @@ -129,7 +129,7 @@ pub fn handle_docker_init(config_path: String, output_dir: String) -> Result<()> METRICS_NETWORK.to_owned(), SIGNER_NETWORK.to_owned(), ]), - volumes: vec![config_volume.clone(), log_volume.clone()], + volumes: vec![config_volume.clone(), log_volume], environment: Environment::KvPair(module_envs), depends_on: DependsOnOptions::Simple(vec!["cb_signer".to_owned()]), ..Service::default() @@ -152,12 +152,13 @@ pub fn handle_docker_init(config_path: String, output_dir: String) -> Result<()> } builder_events_modules.push(format!("{module_cid}:{builder_events_port}")); - + let log_volume = + get_log_volume(cb_config.logs.log_dir_path.clone(), &module.id); Service { container_name: Some(module_cid.clone()), image: Some(module.docker_image), networks: Networks::Simple(vec![METRICS_NETWORK.to_owned()]), - volumes: vec![config_volume.clone(), log_volume.clone()], + volumes: vec![config_volume.clone(), log_volume], environment: Environment::KvPair(module_envs), depends_on: DependsOnOptions::Simple(vec!["cb_pbs".to_owned()]), ..Service::default() @@ -174,6 +175,8 @@ pub fn handle_docker_init(config_path: String, output_dir: String) -> Result<()> let (k, v) = get_env_val(BUILDER_SERVER_ENV, &env); pbs_envs.insert(k, v); } + + let log_volume = get_log_volume(cb_config.logs.log_dir_path.clone(), PBS_MODULE_NAME); exposed_ports_warn .push(format!("pbs has an exported port on {}", cb_config.pbs.pbs_config.port)); let pbs_service = Service { @@ -184,7 +187,7 @@ pub fn handle_docker_init(config_path: String, output_dir: String) -> Result<()> cb_config.pbs.pbs_config.port, cb_config.pbs.pbs_config.port )]), networks: Networks::Simple(vec![METRICS_NETWORK.to_owned()]), - volumes: vec![config_volume.clone(), log_volume.clone()], + volumes: vec![config_volume.clone(), log_volume], environment: Environment::KvPair(pbs_envs), ..Service::default() }; @@ -197,7 +200,9 @@ pub fn handle_docker_init(config_path: String, output_dir: String) -> Result<()> if let Some(signer_config) = cb_config.signer { if needs_signer_module { - let mut volumes = vec![config_volume.clone(), log_volume.clone()]; + let log_volume = + get_log_volume(cb_config.logs.log_dir_path.clone(), SIGNER_MODULE_NAME); + let mut volumes = vec![config_volume.clone(), log_volume]; targets.push(PrometheusTargetConfig { targets: vec![format!("cb_signer:{metrics_port}")], @@ -445,3 +450,12 @@ struct PrometheusTargetConfig { struct PrometheusLabelsConfig { job: String, } + +fn get_log_volume(host_path: PathBuf, module_id: &str) -> Volumes { + let p = host_path.join(module_id); + Volumes::Simple(format!( + "{}:{}", + p.to_str().expect("could not convert pathbuf to str"), + CB_BASE_LOG_PATH + )) +}