1- use std:: { path:: Path , vec} ;
1+ use std:: {
2+ net:: { Ipv4Addr , SocketAddr } ,
3+ path:: Path ,
4+ vec,
5+ } ;
26
37use cb_common:: {
48 config:: {
59 CommitBoostConfig , LogsSettings , ModuleKind , BUILDER_PORT_ENV , BUILDER_URLS_ENV ,
610 CHAIN_SPEC_ENV , CONFIG_DEFAULT , CONFIG_ENV , JWTS_ENV , LOGS_DIR_DEFAULT , LOGS_DIR_ENV ,
7- METRICS_PORT_ENV , MODULE_ID_ENV , MODULE_JWT_ENV , PBS_MODULE_NAME , PROXY_DIR_DEFAULT ,
8- PROXY_DIR_ENV , SIGNER_DEFAULT , SIGNER_DIR_KEYS_DEFAULT , SIGNER_DIR_KEYS_ENV ,
9- SIGNER_DIR_SECRETS_DEFAULT , SIGNER_DIR_SECRETS_ENV , SIGNER_KEYS_ENV , SIGNER_MODULE_NAME ,
10- SIGNER_PORT_ENV , SIGNER_URL_ENV ,
11+ METRICS_PORT_ENV , MODULE_ID_ENV , MODULE_JWT_ENV , PBS_ENDPOINT_ENV , PBS_MODULE_NAME ,
12+ PROXY_DIR_DEFAULT , PROXY_DIR_ENV , SIGNER_DEFAULT , SIGNER_DIR_KEYS_DEFAULT ,
13+ SIGNER_DIR_KEYS_ENV , SIGNER_DIR_SECRETS_DEFAULT , SIGNER_DIR_SECRETS_ENV , SIGNER_KEYS_ENV ,
14+ SIGNER_MODULE_NAME , SIGNER_PORT_ENV , SIGNER_URL_ENV ,
1115 } ,
1216 signer:: { ProxyStore , SignerLoader } ,
1317 types:: ModuleId ,
@@ -233,6 +237,19 @@ pub fn handle_docker_init(config_path: String, output_dir: String) -> Result<()>
233237 pbs_envs. insert ( k, v) ;
234238 }
235239
240+ // ports
241+ let host_endpoint =
242+ SocketAddr :: from ( ( cb_config. pbs . pbs_config . host , cb_config. pbs . pbs_config . port ) ) ;
243+ let ports = Ports :: Short ( vec ! [ format!( "{}:{}" , host_endpoint, cb_config. pbs. pbs_config. port) ] ) ;
244+ exposed_ports_warn
245+ . push ( format ! ( "pbs has an exported port on {}" , cb_config. pbs. pbs_config. port) ) ;
246+
247+ // inside the container expose on 0.0.0.0
248+ let container_endpoint =
249+ SocketAddr :: from ( ( Ipv4Addr :: UNSPECIFIED , cb_config. pbs . pbs_config . port ) ) ;
250+ let ( key, val) = get_env_val ( PBS_ENDPOINT_ENV , & container_endpoint. to_string ( ) ) ;
251+ pbs_envs. insert ( key, val) ;
252+
236253 // volumes
237254 let mut pbs_volumes = vec ! [ config_volume. clone( ) ] ;
238255 pbs_volumes. extend ( chain_spec_volume. clone ( ) ) ;
@@ -245,16 +262,10 @@ pub fn handle_docker_init(config_path: String, output_dir: String) -> Result<()>
245262 Networks :: default ( )
246263 } ;
247264
248- exposed_ports_warn
249- . push ( format ! ( "pbs has an exported port on {}" , cb_config. pbs. pbs_config. port) ) ;
250-
251265 let pbs_service = Service {
252266 container_name : Some ( "cb_pbs" . to_owned ( ) ) ,
253267 image : Some ( cb_config. pbs . docker_image ) ,
254- ports : Ports :: Short ( vec ! [ format!(
255- "{}:{}" ,
256- cb_config. pbs. pbs_config. port, cb_config. pbs. pbs_config. port
257- ) ] ) ,
268+ ports,
258269 networks : pbs_networs,
259270 volumes : pbs_volumes,
260271 environment : Environment :: KvPair ( pbs_envs) ,
@@ -408,7 +419,7 @@ pub fn handle_docker_init(config_path: String, output_dir: String) -> Result<()>
408419 image : Some ( "prom/prometheus:latest" . to_owned ( ) ) ,
409420 volumes : vec ! [ prom_volume, targets_volume, data_volume] ,
410421 // to inspect prometheus from localhost
411- ports : Ports :: Short ( vec ! [ "9090 :9090". to_owned ( ) ] ) ,
422+ ports : Ports :: Short ( vec ! [ format! ( "{} :9090", metrics_config . host ) ] ) ,
412423 networks : Networks :: Simple ( vec ! [ METRICS_NETWORK . to_owned( ) ] ) ,
413424 ..Service :: default ( )
414425 } ;
@@ -435,7 +446,7 @@ pub fn handle_docker_init(config_path: String, output_dir: String) -> Result<()>
435446 let grafana_service = Service {
436447 container_name : Some ( "cb_grafana" . to_owned ( ) ) ,
437448 image : Some ( "grafana/grafana:latest" . to_owned ( ) ) ,
438- ports : Ports :: Short ( vec ! [ "3000 :3000". to_owned ( ) ] ) ,
449+ ports : Ports :: Short ( vec ! [ format! ( "{} :3000", metrics_config . host ) ] ) ,
439450 networks : Networks :: Simple ( vec ! [ METRICS_NETWORK . to_owned( ) ] ) ,
440451 depends_on : DependsOnOptions :: Simple ( vec ! [ "cb_prometheus" . to_owned( ) ] ) ,
441452 environment : Environment :: List ( vec ! [ "GF_SECURITY_ADMIN_PASSWORD=admin" . to_owned( ) ] ) ,
@@ -475,7 +486,7 @@ pub fn handle_docker_init(config_path: String, output_dir: String) -> Result<()>
475486 Some ( Service {
476487 container_name : Some ( "cb_cadvisor" . to_owned ( ) ) ,
477488 image : Some ( "gcr.io/cadvisor/cadvisor" . to_owned ( ) ) ,
478- ports : Ports :: Short ( vec ! [ format!( "{cadvisor_port }:8080" ) ] ) ,
489+ ports : Ports :: Short ( vec ! [ format!( "{}:8080" , metrics_config . host ) ] ) ,
479490 networks : Networks :: Simple ( vec ! [ METRICS_NETWORK . to_owned( ) ] ) ,
480491 volumes : vec ! [
481492 Volumes :: Simple ( "/var/run/docker.sock:/var/run/docker.sock:ro" . to_owned( ) ) ,
@@ -540,17 +551,17 @@ pub fn handle_docker_init(config_path: String, output_dir: String) -> Result<()>
540551 Ok ( ( ) )
541552}
542553
543- // FOO=${FOO}
554+ /// FOO=${FOO}
544555fn get_env_same ( k : & str ) -> ( String , Option < SingleValue > ) {
545556 get_env_interp ( k, k)
546557}
547558
548- // FOO=${BAR}
559+ /// FOO=${BAR}
549560fn get_env_interp ( k : & str , v : & str ) -> ( String , Option < SingleValue > ) {
550561 get_env_val ( k, & format ! ( "${{{v}}}" ) )
551562}
552563
553- // FOO=bar
564+ /// FOO=bar
554565fn get_env_val ( k : & str , v : & str ) -> ( String , Option < SingleValue > ) {
555566 ( k. into ( ) , Some ( SingleValue :: String ( v. into ( ) ) ) )
556567}
0 commit comments