From 63a4ac786f0a2a9752abefd9457b96dbe98ba0c4 Mon Sep 17 00:00:00 2001 From: dnomd343 Date: Sat, 10 Sep 2022 14:05:57 +0800 Subject: [PATCH] build: reduce go build download --- Dockerfile | 53 +++++++++++++++++++++++++---------------------------- 1 file changed, 25 insertions(+), 28 deletions(-) diff --git a/Dockerfile b/Dockerfile index cfde329..3bfd8cc 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,48 +1,45 @@ ARG GOLANG_IMG="golang:1.18-alpine3.16" FROM alpine:3.16 AS upx -ENV UPX_VERSION="3.96" -RUN sed -i 's/v3.\d\d/v3.15/' /etc/apk/repositories && \ - apk add bash build-base perl ucl-dev zlib-dev -RUN wget https://github.com/upx/upx/releases/download/v${UPX_VERSION}/upx-${UPX_VERSION}-src.tar.xz && \ - tar xf upx-${UPX_VERSION}-src.tar.xz -WORKDIR ./upx-${UPX_VERSION}-src/ +ENV UPX_VER="3.96" +RUN sed -i 's/v3.\d\d/v3.15/' /etc/apk/repositories && apk add bash build-base perl ucl-dev zlib-dev +RUN wget https://github.com/upx/upx/releases/download/v${UPX_VER}/upx-${UPX_VER}-src.tar.xz && tar xf upx-${UPX_VER}-src.tar.xz +WORKDIR ./upx-${UPX_VER}-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_IMG} AS xray -ENV XRAY_VERSION="1.5.10" -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/ +ENV XRAY_VER="1.5.10" +RUN wget https://github.com/XTLS/Xray-core/archive/refs/tags/v${XRAY_VER}.tar.gz && tar xf v${XRAY_VER}.tar.gz +WORKDIR ./Xray-core-${XRAY_VER}/main/ +RUN go get -d +RUN env CGO_ENABLED=0 go build -v -o xray -trimpath -ldflags "-s -w" && mv xray /tmp/ FROM ${GOLANG_IMG} AS v2ray -ENV V2FLY_VERSION="5.1.0" -RUN wget https://github.com/v2fly/v2ray-core/archive/refs/tags/v${V2FLY_VERSION}.tar.gz && tar xf v${V2FLY_VERSION}.tar.gz -WORKDIR ./v2ray-core-${V2FLY_VERSION}/ -RUN go mod download -x -RUN env CGO_ENABLED=0 go build -v -o v2ray -trimpath -ldflags "-s -w" ./main/ && mv ./v2ray /tmp/ +ENV V2FLY_VER="5.1.0" +RUN wget https://github.com/v2fly/v2ray-core/archive/refs/tags/v${V2FLY_VER}.tar.gz && tar xf v${V2FLY_VER}.tar.gz +WORKDIR ./v2ray-core-${V2FLY_VER}/main/ +RUN go get -d +RUN env CGO_ENABLED=0 go build -v -o v2ray -trimpath -ldflags "-s -w" && mv v2ray /tmp/ FROM ${GOLANG_IMG} AS sagray -ENV SAGER_VERSION="5.0.16" -RUN wget https://github.com/SagerNet/v2ray-core/archive/refs/tags/v${SAGER_VERSION}.tar.gz && tar xf v${SAGER_VERSION}.tar.gz -WORKDIR ./v2ray-core-${SAGER_VERSION}/ -RUN go mod download -x -RUN env CGO_ENABLED=0 go build -v -o sagray -trimpath -ldflags "-s -w" ./main/ && mv ./sagray /tmp/ +ENV SAGER_VER="5.0.16" +RUN wget https://github.com/SagerNet/v2ray-core/archive/refs/tags/v${SAGER_VER}.tar.gz && tar xf v${SAGER_VER}.tar.gz +WORKDIR ./v2ray-core-${SAGER_VER}/main/ +RUN go get -d +RUN env CGO_ENABLED=0 go build -v -o sagray -trimpath -ldflags "-s -w" && mv sagray /tmp/ FROM ${GOLANG_IMG} AS xproxy COPY . /XProxy -WORKDIR /XProxy -RUN go mod download -x -RUN env CGO_ENABLED=0 go build -v -o xproxy -trimpath -ldflags "-s -w" ./cmd/ && mv ./xproxy /tmp/ +WORKDIR /XProxy/cmd/ +RUN go get -d +RUN env CGO_ENABLED=0 go build -v -o xproxy -trimpath -ldflags "-s -w" && mv xproxy /tmp/ FROM alpine:3.16 AS asset 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 +RUN wget "https://github.com/Loyalsoldier/v2ray-rules-dat/releases/latest/download/geoip.dat" && \ + wget "https://github.com/Loyalsoldier/v2ray-rules-dat/releases/latest/download/geosite.dat" +RUN apk add xz && mkdir -p /asset/ && tar cJf /asset/assets.tar.xz ./*.dat COPY --from=xproxy /tmp/xproxy /asset/usr/bin/ COPY --from=sagray /tmp/sagray /asset/usr/bin/ COPY --from=v2ray /tmp/v2ray /asset/usr/bin/