MCPcopy Index your code
hub / github.com/Commit-Boost/commit-boost-client / handle_docker_init

Function handle_docker_init

crates/cli/src/docker_init.rs:41–578  ·  view source on GitHub ↗

Builds the docker compose file for the Commit-Boost services TODO: do more validation for paths, images, etc

(config_path: PathBuf, output_dir: PathBuf)

Source from the content-addressed store, hash-verified

39/// Builds the docker compose file for the Commit-Boost services
40// TODO: do more validation for paths, images, etc
41pub async fn handle_docker_init(config_path: PathBuf, output_dir: PathBuf) -> Result<()> {
42 println!("Initializing Commit-Boost with config file: {}", config_path.display());
43 let cb_config = CommitBoostConfig::from_file(&config_path)?;
44 cb_config.validate().await?;
45
46 let chain_spec_path = CommitBoostConfig::chain_spec_file(&config_path);
47
48 let log_to_file = cb_config.logs.file.enabled;
49 let mut metrics_port = cb_config.metrics.as_ref().map(|m| m.start_port).unwrap_or_default();
50
51 let mut services = IndexMap::new();
52
53 // config volume to pass to all services
54 let config_volume =
55 Volumes::Simple(format!("./{}:{}:ro", config_path.display(), CONFIG_DEFAULT));
56 let chain_spec_volume = chain_spec_path.as_ref().and_then(|p| {
57 // this is ok since the config has already been loaded once
58 let file_name = p.file_name()?.to_str()?;
59 Some(Volumes::Simple(format!("{}:/{}:ro", p.display(), file_name)))
60 });
61
62 let chain_spec_env = chain_spec_path.and_then(|p| {
63 // this is ok since the config has already been loaded once
64 let file_name = p.file_name()?.to_str()?;
65 Some(get_env_val(CHAIN_SPEC_ENV, &format!("/{file_name}")))
66 });
67
68 let mut jwts = IndexMap::new();
69 // envs to write in .env file
70 let mut envs = IndexMap::new();
71 // targets to pass to prometheus
72 let mut targets = Vec::new();
73
74 // address for signer API communication
75 let signer_port = cb_config.signer.as_ref().map(|s| s.port).unwrap_or(SIGNER_PORT_DEFAULT);
76 let signer_server =
77 if let Some(SignerConfig { inner: SignerType::Remote { url }, .. }) = &cb_config.signer {
78 url.to_string()
79 } else {
80 format!("http://cb_signer:{signer_port}")
81 };
82
83 let mut warnings = Vec::new();
84
85 let needs_signer_module = cb_config.pbs.with_signer ||
86 cb_config.modules.as_ref().is_some_and(|modules| {
87 modules.iter().any(|module| matches!(module.kind, ModuleKind::Commit))
88 });
89
90 // setup modules
91 if let Some(modules_config) = cb_config.modules {
92 for module in modules_config {
93 let module_cid = format!("cb_{}", module.id.to_lowercase());
94
95 let module_service = match module.kind {
96 // a commit module needs a JWT and access to the signer network
97 ModuleKind::Commit => {
98 let mut ports = vec![];

Callers 1

runMethod · 0.85

Calls 9

get_env_valFunction · 0.85
random_jwt_secretFunction · 0.85
get_env_interpFunction · 0.85
get_env_uvalFunction · 0.85
get_log_volumeFunction · 0.85
get_env_sameFunction · 0.85
format_comma_separatedFunction · 0.85
loader_envMethod · 0.80
validateMethod · 0.45

Tested by

no test coverage detected