Skip to content

Commit

Permalink
fix: containers joining 2 networks
Browse files Browse the repository at this point in the history
  • Loading branch information
Ludo Galabru committed Dec 21, 2022
1 parent b379d29 commit 4f4c880
Showing 1 changed file with 32 additions and 150 deletions.
182 changes: 32 additions & 150 deletions components/stacks-network/src/orchestrator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,16 +167,20 @@ impl DevnetOrchestrator {
let mut options = HashMap::new();
options.insert("enable_ip_masquerade".into(), "true".into());
options.insert("enable_icc".into(), "true".into());
options.insert("host_binding_ipv4".into(), "0.0.0.0".into());
options.insert("com.docker.network.bridge.enable_icc".into(), "true".into());
options.insert("com.docker.network.bridge.enable_ip_masquerade".into(), "true".into());
options.insert("com.docker.network.bridge.host_binding_ipv4".into(), "0.0.0.0".into());

let network_id = docker
.create_network::<&str>(CreateNetworkOptions {
name: &self.network_name,
driver: "bridge",
ipam: Ipam {
options: Some(options),
..Default::default()
},
labels,
options: options,
..Default::default()
})
.await
Expand Down Expand Up @@ -722,14 +726,16 @@ rpcport={bitcoin_node_rpc_port}
let config = Config {
labels: Some(labels),
image: Some(devnet_config.bitcoin_node_image_url.clone()),
domainname: Some(self.network_name.to_string()),
// domainname: Some(self.network_name.to_string()),
tty: None,
exposed_ports: Some(exposed_ports),
entrypoint: Some(vec![]),
env: Some(env),
host_config: Some(HostConfig {
port_bindings: Some(port_bindings),
auto_remove: Some(true),
binds: Some(binds),
network_mode: Some(self.network_name.clone()),
port_bindings: Some(port_bindings),
extra_hosts: Some(vec!["host.docker.internal:host-gateway".into()]),
..Default::default()
}),
Expand Down Expand Up @@ -849,21 +855,6 @@ rpcport={bitcoin_node_rpc_port}
.await
.map_err(|e| formatted_docker_error("unable to start bitcoind container", e))?;

let res = docker
.connect_network::<&str>(
&self.network_name,
ConnectNetworkOptions {
container: &container,
..Default::default()
},
)
.await;

if let Err(e) = res {
let err = format!("Error connecting container: {}", e);
return Err(err);
}

Ok(())
}

Expand Down Expand Up @@ -1074,7 +1065,7 @@ start_height = {epoch_2_1}
let config = Config {
labels: Some(labels),
image: Some(devnet_config.stacks_node_image_url.clone()),
domainname: Some(self.network_name.to_string()),
// domainname: Some(self.network_name.to_string()),
tty: None,
exposed_ports: Some(exposed_ports),
entrypoint: Some(vec![
Expand All @@ -1084,8 +1075,10 @@ start_height = {epoch_2_1}
]),
env: Some(env),
host_config: Some(HostConfig {
port_bindings: Some(port_bindings),
auto_remove: Some(true),
binds: Some(binds),
network_mode: Some(self.network_name.clone()),
port_bindings: Some(port_bindings),
extra_hosts: Some(vec!["host.docker.internal:host-gateway".into()]),
..Default::default()
}),
Expand Down Expand Up @@ -1155,21 +1148,6 @@ start_height = {epoch_2_1}
.await
.map_err(|e| formatted_docker_error("unable to start stacks-node container", e))?;

let res = docker
.connect_network::<&str>(
&self.network_name,
ConnectNetworkOptions {
container: &&container,
..Default::default()
},
)
.await;

if let Err(e) = res {
let err = format!("Error connecting container: {}", e);
return Err(err);
}

Ok(())
}

Expand Down Expand Up @@ -1352,7 +1330,7 @@ events_keys = ["*"]
let config = Config {
labels: Some(labels),
image: Some(devnet_config.subnet_node_image_url.clone()),
domainname: Some(self.network_name.to_string()),
// domainname: Some(self.network_name.to_string()),
tty: None,
exposed_ports: Some(exposed_ports),
entrypoint: Some(vec![
Expand All @@ -1366,8 +1344,10 @@ events_keys = ["*"]
// "BLOCKSTACK_USE_TEST_GENESIS_CHAINSTATE=1".to_string(),
]),
host_config: Some(HostConfig {
port_bindings: Some(port_bindings),
auto_remove: Some(true),
binds: Some(binds),
network_mode: Some(self.network_name.clone()),
port_bindings: Some(port_bindings),
extra_hosts: Some(vec!["host.docker.internal:host-gateway".into()]),
..Default::default()
}),
Expand Down Expand Up @@ -1437,21 +1417,6 @@ events_keys = ["*"]
.await
.map_err(|e| format!("unable to start container - {}", e))?;

let res = docker
.connect_network(
&self.network_name,
ConnectNetworkOptions {
container,
..Default::default()
},
)
.await;

if let Err(e) = res {
let err = format!("Error connecting container: {}", e);
return Err(err);
}

Ok(())
}

Expand Down Expand Up @@ -1527,11 +1492,13 @@ events_keys = ["*"]
let config = Config {
labels: Some(labels),
image: Some(devnet_config.stacks_api_image_url.clone()),
domainname: Some(self.network_name.to_string()),
// domainname: Some(self.network_name.to_string()),
tty: None,
exposed_ports: Some(exposed_ports),
env: Some(env),
host_config: Some(HostConfig {
auto_remove: Some(true),
network_mode: Some(self.network_name.clone()),
port_bindings: Some(port_bindings),
extra_hosts: Some(vec!["host.docker.internal:host-gateway".into()]),
..Default::default()
Expand Down Expand Up @@ -1571,21 +1538,6 @@ events_keys = ["*"]
.await
.map_err(|e| formatted_docker_error("unable to start stacks-api container", e))?;

let res = docker
.connect_network(
&self.network_name,
ConnectNetworkOptions {
container,
..Default::default()
},
)
.await;

if let Err(e) = res {
let err = format!("Error connecting container: {}", e);
return Err(err);
}

Ok(())
}

Expand Down Expand Up @@ -1632,7 +1584,7 @@ events_keys = ["*"]
let config = Config {
labels: Some(labels),
image: Some(devnet_config.subnet_api_image_url.clone()),
domainname: Some(self.network_name.to_string()),
// domainname: Some(self.network_name.to_string()),
tty: None,
exposed_ports: Some(exposed_ports),
env: Some(vec![
Expand Down Expand Up @@ -1663,6 +1615,8 @@ events_keys = ["*"]
"NODE_ENV=development".to_string(),
]),
host_config: Some(HostConfig {
auto_remove: Some(true),
network_mode: Some(self.network_name.clone()),
port_bindings: Some(port_bindings),
extra_hosts: Some(vec!["host.docker.internal:host-gateway".into()]),
..Default::default()
Expand Down Expand Up @@ -1738,21 +1692,6 @@ events_keys = ["*"]
.await
.map_err(|e| formatted_docker_error("unable to start stacks-api container", e))?;

let res = docker
.connect_network(
&self.network_name,
ConnectNetworkOptions {
container,
..Default::default()
},
)
.await;

if let Err(e) = res {
let err = format!("Error connecting container: {}", e);
return Err(err);
}

Ok(())
}

Expand Down Expand Up @@ -1795,14 +1734,16 @@ events_keys = ["*"]
let config = Config {
labels: Some(labels),
image: Some(devnet_config.postgres_image_url.clone()),
domainname: Some(self.network_name.to_string()),
// domainname: Some(self.network_name.to_string()),
tty: None,
exposed_ports: Some(exposed_ports),
env: Some(vec![
format!("POSTGRES_PASSWORD={}", devnet_config.postgres_password),
format!("POSTGRES_DB={}", devnet_config.stacks_api_postgres_database),
]),
host_config: Some(HostConfig {
auto_remove: Some(true),
network_mode: Some(self.network_name.clone()),
port_bindings: Some(port_bindings),
extra_hosts: Some(vec!["host.docker.internal:host-gateway".into()]),
..Default::default()
Expand Down Expand Up @@ -1842,21 +1783,6 @@ events_keys = ["*"]
.await
.map_err(|e| formatted_docker_error("unable to start postgres container", e))?;

let res = docker
.connect_network(
&self.network_name,
ConnectNetworkOptions {
container,
..Default::default()
},
)
.await;

if let Err(e) = res {
let err = format!("Error connecting container: {}", e);
return Err(err);
}

Ok(())
}

Expand Down Expand Up @@ -1918,11 +1844,13 @@ events_keys = ["*"]
let config = Config {
labels: Some(labels),
image: Some(devnet_config.stacks_explorer_image_url.clone()),
domainname: Some(self.network_name.to_string()),
// domainname: Some(self.network_name.to_string()),
tty: None,
exposed_ports: Some(exposed_ports),
env: Some(env),
host_config: Some(HostConfig {
auto_remove: Some(true),
network_mode: Some(self.network_name.clone()),
port_bindings: Some(port_bindings),
extra_hosts: Some(vec!["host.docker.internal:host-gateway".into()]),
..Default::default()
Expand Down Expand Up @@ -1964,21 +1892,6 @@ events_keys = ["*"]
.await
.map_err(|e| format!("unable to create container: {}", e))?;

let res = docker
.connect_network(
&self.network_name,
ConnectNetworkOptions {
container,
..Default::default()
},
)
.await;

if let Err(e) = res {
let err = format!("Error connecting container: {}", e);
return Err(err);
}

Ok(())
}

Expand Down Expand Up @@ -2028,7 +1941,7 @@ events_keys = ["*"]
let config = Config {
labels: Some(labels),
image: Some(devnet_config.bitcoin_explorer_image_url.clone()),
domainname: Some(self.network_name.to_string()),
// domainname: Some(self.network_name.to_string()),
tty: None,
exposed_ports: Some(exposed_ports),
env: Some(vec![
Expand All @@ -2054,6 +1967,8 @@ events_keys = ["*"]
format!("BTCEXP_RPC_ALLOWALL=true",),
]),
host_config: Some(HostConfig {
auto_remove: Some(true),
network_mode: Some(self.network_name.clone()),
port_bindings: Some(port_bindings),
extra_hosts: Some(vec!["host.docker.internal:host-gateway".into()]),
..Default::default()
Expand Down Expand Up @@ -2095,21 +2010,6 @@ events_keys = ["*"]
.await
.map_err(|e| format!("unable to create container: {}", e))?;

let res = docker
.connect_network(
&self.network_name,
ConnectNetworkOptions {
container,
..Default::default()
},
)
.await;

if let Err(e) = res {
let err = format!("Error connecting container: {}", e);
return Err(err);
}

Ok(())
}

Expand Down Expand Up @@ -2234,15 +2134,6 @@ events_keys = ["*"]
let _ = docker
.start_container::<String>(&bitcoin_node_c_id, None)
.await;
let _ = docker
.connect_network(
&self.network_name,
ConnectNetworkOptions {
container: bitcoin_node_c_id.clone(),
..Default::default()
},
)
.await;

let _ = docker
.start_container::<String>(bitcoin_explorer_c_id, None)
Expand All @@ -2261,15 +2152,6 @@ events_keys = ["*"]
let _ = docker
.start_container::<String>(&stacks_node_c_id, None)
.await;
let _ = docker
.connect_network(
&self.network_name,
ConnectNetworkOptions {
container: stacks_node_c_id.clone(),
..Default::default()
},
)
.await;

Ok((bitcoin_node_c_id, stacks_node_c_id))
}
Expand Down

0 comments on commit 4f4c880

Please sign in to comment.