Browse Source

feat: docker working demo

master
Dnomd343 3 years ago
parent
commit
5e341ace16
  1. 34
      Dockerfile
  2. 9
      Loop.py
  3. 9
      docker/init.sh

34
Dockerfile

@ -9,6 +9,7 @@ ENV XRAY_VERSION="v1.5.3"
ENV V2FLY_VERSION="v4.44.0" ENV V2FLY_VERSION="v4.44.0"
ENV GO_VERSION="1.17.6" ENV GO_VERSION="1.17.6"
ENV DNSPROXY_VERSION="v0.41.1"
RUN \ RUN \
apk add asciidoc autoconf automake build-base curl c-ares-dev cmake \ 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/shadowsocks/qtun.git && \
git clone https://github.com/Qv2ray/gun.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/XTLS/Xray-core && \
git clone https://github.com/v2fly/v2ray-core && \ git clone https://github.com/v2fly/v2ray-core && \
git clone https://github.com/AdguardTeam/dnsproxy && \
\ \
# Install rust environment (nightly version) # Install rust environment (nightly version)
sh -c "$(curl -sL https://sh.rustup.rs)" @ -y --no-modify-path --default-toolchain nightly && \ 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 && \ env CGO_ENABLED=0 go build -o v2ctl -trimpath -ldflags "-s -w" -tags confonly ./infra/control/main && \
mv ./v2ctl ./v2ray /tmp/release/ && \ 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 # Switch to go 1.16.13
export PATH=/usr/local/go-1.16.13/bin:$PATH && \ 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 FROM alpine:3.15 as asset
COPY --from=build /tmp/release/ /tmp/release/ COPY --from=build /tmp/release/ /tmp/release/
RUN apk add gcc python3 upx && \ RUN apk add gcc python3 upx && \
cd /tmp/ && mkdir ./bin/ && mkdir ./lib/ && \ mkdir -p /tmp/asset/bin/ && mkdir -p /tmp/asset/lib/ && \
mv ./release/packages.tar.gz ./ && tar xf packages.tar.gz && \ mv /tmp/release/packages.tar.gz /tmp/ && \
cd /tmp/ && tar xf packages.tar.gz && \
mv /tmp/release/*.tar.bz2 /tmp/packages/ && \ mv /tmp/release/*.tar.bz2 /tmp/packages/ && \
mv /tmp/release/*.so* /tmp/lib/ && \ mv /tmp/release/*.so* /tmp/asset/lib/ && \
mv /tmp/release/* /tmp/bin && \ mv /tmp/release/* /tmp/asset/bin/ && \
cd /tmp/bin/ && strip * && upx -9 * && \ cd /tmp/asset/bin/ && strip * && upx -9 * && \
cd /tmp/lib/ && strip * && \ cd /tmp/asset/lib/ && strip * && \
cd /tmp/packages/ && \ cd /tmp/packages/ && \
tar xf ssr-python.tar.bz2 && rm -f ./ssr-python.tar.bz2 && \ 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.tar.bz2 && rm -f ./ss-python.tar.bz2 && \
tar xf ss-python-legacy.tar.bz2 && rm -f ./ss-python-legacy.tar.bz2 && \ tar xf ss-python-legacy.tar.bz2 && rm -f ./ss-python-legacy.tar.bz2 && \
PYTHON_DIR=`ls /usr/lib/ | grep ^python` && \ PYTHON_DIR=`ls /usr/lib/ | grep ^python` && \
mkdir -p /tmp/lib/$PYTHON_DIR/ && \ mkdir -p /tmp/asset/lib/$PYTHON_DIR/ && \
mv /tmp/packages/ /tmp/lib/$PYTHON_DIR/site-packages/ mv /tmp/packages/ /tmp/asset/lib/$PYTHON_DIR/site-packages/
FROM alpine:3.15 FROM alpine:3.15
COPY . /usr/local/share/ProxyC COPY . /usr/local/share/ProxyC
COPY --from=asset /tmp/bin/ /usr/bin/ COPY --from=asset /tmp/asset/ /usr/
COPY --from=asset /tmp/lib/ /usr/lib/
RUN apk add --no-cache c-ares ca-certificates glib \ RUN apk add --no-cache c-ares ca-certificates glib \
libev libsodium mbedtls pcre python3 redis udns && \ libev libsodium mbedtls pcre python3 redis udns && \
echo "daemonize yes" >> /etc/redis.conf && \ 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/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/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 $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 EXPOSE 43581
CMD ["sh","/usr/bin/init.sh"]

9
Loop.py

@ -17,25 +17,24 @@ redisObject = redis.StrictRedis(
port = redisPort port = redisPort
) )
runScript = '/usr/local/share/ProxyC/Run.py'
processList = [] processList = []
while True: while True:
spareNum = min( spareNum = min(
maxThread - len(processList), # 空余进程数 maxThread - len(processList), # 空余进程数
len(redisObject.keys(redisPrefix + 'check-*')) # 待检测个数 len(redisObject.keys(redisPrefix + 'check-*')) # 待检测个数
) )
if spareNum < 0: if spareNum < 0: # 待运行进程数 > 0
spareNum = 0 spareNum = 0
print("spareNum = " + str(spareNum))
for i in range(spareNum): # 运行检测进程 for i in range(spareNum): # 运行检测进程
processList.append( processList.append(
subprocess.Popen(['python','Run.py']) subprocess.Popen(['python', runScript])
) )
time.sleep(0.2) time.sleep(0.2)
for process in processList: # 遍历子进程 for process in processList: # 遍历子进程
if process.poll() != None: # 进程已退出 if process.poll() != None: # 进程已退出
print("remove subprocess")
processList.remove(process) processList.remove(process)
time.sleep(0.5) time.sleep(0.5)

9
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 /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

Loading…
Cancel
Save