Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 3 additions & 1 deletion crates/cli/src/docker_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ fn determine_docker_compose_command() -> Option<Command> {
Command::new("docker"),
))
} else if is_command_available("docker-compose") {
println!("using docker-compose. the command is being deprecated, install docker compose plugin");
println!(
"using docker-compose. the command is being deprecated, install docker compose plugin"
);
let mut docker: Command = Command::new("docker-compose");
Some(mem::replace(
docker.stdout(Stdio::inherit()).stderr(Stdio::inherit()),
Expand Down
38 changes: 37 additions & 1 deletion crates/cli/src/docker_init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ pub(super) const CB_COMPOSE_FILE: &str = "cb.docker-compose.yml";
pub(super) const CB_ENV_FILE: &str = ".cb.env";
pub(super) const CB_TARGETS_FILE: &str = "targets.json"; // needs to match prometheus.yml
pub(super) const PROMETHEUS_DATA_VOLUME: &str = "prometheus-data";
pub(super) const GRAFANA_DATA_VOLUME: &str = "grafana-data";

const METRICS_NETWORK: &str = "monitoring_network";
const SIGNER_NETWORK: &str = "signer_network";
Expand Down Expand Up @@ -50,10 +51,10 @@ pub fn handle_docker_init(config_path: String, output_dir: String) -> Result<()>
let mut jwts = IndexMap::new();
// envs to write in .env file
let mut envs = IndexMap::from([(CB_CONFIG_ENV.into(), CB_CONFIG_NAME.into())]);

// targets to pass to prometheus
let mut targets = Vec::new();
let metrics_port = 10000;
let cadvisor_port = 8080;

// address for signer API communication
let signer_port = 20000;
Expand Down Expand Up @@ -286,6 +287,8 @@ pub fn handle_docker_init(config_path: String, output_dir: String) -> Result<()>

let data_volume = Volumes::Simple(format!("{}:/prometheus", PROMETHEUS_DATA_VOLUME));

let grafana_data_volume = Volumes::Simple(format!("{}:/var/lib/grafana", GRAFANA_DATA_VOLUME));

volumes.insert(
PROMETHEUS_DATA_VOLUME.to_owned(),
MapOrEmpty::Map(ComposeVolume {
Expand All @@ -297,6 +300,17 @@ pub fn handle_docker_init(config_path: String, output_dir: String) -> Result<()>
}),
);

volumes.insert(
GRAFANA_DATA_VOLUME.to_owned(),
MapOrEmpty::Map(ComposeVolume {
driver: Some("local".to_owned()),
driver_opts: IndexMap::default(),
external: None,
labels: Labels::default(),
name: None,
}),
);

let prometheus_service = Service {
container_name: Some("cb_prometheus".to_owned()),
image: Some("prom/prometheus:latest".to_owned()),
Expand Down Expand Up @@ -324,6 +338,7 @@ pub fn handle_docker_init(config_path: String, output_dir: String) -> Result<()>
Volumes::Simple(
"./grafana/datasources:/etc/grafana/provisioning/datasources".to_owned(),
),
grafana_data_volume,
],
// TODO: re-enable logging here once we move away from docker logs
logging: Some(LoggingParameters { driver: Some("none".to_owned()), options: None }),
Expand All @@ -333,6 +348,27 @@ pub fn handle_docker_init(config_path: String, output_dir: String) -> Result<()>
services.insert("cb_grafana".to_owned(), Some(grafana_service));
}

services.insert(
"cb_cadvisor".to_owned(),
Some(Service {
container_name: Some("cb_cadvisor".to_owned()),
image: Some("gcr.io/cadvisor/cadvisor".to_owned()),
ports: Ports::Short(vec![format!("{cadvisor_port}:8080")]),
networks: Networks::Simple(vec![METRICS_NETWORK.to_owned()]),
volumes: vec![
Volumes::Simple("/var/run/docker.sock:/var/run/docker.sock:ro".to_owned()),
Volumes::Simple("/sys:/sys:ro".to_owned()),
Volumes::Simple("/var/lib/docker/:/var/lib/docker:ro".to_owned()),
],
..Service::default()
}),
);

targets.push(PrometheusTargetConfig {
targets: vec![format!("cb_cadvisor:{cadvisor_port}")],
labels: PrometheusLabelsConfig { job: "cadvisor".to_owned() },
});

compose.services = Services(services);
compose.volumes = TopLevelVolumes(volumes);

Expand Down
Loading