feat(connection-tests): dynamically discover network interfaces (#3241)

Currently, we are hardcoding the network interface to use in the docker
compose file. This doesn't scale pariticularly well because
docker-compose doesn't like it when networks have overlapping address
ranges. Instead of hard-coding the address, we let docker compose choose
a network range and assign addresses to us.

---------

Co-authored-by: Jamil Bou Kheir <jamilbk@users.noreply.github.com>
This commit is contained in:
Thomas Eizinger
2024-01-16 15:05:16 -08:00
committed by GitHub
parent 0f613d4378
commit 5a679ad264
4 changed files with 77 additions and 19 deletions

66
rust/Cargo.lock generated
View File

@@ -494,12 +494,12 @@ dependencies = [
[[package]]
name = "axum"
version = "0.7.3"
version = "0.7.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d09dbe0e490df5da9d69b36dca48a76635288a82f92eca90024883a56202026d"
checksum = "1236b4b292f6c4d6dc34604bb5120d85c3fe1d1aa596bd5cc52ca054d13e7b9e"
dependencies = [
"async-trait",
"axum-core 0.4.2",
"axum-core 0.4.3",
"bytes",
"futures-util",
"http 1.0.0",
@@ -541,9 +541,9 @@ dependencies = [
[[package]]
name = "axum-core"
version = "0.4.2"
version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e87c8503f93e6d144ee5690907ba22db7ba79ab001a932ab99034f0fe836b3df"
checksum = "a15c63fd72d41492dc4f497196f5da1fb04fb7529e631d73630d1b491e47a2e3"
dependencies = [
"async-trait",
"bytes",
@@ -1955,6 +1955,7 @@ dependencies = [
"serde",
"serde-hex",
"serde_json",
"system-info",
"tokio",
"tracing",
"tracing-subscriber",
@@ -2008,7 +2009,7 @@ name = "firezone-relay"
version = "1.0.0"
dependencies = [
"anyhow",
"axum 0.7.3",
"axum 0.7.4",
"base64 0.21.7",
"bytecodec",
"bytes",
@@ -6096,6 +6097,16 @@ dependencies = [
"version-compare 0.1.1",
]
[[package]]
name = "system-info"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c6649e0c93f64c8ebcb719ba8e8e6fc581258350b67387f440161bfcd775a0ca"
dependencies = [
"libc",
"windows-sys 0.36.1",
]
[[package]]
name = "tao"
version = "0.16.5"
@@ -7775,6 +7786,19 @@ version = "0.39.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9ee5e275231f07c6e240d14f34e1b635bf1faa1c76c57cfd59a5cdb9848e4278"
[[package]]
name = "windows-sys"
version = "0.36.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ea04155a16a59f9eab786fe12a4a450e75cdb175f9e0d80da1e17db09f55b8d2"
dependencies = [
"windows_aarch64_msvc 0.36.1",
"windows_i686_gnu 0.36.1",
"windows_i686_msvc 0.36.1",
"windows_x86_64_gnu 0.36.1",
"windows_x86_64_msvc 0.36.1",
]
[[package]]
name = "windows-sys"
version = "0.42.0"
@@ -7895,6 +7919,12 @@ version = "0.52.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cb7764e35d4db8a7921e09562a0304bf2f93e0a51bfccee0bd0bb0b666b015ea"
[[package]]
name = "windows_aarch64_msvc"
version = "0.36.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9bb8c3fd39ade2d67e9874ac4f3db21f0d710bee00fe7cab16949ec184eeaa47"
[[package]]
name = "windows_aarch64_msvc"
version = "0.37.0"
@@ -7925,6 +7955,12 @@ version = "0.52.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bbaa0368d4f1d2aaefc55b6fcfee13f41544ddf36801e793edbbfd7d7df075ef"
[[package]]
name = "windows_i686_gnu"
version = "0.36.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "180e6ccf01daf4c426b846dfc66db1fc518f074baa793aa7d9b9aaeffad6a3b6"
[[package]]
name = "windows_i686_gnu"
version = "0.37.0"
@@ -7955,6 +7991,12 @@ version = "0.52.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a28637cb1fa3560a16915793afb20081aba2c92ee8af57b4d5f28e4b3e7df313"
[[package]]
name = "windows_i686_msvc"
version = "0.36.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e2e7917148b2812d1eeafaeb22a97e4813dfa60a3f8f78ebe204bcc88f12f024"
[[package]]
name = "windows_i686_msvc"
version = "0.37.0"
@@ -7985,6 +8027,12 @@ version = "0.52.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ffe5e8e31046ce6230cc7215707b816e339ff4d4d67c65dffa206fd0f7aa7b9a"
[[package]]
name = "windows_x86_64_gnu"
version = "0.36.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4dcd171b8776c41b97521e5da127a2d86ad280114807d0b2ab1e462bc764d9e1"
[[package]]
name = "windows_x86_64_gnu"
version = "0.37.0"
@@ -8033,6 +8081,12 @@ version = "0.52.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1a657e1e9d3f514745a572a6846d3c7aa7dbe1658c056ed9c3344c4109a6949e"
[[package]]
name = "windows_x86_64_msvc"
version = "0.36.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c811ca4a8c853ef420abd8592ba53ddbbac90410fab6903b3e79972a631f7680"
[[package]]
name = "windows_x86_64_msvc"
version = "0.37.0"

View File

@@ -21,3 +21,4 @@ serde-hex = "0.1.0"
tokio = { version = "1", features = ["full"] }
tracing = "0.1"
tracing-subscriber = { version = "0.3", features = ["env-filter", "json"] }
system-info = { version = "0.1.2", features = ["std"]}

View File

@@ -13,7 +13,6 @@ services:
init: true
environment:
ROLE: "dialer"
LISTEN_ADDR: 172.28.0.100
REDIS_HOST: redis # All services share the `app` network.
cap_add:
- NET_ADMIN
@@ -23,8 +22,7 @@ services:
# redis:
# condition: "service_healthy"
networks:
app:
ipv4_address: 172.28.0.100
- app
listener:
build:
@@ -38,7 +36,6 @@ services:
init: true
environment:
ROLE: "listener"
LISTEN_ADDR: 172.28.0.101
REDIS_HOST: redis # All services share the `app` network.
cap_add:
- NET_ADMIN
@@ -90,13 +87,11 @@ services:
# healthcheck:
# test: ["CMD-SHELL", "echo 'ready';"]
networks:
app:
ipv4_address: 172.28.0.103
- app
networks:
app:
enable_ipv6: true
ipam:
# enable_ipv6: true Disable until we find a workaround for https://github.com/moby/moby/issues/41438.
ipam:
config:
- subnet: 172.28.0.0/24
- subnet: fc00:ff:2::/48

View File

@@ -1,6 +1,6 @@
use std::{
future::poll_fn,
net::{IpAddr, Ipv4Addr},
net::Ipv4Addr,
str::FromStr,
task::{Context, Poll},
time::{Duration, Instant},
@@ -32,9 +32,17 @@ async fn main() -> Result<()> {
let role = std::env::var("ROLE")
.context("Missing ROLE env variable")?
.parse::<Role>()?;
let listen_addr = std::env::var("LISTEN_ADDR")
.context("Missing LISTEN_ADDR env var")?
.parse::<IpAddr>()?;
let listen_addr = system_info::NetworkInterfaces::new()
.context("Failed to get network interfaces")?
.iter()
.find_map(|i| i.addresses().find(|a| !a.ip.is_loopback()))
.context("Failed to find interface with non-loopback address")?
.ip
.to_std();
tracing::info!(%listen_addr);
let redis_host = std::env::var("REDIS_HOST").context("Missing LISTEN_ADDR env var")?;
let redis_client = redis::Client::open(format!("redis://{redis_host}:6379"))?;