Skip to content

Commit ed0d34f

Browse files
fbrvfbrvltitanb
authored
logs in separate containers (#83)
* logs in separate containers * merge * use const --------- Co-authored-by: fbrv <fabio@gattaca.com> Co-authored-by: ltitanb <163874448+ltitanb@users.noreply.github.com>
1 parent 98fbd74 commit ed0d34f

File tree

1 file changed

+28
-14
lines changed

1 file changed

+28
-14
lines changed

crates/cli/src/docker_init.rs

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
1-
use std::{path::Path, vec};
1+
use std::{
2+
path::{Path, PathBuf},
3+
vec,
4+
};
25

36
use cb_common::{
47
config::{
58
CommitBoostConfig, ModuleKind, BUILDER_SERVER_ENV, CB_BASE_LOG_PATH, CB_CONFIG_ENV,
69
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,
913
},
1014
loader::SignerLoader,
1115
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<()>
4246

4347
// config volume to pass to all services
4448
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-
));
5049

5150
let mut jwts = IndexMap::new();
5251
// envs to write in .env file
@@ -120,7 +119,8 @@ pub fn handle_docker_init(config_path: String, output_dir: String) -> Result<()>
120119

121120
envs.insert(jwt_name.clone(), jwt.clone());
122121
jwts.insert(module.id.clone(), jwt);
123-
122+
let log_volume =
123+
get_log_volume(cb_config.logs.log_dir_path.clone(), &module.id);
124124
Service {
125125
container_name: Some(module_cid.clone()),
126126
image: Some(module.docker_image),
@@ -129,7 +129,7 @@ pub fn handle_docker_init(config_path: String, output_dir: String) -> Result<()>
129129
METRICS_NETWORK.to_owned(),
130130
SIGNER_NETWORK.to_owned(),
131131
]),
132-
volumes: vec![config_volume.clone(), log_volume.clone()],
132+
volumes: vec![config_volume.clone(), log_volume],
133133
environment: Environment::KvPair(module_envs),
134134
depends_on: DependsOnOptions::Simple(vec!["cb_signer".to_owned()]),
135135
..Service::default()
@@ -152,12 +152,13 @@ pub fn handle_docker_init(config_path: String, output_dir: String) -> Result<()>
152152
}
153153

154154
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);
156157
Service {
157158
container_name: Some(module_cid.clone()),
158159
image: Some(module.docker_image),
159160
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],
161162
environment: Environment::KvPair(module_envs),
162163
depends_on: DependsOnOptions::Simple(vec!["cb_pbs".to_owned()]),
163164
..Service::default()
@@ -174,6 +175,8 @@ pub fn handle_docker_init(config_path: String, output_dir: String) -> Result<()>
174175
let (k, v) = get_env_val(BUILDER_SERVER_ENV, &env);
175176
pbs_envs.insert(k, v);
176177
}
178+
179+
let log_volume = get_log_volume(cb_config.logs.log_dir_path.clone(), PBS_MODULE_NAME);
177180
exposed_ports_warn
178181
.push(format!("pbs has an exported port on {}", cb_config.pbs.pbs_config.port));
179182
let pbs_service = Service {
@@ -184,7 +187,7 @@ pub fn handle_docker_init(config_path: String, output_dir: String) -> Result<()>
184187
cb_config.pbs.pbs_config.port, cb_config.pbs.pbs_config.port
185188
)]),
186189
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],
188191
environment: Environment::KvPair(pbs_envs),
189192
..Service::default()
190193
};
@@ -197,7 +200,9 @@ pub fn handle_docker_init(config_path: String, output_dir: String) -> Result<()>
197200

198201
if let Some(signer_config) = cb_config.signer {
199202
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];
201206

202207
targets.push(PrometheusTargetConfig {
203208
targets: vec![format!("cb_signer:{metrics_port}")],
@@ -445,3 +450,12 @@ struct PrometheusTargetConfig {
445450
struct PrometheusLabelsConfig {
446451
job: String,
447452
}
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

Comments
 (0)