diff --git a/Dockerfile b/Dockerfile index bf9ea88..73bcaf6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,27 +1,25 @@ -FROM rust:latest AS builder -RUN apt update && apt install -y git -RUN update-ca-certificates -WORKDIR /tcp-relay-rust -RUN git clone https://github.com/cedric05/tcp-relay-rust . --no-checkout && git checkout 6de9bd191fa97aa73e8696ebefd5a50286eb2b25 -RUN cargo build --release +FROM alpine:3.19 -FROM debian:bullseye-slim -ENV APT_KEY_DONT_WARN_ON_DANGEROUS_USAGE=DontWarn -ENV DEBIAN_FRONTEND=noninteractive -COPY --from=builder /tcp-relay-rust/target/release/tcp-relay-rust /tcp-relay-rust +RUN apk add --no-cache curl \ + && ARCH=$(uname -m) \ + && if [ "${ARCH}" = "i386" ]; then ARCH="386"; fi \ + && if [ "${ARCH}" = "i686" ]; then ARCH="386"; fi \ + && if [ "${ARCH}" = "x86_64" ]; then ARCH="amd64"; fi \ + && if [ "${ARCH}" = "aarch64" ]; then ARCH="arm64"; fi \ + && WGCF_URL=$(curl -fsSL https://api.github.com/repos/ViRb3/wgcf/releases/latest | grep 'browser_download_url' | cut -d'"' -f4 | grep "_linux_${ARCH}") \ + && curl -fsSL "${WGCF_URL}" -o ./wgcf \ + && chmod +x ./wgcf \ + && mv ./wgcf /usr/bin \ + && WIREPROXY_URL=$(curl -fsSL https://api.github.com/repos/pufferffish/wireproxy/releases/latest | grep 'browser_download_url' | cut -d'"' -f4 | grep "wireproxy_linux_${ARCH}.tar.gz") \ + && curl -fsSL "${WIREPROXY_URL}" -o ./wireproxy.tar.gz \ + && tar -xzf wireproxy.tar.gz \ + && rm wireproxy.tar.gz \ + && chmod +x ./wireproxy \ + && mv ./wireproxy /usr/bin -RUN apt update \ - && apt install -y curl gnupg \ - && curl -fsSL https://pkg.cloudflareclient.com/pubkey.gpg | gpg --yes --dearmor --output /usr/share/keyrings/cloudflare-warp-archive-keyring.gpg \ - && echo "deb [arch=amd64 signed-by=/usr/share/keyrings/cloudflare-warp-archive-keyring.gpg] https://pkg.cloudflareclient.com/ bullseye main" | tee /etc/apt/sources.list.d/cloudflare-client.list \ - && apt update \ - && apt install -y cloudflare-warp \ - && apt remove -y curl \ - && apt autoremove -y \ - && apt clean \ - && rm -rf /var/lib/apt/lists/* - -ADD entrypoint.sh /entrypoint.sh +ADD entrypoint.sh /usr/local/bin/entrypoint.sh +ADD warp-health-check.sh /usr/local/bin/warp-health-check.sh EXPOSE 40000/tcp -ENTRYPOINT ["/bin/bash"] -CMD ["/entrypoint.sh"] \ No newline at end of file +ENTRYPOINT ["/usr/local/bin/entrypoint.sh"] +CMD [] +HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 CMD [ "/usr/local/bin/warp-health-check.sh" ] diff --git a/entrypoint.sh b/entrypoint.sh index 825c47f..0463a31 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,15 +1,13 @@ -#!/bin/bash +#!/bin/sh +mkdir -p /opt/wgcf +wgcf register --accept-tos --config /opt/wgcf/wgcf-account.toml +wgcf generate --config /opt/wgcf/wgcf-account.toml +mv wgcf-profile.conf /opt/wireproxy.conf -( -while ! warp-cli --accept-tos register; do - sleep 1 - >&2 echo "Awaiting warp-svc become online..." -done -warp-cli --accept-tos set-mode proxy -warp-cli --accept-tos set-proxy-port 40001 -warp-cli --accept-tos connect -warp-cli --accept-tos enable-always-on -/tcp-relay-rust 127.0.0.1:40001 0.0.0.0:40000 -) & +echo -e "\n[Socks5]\nBindAddress = 0.0.0.0:40000" >>/opt/wireproxy.conf -exec warp-svc +if [ -n "$SOCKS5_USERNAME" ]; then + echo -e "\nUsername = $SOCKS5_USERNAME\nPassword = $SOCKS5_PASSWORD" >>/opt/wireproxy.conf +fi + +wireproxy -c /opt/wireproxy.conf diff --git a/warp-health-check.sh b/warp-health-check.sh new file mode 100644 index 0000000..972af88 --- /dev/null +++ b/warp-health-check.sh @@ -0,0 +1,6 @@ +#!/bin/sh +if [ -n "$SOCKS5_USERNAME" ]; then + curl --proxy-user $SOCKS5_USERNAME:$SOCKS5_PASSWORD -x socks5h://localhost:40000 -f -s https://www.cloudflare.com/cdn-cgi/trace +else + curl -x socks5h://localhost:40000 -f -s https://www.cloudflare.com/cdn-cgi/trace +fi