Browse Source

build: perf docker build

v1.x.x
dnomd343 2 years ago
parent
commit
5931257055
  1. 25
      Dockerfile
  2. 2
      cmd/network/network.go

25
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 && \ 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/ 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" 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 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}/ WORKDIR ./Xray-core-${XRAY_VERSION}/
RUN go mod download -x RUN go mod download -x
RUN env CGO_ENABLED=0 go build -v -o xray -trimpath -ldflags "-s -w" ./main/ && mv ./xray /tmp/ RUN env CGO_ENABLED=0 go build -v -o xray -trimpath -ldflags "-s -w" ./main/ && mv ./xray /tmp/
COPY --from=upx /upx/ /usr/ COPY --from=upx /upx/ /usr/
RUN upx -9 /tmp/xray RUN ls /tmp/*ray | xargs -P0 -n1 upx -9
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 golang:1.18-alpine3.16 AS xproxy FROM golang:1.18-alpine3.16 AS xproxy
COPY . /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/ COPY --from=upx /upx/ /usr/
RUN upx -9 /tmp/xproxy 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 FROM alpine:3.16 AS asset
RUN apk add xz
WORKDIR /tmp/ 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/geoip.dat"
RUN wget "https://github.com/Loyalsoldier/v2ray-rules-dat/releases/latest/download/geosite.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 RUN mkdir -p /asset/ && tar cJf /asset/assets.tar.xz ./*.dat
COPY --from=xproxy /tmp/xproxy /asset/usr/bin/ COPY --from=xproxy /tmp/xproxy /asset/usr/bin/
COPY --from=radvd /tmp/radvd* /asset/usr/sbin/ 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 FROM alpine:3.16
COPY --from=asset /asset/ /
ENV XRAY_LOCATION_ASSET=/xproxy/assets ENV XRAY_LOCATION_ASSET=/xproxy/assets
RUN apk add --no-cache iptables ip6tables RUN apk add --no-cache iptables ip6tables
COPY --from=asset /asset/ /
CMD ["xproxy"]

2
cmd/network/network.go

@ -28,7 +28,7 @@ func flushNetwork() {
run("ip", "link", "set", "eth0", "down") run("ip", "link", "set", "eth0", "down")
run("ip", "-4", "addr", "flush", "dev", "eth0") run("ip", "-4", "addr", "flush", "dev", "eth0")
run("ip", "-6", "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) { func loadV4Network(v4 Config) {

Loading…
Cancel
Save