Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

logs in separate containers #83

Merged
merged 4 commits into from
Aug 12, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 23 additions & 13 deletions crates/cli/src/docker_init.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use std::{path::Path, vec};
use std::{
path::{Path, PathBuf},
vec,
};

use cb_common::{
config::{
Expand Down Expand Up @@ -42,11 +45,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
Expand Down Expand Up @@ -118,7 +116,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),
Expand All @@ -127,7 +126,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()
Expand All @@ -150,12 +149,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()
Expand All @@ -172,7 +172,7 @@ 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");
let pbs_service = Service {
fbrv marked this conversation as resolved.
Show resolved Hide resolved
container_name: Some("cb_pbs".to_owned()),
image: Some(cb_config.pbs.docker_image),
Expand All @@ -181,7 +181,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()
};
Expand All @@ -194,7 +194,8 @@ 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");
let mut volumes = vec![config_volume.clone(), log_volume];
fbrv marked this conversation as resolved.
Show resolved Hide resolved

targets.push(PrometheusTargetConfig {
targets: vec![format!("cb_signer:{metrics_port}")],
Expand Down Expand Up @@ -434,3 +435,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
))
}
Loading