From dc7215f367d151e637fe484d33e1e17b4ff743c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CE=A3rebe=20-=20Romain=20GERARD?= Date: Sat, 21 Oct 2023 16:49:24 +0200 Subject: [PATCH] Add dockerfile --- .dockerignore | 4 ++-- Dockerfile | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++ src/main.rs | 1 + src/socks5.rs | 1 + 4 files changed, 65 insertions(+), 2 deletions(-) create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore index 95315a76..dace21dc 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,2 +1,2 @@ -.stack-work -.travis.yml +target +.github diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..eb82ccfc --- /dev/null +++ b/Dockerfile @@ -0,0 +1,61 @@ +ARG BUILDER_IMAGE=builder_cache +ARG ALPINE_IMAGE_TAG=3.18 + +############################################################ +# Cache image with all the deps +FROM rust:1.73-alpine${ALPINE_IMAGE_TAG} AS builder_cache + +RUN apk add musl-dev +RUN rustup component add rustfmt clippy + +WORKDIR /build +COPY . ./ + + +RUN cargo fmt --all -- --check --color=always || (echo "Use cargo fmt to format your code"; exit 1) +RUN cargo clippy --all --all-features -- -D warnings || (echo "Solve your clippy warnings to succeed"; exit 1) + +#RUN cargo test --all --all-features +#RUN just test "tcp://localhost:2375" || (echo "Test are failing"; exit 1) + +#ENV RUSTFLAGS="-C link-arg=-Wl,--compress-debug-sections=zlib -C force-frame-pointers=yes" +RUN cargo build --tests --all-features +#RUN cargo build --release --all-features + + +############################################################ +# Builder for production image +FROM ${BUILDER_IMAGE} AS builder_release + +WORKDIR /build +COPY . ./ + +ARG BIN_TARGET=--bins +ARG PROFILE=release + +#ENV RUSTFLAGS="-C link-arg=-Wl,--compress-debug-sections=zlib -C force-frame-pointers=yes" +RUN cargo build --profile=${PROFILE} ${BIN_TARGET} + + +############################################################ +# Final image +FROM alpine:${ALPINE_IMAGE_TAG} as final-image + +RUN apk add dumb-init && \ + adduser -Ds /bin/sh app + +WORKDIR /home/app + +ARG PROFILE=release +COPY --from=builder_release /build/target/${PROFILE}/wstunnel wstunnel + +ENV RUST_LOG="INFO" +ENV SERVER_PROTOCOL="wss" +ENV SERVER_LISTEN="[::]" +ENV SERVER_PORT="8080" +EXPOSE 8080 + +USER app + +ENTRYPOINT ["/usr/bin/dumb-init", "-v", "--"] +CMD ["/bin/sh", "-c", "exec /home/app/wstunnel server ${SERVER_PROTOCOL}://${SERVER_LISTEN}:${SERVER_PORT}"] diff --git a/src/main.rs b/src/main.rs index 25210569..16474ad9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -225,6 +225,7 @@ fn parse_local_bind(arg: &str) -> Result<(SocketAddr, &str), io::Error> { Ok((SocketAddr::new(bind, bind_port), remaining)) } +#[allow(clippy::type_complexity)] fn parse_tunnel_dest( remaining: &str, ) -> Result<(Host, u16, BTreeMap), io::Error> { diff --git a/src/socks5.rs b/src/socks5.rs index d75a6f08..04002e69 100644 --- a/src/socks5.rs +++ b/src/socks5.rs @@ -11,6 +11,7 @@ use tokio::net::TcpStream; use tracing::{info, warn}; use url::Host; +#[allow(clippy::type_complexity)] pub struct Socks5Listener { stream: Pin> + Send>>, }