Browse Source

build: combine upx compact process

v1.x.x
dnomd343 2 years ago
parent
commit
b23352b377
  1. 20
      Dockerfile

20
Dockerfile

@ -1,3 +1,5 @@
ARG GOLANG_IMG="golang:1.18-alpine3.16"
FROM alpine:3.16 AS upx FROM alpine:3.16 AS upx
ENV UPX_VERSION="3.96" ENV UPX_VERSION="3.96"
RUN sed -i 's/v3.\d\d/v3.15/' /etc/apk/repositories && \ RUN sed -i 's/v3.\d\d/v3.15/' /etc/apk/repositories && \
@ -8,41 +10,33 @@ 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_IMG} AS xray
ENV XRAY_VERSION="1.5.10" 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 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/
RUN upx -9 /tmp/xray
FROM golang:1.18-alpine3.16 AS v2ray FROM ${GOLANG_IMG} AS v2ray
ENV V2FLY_VERSION="5.1.0" 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 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}/ WORKDIR ./v2ray-core-${V2FLY_VERSION}/
RUN go mod download -x RUN go mod download -x
RUN env CGO_ENABLED=0 go build -v -o v2ray -trimpath -ldflags "-s -w" ./main/ && mv ./v2ray /tmp/ RUN env CGO_ENABLED=0 go build -v -o v2ray -trimpath -ldflags "-s -w" ./main/ && mv ./v2ray /tmp/
COPY --from=upx /upx/ /usr/
RUN upx -9 /tmp/v2ray
FROM golang:1.18-alpine3.16 AS sagray FROM ${GOLANG_IMG} AS sagray
ENV SAGER_VERSION="5.0.16" 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 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}/ WORKDIR ./v2ray-core-${SAGER_VERSION}/
RUN go mod download -x RUN go mod download -x
RUN env CGO_ENABLED=0 go build -v -o sagray -trimpath -ldflags "-s -w" ./main/ && mv ./sagray /tmp/ RUN env CGO_ENABLED=0 go build -v -o sagray -trimpath -ldflags "-s -w" ./main/ && mv ./sagray /tmp/
COPY --from=upx /upx/ /usr/
RUN upx -9 /tmp/sagray
FROM golang:1.18-alpine3.16 AS xproxy FROM ${GOLANG_IMG} AS xproxy
COPY . /XProxy COPY . /XProxy
WORKDIR /XProxy WORKDIR /XProxy
RUN go mod download -x RUN go mod download -x
RUN env CGO_ENABLED=0 go build -v -o xproxy -trimpath \ RUN env CGO_ENABLED=0 go build -v -o xproxy -trimpath \
-ldflags "-X 'main.goVersion=$(go version)' -s -w" ./cmd/ && mv ./xproxy /tmp/ -ldflags "-X 'main.goVersion=$(go version)' -s -w" ./cmd/ && mv ./xproxy /tmp/
COPY --from=upx /upx/ /usr/
RUN upx -9 /tmp/xproxy
FROM alpine:3.16 AS asset FROM alpine:3.16 AS asset
WORKDIR /tmp/ WORKDIR /tmp/
@ -54,6 +48,8 @@ COPY --from=xproxy /tmp/xproxy /asset/usr/bin/
COPY --from=sagray /tmp/sagray /asset/usr/bin/ COPY --from=sagray /tmp/sagray /asset/usr/bin/
COPY --from=v2ray /tmp/v2ray /asset/usr/bin/ COPY --from=v2ray /tmp/v2ray /asset/usr/bin/
COPY --from=xray /tmp/xray /asset/usr/bin/ COPY --from=xray /tmp/xray /asset/usr/bin/
COPY --from=upx /upx/ /usr/
RUN ls /asset/usr/bin/* | xargs -P0 -n1 upx -9
FROM alpine:3.16 FROM alpine:3.16
RUN apk add --no-cache dhcp iptables ip6tables radvd && \ RUN apk add --no-cache dhcp iptables ip6tables radvd && \

Loading…
Cancel
Save