aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.dockerignore3
-rw-r--r--Dockerfile23
-rw-r--r--README.md2
-rw-r--r--docker-compose.yml14
-rw-r--r--src/consul_actor.rs2
-rw-r--r--src/main.rs17
6 files changed, 42 insertions, 19 deletions
diff --git a/.dockerignore b/.dockerignore
new file mode 100644
index 0000000..38621e0
--- /dev/null
+++ b/.dockerignore
@@ -0,0 +1,3 @@
+target
+.git
+
diff --git a/Dockerfile b/Dockerfile
new file mode 100644
index 0000000..41c7da9
--- /dev/null
+++ b/Dockerfile
@@ -0,0 +1,23 @@
+FROM debian:bullseye-slim as builder
+
+RUN apt-get update && \
+ apt-get install -y rustc cargo libssl-dev pkg-config
+
+WORKDIR /srv
+
+# Build dependencies and cache them
+COPY Cargo.* ./
+RUN mkdir -p src && \
+ echo "fn main() {println!(\"if you see this, the build broke\")}" > src/main.rs && \
+ cargo build --release && \
+ rm -r src && \
+ rm target/release/deps/diplonat*
+
+# Build final app
+COPY ./src ./src
+RUN cargo build --release
+
+FROM debian:bullseye-slim
+RUN apt-get update && apt-get install -y libssl1.1
+COPY --from=builder /srv/target/release/diplonat /usr/local/sbin/diplonat
+CMD ["/usr/local/sbin/diplonat"]
diff --git a/README.md b/README.md
index 68f33bd..518061b 100644
--- a/README.md
+++ b/README.md
@@ -3,7 +3,7 @@ Diplonat
## Feature set
- * [ ] (Re)Configure NAT via UPNP/IGD (prio: high)
+ * [X] (Re)Configure NAT via UPNP/IGD (prio: high)
* [ ] (Re)Configure nftable (prio: low)
* [ ] (Re)Configure DNS via ??? (prio: low)
diff --git a/docker-compose.yml b/docker-compose.yml
new file mode 100644
index 0000000..5e8e190
--- /dev/null
+++ b/docker-compose.yml
@@ -0,0 +1,14 @@
+version: '3.4'
+services:
+ diplonat:
+ build: .
+ image: superboum/amd64_diplonat:v1
+ network_mode: host # required by UPNP/IGD
+ environment:
+ DIPLONAT_PRIVATE_IP: 192.168.0.18
+ DIPLONAT_REFRESH_TIME: 60
+ DIPLONAT_EXPIRATION_TIME: 300
+ DIPLONAT_CONSUL_NODE_NAME: lheureduthe
+ RUST_LOG: debug
+
+
diff --git a/src/consul_actor.rs b/src/consul_actor.rs
index 877ea10..1cbb1b8 100644
--- a/src/consul_actor.rs
+++ b/src/consul_actor.rs
@@ -92,7 +92,7 @@ impl ConsulActor {
Ok(c) => c,
Err(e) => {
self.consul.watch_node_reset();
- self.retries = cmp::min(u32::MAX - 1, self.retries) + 1;
+ self.retries = cmp::min(std::u32::MAX - 1, self.retries) + 1;
let will_retry_in = retry_to_time(self.retries, Duration::from_secs(600));
error!("Failed to query consul. Will retry in {}s. {}", will_retry_in.as_secs(), e);
delay_for(will_retry_in).await;
diff --git a/src/main.rs b/src/main.rs
index 4df32c8..a35916a 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -5,9 +5,6 @@ mod consul_actor;
mod igd_actor;
mod diplonat;
-//use std::net::SocketAddrV4;
-//use std::collections::HashMap;
-//use igd::PortMappingProtocol;
use log::*;
use diplonat::Diplonat;
@@ -18,18 +15,4 @@ async fn main() {
let mut diplo = Diplonat::new().await.expect("Setup failed");
diplo.listen().await.expect("A runtime error occured");
-
-/*
- let gateway = match search_gateway(Default::default()).await {
- Ok(g) => g,
- Err(err) => return println!("Faild to find IGD: {}", err),
- };
-
- let service = format!("{}:{}", config.private_ip, 1234);
- let service: SocketAddrV4 = service.parse().expect("Invalid socket address");
- match gateway.add_port(PortMappingProtocol::TCP, 1234, service, config.expiration_time, "diplonat").await {
- Ok(_) => (),
- Err(e) => return println!("Unable to insert port 1234: {}", e),
- };
- */
}