build hickory from a local/remote git source
DNS_TEST_SUBJECT now needs to contain the URL to the hickory source code
This commit is contained in:
parent
0e2b35699c
commit
55184172e3
@ -13,7 +13,7 @@ pub struct Client {
|
|||||||
impl Client {
|
impl Client {
|
||||||
pub fn new(network: &Network) -> Result<Self> {
|
pub fn new(network: &Network) -> Result<Self> {
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
inner: Container::run(Implementation::Unbound, network)?,
|
inner: Container::run(&Implementation::Unbound, network)?,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@ const PACKAGE_NAME: &str = env!("CARGO_PKG_NAME");
|
|||||||
|
|
||||||
impl Container {
|
impl Container {
|
||||||
/// Starts the container in a "parked" state
|
/// Starts the container in a "parked" state
|
||||||
pub fn run(implementation: Implementation, network: &Network) -> Result<Self> {
|
pub fn run(implementation: &Implementation, network: &Network) -> Result<Self> {
|
||||||
// TODO make this configurable and support hickory & bind
|
// TODO make this configurable and support hickory & bind
|
||||||
let dockerfile = implementation.dockerfile();
|
let dockerfile = implementation.dockerfile();
|
||||||
let docker_build_dir = TempDir::new()?;
|
let docker_build_dir = TempDir::new()?;
|
||||||
@ -37,7 +37,26 @@ impl Container {
|
|||||||
.arg(&image_tag)
|
.arg(&image_tag)
|
||||||
.arg(docker_build_dir);
|
.arg(docker_build_dir);
|
||||||
|
|
||||||
|
let srcdir = if let Implementation::Hickory { url } = implementation {
|
||||||
|
Some(url)
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
};
|
||||||
|
|
||||||
implementation.once().call_once(|| {
|
implementation.once().call_once(|| {
|
||||||
|
if let Some(srcdir) = srcdir {
|
||||||
|
let mut cp_r = Command::new("git");
|
||||||
|
cp_r.args([
|
||||||
|
"clone",
|
||||||
|
"--depth",
|
||||||
|
"1",
|
||||||
|
srcdir,
|
||||||
|
&docker_build_dir.join("src").display().to_string(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
exec_or_panic(&mut cp_r, false);
|
||||||
|
}
|
||||||
|
|
||||||
exec_or_panic(&mut command, verbose_docker_build());
|
exec_or_panic(&mut command, verbose_docker_build());
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -312,7 +331,7 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn run_works() -> Result<()> {
|
fn run_works() -> Result<()> {
|
||||||
let network = Network::new()?;
|
let network = Network::new()?;
|
||||||
let container = Container::run(Implementation::Unbound, &network)?;
|
let container = Container::run(&Implementation::Unbound, &network)?;
|
||||||
|
|
||||||
let output = container.output(&["true"])?;
|
let output = container.output(&["true"])?;
|
||||||
assert!(output.status.success());
|
assert!(output.status.success());
|
||||||
@ -323,7 +342,7 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn ipv4_addr_works() -> Result<()> {
|
fn ipv4_addr_works() -> Result<()> {
|
||||||
let network = Network::new()?;
|
let network = Network::new()?;
|
||||||
let container = Container::run(Implementation::Unbound, &network)?;
|
let container = Container::run(&Implementation::Unbound, &network)?;
|
||||||
let ipv4_addr = container.ipv4_addr();
|
let ipv4_addr = container.ipv4_addr();
|
||||||
|
|
||||||
let output = container.output(&["ping", "-c1", &format!("{ipv4_addr}")])?;
|
let output = container.output(&["ping", "-c1", &format!("{ipv4_addr}")])?;
|
||||||
@ -335,7 +354,7 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn cp_works() -> Result<()> {
|
fn cp_works() -> Result<()> {
|
||||||
let network = Network::new()?;
|
let network = Network::new()?;
|
||||||
let container = Container::run(Implementation::Unbound, &network)?;
|
let container = Container::run(&Implementation::Unbound, &network)?;
|
||||||
|
|
||||||
let path = "/tmp/somefile";
|
let path = "/tmp/somefile";
|
||||||
let contents = "hello";
|
let contents = "hello";
|
||||||
|
@ -146,7 +146,7 @@ mod tests {
|
|||||||
let network = Network::new().expect("Failed to create network");
|
let network = Network::new().expect("Failed to create network");
|
||||||
let network_name = network.name().to_string();
|
let network_name = network.name().to_string();
|
||||||
let container =
|
let container =
|
||||||
Container::run(Implementation::Unbound, &network).expect("Failed to start container");
|
Container::run(&Implementation::Unbound, &network).expect("Failed to start container");
|
||||||
|
|
||||||
assert!(exists_network(&network_name));
|
assert!(exists_network(&network_name));
|
||||||
drop(network);
|
drop(network);
|
||||||
|
@ -4,5 +4,6 @@ RUN apt-get update && \
|
|||||||
apt-get install -y \
|
apt-get install -y \
|
||||||
tshark
|
tshark
|
||||||
|
|
||||||
RUN cargo install hickory-dns --version 0.24.0 --features recursor --debug
|
COPY ./src /usr/src/hickory
|
||||||
|
RUN cargo install --path /usr/src/hickory/bin --features recursor --debug
|
||||||
env RUST_LOG=debug
|
env RUST_LOG=debug
|
||||||
|
@ -21,17 +21,17 @@ mod trust_anchor;
|
|||||||
pub mod tshark;
|
pub mod tshark;
|
||||||
pub mod zone_file;
|
pub mod zone_file;
|
||||||
|
|
||||||
#[derive(Clone, Copy)]
|
#[derive(Clone)]
|
||||||
pub enum Implementation {
|
pub enum Implementation {
|
||||||
Unbound,
|
Unbound,
|
||||||
Hickory,
|
Hickory { url: String },
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Implementation {
|
impl Implementation {
|
||||||
fn dockerfile(&self) -> &'static str {
|
fn dockerfile(&self) -> &'static str {
|
||||||
match self {
|
match self {
|
||||||
Implementation::Unbound => include_str!("docker/unbound.Dockerfile"),
|
Implementation::Unbound => include_str!("docker/unbound.Dockerfile"),
|
||||||
Implementation::Hickory => include_str!("docker/hickory.Dockerfile"),
|
Implementation::Hickory { .. } => include_str!("docker/hickory.Dockerfile"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -41,7 +41,8 @@ impl Implementation {
|
|||||||
static UNBOUND_ONCE: Once = Once::new();
|
static UNBOUND_ONCE: Once = Once::new();
|
||||||
&UNBOUND_ONCE
|
&UNBOUND_ONCE
|
||||||
}
|
}
|
||||||
Implementation::Hickory => {
|
|
||||||
|
Implementation::Hickory { .. } => {
|
||||||
static HICKORY_ONCE: Once = Once::new();
|
static HICKORY_ONCE: Once = Once::new();
|
||||||
&HICKORY_ONCE
|
&HICKORY_ONCE
|
||||||
}
|
}
|
||||||
@ -59,7 +60,7 @@ impl fmt::Display for Implementation {
|
|||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
let s = match self {
|
let s = match self {
|
||||||
Implementation::Unbound => "unbound",
|
Implementation::Unbound => "unbound",
|
||||||
Implementation::Hickory => "hickory",
|
Implementation::Hickory { .. } => "hickory",
|
||||||
};
|
};
|
||||||
f.write_str(s)
|
f.write_str(s)
|
||||||
}
|
}
|
||||||
@ -67,10 +68,20 @@ impl fmt::Display for Implementation {
|
|||||||
|
|
||||||
pub fn subject() -> Implementation {
|
pub fn subject() -> Implementation {
|
||||||
if let Ok(subject) = std::env::var("DNS_TEST_SUBJECT") {
|
if let Ok(subject) = std::env::var("DNS_TEST_SUBJECT") {
|
||||||
match subject.as_str() {
|
if subject == "unbound" {
|
||||||
"hickory" => Implementation::Hickory,
|
return Implementation::Unbound;
|
||||||
"unbound" => Implementation::Unbound,
|
}
|
||||||
_ => panic!("unknown implementation: {subject}"),
|
|
||||||
|
if subject.starts_with("hickory") {
|
||||||
|
if let Some(url) = subject.strip_prefix("hickory ") {
|
||||||
|
Implementation::Hickory {
|
||||||
|
url: url.to_string(),
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
panic!("the syntax of DNS_TEST_SUBJECT is 'hickory $URL', e.g. 'hickory /tmp/hickory' or 'hickory https://github.com/owner/repo'")
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
panic!("unknown implementation: {subject}")
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Implementation::default()
|
Implementation::default()
|
||||||
|
@ -43,7 +43,7 @@ impl<'a> NameServer<'a, Stopped> {
|
|||||||
});
|
});
|
||||||
|
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
container: Container::run(Implementation::Unbound, network)?,
|
container: Container::run(&Implementation::Unbound, network)?,
|
||||||
zone_file,
|
zone_file,
|
||||||
state: Stopped,
|
state: Stopped,
|
||||||
})
|
})
|
||||||
|
@ -33,7 +33,7 @@ impl Resolver {
|
|||||||
"must configure at least one local root server"
|
"must configure at least one local root server"
|
||||||
);
|
);
|
||||||
|
|
||||||
let container = Container::run(implementation, network)?;
|
let container = Container::run(&implementation, network)?;
|
||||||
|
|
||||||
let mut hints = String::new();
|
let mut hints = String::new();
|
||||||
for root in roots {
|
for root in roots {
|
||||||
@ -51,7 +51,7 @@ impl Resolver {
|
|||||||
)?;
|
)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Implementation::Hickory => {
|
Implementation::Hickory { .. } => {
|
||||||
container.status_ok(&["mkdir", "-p", "/etc/hickory"])?;
|
container.status_ok(&["mkdir", "-p", "/etc/hickory"])?;
|
||||||
|
|
||||||
container.cp("/etc/hickory/root.hints", &hints)?;
|
container.cp("/etc/hickory/root.hints", &hints)?;
|
||||||
@ -66,7 +66,7 @@ impl Resolver {
|
|||||||
|
|
||||||
let command: &[_] = match implementation {
|
let command: &[_] = match implementation {
|
||||||
Implementation::Unbound => &["unbound", "-d"],
|
Implementation::Unbound => &["unbound", "-d"],
|
||||||
Implementation::Hickory => &["hickory-dns", "-d"],
|
Implementation::Hickory { .. } => &["hickory-dns", "-d"],
|
||||||
};
|
};
|
||||||
let child = container.spawn(command)?;
|
let child = container.spawn(command)?;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user