From 5e341ace1609e75a17ab2a5a7cd01dad18d80569 Mon Sep 17 00:00:00 2001 From: Dnomd343 Date: Thu, 17 Feb 2022 22:48:48 +0800 Subject: [PATCH] feat: docker working demo --- Dockerfile | 34 ++++++++++++++++++++++------------ Loop.py | 9 ++++----- docker/init.sh | 9 +++++++-- 3 files changed, 33 insertions(+), 19 deletions(-) diff --git a/Dockerfile b/Dockerfile index dd66e3b..4de1b1a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,6 +9,7 @@ ENV XRAY_VERSION="v1.5.3" ENV V2FLY_VERSION="v4.44.0" ENV GO_VERSION="1.17.6" +ENV DNSPROXY_VERSION="v0.41.1" RUN \ apk add asciidoc autoconf automake build-base curl c-ares-dev cmake \ @@ -44,9 +45,10 @@ git clone https://github.com/ihciah/rabbit-tcp.git && \ git clone https://github.com/shadowsocks/qtun.git && \ git clone https://github.com/Qv2ray/gun.git && \ \ -# Get source code of Xray-core and v2fly-core +# Get source code git clone https://github.com/XTLS/Xray-core && \ git clone https://github.com/v2fly/v2ray-core && \ +git clone https://github.com/AdguardTeam/dnsproxy && \ \ # Install rust environment (nightly version) sh -c "$(curl -sL https://sh.rustup.rs)" @ -y --no-modify-path --default-toolchain nightly && \ @@ -192,6 +194,12 @@ env CGO_ENABLED=0 go build -o v2ray -trimpath -ldflags "-s -w" ./main && \ env CGO_ENABLED=0 go build -o v2ctl -trimpath -ldflags "-s -w" -tags confonly ./infra/control/main && \ mv ./v2ctl ./v2ray /tmp/release/ && \ \ +# Compile dnsproxy +cd /tmp/dnsproxy/ && \ +git checkout $DNSPROXY_VERSION && VERSION=`git describe --tags` && \ +env CGO_ENABLED=0 go build -trimpath -ldflags "-X main.VersionString=$VERSION -s -w" && \ +mv ./dnsproxy /tmp/release/ && \ +\ # Switch to go 1.16.13 export PATH=/usr/local/go-1.16.13/bin:$PATH && \ \ @@ -251,25 +259,25 @@ mv ./target/release/qtun-server /tmp/release/ FROM alpine:3.15 as asset COPY --from=build /tmp/release/ /tmp/release/ RUN apk add gcc python3 upx && \ -cd /tmp/ && mkdir ./bin/ && mkdir ./lib/ && \ -mv ./release/packages.tar.gz ./ && tar xf packages.tar.gz && \ +mkdir -p /tmp/asset/bin/ && mkdir -p /tmp/asset/lib/ && \ +mv /tmp/release/packages.tar.gz /tmp/ && \ +cd /tmp/ && tar xf packages.tar.gz && \ mv /tmp/release/*.tar.bz2 /tmp/packages/ && \ -mv /tmp/release/*.so* /tmp/lib/ && \ -mv /tmp/release/* /tmp/bin && \ -cd /tmp/bin/ && strip * && upx -9 * && \ -cd /tmp/lib/ && strip * && \ +mv /tmp/release/*.so* /tmp/asset/lib/ && \ +mv /tmp/release/* /tmp/asset/bin/ && \ +cd /tmp/asset/bin/ && strip * && upx -9 * && \ +cd /tmp/asset/lib/ && strip * && \ cd /tmp/packages/ && \ tar xf ssr-python.tar.bz2 && rm -f ./ssr-python.tar.bz2 && \ tar xf ss-python.tar.bz2 && rm -f ./ss-python.tar.bz2 && \ tar xf ss-python-legacy.tar.bz2 && rm -f ./ss-python-legacy.tar.bz2 && \ PYTHON_DIR=`ls /usr/lib/ | grep ^python` && \ -mkdir -p /tmp/lib/$PYTHON_DIR/ && \ -mv /tmp/packages/ /tmp/lib/$PYTHON_DIR/site-packages/ +mkdir -p /tmp/asset/lib/$PYTHON_DIR/ && \ +mv /tmp/packages/ /tmp/asset/lib/$PYTHON_DIR/site-packages/ FROM alpine:3.15 COPY . /usr/local/share/ProxyC -COPY --from=asset /tmp/bin/ /usr/bin/ -COPY --from=asset /tmp/lib/ /usr/lib/ +COPY --from=asset /tmp/asset/ /usr/ RUN apk add --no-cache c-ares ca-certificates glib \ libev libsodium mbedtls pcre python3 redis udns && \ echo "daemonize yes" >> /etc/redis.conf && \ @@ -281,5 +289,7 @@ ln -s $PKG_DIR/ss-python/local.py /usr/bin/ss-python-local && \ ln -s $PKG_DIR/ss-python/server.py /usr/bin/ss-python-server && \ ln -s $PKG_DIR/ss-python-legacy/local.py /usr/bin/ss-python-legacy-local && \ ln -s $PKG_DIR/ss-python-legacy/server.py /usr/bin/ss-python-legacy-server && \ -ln -s /usr/bin/python3 /usr/bin/python +ln -s /usr/bin/python3 /usr/bin/python && \ +cp /usr/local/share/ProxyC/docker/init.sh /usr/bin/ EXPOSE 43581 +CMD ["sh","/usr/bin/init.sh"] \ No newline at end of file diff --git a/Loop.py b/Loop.py index 32bdc45..943bb47 100644 --- a/Loop.py +++ b/Loop.py @@ -17,25 +17,24 @@ redisObject = redis.StrictRedis( port = redisPort ) +runScript = '/usr/local/share/ProxyC/Run.py' + processList = [] while True: spareNum = min( maxThread - len(processList), # 空余进程数 len(redisObject.keys(redisPrefix + 'check-*')) # 待检测个数 ) - if spareNum < 0: + if spareNum < 0: # 待运行进程数 > 0 spareNum = 0 - print("spareNum = " + str(spareNum)) - for i in range(spareNum): # 运行检测进程 processList.append( - subprocess.Popen(['python','Run.py']) + subprocess.Popen(['python', runScript]) ) time.sleep(0.2) for process in processList: # 遍历子进程 if process.poll() != None: # 进程已退出 - print("remove subprocess") processList.remove(process) time.sleep(0.5) diff --git a/docker/init.sh b/docker/init.sh index e48aa5e..42d9b55 100644 --- a/docker/init.sh +++ b/docker/init.sh @@ -1,3 +1,8 @@ -python /usr/local/share/ProxyC/docker/compile.py & +python /usr/local/share/ProxyC/docker/compile.py& /usr/bin/redis-server /etc/redis.conf -echo "ProxyC is running..." + +dnsproxy -p 53 -u 223.5.5.5 & +echo "nameserver 127.0.0.1" > /etc/resolv.conf + +python /usr/local/share/ProxyC/Loop.py& +python /usr/local/share/ProxyC/Web.py