Merge pull request #1 from Istador/udp-patch-1

[UDP] improve Dockerfiles, example docker-compose.yml, Proxy: dns lookup for server_addr string
This commit is contained in:
Jack Garrard
2022-08-23 18:27:16 -07:00
committed by GitHub
6 changed files with 124 additions and 12 deletions

7
.dockerignore Normal file
View File

@@ -0,0 +1,7 @@
/.git/
/.dockerignore
/.gitignore
/docker-compose.yml
/Dockerfile
/proxy.Dockerfile
/settings.json

View File

@@ -1,7 +1,29 @@
FROM rust:1.63 AS builder
FROM rust:1.63 AS base
RUN cargo install cargo-chef
########################################################################
FROM base AS planner
WORKDIR /app/
COPY . .
RUN cargo chef prepare --recipe-path recipe.json
########################################################################
FROM base AS builder
COPY --from=planner /app/recipe.json ./recipe.json
RUN cargo chef cook --release --recipe-path recipe.json
COPY . .
RUN cargo build --release --bin smo-rs
FROM debian:buster-slim
########################################################################
FROM debian:buster-slim AS runtime
COPY --from=builder ./target/release/smo-rs ./target/release/smo-rs
CMD ["/target/release/smo-rs"]
ENTRYPOINT ["/target/release/smo-rs"]

View File

@@ -1,7 +0,0 @@
FROM rust:1.63 AS builder
COPY . .
RUN cargo build --package proxy --release
FROM debian:buster-slim
COPY --from=builder ./target/release/proxy ./target/release/proxy
CMD ["/target/release/proxy"]

54
docker-compose.yml Normal file
View File

@@ -0,0 +1,54 @@
version: "3.7"
services:
server:
build:
context: .
dockerfile: ./Dockerfile
user: 1000:1000
stdin_open: true
restart: unless-stopped
ports:
- 1027:1027/tcp
- 51888-51920:51888-51920/udp
environment:
RUST_LOG : info
#RUST_BACKTRACE : 1
volumes:
- ./settings.json:/settings.json
proxy1:
build:
context: .
dockerfile: ./proxy.Dockerfile
user: 1000:1000
stdin_open: true
restart: unless-stopped
ports:
- 1028:1028/tcp
environment:
RUST_LOG : info
#RUST_BACKTRACE : 1
command:
- "proxy"
- "server:1027"
- "0.0.0.0:1028"
- "0.0.0.0:54486"
proxy2:
build:
context: .
dockerfile: ./proxy.Dockerfile
user: 1000:1000
stdin_open: true
restart: unless-stopped
ports:
- 1029:1029/tcp
environment:
RUST_LOG : info
#RUST_BACKTRACE : 1
command:
- "proxy"
- "server:1027"
- "0.0.0.0:1029"
- "0.0.0.0:54487"

View File

@@ -6,7 +6,7 @@ use smoo::net::{encoding::Encodable, Packet, PacketData};
use smoo::types::Result;
use std::ops::Not;
use std::time::Instant;
use std::{io::Cursor, net::SocketAddr};
use std::{io::Cursor, net::SocketAddr, net::ToSocketAddrs};
use tokio;
use tokio::net::UdpSocket;
use tokio::net::{TcpListener, TcpSocket, TcpStream};
@@ -66,8 +66,15 @@ async fn main() -> Result<()> {
local_udp_ip.parse().unwrap(), // UDP
);
// dns resolve server string, otherwise try to parse it as IPv4
let mut server_addrs = serv_ip.to_socket_addrs().unwrap();
let server_addr: SocketAddr = match server_addrs.next() {
Some(addr) => addr,
None => serv_ip.parse().unwrap(),
};
let remote_addrs: RemoteAddrs = (
serv_ip.parse().unwrap(),
server_addr,
"127.0.0.1:55445".parse().unwrap(), // Junk address
Origin::Server,
);

29
proxy.Dockerfile Normal file
View File

@@ -0,0 +1,29 @@
FROM rust:1.63 AS base
RUN cargo install cargo-chef
########################################################################
FROM base AS planner
WORKDIR /app/
COPY . .
RUN cargo chef prepare --recipe-path recipe.json
########################################################################
FROM base AS builder
COPY --from=planner /app/recipe.json ./recipe.json
RUN cargo chef cook --release --recipe-path recipe.json
COPY . .
RUN cargo build --package proxy --release
########################################################################
FROM debian:buster-slim AS runtime
COPY --from=builder ./target/release/proxy ./target/release/proxy
ENTRYPOINT ["/target/release/proxy"]