From 593125705570102e41add6139c31f14963c952e1 Mon Sep 17 00:00:00 2001 From: dnomd343 Date: Thu, 18 Aug 2022 03:20:33 +0800 Subject: [PATCH] build: perf docker build --- Dockerfile | 25 +++++++++++++------------ cmd/network/network.go | 2 +- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/Dockerfile b/Dockerfile index a617641..10597ff 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,21 +8,14 @@ WORKDIR ./upx-${UPX_VERSION}-src/ RUN make -C ./src/ && mkdir -p /upx/bin/ && mv ./src/upx.out /upx/bin/upx && \ mkdir -p /upx/lib/ && cd /usr/lib/ && cp -d ./libgcc_s.so* ./libstdc++.so* ./libucl.so* /upx/lib/ -FROM golang:1.18-alpine3.16 AS xray +FROM golang:1.18-alpine3.16 AS proxy ENV XRAY_VERSION="1.5.9" RUN wget https://github.com/XTLS/Xray-core/archive/refs/tags/v${XRAY_VERSION}.tar.gz && tar xf v${XRAY_VERSION}.tar.gz WORKDIR ./Xray-core-${XRAY_VERSION}/ RUN go mod download -x RUN env CGO_ENABLED=0 go build -v -o xray -trimpath -ldflags "-s -w" ./main/ && mv ./xray /tmp/ COPY --from=upx /upx/ /usr/ -RUN upx -9 /tmp/xray - -FROM alpine:3.16 AS radvd -ENV RADVD_VERSION="2.19" -RUN apk add build-base byacc flex-dev linux-headers -RUN wget https://radvd.litech.org/dist/radvd-${RADVD_VERSION}.tar.xz && tar xf radvd-${RADVD_VERSION}.tar.xz -WORKDIR ./radvd-${RADVD_VERSION}/ -RUN ./configure && make && mv ./radvd ./radvdump /tmp/ && strip /tmp/radvd* +RUN ls /tmp/*ray | xargs -P0 -n1 upx -9 FROM golang:1.18-alpine3.16 AS xproxy COPY . /XProxy @@ -31,17 +24,25 @@ RUN env CGO_ENABLED=0 go build -v -o xproxy -trimpath -ldflags "-s -w" ./cmd/ && COPY --from=upx /upx/ /usr/ RUN upx -9 /tmp/xproxy +FROM alpine:3.16 AS radvd +ENV RADVD_VERSION="2.19" +RUN apk add build-base byacc flex-dev linux-headers +RUN wget https://radvd.litech.org/dist/radvd-${RADVD_VERSION}.tar.xz && tar xf radvd-${RADVD_VERSION}.tar.xz +WORKDIR ./radvd-${RADVD_VERSION}/ +RUN ./configure && make && mv ./radvd ./radvdump /tmp/ && strip /tmp/radvd* + FROM alpine:3.16 AS asset -RUN apk add xz WORKDIR /tmp/ +RUN apk add xz RUN wget "https://github.com/Loyalsoldier/v2ray-rules-dat/releases/latest/download/geoip.dat" RUN wget "https://github.com/Loyalsoldier/v2ray-rules-dat/releases/latest/download/geosite.dat" RUN mkdir -p /asset/ && tar cJf /asset/assets.tar.xz ./*.dat COPY --from=xproxy /tmp/xproxy /asset/usr/bin/ COPY --from=radvd /tmp/radvd* /asset/usr/sbin/ -COPY --from=xray /tmp/xray /asset/usr/bin/ +COPY --from=proxy /tmp/*ray /asset/usr/bin/ FROM alpine:3.16 -COPY --from=asset /asset/ / ENV XRAY_LOCATION_ASSET=/xproxy/assets RUN apk add --no-cache iptables ip6tables +COPY --from=asset /asset/ / +CMD ["xproxy"] diff --git a/cmd/network/network.go b/cmd/network/network.go index 99d3954..44a6ba1 100644 --- a/cmd/network/network.go +++ b/cmd/network/network.go @@ -28,7 +28,7 @@ func flushNetwork() { run("ip", "link", "set", "eth0", "down") run("ip", "-4", "addr", "flush", "dev", "eth0") run("ip", "-6", "addr", "flush", "dev", "eth0") - run("ip", "link", "set", "eth0", "down") + run("ip", "link", "set", "eth0", "up") } func loadV4Network(v4 Config) {