Skip to content

Commit 98fbd74

Browse files
fbrvfbrv
andauthored
warning for exposed port (#84)
* warning for exposed port * fmt --------- Co-authored-by: fbrv <fabio@gattaca.com>
1 parent ab9fbf7 commit 98fbd74

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

crates/cli/src/docker_init.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ pub fn handle_docker_init(config_path: String, output_dir: String) -> Result<()>
6363
let builder_events_port = 30000;
6464
let mut builder_events_modules = Vec::new();
6565

66+
let mut exposed_ports_warn = Vec::new();
67+
6668
// setup pbs service
6769
targets.push(PrometheusTargetConfig {
6870
targets: vec![format!("cb_pbs:{metrics_port}")],
@@ -172,7 +174,8 @@ pub fn handle_docker_init(config_path: String, output_dir: String) -> Result<()>
172174
let (k, v) = get_env_val(BUILDER_SERVER_ENV, &env);
173175
pbs_envs.insert(k, v);
174176
}
175-
177+
exposed_ports_warn
178+
.push(format!("pbs has an exported port on {}", cb_config.pbs.pbs_config.port));
176179
let pbs_service = Service {
177180
container_name: Some("cb_pbs".to_owned()),
178181
image: Some(cb_config.pbs.docker_image),
@@ -310,7 +313,7 @@ pub fn handle_docker_init(config_path: String, output_dir: String) -> Result<()>
310313
name: None,
311314
}),
312315
);
313-
316+
exposed_ports_warn.push("prometheus has an exported port on 9090".to_string());
314317
let prometheus_service = Service {
315318
container_name: Some("cb_prometheus".to_owned()),
316319
image: Some("prom/prometheus:latest".to_owned()),
@@ -324,6 +327,7 @@ pub fn handle_docker_init(config_path: String, output_dir: String) -> Result<()>
324327
services.insert("cb_prometheus".to_owned(), Some(prometheus_service));
325328

326329
if cb_config.metrics.use_grafana {
330+
exposed_ports_warn.push("grafana has an exported port on 3000".to_string());
327331
let grafana_service = Service {
328332
container_name: Some("cb_grafana".to_owned()),
329333
image: Some("grafana/grafana:latest".to_owned()),
@@ -347,7 +351,7 @@ pub fn handle_docker_init(config_path: String, output_dir: String) -> Result<()>
347351

348352
services.insert("cb_grafana".to_owned(), Some(grafana_service));
349353
}
350-
354+
exposed_ports_warn.push("cadvisor has an exported port on 8080".to_string());
351355
services.insert(
352356
"cb_cadvisor".to_owned(),
353357
Some(Service {
@@ -377,6 +381,13 @@ pub fn handle_docker_init(config_path: String, output_dir: String) -> Result<()>
377381
let compose_path = Path::new(&output_dir).join(CB_COMPOSE_FILE);
378382
// TODO: check if file exists already and avoid overwriting
379383
std::fs::write(&compose_path, compose_str)?;
384+
if !exposed_ports_warn.is_empty() {
385+
println!("\n");
386+
for exposed_port in exposed_ports_warn {
387+
println!("Warning: {}", exposed_port);
388+
}
389+
println!("\n");
390+
}
380391
println!("Compose file written to: {:?}", compose_path);
381392

382393
// write envs to .env file

0 commit comments

Comments
 (0)