From ccc3c343516a970739af9e797b5511554e7daec2 Mon Sep 17 00:00:00 2001 From: dnomd343 Date: Tue, 2 Aug 2022 23:11:06 +0800 Subject: [PATCH 1/4] build: optimize docker build --- Dockerfile | 142 ++++++++++++++++++++++++++++++++++------------------- 1 file changed, 91 insertions(+), 51 deletions(-) diff --git a/Dockerfile b/Dockerfile index b85f32c..45c4bc9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,3 +1,10 @@ +ARG ALPINE="alpine:3.16" +ARG PYTHON="python:3.10-alpine3.16" +ARG RUST="rust:1.62-alpine3.16" +ARG GO18="golang:1.18-alpine3.16" +ARG GO17="golang:1.17-alpine3.16" +ARG GO16="golang:1.16-alpine3.15" + # Compile upx (can't use gcc11 for now) FROM alpine:3.15 AS upx ENV UPX_VERSION="3.96" @@ -13,25 +20,37 @@ RUN \ cp -d /usr/lib/libgcc_s.so* /usr/lib/libstdc++.so* /usr/lib/libucl.so* ./lib/ && \ cp /usr/bin/upx ./bin/ +# Download build-base +FROM ${ALPINE} AS build-base +RUN \ + mkdir /apk/ && cd /apk/ && \ + apk add build-base | grep -oE 'Installing \S+' | cut -b 12- > build-base && \ + chmod +x build-base && cat build-base | xargs -n1 apk fetch && \ + sed -i 's/^/apk add \/apk\/&/g;s/$/&-*.apk/g;1i\#!/bin/sh' build-base + # Compile shadowsocks-rust -FROM rust:1.62-alpine3.16 AS ss-rust +FROM ${RUST} AS ss-rust +COPY --from=build-base /apk/ /apk/ ENV SS_RUST="v1.15.0-alpha.8" RUN \ - apk add build-base && \ + /apk/build-base && \ wget https://github.com/shadowsocks/shadowsocks-rust/archive/refs/tags/${SS_RUST}.tar.gz +RUN tar xf ${SS_RUST}.tar.gz && cd ./shadowsocks-rust-*/ && cargo update RUN \ - tar xf ${SS_RUST}.tar.gz && cd ./shadowsocks-rust-*/ && \ + cd ./shadowsocks-rust-*/ && \ cargo build --release --bin sslocal --bin ssserver \ --features "stream-cipher aead-cipher-extra aead-cipher-2022 aead-cipher-2022-extra" && \ cd ./target/release/ && mv ./sslocal /tmp/ss-rust-local && mv ./ssserver /tmp/ss-rust-server +RUN strip /tmp/ss-rust-* COPY --from=upx /upx/ /usr/ -RUN strip /tmp/ss-rust-* && upx -9 /tmp/ss-rust-* +RUN upx -9 /tmp/ss-rust-* # Compile shadowsocks-libev -FROM alpine:3.16 AS ss-libev +FROM ${ALPINE} AS ss-libev +COPY --from=build-base /apk/ /apk/ ENV SS_LIBEV="3.3.5" RUN \ - apk add build-base c-ares-dev libev-dev libsodium-dev linux-headers mbedtls-dev pcre-dev && \ + /apk/build-base && apk add c-ares-dev libev-dev libsodium-dev linux-headers mbedtls-dev pcre-dev && \ wget https://github.com/shadowsocks/shadowsocks-libev/releases/download/v${SS_LIBEV}/shadowsocks-libev-${SS_LIBEV}.tar.gz RUN \ tar xf shadowsocks-libev-*.tar.gz && cd ./shadowsocks-libev-*/ && \ @@ -40,7 +59,7 @@ RUN \ RUN strip /tmp/ss-libev-* # Package shadowsocks-python (lastest version, legacy version, R version aka ssr) -FROM python:3.10-alpine3.16 AS ss-python +FROM ${PYTHON} AS ss-python ENV SS_PYTHON_LEGACY="2.6.2" RUN \ apk add git && mkdir /packages/ && \ @@ -80,9 +99,10 @@ RUN \ mv ../../lib/ /packages/ss-python-legacy/ # Compile shadowsocks-bootstrap -FROM alpine:3.16 AS ss-bootstrap +FROM ${ALPINE} AS ss-bootstrap +COPY --from=build-base /apk/ /apk/ RUN \ - apk add build-base cmake git glib-dev && \ + /apk/build-base && apk add cmake git glib-dev && \ git clone https://github.com/dnomd343/shadowsocks-bootstrap.git RUN \ cd ./shadowsocks-bootstrap/ && mkdir ./build/ && cd ./build/ && \ @@ -91,7 +111,7 @@ RUN \ RUN strip /tmp/ss-bootstrap-* # Combine shadowsocks dependencies -FROM python:3.10-alpine3.16 AS shadowsocks +FROM ${PYTHON} AS shadowsocks COPY --from=ss-rust /tmp/ss-rust-* /release/ COPY --from=ss-libev /tmp/ss-libev-* /release/ COPY --from=ss-bootstrap /tmp/ss-bootstrap-* /release/ @@ -104,12 +124,41 @@ RUN \ ln -s ${PYTHON_PACKAGE}/ss-python-legacy/local.py /release/ss-python-legacy-local && \ ln -s ${PYTHON_PACKAGE}/ss-python-legacy/server.py /release/ss-python-legacy-server +# Compile gevent +FROM ${PYTHON} AS gevent +COPY --from=build-base /apk/ /apk/ +RUN /apk/build-base && apk add libffi-dev +RUN cd /tmp/ && pip wheel gevent + +# Compile numpy +FROM ${PYTHON} AS numpy +COPY --from=build-base /apk/ /apk/ +RUN /apk/build-base +RUN cd /tmp/ && pip wheel numpy + +# Build python wheels +FROM ${PYTHON} AS wheels +COPY --from=build-base /apk/ /apk/ +RUN /apk/build-base && apk add linux-headers +RUN cd /tmp/ && pip wheel colorlog flask IPy psutil pysocks requests salsa20 +COPY --from=gevent /tmp/*.whl /tmp/ +COPY --from=numpy /tmp/*.whl /tmp/ + +# Pack python modules +FROM ${ALPINE} AS python-pkg +COPY --from=wheels /tmp/*.whl /site-packages/ +RUN cd /site-packages/ && ls | xargs -n1 unzip && rm ./*.whl +COPY --from=ss-python /packages/ /site-packages/ +RUN rm -rf $(find / -name '__pycache__') +RUN BZIP2=-9 tar czf /packages.tar.gz ./site-packages/ + # Compile openssl (old version, for shadowsocks method -> idea-cfb / seed-cfb) -FROM alpine:3.16 AS openssl +FROM ${ALPINE} AS openssl +COPY --from=build-base /apk/ /apk/ ENV OPENSSL_VER="1.0.2" ENV OPENSSL_SUB_VER="u" RUN \ - apk add build-base perl && \ + /apk/build-base && apk add perl && \ wget https://www.openssl.org/source/old/${OPENSSL_VER}/openssl-${OPENSSL_VER}${OPENSSL_SUB_VER}.tar.gz RUN \ tar xf openssl-*.tar.gz && cd ./openssl-*/ && \ @@ -117,21 +166,11 @@ RUN \ mv ./libcrypto.so.1.0.0 /tmp/ RUN strip /tmp/libcrypto.so.1.0.0 -# Build python module (numpy salsa20 psutil) -FROM python:3.10-alpine3.16 AS python-pkg -RUN apk add build-base linux-headers -RUN \ - pip3 install numpy salsa20 psutil && \ - cd /usr/local/lib/python*/site-packages/ && \ - mkdir /site-packages/ && mv ./*numpy* ./*salsa20* ./psutil* /site-packages/ && \ - rm -rf $(find /site-packages/ -name '__pycache__') -COPY --from=ss-python /packages/ /site-packages/ -RUN BZIP2=-9 tar czf /packages.tar.gz ./site-packages/ - # Compile sip003 plugins (part1 -> gcc & cargo) -FROM rust:1.62-alpine3.16 AS plugin-1 +FROM ${RUST} AS plugin-1 +COPY --from=build-base /apk/ /apk/ RUN \ - apk add autoconf automake build-base git libev-dev libtool linux-headers && \ + /apk/build-base && apk add autoconf automake git libev-dev libtool linux-headers && \ git clone https://github.com/shadowsocks/simple-obfs.git && \ git clone https://github.com/shadowsocks/qtun.git && \ mkdir /plugins/ @@ -141,14 +180,16 @@ RUN \ ./autogen.sh && ./configure --disable-documentation && make && \ cd ./src/ && mv ./obfs-local ./obfs-server /plugins/ # Compile qtun +RUN cd ./qtun && cargo update RUN \ cd ./qtun/ && cargo build --release && \ cd ./target/release/ && mv ./qtun-client ./qtun-server /plugins/ +RUN strip /plugins/* COPY --from=upx /upx/ /usr/ -RUN strip /plugins/* && upx -9 /plugins/qtun-* +RUN upx -9 /plugins/qtun-* # Compile sip003 plugins (part2 -> go1.16) -FROM golang:1.16-alpine3.15 AS plugin-2 +FROM ${GO16} AS plugin-2 ENV GOST_PLUGIN="v1.6.3" RUN \ apk add git && mkdir /plugins/ && \ @@ -209,7 +250,7 @@ COPY --from=upx /upx/ /usr/ RUN upx -9 /plugins/* # Compile sip003 plugins (part3 -> go1.17) -FROM golang:1.17-alpine3.16 AS plugin-3 +FROM ${GO17} AS plugin-3 ENV SIMPLE_TLS="v0.7.0" ENV CLOAK="v2.6.0" RUN \ @@ -238,13 +279,13 @@ COPY --from=upx /upx/ /usr/ RUN upx -9 /plugins/* # Combine sip003 plugins -FROM alpine:3.16 AS plugin +FROM ${ALPINE} AS plugin COPY --from=plugin-1 /plugins/ /release/ COPY --from=plugin-2 /plugins/ /release/ COPY --from=plugin-3 /plugins/ /release/ # Compile v2fly-core -FROM golang:1.18-alpine3.16 AS v2ray +FROM ${GO18} AS v2ray ENV V2RAY_VERSION="v4.45.2" RUN \ wget https://github.com/v2fly/v2ray-core/archive/refs/tags/${V2RAY_VERSION}.tar.gz && \ @@ -256,7 +297,7 @@ COPY --from=upx /upx/ /usr/ RUN upx -9 /tmp/v2* # Compile xray-core -FROM golang:1.18-alpine3.16 AS xray +FROM ${GO18} AS xray ENV XRAY_VERSION="v1.5.9" RUN \ wget https://github.com/XTLS/Xray-core/archive/refs/tags/${XRAY_VERSION}.tar.gz && \ @@ -267,7 +308,7 @@ COPY --from=upx /upx/ /usr/ RUN upx -9 /tmp/xray # Compile trojan-go -FROM golang:1.17-alpine3.16 AS trojan-go +FROM ${GO17} AS trojan-go ENV TROJAN_GO_VERSION="v0.10.6" RUN \ apk add git && \ @@ -281,10 +322,11 @@ COPY --from=upx /upx/ /usr/ RUN upx -9 /tmp/trojan-go # Compile trojan -FROM alpine:3.16 AS trojan +FROM ${ALPINE} AS trojan +COPY --from=build-base /apk/ /apk/ ENV TROJAN_VERSION="v1.16.0" RUN \ - apk add boost-dev build-base cmake openssl-dev && \ + /apk/build-base && apk add boost-dev cmake openssl-dev && \ wget https://github.com/trojan-gfw/trojan/archive/refs/tags/${TROJAN_VERSION}.tar.gz RUN \ tar xf ${TROJAN_VERSION}.tar.gz && cd ./trojan-*/ && \ @@ -294,7 +336,7 @@ RUN strip /tmp/trojan COPY --from=trojan-go /tmp/trojan-go /tmp/ # Compile gost-v3 -FROM golang:1.18-alpine3.16 AS gost-v3 +FROM ${GO18} AS gost-v3 RUN \ apk add git && \ git clone https://github.com/go-gost/gost.git && cd ./gost/ && \ @@ -304,7 +346,7 @@ COPY --from=upx /upx/ /usr/ RUN upx -9 /tmp/gost-v3 # Compile gost -FROM golang:1.17-alpine3.16 AS gost +FROM ${GO17} AS gost ENV GOST_VERSION="v2.11.2" RUN \ wget https://github.com/ginuerzh/gost/archive/refs/tags/${GOST_VERSION}.tar.gz && \ @@ -316,7 +358,7 @@ RUN upx -9 /tmp/gost COPY --from=gost-v3 /tmp/gost-v3 /tmp/ # Compile brook -FROM golang:1.16-alpine3.15 AS brook +FROM ${GO16} AS brook ENV BROOK_VERSION="v20220707" RUN \ wget https://github.com/txthinking/brook/archive/refs/tags/${BROOK_VERSION}.tar.gz && \ @@ -327,7 +369,7 @@ COPY --from=upx /upx/ /usr/ RUN upx -9 /tmp/brook # Compile clash -FROM golang:1.18-alpine3.16 AS clash +FROM ${GO18} AS clash ENV CLASH_VERSION="v1.11.4" RUN \ wget https://github.com/Dreamacro/clash/archive/refs/tags/${CLASH_VERSION}.tar.gz && \ @@ -340,7 +382,7 @@ COPY --from=upx /upx/ /usr/ RUN upx -9 /tmp/clash # Compile caddy -FROM golang:1.18-alpine3.16 AS caddy +FROM ${GO18} AS caddy RUN \ go install github.com/caddyserver/xcaddy/cmd/xcaddy@latest && \ xcaddy build --with github.com/caddyserver/forwardproxy@caddy2=github.com/klzgrad/forwardproxy@naive && \ @@ -349,7 +391,7 @@ COPY --from=upx /upx/ /usr/ RUN upx -9 /tmp/caddy # Download naiveproxy -FROM alpine:3.16 AS naiveproxy +FROM ${ALPINE} AS naiveproxy ENV NAIVE_VERSION="v103.0.5060.53-3" RUN \ apk add curl libgcc jq && \ @@ -364,7 +406,7 @@ RUN apk add gcc && strip /tmp/naive COPY --from=caddy /tmp/caddy /tmp/ # Compile open-snell -FROM golang:1.17-alpine3.16 AS snell +FROM ${GO17} AS snell ENV SNELL_VERSION="v3.0.1" RUN \ wget https://github.com/icpz/open-snell/archive/refs/tags/${SNELL_VERSION}.tar.gz && \ @@ -378,7 +420,7 @@ COPY --from=upx /upx/ /usr/ RUN upx -9 /tmp/snell-* # Compile hysteria -FROM golang:1.17-alpine3.16 AS hysteria +FROM ${GO17} AS hysteria ENV HYSTERIA_VERSION="v1.1.0" RUN \ apk add git && \ @@ -405,7 +447,7 @@ COPY --from=upx /upx/ /usr/ RUN upx -9 /tmp/relaybaton # Compile pingtunnel -FROM golang:1.18-alpine3.16 AS pingtunnel +FROM ${GO18} AS pingtunnel RUN \ apk add git && \ git clone https://github.com/esrrhs/pingtunnel.git && cd ./pingtunnel/ && \ @@ -416,7 +458,7 @@ COPY --from=upx /upx/ /usr/ RUN upx -9 /tmp/pingtunnel # Compile wireproxy -FROM golang:1.17-alpine3.16 AS wireproxy +FROM ${GO17} AS wireproxy ENV WIREPROXY_VERSION="v1.0.3" RUN \ wget https://github.com/octeep/wireproxy/archive/refs/tags/${WIREPROXY_VERSION}.tar.gz && \ @@ -427,7 +469,7 @@ COPY --from=upx /upx/ /usr/ RUN upx -9 /tmp/wireproxy # Compile dnsproxy -FROM golang:1.18-alpine3.16 AS dnsproxy +FROM ${GO18} AS dnsproxy ENV DNSPROXY_VERSION="v0.43.1" RUN \ wget https://github.com/AdguardTeam/dnsproxy/archive/refs/tags/${DNSPROXY_VERSION}.tar.gz && \ @@ -438,7 +480,7 @@ COPY --from=upx /upx/ /usr/ RUN upx -9 /tmp/dnsproxy # Compile mad -FROM golang:1.16-alpine3.15 AS mad +FROM ${GO16} AS mad ENV MAD_VERSION="v20210401" RUN \ wget https://github.com/txthinking/mad/archive/refs/tags/${MAD_VERSION}.tar.gz && \ @@ -449,7 +491,7 @@ COPY --from=upx /upx/ /usr/ RUN upx -9 /tmp/mad # Combine all release -FROM python:3.10-alpine3.16 AS asset +FROM ${PYTHON} AS asset COPY --from=python-pkg /packages.tar.gz / RUN \ PACKAGE_DIR="/asset/usr/local/lib/$(ls /usr/local/lib/ | grep ^python)" && \ @@ -474,13 +516,11 @@ COPY --from=dnsproxy /tmp/dnsproxy /asset/usr/bin/ COPY --from=mad /tmp/mad /asset/usr/bin/ # Release docker image -FROM python:3.10-alpine3.16 +FROM ${PYTHON} RUN \ apk add --no-cache boost-program_options c-ares \ ca-certificates glib libev libsodium libstdc++ mbedtls pcre && \ - pip3 --no-cache-dir install colorlog flask gevent IPy pysocks requests && \ - ln -s /usr/local/share/ProxyC/main.py /usr/bin/proxyc && \ - rm -rf $(find / -name '__pycache__') + ln -s /usr/local/share/ProxyC/main.py /usr/bin/proxyc COPY --from=asset /asset / COPY . /usr/local/share/ProxyC/ EXPOSE 7839 From de0c32e29a147b687b28b8387cd466e2b8d4ca93 Mon Sep 17 00:00:00 2001 From: dnomd343 Date: Wed, 3 Aug 2022 02:50:01 +0800 Subject: [PATCH 2/4] build: improve docker build stability --- Dockerfile | 585 ++++++++++++++++++++++++++--------------------------- 1 file changed, 287 insertions(+), 298 deletions(-) diff --git a/Dockerfile b/Dockerfile index 45c4bc9..3cd9f38 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,39 +8,54 @@ ARG GO16="golang:1.16-alpine3.15" # Compile upx (can't use gcc11 for now) FROM alpine:3.15 AS upx ENV UPX_VERSION="3.96" -RUN \ - apk add bash build-base perl ucl-dev zlib-dev && \ - wget https://github.com/upx/upx/releases/download/v${UPX_VERSION}/upx-${UPX_VERSION}-src.tar.xz -RUN \ - tar xf upx-${UPX_VERSION}-src.tar.xz && \ - cd upx-${UPX_VERSION}-src/ && make all && \ - mv ./src/upx.out /usr/bin/upx -RUN \ - mkdir -p /upx/lib/ && mkdir -p /upx/bin/ && cd /upx/ && \ - cp -d /usr/lib/libgcc_s.so* /usr/lib/libstdc++.so* /usr/lib/libucl.so* ./lib/ && \ - cp /usr/bin/upx ./bin/ +RUN 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 +RUN tar xf upx-${UPX_VERSION}-src.tar.xz +WORKDIR ./upx-${UPX_VERSION}-src/ +RUN make all && mv ./src/upx.out /usr/bin/upx +RUN mkdir -p /upx/lib/ && mkdir -p /upx/bin/ +RUN cp -d /usr/lib/libgcc_s.so* /usr/lib/libstdc++.so* /usr/lib/libucl.so* /upx/lib/ +RUN cp /usr/bin/upx /upx/bin/ # Download build-base FROM ${ALPINE} AS build-base -RUN \ - mkdir /apk/ && cd /apk/ && \ - apk add build-base | grep -oE 'Installing \S+' | cut -b 12- > build-base && \ - chmod +x build-base && cat build-base | xargs -n1 apk fetch && \ - sed -i 's/^/apk add \/apk\/&/g;s/$/&-*.apk/g;1i\#!/bin/sh' build-base +WORKDIR /apk/ +RUN apk add build-base | grep -oE 'Installing \S+' | cut -b 12- > build-base && chmod +x build-base +RUN cat ./build-base | xargs -n1 apk fetch +RUN sed -i 's/^/apk add \/apk\/&/g;s/$/&-*.apk/g;1i\#!/bin/sh' ./build-base + +# Compile gevent +FROM ${PYTHON} AS gevent +COPY --from=build-base /apk/ /apk/ +RUN /apk/build-base && apk add libffi-dev +RUN cd /tmp/ && pip wheel gevent + +# Compile numpy +FROM ${PYTHON} AS numpy +COPY --from=build-base /apk/ /apk/ +RUN /apk/build-base +RUN cd /tmp/ && pip wheel numpy + +# Build python wheels +FROM ${PYTHON} AS wheels +COPY --from=build-base /apk/ /apk/ +RUN /apk/build-base && apk add linux-headers +RUN cd /tmp/ && pip wheel colorlog flask IPy psutil pysocks requests salsa20 +COPY --from=gevent /tmp/*.whl /tmp/ +COPY --from=numpy /tmp/*.whl /tmp/ # Compile shadowsocks-rust FROM ${RUST} AS ss-rust COPY --from=build-base /apk/ /apk/ ENV SS_RUST="v1.15.0-alpha.8" -RUN \ - /apk/build-base && \ - wget https://github.com/shadowsocks/shadowsocks-rust/archive/refs/tags/${SS_RUST}.tar.gz -RUN tar xf ${SS_RUST}.tar.gz && cd ./shadowsocks-rust-*/ && cargo update -RUN \ - cd ./shadowsocks-rust-*/ && \ - cargo build --release --bin sslocal --bin ssserver \ - --features "stream-cipher aead-cipher-extra aead-cipher-2022 aead-cipher-2022-extra" && \ - cd ./target/release/ && mv ./sslocal /tmp/ss-rust-local && mv ./ssserver /tmp/ss-rust-server +RUN /apk/build-base +RUN wget https://github.com/shadowsocks/shadowsocks-rust/archive/refs/tags/${SS_RUST}.tar.gz +RUN tar xf ${SS_RUST}.tar.gz && mv ./shadowsocks-rust-*/ ./shadowsocks-rust/ +WORKDIR ./shadowsocks-rust/ +RUN cargo update +RUN cargo build --release --bin sslocal --bin ssserver \ + --features "stream-cipher aead-cipher-extra aead-cipher-2022 aead-cipher-2022-extra" +RUN cd ./target/release/ && mv ./sslocal /tmp/ss-rust-local && mv ./ssserver /tmp/ss-rust-server RUN strip /tmp/ss-rust-* COPY --from=upx /upx/ /usr/ RUN upx -9 /tmp/ss-rust-* @@ -49,65 +64,60 @@ RUN upx -9 /tmp/ss-rust-* FROM ${ALPINE} AS ss-libev COPY --from=build-base /apk/ /apk/ ENV SS_LIBEV="3.3.5" -RUN \ - /apk/build-base && apk add c-ares-dev libev-dev libsodium-dev linux-headers mbedtls-dev pcre-dev && \ - wget https://github.com/shadowsocks/shadowsocks-libev/releases/download/v${SS_LIBEV}/shadowsocks-libev-${SS_LIBEV}.tar.gz -RUN \ - tar xf shadowsocks-libev-*.tar.gz && cd ./shadowsocks-libev-*/ && \ - ./configure --disable-documentation && make && \ - mv ./src/ss-local /tmp/ss-libev-local && mv ./src/ss-server /tmp/ss-libev-server +RUN /apk/build-base +RUN apk add c-ares-dev libev-dev libsodium-dev linux-headers mbedtls-dev pcre-dev +RUN wget https://github.com/shadowsocks/shadowsocks-libev/releases/download/v${SS_LIBEV}/shadowsocks-libev-${SS_LIBEV}.tar.gz +RUN tar xf shadowsocks-libev-*.tar.gz && mv ./shadowsocks-libev-*/ ./shadowsocks-libev/ +WORKDIR ./shadowsocks-libev/ +RUN ./configure --disable-documentation && make +RUN mv ./src/ss-local /tmp/ss-libev-local && mv ./src/ss-server /tmp/ss-libev-server RUN strip /tmp/ss-libev-* # Package shadowsocks-python (lastest version, legacy version, R version aka ssr) FROM ${PYTHON} AS ss-python ENV SS_PYTHON_LEGACY="2.6.2" -RUN \ - apk add git && mkdir /packages/ && \ - git clone https://github.com/dnomd343/shadowsocksr.git && \ - git clone https://github.com/shadowsocks/shadowsocks.git && \ - wget https://github.com/shadowsocks/shadowsocks/archive/refs/tags/${SS_PYTHON_LEGACY}.tar.gz && \ - tar xf ${SS_PYTHON_LEGACY}.tar.gz +RUN apk add git && mkdir /packages/ +RUN git clone https://github.com/dnomd343/shadowsocksr.git +RUN git clone https://github.com/shadowsocks/shadowsocks.git +RUN wget https://github.com/shadowsocks/shadowsocks/archive/refs/tags/${SS_PYTHON_LEGACY}.tar.gz +RUN tar xf ${SS_PYTHON_LEGACY}.tar.gz # shadowsocks-python (R version) -RUN \ - cd ./shadowsocksr/ && \ - sed -i 's/MutableMapping/abc.MutableMapping/' ./shadowsocks/lru_cache.py && \ - sed -i 's/MutableMapping/abc.MutableMapping/' ./shadowsocks/ordereddict.py && \ - sed -i "s/find_library(p)/'libcrypto.so.1.0.0'/g" ./shadowsocks/crypto/ctypes_openssl.py && \ - sed -i "/for path in paths:/a\ if 'libcrypto.so' in path:" ./shadowsocks/crypto/util.py && \ - sed -i "/libcrypto.so/a\ path = 'libcrypto.so.1.0.0'" ./shadowsocks/crypto/util.py && \ - python3 setup.py build && cd ./build/lib/shadowsocks/ && \ - chmod +x ./local.py ./server.py && mv ./local.py ./server.py ../ && \ - mv ../../lib/ /packages/ssr-python/ +WORKDIR ./shadowsocksr/ +RUN sed -i 's/MutableMapping/abc.MutableMapping/' ./shadowsocks/lru_cache.py && \ + sed -i 's/MutableMapping/abc.MutableMapping/' ./shadowsocks/ordereddict.py && \ + sed -i "s/find_library(p)/'libcrypto.so.1.0.0'/g" ./shadowsocks/crypto/ctypes_openssl.py && \ + sed -i "/for path in paths:/a\ if 'libcrypto.so' in path:" ./shadowsocks/crypto/util.py && \ + sed -i "/libcrypto.so/a\ path = 'libcrypto.so.1.0.0'" ./shadowsocks/crypto/util.py +RUN python3 setup.py build && cd ./build/lib/shadowsocks/ && \ + chmod +x ./local.py ./server.py && mv ./local.py ./server.py ../ && \ + mv ../../lib/ /packages/ssr-python/ # shadowsocks-python (latest version) -RUN \ - cd ./shadowsocks/ && git checkout master && \ - sed -i 's/if addr is/if addr ==/g' ./shadowsocks/common.py && \ - sed -i 's/and ip is not/and ip !=/g' ./shadowsocks/common.py && \ - sed -i 's/if len(block) is/if len(block) ==/g' ./shadowsocks/common.py && \ - sed -i 's/MutableMapping/abc.MutableMapping/' ./shadowsocks/lru_cache.py && \ - python3 setup.py build && cd ./build/lib/shadowsocks/ && \ - chmod +x ./local.py ./server.py && mv ./local.py ./server.py ../ && \ - mv ../../lib/ /packages/ss-python/ +WORKDIR ../shadowsocks/ +RUN git checkout master +RUN sed -i 's/if addr is/if addr ==/g' ./shadowsocks/common.py && \ + sed -i 's/and ip is not/and ip !=/g' ./shadowsocks/common.py && \ + sed -i 's/if len(block) is/if len(block) ==/g' ./shadowsocks/common.py && \ + sed -i 's/MutableMapping/abc.MutableMapping/' ./shadowsocks/lru_cache.py +RUN python3 setup.py build && cd ./build/lib/shadowsocks/ && \ + chmod +x ./local.py ./server.py && mv ./local.py ./server.py ../ && \ + mv ../../lib/ /packages/ss-python/ # shadowsocks-python (legacy version) -RUN \ - cd ./shadowsocks-${SS_PYTHON_LEGACY}/ && \ - sed -i 's/MutableMapping/abc.MutableMapping/' ./shadowsocks/lru_cache.py && \ - sed -i "s/find_library(p)/'libsodium.so.23'/g" ./shadowsocks/crypto/ctypes_libsodium.py && \ - sed -i "s/find_library(p)/'libcrypto.so.1.0.0'/g" ./shadowsocks/crypto/ctypes_openssl.py && \ - python3 setup.py build && cd ./build/lib/shadowsocks/ && \ - chmod +x ./local.py ./server.py && mv ./local.py ./server.py ../ && \ - mv ../../lib/ /packages/ss-python-legacy/ +WORKDIR ../shadowsocks-${SS_PYTHON_LEGACY}/ +RUN sed -i 's/MutableMapping/abc.MutableMapping/' ./shadowsocks/lru_cache.py && \ + sed -i "s/find_library(p)/'libsodium.so.23'/g" ./shadowsocks/crypto/ctypes_libsodium.py && \ + sed -i "s/find_library(p)/'libcrypto.so.1.0.0'/g" ./shadowsocks/crypto/ctypes_openssl.py +RUN python3 setup.py build && cd ./build/lib/shadowsocks/ && \ + chmod +x ./local.py ./server.py && mv ./local.py ./server.py ../ && \ + mv ../../lib/ /packages/ss-python-legacy/ # Compile shadowsocks-bootstrap FROM ${ALPINE} AS ss-bootstrap COPY --from=build-base /apk/ /apk/ -RUN \ - /apk/build-base && apk add cmake git glib-dev && \ - git clone https://github.com/dnomd343/shadowsocks-bootstrap.git -RUN \ - cd ./shadowsocks-bootstrap/ && mkdir ./build/ && cd ./build/ && \ - cmake -DCMAKE_BUILD_TYPE=Release .. && make && \ - mv ../bin/ss-bootstrap-* /tmp/ +RUN /apk/build-base && apk add cmake git glib-dev +RUN git clone https://github.com/dnomd343/shadowsocks-bootstrap.git +WORKDIR ./shadowsocks-bootstrap/build/ +RUN cmake -DCMAKE_BUILD_TYPE=Release .. && make +RUN mv ../bin/ss-bootstrap-* /tmp/ RUN strip /tmp/ss-bootstrap-* # Combine shadowsocks dependencies @@ -116,33 +126,13 @@ COPY --from=ss-rust /tmp/ss-rust-* /release/ COPY --from=ss-libev /tmp/ss-libev-* /release/ COPY --from=ss-bootstrap /tmp/ss-bootstrap-* /release/ RUN \ - PYTHON_PACKAGE="/usr/local/lib/$(ls /usr/local/lib/ | grep ^python)/site-packages" && \ - ln -s ${PYTHON_PACKAGE}/ssr-python/local.py /release/ssr-local && \ - ln -s ${PYTHON_PACKAGE}/ssr-python/server.py /release/ssr-server && \ - ln -s ${PYTHON_PACKAGE}/ss-python/local.py /release/ss-python-local && \ - ln -s ${PYTHON_PACKAGE}/ss-python/server.py /release/ss-python-server && \ - ln -s ${PYTHON_PACKAGE}/ss-python-legacy/local.py /release/ss-python-legacy-local && \ - ln -s ${PYTHON_PACKAGE}/ss-python-legacy/server.py /release/ss-python-legacy-server - -# Compile gevent -FROM ${PYTHON} AS gevent -COPY --from=build-base /apk/ /apk/ -RUN /apk/build-base && apk add libffi-dev -RUN cd /tmp/ && pip wheel gevent - -# Compile numpy -FROM ${PYTHON} AS numpy -COPY --from=build-base /apk/ /apk/ -RUN /apk/build-base -RUN cd /tmp/ && pip wheel numpy - -# Build python wheels -FROM ${PYTHON} AS wheels -COPY --from=build-base /apk/ /apk/ -RUN /apk/build-base && apk add linux-headers -RUN cd /tmp/ && pip wheel colorlog flask IPy psutil pysocks requests salsa20 -COPY --from=gevent /tmp/*.whl /tmp/ -COPY --from=numpy /tmp/*.whl /tmp/ + PYTHON_PACKAGE="/usr/local/lib/$(ls /usr/local/lib/ | grep ^python)/site-packages" && \ + ln -s ${PYTHON_PACKAGE}/ssr-python/local.py /release/ssr-local && \ + ln -s ${PYTHON_PACKAGE}/ssr-python/server.py /release/ssr-server && \ + ln -s ${PYTHON_PACKAGE}/ss-python/local.py /release/ss-python-local && \ + ln -s ${PYTHON_PACKAGE}/ss-python/server.py /release/ss-python-server && \ + ln -s ${PYTHON_PACKAGE}/ss-python-legacy/local.py /release/ss-python-legacy-local && \ + ln -s ${PYTHON_PACKAGE}/ss-python-legacy/server.py /release/ss-python-legacy-server # Pack python modules FROM ${ALPINE} AS python-pkg @@ -157,33 +147,31 @@ FROM ${ALPINE} AS openssl COPY --from=build-base /apk/ /apk/ ENV OPENSSL_VER="1.0.2" ENV OPENSSL_SUB_VER="u" -RUN \ - /apk/build-base && apk add perl && \ - wget https://www.openssl.org/source/old/${OPENSSL_VER}/openssl-${OPENSSL_VER}${OPENSSL_SUB_VER}.tar.gz -RUN \ - tar xf openssl-*.tar.gz && cd ./openssl-*/ && \ - ./config --shared --prefix=/usr && make && \ - mv ./libcrypto.so.1.0.0 /tmp/ +RUN /apk/build-base && apk add perl +RUN wget https://www.openssl.org/source/old/${OPENSSL_VER}/openssl-${OPENSSL_VER}${OPENSSL_SUB_VER}.tar.gz +RUN tar xf openssl-*.tar.gz && mv ./openssl-*/ ./openssl/ +WORKDIR ./openssl/ +RUN ./config --shared --prefix=/usr && make +RUN mv ./libcrypto.so.1.0.0 /tmp/ RUN strip /tmp/libcrypto.so.1.0.0 # Compile sip003 plugins (part1 -> gcc & cargo) FROM ${RUST} AS plugin-1 COPY --from=build-base /apk/ /apk/ -RUN \ - /apk/build-base && apk add autoconf automake git libev-dev libtool linux-headers && \ - git clone https://github.com/shadowsocks/simple-obfs.git && \ - git clone https://github.com/shadowsocks/qtun.git && \ - mkdir /plugins/ +RUN apk add git && mkdir /plugins/ +RUN /apk/build-base && apk add autoconf automake libev-dev libtool linux-headers +RUN git clone https://github.com/shadowsocks/simple-obfs.git +RUN git clone https://github.com/shadowsocks/qtun.git # Compile simple-obfs -RUN \ - cd ./simple-obfs/ && git submodule update --init --recursive && \ - ./autogen.sh && ./configure --disable-documentation && make && \ - cd ./src/ && mv ./obfs-local ./obfs-server /plugins/ +WORKDIR ./simple-obfs/ +RUN git submodule update --init --recursive +RUN ./autogen.sh && ./configure --disable-documentation && make +RUN cd ./src/ && mv ./obfs-local ./obfs-server /plugins/ # Compile qtun -RUN cd ./qtun && cargo update -RUN \ - cd ./qtun/ && cargo build --release && \ - cd ./target/release/ && mv ./qtun-client ./qtun-server /plugins/ +WORKDIR ../qtun/ +RUN cargo update +RUN cargo build --release +RUN cd ./target/release/ && mv ./qtun-client ./qtun-server /plugins/ RUN strip /plugins/* COPY --from=upx /upx/ /usr/ RUN upx -9 /plugins/qtun-* @@ -191,61 +179,58 @@ RUN upx -9 /plugins/qtun-* # Compile sip003 plugins (part2 -> go1.16) FROM ${GO16} AS plugin-2 ENV GOST_PLUGIN="v1.6.3" -RUN \ - apk add git && mkdir /plugins/ && \ - git clone https://github.com/Qv2ray/gun.git && \ - git clone https://github.com/dnomd343/kcptun.git && \ - git clone https://github.com/dnomd343/GoQuiet.git && \ - git clone https://github.com/ihciah/rabbit-tcp.git && \ - git clone https://github.com/dnomd343/rabbit-plugin.git && \ - git clone https://github.com/maskedeken/gost-plugin.git && \ - git clone https://github.com/shadowsocks/v2ray-plugin.git && \ - git clone https://github.com/IrineSistiana/mos-tls-tunnel.git +RUN apk add git && mkdir /plugins/ +RUN git clone https://github.com/Qv2ray/gun.git +RUN git clone https://github.com/dnomd343/kcptun.git +RUN git clone https://github.com/dnomd343/GoQuiet.git +RUN git clone https://github.com/ihciah/rabbit-tcp.git +RUN git clone https://github.com/dnomd343/rabbit-plugin.git +RUN git clone https://github.com/maskedeken/gost-plugin.git +RUN git clone https://github.com/shadowsocks/v2ray-plugin.git +RUN git clone https://github.com/IrineSistiana/mos-tls-tunnel.git # Compile v2ray-plugin -RUN \ - cd ./v2ray-plugin/ && \ - env CGO_ENABLED=0 go build -trimpath -ldflags "-X main.VERSION=$(git describe --tags) -s -w" && \ - mv ./v2ray-plugin /plugins/ +WORKDIR ./v2ray-plugin/ +RUN env CGO_ENABLED=0 go build -v -trimpath -ldflags "-X main.VERSION=$(git describe --tags) -s -w" +RUN mv ./v2ray-plugin /plugins/ # Compile kcptun -RUN \ - cd ./kcptun/ && git checkout sip003 && \ - go mod init github.com/shadowsocks/kcptun && go mod tidy && \ - env CGO_ENABLED=0 go build -o kcptun-client -trimpath -ldflags "-X main.VERSION=$(git describe --tags) -s -w" ./client && \ - env CGO_ENABLED=0 go build -o kcptun-server -trimpath -ldflags "-X main.VERSION=$(git describe --tags) -s -w" ./server && \ - mv ./kcptun-client ./kcptun-server /plugins/ +WORKDIR ../kcptun/ +RUN git checkout sip003 +RUN go mod init github.com/shadowsocks/kcptun && go mod tidy +RUN env CGO_ENABLED=0 go build -v -o kcptun-client -trimpath -ldflags "-X main.VERSION=$(git describe --tags) -s -w" ./client +RUN env CGO_ENABLED=0 go build -v -o kcptun-server -trimpath -ldflags "-X main.VERSION=$(git describe --tags) -s -w" ./server +RUN mv ./kcptun-client ./kcptun-server /plugins/ # Compile gost-plugin -RUN \ - cd ./gost-plugin/ && git checkout ${GOST_PLUGIN} && \ - env CGO_ENABLED=0 go build -trimpath -ldflags "-X main.VERSION=$(git describe --tags) -s -w" && \ - mv ./gost-plugin /plugins/ +WORKDIR ../gost-plugin/ +RUN git checkout ${GOST_PLUGIN} && go mod download -x +RUN env CGO_ENABLED=0 go build -v -trimpath -ldflags "-X main.VERSION=$(git describe --tags) -s -w" +RUN mv ./gost-plugin /plugins/ # Compile GoQuiet -RUN \ - cd ./GoQuiet/ && go mod init github.com/cbeuw/GoQuiet && \ - env CGO_ENABLED=0 go build -trimpath -ldflags "-X main.version=$(git describe --tags) -s -w" ./cmd/gq-client && \ - env CGO_ENABLED=0 go build -trimpath -ldflags "-X main.version=$(git describe --tags) -s -w" ./cmd/gq-server && \ - mv ./gq-client ./gq-server /plugins/ +WORKDIR ../GoQuiet/ +RUN go mod init github.com/cbeuw/GoQuiet +RUN env CGO_ENABLED=0 go build -v -trimpath -ldflags "-X main.version=$(git describe --tags) -s -w" ./cmd/gq-client +RUN env CGO_ENABLED=0 go build -v -trimpath -ldflags "-X main.version=$(git describe --tags) -s -w" ./cmd/gq-server +RUN mv ./gq-client ./gq-server /plugins/ # Compile mos-tls-tunnel -RUN \ - cd ./mos-tls-tunnel/ && \ - go mod init github.com/IrineSistiana/mos-tls-tunnel && go mod vendor && \ - env CGO_ENABLED=0 go build -mod=vendor -trimpath -ldflags "-s -w" ./cmd/mtt-client && \ - env CGO_ENABLED=0 go build -mod=vendor -trimpath -ldflags "-s -w" ./cmd/mtt-server && \ - mv ./mtt-client ./mtt-server /plugins/ +WORKDIR ../mos-tls-tunnel/ +RUN go mod init github.com/IrineSistiana/mos-tls-tunnel && go mod vendor +RUN env CGO_ENABLED=0 go build -v -mod=vendor -trimpath -ldflags "-s -w" ./cmd/mtt-client +RUN env CGO_ENABLED=0 go build -v -mod=vendor -trimpath -ldflags "-s -w" ./cmd/mtt-server +RUN mv ./mtt-client ./mtt-server /plugins/ # Compile rabbit-plugin -RUN \ - cd ./rabbit-plugin/ && \ - env CGO_ENABLED=0 go build -trimpath -ldflags "-s -w" && \ - mv ./rabbit-plugin /plugins/ +WORKDIR ../rabbit-plugin/ +RUN go mod download -x +RUN env CGO_ENABLED=0 go build -v -trimpath -ldflags "-s -w" +RUN mv ./rabbit-plugin /plugins/ # Compile rabbit-tcp -RUN \ - cd ./rabbit-tcp/ && \ - env CGO_ENABLED=0 go build -trimpath -ldflags "-X main.Version=$(git describe --tags) -s -w" ./cmd/rabbit.go && \ - mv ./rabbit /plugins/ +WORKDIR ../rabbit-tcp/ +RUN go mod download -x +RUN env CGO_ENABLED=0 go build -v -trimpath -ldflags "-X main.Version=$(git describe --tags) -s -w" ./cmd/rabbit.go +RUN mv ./rabbit /plugins/ # Compile gun-plugin -RUN \ - cd ./gun/ && \ - env CGO_ENABLED=0 go build -o gun-plugin -trimpath -ldflags "-s -w" ./cmd/sip003/ && \ - mv ./gun-plugin /plugins/ +WORKDIR ../gun/ +RUN go mod download -x +RUN env CGO_ENABLED=0 go build -v -o gun-plugin -trimpath -ldflags "-s -w" ./cmd/sip003/ +RUN mv ./gun-plugin /plugins/ COPY --from=upx /upx/ /usr/ RUN upx -9 /plugins/* @@ -253,28 +238,27 @@ RUN upx -9 /plugins/* FROM ${GO17} AS plugin-3 ENV SIMPLE_TLS="v0.7.0" ENV CLOAK="v2.6.0" -RUN \ - apk add git && mkdir /plugins/ && \ - git clone https://github.com/cbeuw/Cloak.git && \ - git clone https://github.com/teddysun/xray-plugin.git && \ - git clone https://github.com/IrineSistiana/simple-tls.git +RUN apk add git && mkdir /plugins/ +RUN git clone https://github.com/cbeuw/Cloak.git +RUN git clone https://github.com/teddysun/xray-plugin.git +RUN git clone https://github.com/IrineSistiana/simple-tls.git # Compile simple-tls -RUN \ - cd ./simple-tls/ && git checkout ${SIMPLE_TLS} && \ - sed -i 's/version = "unknown\/dev"/version = "'$(git describe --tags)'"/g' main.go && \ - env CGO_ENABLED=0 go build -trimpath -ldflags "-s -w" && \ - mv ./simple-tls /plugins/ +WORKDIR ./simple-tls/ +RUN git checkout ${SIMPLE_TLS} && go mod download -x +RUN sed -i 's/version = "unknown\/dev"/version = "'$(git describe --tags)'"/g' main.go +RUN env CGO_ENABLED=0 go build -v -trimpath -ldflags "-s -w" +RUN mv ./simple-tls /plugins/ # Compile xray-plugin -RUN \ - cd ./xray-plugin/ && \ - env CGO_ENABLED=0 go build -trimpath -ldflags "-X main.VERSION=$(git describe --tags) -s -w" && \ - mv ./xray-plugin /plugins/ +WORKDIR ../xray-plugin/ +RUN go mod download -x +RUN env CGO_ENABLED=0 go build -v -trimpath -ldflags "-X main.VERSION=$(git describe --tags) -s -w" +RUN mv ./xray-plugin /plugins/ # Compile Cloak -RUN \ - cd ./Cloak/ && git checkout ${CLOAK} && \ - env CGO_ENABLED=0 go build -trimpath -ldflags "-X main.version=$(git describe --tags) -s -w" ./cmd/ck-client && \ - env CGO_ENABLED=0 go build -trimpath -ldflags "-X main.version=$(git describe --tags) -s -w" ./cmd/ck-server && \ - mv ./ck-client ./ck-server /plugins/ +WORKDIR ../Cloak/ +RUN git checkout ${CLOAK} && go mod download -x +RUN env CGO_ENABLED=0 go build -v -trimpath -ldflags "-X main.version=$(git describe --tags) -s -w" ./cmd/ck-client +RUN env CGO_ENABLED=0 go build -v -trimpath -ldflags "-X main.version=$(git describe --tags) -s -w" ./cmd/ck-server +RUN mv ./ck-client ./ck-server /plugins/ COPY --from=upx /upx/ /usr/ RUN upx -9 /plugins/* @@ -287,37 +271,39 @@ COPY --from=plugin-3 /plugins/ /release/ # Compile v2fly-core FROM ${GO18} AS v2ray ENV V2RAY_VERSION="v4.45.2" -RUN \ - wget https://github.com/v2fly/v2ray-core/archive/refs/tags/${V2RAY_VERSION}.tar.gz && \ - tar xf ${V2RAY_VERSION}.tar.gz && cd ./v2ray-core-*/ && \ - 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 && \ - mv ./v2ctl ./v2ray /tmp/ +RUN wget https://github.com/v2fly/v2ray-core/archive/refs/tags/${V2RAY_VERSION}.tar.gz +RUN tar xf ${V2RAY_VERSION}.tar.gz && mv ./v2ray-core-*/ ./v2ray-core/ +WORKDIR ./v2ray-core/ +RUN go mod download -x +RUN env CGO_ENABLED=0 go build -v -o v2ray -trimpath -ldflags "-s -w" ./main +RUN env CGO_ENABLED=0 go build -v -o v2ctl -trimpath -ldflags "-s -w" -tags confonly ./infra/control/main +RUN mv ./v2ctl ./v2ray /tmp/ COPY --from=upx /upx/ /usr/ RUN upx -9 /tmp/v2* # Compile xray-core FROM ${GO18} AS xray ENV XRAY_VERSION="v1.5.9" -RUN \ - wget https://github.com/XTLS/Xray-core/archive/refs/tags/${XRAY_VERSION}.tar.gz && \ - tar xf ${XRAY_VERSION}.tar.gz && cd ./Xray-core-*/ && \ - env CGO_ENABLED=0 go build -o xray -trimpath -ldflags "-s -w" ./main && \ - mv ./xray /tmp/ +RUN wget https://github.com/XTLS/Xray-core/archive/refs/tags/${XRAY_VERSION}.tar.gz +RUN tar xf ${XRAY_VERSION}.tar.gz && mv ./Xray-core-*/ ./Xray-core/ +WORKDIR ./Xray-core/ +RUN go mod download -x +RUN env CGO_ENABLED=0 go build -v -o xray -trimpath -ldflags "-s -w" ./main +RUN mv ./xray /tmp/ COPY --from=upx /upx/ /usr/ RUN upx -9 /tmp/xray # Compile trojan-go FROM ${GO17} AS trojan-go ENV TROJAN_GO_VERSION="v0.10.6" -RUN \ - apk add git && \ - git clone https://github.com/p4gefau1t/trojan-go.git && \ - cd ./trojan-go/ && git checkout ${TROJAN_GO_VERSION} && \ - env CGO_ENABLED=0 go build -trimpath \ - -ldflags "-X github.com/p4gefau1t/trojan-go/constant.Version=$(git describe --dirty) \ - -X github.com/p4gefau1t/trojan-go/constant.Commit=$(git rev-parse HEAD) -s -w" -tags "full" && \ - mv ./trojan-go /tmp/ +RUN apk add git +RUN git clone https://github.com/p4gefau1t/trojan-go.git +WORKDIR ./trojan-go/ +RUN git checkout ${TROJAN_GO_VERSION} && go mod download -x +RUN env CGO_ENABLED=0 go build -v -trimpath -ldflags " \ + -X github.com/p4gefau1t/trojan-go/constant.Version=$(git describe --dirty) \ + -X github.com/p4gefau1t/trojan-go/constant.Commit=$(git rev-parse HEAD) -s -w" -tags "full" +RUN mv ./trojan-go /tmp/ COPY --from=upx /upx/ /usr/ RUN upx -9 /tmp/trojan-go @@ -325,168 +311,172 @@ RUN upx -9 /tmp/trojan-go FROM ${ALPINE} AS trojan COPY --from=build-base /apk/ /apk/ ENV TROJAN_VERSION="v1.16.0" -RUN \ - /apk/build-base && apk add boost-dev cmake openssl-dev && \ - wget https://github.com/trojan-gfw/trojan/archive/refs/tags/${TROJAN_VERSION}.tar.gz -RUN \ - tar xf ${TROJAN_VERSION}.tar.gz && cd ./trojan-*/ && \ - mkdir ./build/ && cd ./build/ && cmake .. -DENABLE_MYSQL=OFF -DSYSTEMD_SERVICE=OFF && make && \ - mv ./trojan /tmp/ +RUN /apk/build-base && apk add boost-dev cmake openssl-dev +RUN wget https://github.com/trojan-gfw/trojan/archive/refs/tags/${TROJAN_VERSION}.tar.gz +RUN tar xf ${TROJAN_VERSION}.tar.gz && mv ./trojan-*/ ./trojan/ +WORKDIR ./trojan/build/ +RUN cmake .. -DENABLE_MYSQL=OFF -DSYSTEMD_SERVICE=OFF && make +RUN mv ./trojan /tmp/ RUN strip /tmp/trojan COPY --from=trojan-go /tmp/trojan-go /tmp/ # Compile gost-v3 FROM ${GO18} AS gost-v3 -RUN \ - apk add git && \ - git clone https://github.com/go-gost/gost.git && cd ./gost/ && \ - env CGO_ENABLED=0 go build -trimpath -ldflags "-s -w" ./cmd/gost && \ - mv ./gost /tmp/gost-v3 +RUN apk add git +RUN git clone https://github.com/go-gost/gost.git +WORKDIR ./gost/ +RUN go mod download -x +RUN env CGO_ENABLED=0 go build -v -trimpath -ldflags "-s -w" ./cmd/gost +RUN mv ./gost /tmp/gost-v3 COPY --from=upx /upx/ /usr/ RUN upx -9 /tmp/gost-v3 # Compile gost FROM ${GO17} AS gost ENV GOST_VERSION="v2.11.2" -RUN \ - wget https://github.com/ginuerzh/gost/archive/refs/tags/${GOST_VERSION}.tar.gz && \ - tar xf ${GOST_VERSION}.tar.gz && cd ./gost-*/cmd/gost/ && \ - env CGO_ENABLED=0 go build -trimpath -ldflags "-s -w" && \ - mv ./gost /tmp/ +RUN wget https://github.com/ginuerzh/gost/archive/refs/tags/${GOST_VERSION}.tar.gz +RUN tar xf ${GOST_VERSION}.tar.gz && mv ./gost-*/ ./gost/ +WORKDIR ./gost/ +RUN go mod download -x +RUN env CGO_ENABLED=0 go build -v -trimpath -ldflags "-s -w" ./cmd/gost +RUN mv ./gost /tmp/ +COPY --from=gost-v3 /tmp/gost-v3 /tmp/ COPY --from=upx /upx/ /usr/ RUN upx -9 /tmp/gost -COPY --from=gost-v3 /tmp/gost-v3 /tmp/ # Compile brook FROM ${GO16} AS brook ENV BROOK_VERSION="v20220707" -RUN \ - wget https://github.com/txthinking/brook/archive/refs/tags/${BROOK_VERSION}.tar.gz && \ - tar xf ${BROOK_VERSION}.tar.gz && cd ./brook-*/ && \ - env CGO_ENABLED=0 go build -trimpath -ldflags "-s -w" ./cli/brook && \ - mv ./brook /tmp/ +RUN wget https://github.com/txthinking/brook/archive/refs/tags/${BROOK_VERSION}.tar.gz +RUN tar xf ${BROOK_VERSION}.tar.gz && mv ./brook-*/ ./brook/ +WORKDIR ./brook/ +RUN go mod download -x +RUN env CGO_ENABLED=0 go build -v -trimpath -ldflags "-s -w" ./cli/brook +RUN mv ./brook /tmp/ COPY --from=upx /upx/ /usr/ RUN upx -9 /tmp/brook # Compile clash FROM ${GO18} AS clash ENV CLASH_VERSION="v1.11.4" -RUN \ - wget https://github.com/Dreamacro/clash/archive/refs/tags/${CLASH_VERSION}.tar.gz && \ - tar xf ${CLASH_VERSION}.tar.gz && cd ./clash-*/ && \ - env CGO_ENABLED=0 go build -trimpath -ldflags "-s -w \ - -X 'github.com/Dreamacro/clash/constant.Version=${CLASH_VERSION}' \ - -X 'github.com/Dreamacro/clash/constant.BuildTime=$(date -u)'" && \ - mv ./clash /tmp/ +RUN wget https://github.com/Dreamacro/clash/archive/refs/tags/${CLASH_VERSION}.tar.gz +RUN tar xf ${CLASH_VERSION}.tar.gz && mv ./clash-*/ ./clash/ +WORKDIR ./clash/ +RUN go mod download -x +RUN env CGO_ENABLED=0 go build -v -trimpath -ldflags "-s -w \ + -X 'github.com/Dreamacro/clash/constant.Version=${CLASH_VERSION}' \ + -X 'github.com/Dreamacro/clash/constant.BuildTime=$(date -u)'" +RUN mv ./clash /tmp/ COPY --from=upx /upx/ /usr/ RUN upx -9 /tmp/clash # Compile caddy FROM ${GO18} AS caddy -RUN \ - go install github.com/caddyserver/xcaddy/cmd/xcaddy@latest && \ - xcaddy build --with github.com/caddyserver/forwardproxy@caddy2=github.com/klzgrad/forwardproxy@naive && \ - mv ./caddy /tmp/ +RUN go install github.com/caddyserver/xcaddy/cmd/xcaddy@latest +RUN xcaddy build --with github.com/caddyserver/forwardproxy@caddy2=github.com/klzgrad/forwardproxy@naive +RUN mv ./caddy /tmp/ COPY --from=upx /upx/ /usr/ RUN upx -9 /tmp/caddy # Download naiveproxy FROM ${ALPINE} AS naiveproxy ENV NAIVE_VERSION="v103.0.5060.53-3" -RUN \ - apk add curl libgcc jq && \ - curl -sL https://api.github.com/repos/klzgrad/naiveproxy/releases/tags/${NAIVE_VERSION} | jq .assets | jq .[].name \ - | grep naiveproxy-${NAIVE_VERSION}-openwrt-$(uname -m) | cut -b 2- | rev | cut -b 2- | rev | tac > list.dat -RUN \ - echo -e "while read FILE_NAME;do\nwget https://github.com/klzgrad/naiveproxy/releases/download/\${NAIVE_VERSION}/\${FILE_NAME}\n \ - tar xf \${FILE_NAME} && ldd ./\$(echo \$FILE_NAME | rev | cut -b 8- | rev)/naive\n \ - [ \$? -eq 0 ] && cp ./\$(echo \$FILE_NAME | rev | cut -b 8- | rev)/naive /tmp/ && break\ndone < list.dat" > naiveproxy.sh && \ - sh naiveproxy.sh -RUN apk add gcc && strip /tmp/naive +RUN apk add curl libgcc jq +RUN curl -sL https://api.github.com/repos/klzgrad/naiveproxy/releases/tags/${NAIVE_VERSION} \ + | jq .assets | jq .[].name | grep naiveproxy-${NAIVE_VERSION}-openwrt-$(uname -m) \ + | cut -b 2- | rev | cut -b 2- | rev | tac > list.dat +RUN echo -e "while read FILE_NAME;do\nwget https://github.com/klzgrad/naiveproxy/releases/download/\${NAIVE_VERSION}/\${FILE_NAME}\n \ + tar xf \${FILE_NAME} && ldd ./\$(echo \$FILE_NAME | rev | cut -b 8- | rev)/naive\n \ + [ \$? -eq 0 ] && cp ./\$(echo \$FILE_NAME | rev | cut -b 8- | rev)/naive /tmp/ && break\ndone < list.dat" > naiveproxy.sh +RUN sh naiveproxy.sh +COPY --from=build-base /apk/ /apk/ +RUN /apk/build-base && strip /tmp/naive COPY --from=caddy /tmp/caddy /tmp/ # Compile open-snell FROM ${GO17} AS snell ENV SNELL_VERSION="v3.0.1" -RUN \ - wget https://github.com/icpz/open-snell/archive/refs/tags/${SNELL_VERSION}.tar.gz && \ - tar xf ${SNELL_VERSION}.tar.gz && cd ./open-snell-*/ && \ - env CGO_ENABLED=0 go build -trimpath \ - -ldflags "-s -w -X 'github.com/icpz/open-snell/constants.Version=${SNELL_VERSION}'" ./cmd/snell-client && \ - env CGO_ENABLED=0 go build -trimpath \ - -ldflags "-s -w -X 'github.com/icpz/open-snell/constants.Version=${SNELL_VERSION}'" ./cmd/snell-server && \ - mv ./snell-client ./snell-server /tmp/ +RUN wget https://github.com/icpz/open-snell/archive/refs/tags/${SNELL_VERSION}.tar.gz +RUN tar xf ${SNELL_VERSION}.tar.gz && mv ./open-snell-*/ ./open-snell/ +WORKDIR ./open-snell/ +RUN go mod download -x +RUN env CGO_ENABLED=0 go build -v -trimpath -ldflags \ + "-s -w -X 'github.com/icpz/open-snell/constants.Version=${SNELL_VERSION}'" ./cmd/snell-client +RUN env CGO_ENABLED=0 go build -v -trimpath -ldflags \ + "-s -w -X 'github.com/icpz/open-snell/constants.Version=${SNELL_VERSION}'" ./cmd/snell-server +RUN mv ./snell-client ./snell-server /tmp/ COPY --from=upx /upx/ /usr/ RUN upx -9 /tmp/snell-* # Compile hysteria FROM ${GO17} AS hysteria ENV HYSTERIA_VERSION="v1.1.0" -RUN \ - apk add git && \ - git clone https://github.com/HyNetwork/hysteria.git && \ - cd ./hysteria/ && git checkout ${HYSTERIA_VERSION} && cd ./cmd/ && \ - env CGO_ENABLED=0 go build -o hysteria -trimpath -ldflags "-s -w \ - -X 'main.appVersion=$(git describe --tags)' \ - -X 'main.appCommit=$(git rev-parse HEAD)' \ - -X 'main.appDate=$(date "+%F %T")'" && \ - mv ./hysteria /tmp/ +RUN apk add git +RUN git clone https://github.com/HyNetwork/hysteria.git +WORKDIR ./hysteria/ +RUN git checkout ${HYSTERIA_VERSION} && go mod download -x +RUN env CGO_ENABLED=0 go build -v -o hysteria -trimpath -ldflags "-s -w \ + -X 'main.appVersion=$(git describe --tags)' \ + -X 'main.appCommit=$(git rev-parse HEAD)' \ + -X 'main.appDate=$(date "+%F %T")'" ./cmd +RUN mv ./hysteria /tmp/ COPY --from=upx /upx/ /usr/ RUN upx -9 /tmp/hysteria # Compile relaybaton FROM golang:1.14-alpine3.13 AS relaybaton ENV RELAYBATON_VERSION="v0.6.0" -RUN \ - apk add build-base git perl rsync && \ - wget https://github.com/iyouport-org/relaybaton/archive/refs/tags/${RELAYBATON_VERSION}.tar.gz -RUN \ - tar xf ${RELAYBATON_VERSION}.tar.gz && cd ./relaybaton-*/ && \ - make && mv ./bin/relaybaton /tmp/ +RUN apk add build-base git perl rsync +RUN wget https://github.com/iyouport-org/relaybaton/archive/refs/tags/${RELAYBATON_VERSION}.tar.gz +RUN tar xf ${RELAYBATON_VERSION}.tar.gz && cd ./relaybaton-*/ && go mod download -x +RUN cd ./relaybaton-*/ && make && mv ./bin/relaybaton /tmp/ COPY --from=upx /upx/ /usr/ RUN upx -9 /tmp/relaybaton # Compile pingtunnel FROM ${GO18} AS pingtunnel -RUN \ - apk add git && \ - git clone https://github.com/esrrhs/pingtunnel.git && cd ./pingtunnel/ && \ - env GO111MODULE=off go get github.com/esrrhs/pingtunnel/... && \ - env GO111MODULE=off CGO_ENABLED=0 go build -ldflags="-s -w" && \ - mv ./pingtunnel /tmp/ +RUN apk add git +RUN git clone https://github.com/esrrhs/pingtunnel.git +RUN env GO111MODULE=off go get -v github.com/esrrhs/pingtunnel/... +WORKDIR ./pingtunnel/ +RUN env GO111MODULE=off CGO_ENABLED=0 go build -v -ldflags="-s -w" +RUN mv ./pingtunnel /tmp/ COPY --from=upx /upx/ /usr/ RUN upx -9 /tmp/pingtunnel # Compile wireproxy FROM ${GO17} AS wireproxy ENV WIREPROXY_VERSION="v1.0.3" -RUN \ - wget https://github.com/octeep/wireproxy/archive/refs/tags/${WIREPROXY_VERSION}.tar.gz && \ - tar xf ${WIREPROXY_VERSION}.tar.gz && cd ./wireproxy-*/ && \ - env CGO_ENABLED=0 go build -trimpath -ldflags "-s -w" ./cmd/wireproxy && \ - mv ./wireproxy /tmp/ +RUN wget https://github.com/octeep/wireproxy/archive/refs/tags/${WIREPROXY_VERSION}.tar.gz +RUN tar xf ${WIREPROXY_VERSION}.tar.gz && mv ./wireproxy-*/ ./wireproxy/ +WORKDIR ./wireproxy/ +RUN go mod download -x +RUN env CGO_ENABLED=0 go build -v -trimpath -ldflags "-s -w" ./cmd/wireproxy +RUN mv ./wireproxy /tmp/ COPY --from=upx /upx/ /usr/ RUN upx -9 /tmp/wireproxy # Compile dnsproxy FROM ${GO18} AS dnsproxy ENV DNSPROXY_VERSION="v0.43.1" -RUN \ - wget https://github.com/AdguardTeam/dnsproxy/archive/refs/tags/${DNSPROXY_VERSION}.tar.gz && \ - tar xf ${DNSPROXY_VERSION}.tar.gz && cd ./dnsproxy-*/ && \ - env CGO_ENABLED=0 go build -trimpath -ldflags "-X main.VersionString=${DNSPROXY_VERSION} -s -w" && \ - mv ./dnsproxy /tmp/ +RUN wget https://github.com/AdguardTeam/dnsproxy/archive/refs/tags/${DNSPROXY_VERSION}.tar.gz +RUN tar xf ${DNSPROXY_VERSION}.tar.gz && mv ./dnsproxy-*/ ./dnsproxy/ +WORKDIR ./dnsproxy/ +RUN go mod download -x +RUN env CGO_ENABLED=0 go build -v -trimpath -ldflags "-X main.VersionString=${DNSPROXY_VERSION} -s -w" +RUN mv ./dnsproxy /tmp/ COPY --from=upx /upx/ /usr/ RUN upx -9 /tmp/dnsproxy # Compile mad FROM ${GO16} AS mad ENV MAD_VERSION="v20210401" -RUN \ - wget https://github.com/txthinking/mad/archive/refs/tags/${MAD_VERSION}.tar.gz && \ - tar xf ${MAD_VERSION}.tar.gz && cd ./mad-*/cli/mad/ && \ - CGO_ENABLED=0 go build -ldflags="-s -w" && \ - mv ./mad /tmp/ +RUN wget https://github.com/txthinking/mad/archive/refs/tags/${MAD_VERSION}.tar.gz +RUN tar xf ${MAD_VERSION}.tar.gz && mv ./mad-*/ ./mad/ +WORKDIR ./mad/ +RUN go mod download -x +RUN env CGO_ENABLED=0 go build -v -ldflags="-s -w" ./cli/mad +RUN mv ./mad /tmp/ COPY --from=upx /upx/ /usr/ RUN upx -9 /tmp/mad @@ -494,8 +484,8 @@ RUN upx -9 /tmp/mad FROM ${PYTHON} AS asset COPY --from=python-pkg /packages.tar.gz / RUN \ - PACKAGE_DIR="/asset/usr/local/lib/$(ls /usr/local/lib/ | grep ^python)" && \ - mkdir -p ${PACKAGE_DIR}/ && tar xf /packages.tar.gz -C ${PACKAGE_DIR}/ + PACKAGE_DIR="/asset/usr/local/lib/$(ls /usr/local/lib/ | grep ^python)" && \ + mkdir -p ${PACKAGE_DIR}/ && tar xf /packages.tar.gz -C ${PACKAGE_DIR}/ COPY --from=openssl /tmp/libcrypto.so* /asset/lib/ COPY --from=shadowsocks /release/ /asset/usr/bin/ COPY --from=plugin /release/ /asset/usr/bin/ @@ -517,10 +507,9 @@ COPY --from=mad /tmp/mad /asset/usr/bin/ # Release docker image FROM ${PYTHON} -RUN \ - apk add --no-cache boost-program_options c-ares \ - ca-certificates glib libev libsodium libstdc++ mbedtls pcre && \ - ln -s /usr/local/share/ProxyC/main.py /usr/bin/proxyc +RUN apk add --no-cache boost-program_options c-ares \ + ca-certificates glib libev libsodium libstdc++ mbedtls pcre && \ + ln -s /usr/local/share/ProxyC/main.py /usr/bin/proxyc COPY --from=asset /asset / COPY . /usr/local/share/ProxyC/ EXPOSE 7839 From 77a1d854ee90b2e584c6546fa7ed27a7716b5788 Mon Sep 17 00:00:00 2001 From: dnomd343 Date: Wed, 3 Aug 2022 15:15:33 +0800 Subject: [PATCH 3/4] build: less layer in docker --- Dockerfile | 502 +++++++++++++++++++++++++++-------------------------- 1 file changed, 252 insertions(+), 250 deletions(-) diff --git a/Dockerfile b/Dockerfile index 3cd9f38..a760e8b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,94 +1,94 @@ -ARG ALPINE="alpine:3.16" -ARG PYTHON="python:3.10-alpine3.16" -ARG RUST="rust:1.62-alpine3.16" -ARG GO18="golang:1.18-alpine3.16" -ARG GO17="golang:1.17-alpine3.16" -ARG GO16="golang:1.16-alpine3.15" - -# Compile upx (can't use gcc11 for now) -FROM alpine:3.15 AS upx +ARG ALPINE_IMG="alpine:3.16" +ARG RUST_IMG="rust:1.62-alpine3.16" +ARG GO14_IMG="golang:1.14-alpine3.13" +ARG GO16_IMG="golang:1.16-alpine3.15" +ARG GO17_IMG="golang:1.17-alpine3.16" +ARG GO18_IMG="golang:1.18-alpine3.16" +ARG PYTHON_IMG="python:3.10-alpine3.16" + +# Compile upx (under gcc10) +FROM ${ALPINE_IMG} AS upx ENV UPX_VERSION="3.96" -RUN 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 -RUN tar xf upx-${UPX_VERSION}-src.tar.xz +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/ -RUN make all && mv ./src/upx.out /usr/bin/upx -RUN mkdir -p /upx/lib/ && mkdir -p /upx/bin/ -RUN cp -d /usr/lib/libgcc_s.so* /usr/lib/libstdc++.so* /usr/lib/libucl.so* /upx/lib/ -RUN cp /usr/bin/upx /upx/bin/ +RUN make all && 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/ # Download build-base -FROM ${ALPINE} AS build-base +FROM ${ALPINE_IMG} AS build-base WORKDIR /apk/ -RUN apk add build-base | grep -oE 'Installing \S+' | cut -b 12- > build-base && chmod +x build-base -RUN cat ./build-base | xargs -n1 apk fetch -RUN sed -i 's/^/apk add \/apk\/&/g;s/$/&-*.apk/g;1i\#!/bin/sh' ./build-base +RUN apk add build-base | grep -oE 'Installing \S+' | cut -b 12- > ./build-base +RUN chmod +x ./build-base && cat ./build-base | xargs -n1 apk fetch && \ + sed -i 's/^/apk add \/apk\/&/g;s/$/&-*.apk/g;1i\#!/bin/sh' ./build-base # Compile gevent -FROM ${PYTHON} AS gevent +FROM ${PYTHON_IMG} AS gevent +WORKDIR /wheels/ +RUN apk add libffi-dev COPY --from=build-base /apk/ /apk/ -RUN /apk/build-base && apk add libffi-dev -RUN cd /tmp/ && pip wheel gevent +RUN /apk/build-base && pip wheel gevent # Compile numpy -FROM ${PYTHON} AS numpy +FROM ${PYTHON_IMG} AS numpy +WORKDIR /wheels/ COPY --from=build-base /apk/ /apk/ -RUN /apk/build-base -RUN cd /tmp/ && pip wheel numpy +RUN /apk/build-base && pip wheel numpy # Build python wheels -FROM ${PYTHON} AS wheels +FROM ${PYTHON_IMG} AS wheels +WORKDIR /wheels/ +RUN apk add linux-headers COPY --from=build-base /apk/ /apk/ -RUN /apk/build-base && apk add linux-headers -RUN cd /tmp/ && pip wheel colorlog flask IPy psutil pysocks requests salsa20 -COPY --from=gevent /tmp/*.whl /tmp/ -COPY --from=numpy /tmp/*.whl /tmp/ +RUN /apk/build-base && pip wheel colorlog flask IPy psutil pysocks requests salsa20 +COPY --from=gevent /wheels/*.whl /wheels/ +COPY --from=numpy /wheels/*.whl /wheels/ # Compile shadowsocks-rust -FROM ${RUST} AS ss-rust +FROM ${RUST_IMG} AS ss-rust +ENV SS_RUST="1.15.0-alpha.8" COPY --from=build-base /apk/ /apk/ -ENV SS_RUST="v1.15.0-alpha.8" -RUN /apk/build-base -RUN wget https://github.com/shadowsocks/shadowsocks-rust/archive/refs/tags/${SS_RUST}.tar.gz -RUN tar xf ${SS_RUST}.tar.gz && mv ./shadowsocks-rust-*/ ./shadowsocks-rust/ -WORKDIR ./shadowsocks-rust/ +RUN wget https://github.com/shadowsocks/shadowsocks-rust/archive/refs/tags/v${SS_RUST}.tar.gz && \ + tar xf v${SS_RUST}.tar.gz && /apk/build-base +WORKDIR ./shadowsocks-rust-${SS_RUST}/ RUN cargo update -RUN cargo build --release --bin sslocal --bin ssserver \ - --features "stream-cipher aead-cipher-extra aead-cipher-2022 aead-cipher-2022-extra" -RUN cd ./target/release/ && mv ./sslocal /tmp/ss-rust-local && mv ./ssserver /tmp/ss-rust-server -RUN strip /tmp/ss-rust-* +RUN cargo build --target-dir ./ --release --bin sslocal --bin ssserver \ + --features "stream-cipher aead-cipher-extra aead-cipher-2022 aead-cipher-2022-extra" && \ + mv ./release/sslocal /tmp/ss-rust-local && mv ./release/ssserver /tmp/ss-rust-server && \ + strip /tmp/ss-rust-* COPY --from=upx /upx/ /usr/ RUN upx -9 /tmp/ss-rust-* # Compile shadowsocks-libev -FROM ${ALPINE} AS ss-libev -COPY --from=build-base /apk/ /apk/ +FROM ${ALPINE_IMG} AS ss-libev ENV SS_LIBEV="3.3.5" -RUN /apk/build-base RUN apk add c-ares-dev libev-dev libsodium-dev linux-headers mbedtls-dev pcre-dev -RUN wget https://github.com/shadowsocks/shadowsocks-libev/releases/download/v${SS_LIBEV}/shadowsocks-libev-${SS_LIBEV}.tar.gz -RUN tar xf shadowsocks-libev-*.tar.gz && mv ./shadowsocks-libev-*/ ./shadowsocks-libev/ -WORKDIR ./shadowsocks-libev/ -RUN ./configure --disable-documentation && make -RUN mv ./src/ss-local /tmp/ss-libev-local && mv ./src/ss-server /tmp/ss-libev-server -RUN strip /tmp/ss-libev-* +COPY --from=build-base /apk/ /apk/ +RUN wget https://github.com/shadowsocks/shadowsocks-libev/releases/download/v${SS_LIBEV}/shadowsocks-libev-${SS_LIBEV}.tar.gz && \ + tar xf shadowsocks-libev-*.tar.gz && /apk/build-base +WORKDIR ./shadowsocks-libev-${SS_LIBEV}/ +RUN ./configure --disable-documentation && make && \ + mv ./src/ss-local /tmp/ss-libev-local && mv ./src/ss-server /tmp/ss-libev-server && \ + strip /tmp/ss-libev-* # Package shadowsocks-python (lastest version, legacy version, R version aka ssr) -FROM ${PYTHON} AS ss-python +FROM ${PYTHON_IMG} AS ss-python ENV SS_PYTHON_LEGACY="2.6.2" -RUN apk add git && mkdir /packages/ -RUN git clone https://github.com/dnomd343/shadowsocksr.git -RUN git clone https://github.com/shadowsocks/shadowsocks.git -RUN wget https://github.com/shadowsocks/shadowsocks/archive/refs/tags/${SS_PYTHON_LEGACY}.tar.gz -RUN tar xf ${SS_PYTHON_LEGACY}.tar.gz +RUN apk add git && mkdir /packages/ && \ + git clone https://github.com/dnomd343/shadowsocksr.git && \ + git clone https://github.com/shadowsocks/shadowsocks.git && \ + wget https://github.com/shadowsocks/shadowsocks/archive/refs/tags/${SS_PYTHON_LEGACY}.tar.gz && \ + tar xf ${SS_PYTHON_LEGACY}.tar.gz # shadowsocks-python (R version) WORKDIR ./shadowsocksr/ RUN sed -i 's/MutableMapping/abc.MutableMapping/' ./shadowsocks/lru_cache.py && \ sed -i 's/MutableMapping/abc.MutableMapping/' ./shadowsocks/ordereddict.py && \ sed -i "s/find_library(p)/'libcrypto.so.1.0.0'/g" ./shadowsocks/crypto/ctypes_openssl.py && \ sed -i "/for path in paths:/a\ if 'libcrypto.so' in path:" ./shadowsocks/crypto/util.py && \ - sed -i "/libcrypto.so/a\ path = 'libcrypto.so.1.0.0'" ./shadowsocks/crypto/util.py -RUN python3 setup.py build && cd ./build/lib/shadowsocks/ && \ + sed -i "/libcrypto.so/a\ path = 'libcrypto.so.1.0.0'" ./shadowsocks/crypto/util.py && \ + python3 setup.py build && cd ./build/lib/shadowsocks/ && \ chmod +x ./local.py ./server.py && mv ./local.py ./server.py ../ && \ mv ../../lib/ /packages/ssr-python/ # shadowsocks-python (latest version) @@ -97,204 +97,204 @@ RUN git checkout master RUN sed -i 's/if addr is/if addr ==/g' ./shadowsocks/common.py && \ sed -i 's/and ip is not/and ip !=/g' ./shadowsocks/common.py && \ sed -i 's/if len(block) is/if len(block) ==/g' ./shadowsocks/common.py && \ - sed -i 's/MutableMapping/abc.MutableMapping/' ./shadowsocks/lru_cache.py -RUN python3 setup.py build && cd ./build/lib/shadowsocks/ && \ + sed -i 's/MutableMapping/abc.MutableMapping/' ./shadowsocks/lru_cache.py && \ + python3 setup.py build && cd ./build/lib/shadowsocks/ && \ chmod +x ./local.py ./server.py && mv ./local.py ./server.py ../ && \ mv ../../lib/ /packages/ss-python/ # shadowsocks-python (legacy version) WORKDIR ../shadowsocks-${SS_PYTHON_LEGACY}/ RUN sed -i 's/MutableMapping/abc.MutableMapping/' ./shadowsocks/lru_cache.py && \ sed -i "s/find_library(p)/'libsodium.so.23'/g" ./shadowsocks/crypto/ctypes_libsodium.py && \ - sed -i "s/find_library(p)/'libcrypto.so.1.0.0'/g" ./shadowsocks/crypto/ctypes_openssl.py -RUN python3 setup.py build && cd ./build/lib/shadowsocks/ && \ + sed -i "s/find_library(p)/'libcrypto.so.1.0.0'/g" ./shadowsocks/crypto/ctypes_openssl.py && \ + python3 setup.py build && cd ./build/lib/shadowsocks/ && \ chmod +x ./local.py ./server.py && mv ./local.py ./server.py ../ && \ mv ../../lib/ /packages/ss-python-legacy/ # Compile shadowsocks-bootstrap -FROM ${ALPINE} AS ss-bootstrap +FROM ${ALPINE_IMG} AS ss-bootstrap +RUN apk add cmake git glib-dev COPY --from=build-base /apk/ /apk/ -RUN /apk/build-base && apk add cmake git glib-dev -RUN git clone https://github.com/dnomd343/shadowsocks-bootstrap.git +RUN git clone https://github.com/dnomd343/shadowsocks-bootstrap.git && /apk/build-base WORKDIR ./shadowsocks-bootstrap/build/ -RUN cmake -DCMAKE_BUILD_TYPE=Release .. && make -RUN mv ../bin/ss-bootstrap-* /tmp/ -RUN strip /tmp/ss-bootstrap-* +RUN cmake -DCMAKE_BUILD_TYPE=Release .. && make && \ + mv ../bin/ss-bootstrap-* /tmp/ && \ + strip /tmp/ss-bootstrap-* # Combine shadowsocks dependencies -FROM ${PYTHON} AS shadowsocks +FROM ${PYTHON_IMG} AS shadowsocks COPY --from=ss-rust /tmp/ss-rust-* /release/ COPY --from=ss-libev /tmp/ss-libev-* /release/ COPY --from=ss-bootstrap /tmp/ss-bootstrap-* /release/ -RUN \ - PYTHON_PACKAGE="/usr/local/lib/$(ls /usr/local/lib/ | grep ^python)/site-packages" && \ - ln -s ${PYTHON_PACKAGE}/ssr-python/local.py /release/ssr-local && \ - ln -s ${PYTHON_PACKAGE}/ssr-python/server.py /release/ssr-server && \ - ln -s ${PYTHON_PACKAGE}/ss-python/local.py /release/ss-python-local && \ - ln -s ${PYTHON_PACKAGE}/ss-python/server.py /release/ss-python-server && \ - ln -s ${PYTHON_PACKAGE}/ss-python-legacy/local.py /release/ss-python-legacy-local && \ - ln -s ${PYTHON_PACKAGE}/ss-python-legacy/server.py /release/ss-python-legacy-server +ARG PYTHON="3.10" +RUN ln -s /usr/local/lib/python${PYTHON}/site-packages/ssr-python/local.py /release/ssr-local && \ + ln -s /usr/local/lib/python${PYTHON}/site-packages/ssr-python/server.py /release/ssr-server && \ + ln -s /usr/local/lib/python${PYTHON}/site-packages/ss-python/local.py /release/ss-python-local && \ + ln -s /usr/local/lib/python${PYTHON}/site-packages/ss-python/server.py /release/ss-python-server && \ + ln -s /usr/local/lib/python${PYTHON}/site-packages/ss-python-legacy/local.py /release/ss-python-legacy-local && \ + ln -s /usr/local/lib/python${PYTHON}/site-packages/ss-python-legacy/server.py /release/ss-python-legacy-server # Pack python modules -FROM ${ALPINE} AS python-pkg -COPY --from=wheels /tmp/*.whl /site-packages/ -RUN cd /site-packages/ && ls | xargs -n1 unzip && rm ./*.whl +FROM ${ALPINE_IMG} AS python-pkg +COPY --from=wheels /wheels/*.whl /site-packages/ COPY --from=ss-python /packages/ /site-packages/ -RUN rm -rf $(find / -name '__pycache__') -RUN BZIP2=-9 tar czf /packages.tar.gz ./site-packages/ +WORKDIR /site-packages/ +RUN ls ./*.whl | xargs -n1 unzip && rm ./*.whl && \ + rm -rf $(find ./ -name '__pycache__') && \ + BZIP2=-9 tar czf /packages.tar.gz ./ # Compile openssl (old version, for shadowsocks method -> idea-cfb / seed-cfb) -FROM ${ALPINE} AS openssl -COPY --from=build-base /apk/ /apk/ +FROM ${ALPINE_IMG} AS openssl ENV OPENSSL_VER="1.0.2" ENV OPENSSL_SUB_VER="u" -RUN /apk/build-base && apk add perl -RUN wget https://www.openssl.org/source/old/${OPENSSL_VER}/openssl-${OPENSSL_VER}${OPENSSL_SUB_VER}.tar.gz -RUN tar xf openssl-*.tar.gz && mv ./openssl-*/ ./openssl/ -WORKDIR ./openssl/ -RUN ./config --shared --prefix=/usr && make -RUN mv ./libcrypto.so.1.0.0 /tmp/ -RUN strip /tmp/libcrypto.so.1.0.0 +RUN apk add perl +COPY --from=build-base /apk/ /apk/ +RUN wget https://www.openssl.org/source/old/${OPENSSL_VER}/openssl-${OPENSSL_VER}${OPENSSL_SUB_VER}.tar.gz && \ + tar xf openssl-*.tar.gz && /apk/build-base +WORKDIR ./openssl-${OPENSSL_VER}${OPENSSL_SUB_VER}/ +RUN ./config --shared --prefix=/usr && make && \ + mv ./libcrypto.so.1.0.0 /tmp/ && \ + strip /tmp/libcrypto.so.1.0.0 # Compile sip003 plugins (part1 -> gcc & cargo) -FROM ${RUST} AS plugin-1 +FROM ${RUST_IMG} AS plugin-1 +RUN apk add autoconf automake git libev-dev libtool linux-headers COPY --from=build-base /apk/ /apk/ -RUN apk add git && mkdir /plugins/ -RUN /apk/build-base && apk add autoconf automake libev-dev libtool linux-headers -RUN git clone https://github.com/shadowsocks/simple-obfs.git -RUN git clone https://github.com/shadowsocks/qtun.git +RUN git clone https://github.com/shadowsocks/qtun.git && \ + git clone https://github.com/shadowsocks/simple-obfs.git && \ + /apk/build-base && mkdir -p /plugins/ # Compile simple-obfs WORKDIR ./simple-obfs/ -RUN git submodule update --init --recursive -RUN ./autogen.sh && ./configure --disable-documentation && make -RUN cd ./src/ && mv ./obfs-local ./obfs-server /plugins/ +RUN git submodule update --init --recursive && \ + ./autogen.sh && ./configure --disable-documentation && make && \ + mv ./src//obfs-local ./src//obfs-server /plugins/ # Compile qtun WORKDIR ../qtun/ RUN cargo update -RUN cargo build --release -RUN cd ./target/release/ && mv ./qtun-client ./qtun-server /plugins/ -RUN strip /plugins/* +RUN cargo build --target-dir ./ --release && \ + mv ./release//qtun-client ./release//qtun-server /plugins/ && \ + strip /plugins/* COPY --from=upx /upx/ /usr/ RUN upx -9 /plugins/qtun-* # Compile sip003 plugins (part2 -> go1.16) -FROM ${GO16} AS plugin-2 +FROM ${GO16_IMG} AS plugin-2 ENV GOST_PLUGIN="v1.6.3" RUN apk add git && mkdir /plugins/ -RUN git clone https://github.com/Qv2ray/gun.git -RUN git clone https://github.com/dnomd343/kcptun.git -RUN git clone https://github.com/dnomd343/GoQuiet.git -RUN git clone https://github.com/ihciah/rabbit-tcp.git -RUN git clone https://github.com/dnomd343/rabbit-plugin.git -RUN git clone https://github.com/maskedeken/gost-plugin.git -RUN git clone https://github.com/shadowsocks/v2ray-plugin.git -RUN git clone https://github.com/IrineSistiana/mos-tls-tunnel.git +RUN git clone https://github.com/Qv2ray/gun.git && \ + git clone https://github.com/dnomd343/kcptun.git && \ + git clone https://github.com/dnomd343/GoQuiet.git && \ + git clone https://github.com/ihciah/rabbit-tcp.git && \ + git clone https://github.com/dnomd343/rabbit-plugin.git && \ + git clone https://github.com/maskedeken/gost-plugin.git && \ + git clone https://github.com/shadowsocks/v2ray-plugin.git && \ + git clone https://github.com/IrineSistiana/mos-tls-tunnel.git # Compile v2ray-plugin WORKDIR ./v2ray-plugin/ -RUN env CGO_ENABLED=0 go build -v -trimpath -ldflags "-X main.VERSION=$(git describe --tags) -s -w" -RUN mv ./v2ray-plugin /plugins/ +RUN env CGO_ENABLED=0 go build -v -trimpath -ldflags "-X main.VERSION=$(git describe --tags) -s -w" && \ + mv ./v2ray-plugin /plugins/ # Compile kcptun WORKDIR ../kcptun/ -RUN git checkout sip003 -RUN go mod init github.com/shadowsocks/kcptun && go mod tidy -RUN env CGO_ENABLED=0 go build -v -o kcptun-client -trimpath -ldflags "-X main.VERSION=$(git describe --tags) -s -w" ./client -RUN env CGO_ENABLED=0 go build -v -o kcptun-server -trimpath -ldflags "-X main.VERSION=$(git describe --tags) -s -w" ./server -RUN mv ./kcptun-client ./kcptun-server /plugins/ +RUN git checkout sip003 && \ + go mod init github.com/shadowsocks/kcptun && go mod tidy +RUN env CGO_ENABLED=0 go build -v -o kcptun-client -trimpath -ldflags "-X main.VERSION=$(git describe --tags) -s -w" ./client && \ + env CGO_ENABLED=0 go build -v -o kcptun-server -trimpath -ldflags "-X main.VERSION=$(git describe --tags) -s -w" ./server && \ + mv ./kcptun-client ./kcptun-server /plugins/ # Compile gost-plugin WORKDIR ../gost-plugin/ RUN git checkout ${GOST_PLUGIN} && go mod download -x -RUN env CGO_ENABLED=0 go build -v -trimpath -ldflags "-X main.VERSION=$(git describe --tags) -s -w" -RUN mv ./gost-plugin /plugins/ +RUN env CGO_ENABLED=0 go build -v -trimpath -ldflags "-X main.VERSION=$(git describe --tags) -s -w" && \ + mv ./gost-plugin /plugins/ # Compile GoQuiet WORKDIR ../GoQuiet/ RUN go mod init github.com/cbeuw/GoQuiet -RUN env CGO_ENABLED=0 go build -v -trimpath -ldflags "-X main.version=$(git describe --tags) -s -w" ./cmd/gq-client -RUN env CGO_ENABLED=0 go build -v -trimpath -ldflags "-X main.version=$(git describe --tags) -s -w" ./cmd/gq-server -RUN mv ./gq-client ./gq-server /plugins/ +RUN env CGO_ENABLED=0 go build -v -trimpath -ldflags "-X main.version=$(git describe --tags) -s -w" ./cmd/gq-client && \ + env CGO_ENABLED=0 go build -v -trimpath -ldflags "-X main.version=$(git describe --tags) -s -w" ./cmd/gq-server && \ + mv ./gq-client ./gq-server /plugins/ # Compile mos-tls-tunnel WORKDIR ../mos-tls-tunnel/ RUN go mod init github.com/IrineSistiana/mos-tls-tunnel && go mod vendor -RUN env CGO_ENABLED=0 go build -v -mod=vendor -trimpath -ldflags "-s -w" ./cmd/mtt-client -RUN env CGO_ENABLED=0 go build -v -mod=vendor -trimpath -ldflags "-s -w" ./cmd/mtt-server -RUN mv ./mtt-client ./mtt-server /plugins/ +RUN env CGO_ENABLED=0 go build -v -mod=vendor -trimpath -ldflags "-s -w" ./cmd/mtt-client && \ + env CGO_ENABLED=0 go build -v -mod=vendor -trimpath -ldflags "-s -w" ./cmd/mtt-server && \ + mv ./mtt-client ./mtt-server /plugins/ # Compile rabbit-plugin WORKDIR ../rabbit-plugin/ RUN go mod download -x -RUN env CGO_ENABLED=0 go build -v -trimpath -ldflags "-s -w" -RUN mv ./rabbit-plugin /plugins/ +RUN env CGO_ENABLED=0 go build -v -trimpath -ldflags "-s -w" && \ + mv ./rabbit-plugin /plugins/ # Compile rabbit-tcp WORKDIR ../rabbit-tcp/ RUN go mod download -x -RUN env CGO_ENABLED=0 go build -v -trimpath -ldflags "-X main.Version=$(git describe --tags) -s -w" ./cmd/rabbit.go -RUN mv ./rabbit /plugins/ +RUN env CGO_ENABLED=0 go build -v -trimpath -ldflags "-X main.Version=$(git describe --tags) -s -w" ./cmd/rabbit.go && \ + mv ./rabbit /plugins/ # Compile gun-plugin WORKDIR ../gun/ RUN go mod download -x -RUN env CGO_ENABLED=0 go build -v -o gun-plugin -trimpath -ldflags "-s -w" ./cmd/sip003/ -RUN mv ./gun-plugin /plugins/ +RUN env CGO_ENABLED=0 go build -v -o gun-plugin -trimpath -ldflags "-s -w" ./cmd/sip003/ && \ + mv ./gun-plugin /plugins/ COPY --from=upx /upx/ /usr/ RUN upx -9 /plugins/* # Compile sip003 plugins (part3 -> go1.17) -FROM ${GO17} AS plugin-3 +FROM ${GO17_IMG} AS plugin-3 ENV SIMPLE_TLS="v0.7.0" ENV CLOAK="v2.6.0" RUN apk add git && mkdir /plugins/ -RUN git clone https://github.com/cbeuw/Cloak.git -RUN git clone https://github.com/teddysun/xray-plugin.git -RUN git clone https://github.com/IrineSistiana/simple-tls.git +RUN git clone https://github.com/cbeuw/Cloak.git && \ + git clone https://github.com/teddysun/xray-plugin.git && \ + git clone https://github.com/IrineSistiana/simple-tls.git # Compile simple-tls WORKDIR ./simple-tls/ RUN git checkout ${SIMPLE_TLS} && go mod download -x -RUN sed -i 's/version = "unknown\/dev"/version = "'$(git describe --tags)'"/g' main.go -RUN env CGO_ENABLED=0 go build -v -trimpath -ldflags "-s -w" -RUN mv ./simple-tls /plugins/ +RUN sed -i 's/version = "unknown\/dev"/version = "'$(git describe --tags)'"/g' main.go && \ + env CGO_ENABLED=0 go build -v -trimpath -ldflags "-s -w" && \ + mv ./simple-tls /plugins/ # Compile xray-plugin WORKDIR ../xray-plugin/ RUN go mod download -x -RUN env CGO_ENABLED=0 go build -v -trimpath -ldflags "-X main.VERSION=$(git describe --tags) -s -w" -RUN mv ./xray-plugin /plugins/ +RUN env CGO_ENABLED=0 go build -v -trimpath -ldflags "-X main.VERSION=$(git describe --tags) -s -w" && \ + mv ./xray-plugin /plugins/ # Compile Cloak WORKDIR ../Cloak/ RUN git checkout ${CLOAK} && go mod download -x -RUN env CGO_ENABLED=0 go build -v -trimpath -ldflags "-X main.version=$(git describe --tags) -s -w" ./cmd/ck-client -RUN env CGO_ENABLED=0 go build -v -trimpath -ldflags "-X main.version=$(git describe --tags) -s -w" ./cmd/ck-server -RUN mv ./ck-client ./ck-server /plugins/ +RUN env CGO_ENABLED=0 go build -v -trimpath -ldflags "-X main.version=$(git describe --tags) -s -w" ./cmd/ck-client && \ + env CGO_ENABLED=0 go build -v -trimpath -ldflags "-X main.version=$(git describe --tags) -s -w" ./cmd/ck-server && \ + mv ./ck-client ./ck-server /plugins/ COPY --from=upx /upx/ /usr/ RUN upx -9 /plugins/* # Combine sip003 plugins -FROM ${ALPINE} AS plugin +FROM ${ALPINE_IMG} AS plugin COPY --from=plugin-1 /plugins/ /release/ COPY --from=plugin-2 /plugins/ /release/ COPY --from=plugin-3 /plugins/ /release/ # Compile v2fly-core -FROM ${GO18} AS v2ray -ENV V2RAY_VERSION="v4.45.2" -RUN wget https://github.com/v2fly/v2ray-core/archive/refs/tags/${V2RAY_VERSION}.tar.gz -RUN tar xf ${V2RAY_VERSION}.tar.gz && mv ./v2ray-core-*/ ./v2ray-core/ -WORKDIR ./v2ray-core/ +FROM ${GO18_IMG} AS v2ray +ENV V2RAY_VERSION="4.45.2" +RUN wget https://github.com/v2fly/v2ray-core/archive/refs/tags/v${V2RAY_VERSION}.tar.gz && \ + tar xf v${V2RAY_VERSION}.tar.gz +WORKDIR ./v2ray-core-${V2RAY_VERSION}/ RUN go mod download -x -RUN env CGO_ENABLED=0 go build -v -o v2ray -trimpath -ldflags "-s -w" ./main -RUN env CGO_ENABLED=0 go build -v -o v2ctl -trimpath -ldflags "-s -w" -tags confonly ./infra/control/main -RUN mv ./v2ctl ./v2ray /tmp/ +RUN env CGO_ENABLED=0 go build -v -o v2ray -trimpath -ldflags "-s -w" ./main && \ + env CGO_ENABLED=0 go build -v -o v2ctl -trimpath -ldflags "-s -w" -tags confonly ./infra/control/main && \ + mv ./v2ctl ./v2ray /tmp/ COPY --from=upx /upx/ /usr/ RUN upx -9 /tmp/v2* # Compile xray-core -FROM ${GO18} AS xray -ENV XRAY_VERSION="v1.5.9" -RUN wget https://github.com/XTLS/Xray-core/archive/refs/tags/${XRAY_VERSION}.tar.gz -RUN tar xf ${XRAY_VERSION}.tar.gz && mv ./Xray-core-*/ ./Xray-core/ -WORKDIR ./Xray-core/ +FROM ${GO18_IMG} AS xray +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 -RUN 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 # Compile trojan-go -FROM ${GO17} AS trojan-go +FROM ${GO17_IMG} AS trojan-go ENV TROJAN_GO_VERSION="v0.10.6" RUN apk add git RUN git clone https://github.com/p4gefau1t/trojan-go.git @@ -302,84 +302,84 @@ WORKDIR ./trojan-go/ RUN git checkout ${TROJAN_GO_VERSION} && go mod download -x RUN env CGO_ENABLED=0 go build -v -trimpath -ldflags " \ -X github.com/p4gefau1t/trojan-go/constant.Version=$(git describe --dirty) \ - -X github.com/p4gefau1t/trojan-go/constant.Commit=$(git rev-parse HEAD) -s -w" -tags "full" -RUN mv ./trojan-go /tmp/ + -X github.com/p4gefau1t/trojan-go/constant.Commit=$(git rev-parse HEAD) -s -w" -tags "full" && \ + mv ./trojan-go /tmp/ COPY --from=upx /upx/ /usr/ RUN upx -9 /tmp/trojan-go # Compile trojan -FROM ${ALPINE} AS trojan +FROM ${ALPINE_IMG} AS trojan +ENV TROJAN_VERSION="1.16.0" +RUN apk add boost-dev cmake openssl-dev COPY --from=build-base /apk/ /apk/ -ENV TROJAN_VERSION="v1.16.0" -RUN /apk/build-base && apk add boost-dev cmake openssl-dev -RUN wget https://github.com/trojan-gfw/trojan/archive/refs/tags/${TROJAN_VERSION}.tar.gz -RUN tar xf ${TROJAN_VERSION}.tar.gz && mv ./trojan-*/ ./trojan/ -WORKDIR ./trojan/build/ -RUN cmake .. -DENABLE_MYSQL=OFF -DSYSTEMD_SERVICE=OFF && make -RUN mv ./trojan /tmp/ -RUN strip /tmp/trojan +RUN wget https://github.com/trojan-gfw/trojan/archive/refs/tags/v${TROJAN_VERSION}.tar.gz && \ + tar xf v${TROJAN_VERSION}.tar.gz && /apk/build-base +WORKDIR ./trojan-${TROJAN_VERSION}/build/ +RUN cmake .. -DENABLE_MYSQL=OFF -DSYSTEMD_SERVICE=OFF && make && \ + mv ./trojan /tmp/ && \ + strip /tmp/trojan COPY --from=trojan-go /tmp/trojan-go /tmp/ # Compile gost-v3 -FROM ${GO18} AS gost-v3 +FROM ${GO18_IMG} AS gost-v3 RUN apk add git RUN git clone https://github.com/go-gost/gost.git WORKDIR ./gost/ RUN go mod download -x -RUN env CGO_ENABLED=0 go build -v -trimpath -ldflags "-s -w" ./cmd/gost -RUN mv ./gost /tmp/gost-v3 +RUN env CGO_ENABLED=0 go build -v -trimpath -ldflags "-s -w" ./cmd/gost && \ + mv ./gost /tmp/gost-v3 COPY --from=upx /upx/ /usr/ RUN upx -9 /tmp/gost-v3 # Compile gost -FROM ${GO17} AS gost -ENV GOST_VERSION="v2.11.2" -RUN wget https://github.com/ginuerzh/gost/archive/refs/tags/${GOST_VERSION}.tar.gz -RUN tar xf ${GOST_VERSION}.tar.gz && mv ./gost-*/ ./gost/ -WORKDIR ./gost/ +FROM ${GO17_IMG} AS gost +ENV GOST_VERSION="2.11.2" +RUN wget https://github.com/ginuerzh/gost/archive/refs/tags/v${GOST_VERSION}.tar.gz && \ + tar xf v${GOST_VERSION}.tar.gz +WORKDIR ./gost-${GOST_VERSION}/ RUN go mod download -x -RUN env CGO_ENABLED=0 go build -v -trimpath -ldflags "-s -w" ./cmd/gost -RUN mv ./gost /tmp/ -COPY --from=gost-v3 /tmp/gost-v3 /tmp/ +RUN env CGO_ENABLED=0 go build -v -trimpath -ldflags "-s -w" ./cmd/gost && \ + mv ./gost /tmp/ COPY --from=upx /upx/ /usr/ RUN upx -9 /tmp/gost +COPY --from=gost-v3 /tmp/gost-v3 /tmp/ # Compile brook -FROM ${GO16} AS brook -ENV BROOK_VERSION="v20220707" -RUN wget https://github.com/txthinking/brook/archive/refs/tags/${BROOK_VERSION}.tar.gz -RUN tar xf ${BROOK_VERSION}.tar.gz && mv ./brook-*/ ./brook/ -WORKDIR ./brook/ +FROM ${GO16_IMG} AS brook +ENV BROOK_VERSION="20220707" +RUN wget https://github.com/txthinking/brook/archive/refs/tags/v${BROOK_VERSION}.tar.gz && \ + tar xf v${BROOK_VERSION}.tar.gz +WORKDIR ./brook-${BROOK_VERSION}/ RUN go mod download -x -RUN env CGO_ENABLED=0 go build -v -trimpath -ldflags "-s -w" ./cli/brook -RUN mv ./brook /tmp/ +RUN env CGO_ENABLED=0 go build -v -trimpath -ldflags "-s -w" ./cli/brook && \ + mv ./brook /tmp/ COPY --from=upx /upx/ /usr/ RUN upx -9 /tmp/brook # Compile clash -FROM ${GO18} AS clash -ENV CLASH_VERSION="v1.11.4" -RUN wget https://github.com/Dreamacro/clash/archive/refs/tags/${CLASH_VERSION}.tar.gz -RUN tar xf ${CLASH_VERSION}.tar.gz && mv ./clash-*/ ./clash/ -WORKDIR ./clash/ +FROM ${GO18_IMG} AS clash +ENV CLASH_VERSION="1.11.4" +RUN wget https://github.com/Dreamacro/clash/archive/refs/tags/v${CLASH_VERSION}.tar.gz && \ + tar xf v${CLASH_VERSION}.tar.gz +WORKDIR ./clash-${CLASH_VERSION}/ RUN go mod download -x RUN env CGO_ENABLED=0 go build -v -trimpath -ldflags "-s -w \ -X 'github.com/Dreamacro/clash/constant.Version=${CLASH_VERSION}' \ - -X 'github.com/Dreamacro/clash/constant.BuildTime=$(date -u)'" -RUN mv ./clash /tmp/ + -X 'github.com/Dreamacro/clash/constant.BuildTime=$(date -u)'" && \ + mv ./clash /tmp/ COPY --from=upx /upx/ /usr/ RUN upx -9 /tmp/clash # Compile caddy -FROM ${GO18} AS caddy +FROM ${GO18_IMG} AS caddy RUN go install github.com/caddyserver/xcaddy/cmd/xcaddy@latest -RUN xcaddy build --with github.com/caddyserver/forwardproxy@caddy2=github.com/klzgrad/forwardproxy@naive -RUN mv ./caddy /tmp/ +RUN xcaddy build --with github.com/caddyserver/forwardproxy@caddy2=github.com/klzgrad/forwardproxy@naive && \ + mv ./caddy /tmp/ COPY --from=upx /upx/ /usr/ RUN upx -9 /tmp/caddy # Download naiveproxy -FROM ${ALPINE} AS naiveproxy +FROM ${ALPINE_IMG} AS naiveproxy ENV NAIVE_VERSION="v103.0.5060.53-3" RUN apk add curl libgcc jq RUN curl -sL https://api.github.com/repos/klzgrad/naiveproxy/releases/tags/${NAIVE_VERSION} \ @@ -387,29 +387,29 @@ RUN curl -sL https://api.github.com/repos/klzgrad/naiveproxy/releases/tags/${NAI | cut -b 2- | rev | cut -b 2- | rev | tac > list.dat RUN echo -e "while read FILE_NAME;do\nwget https://github.com/klzgrad/naiveproxy/releases/download/\${NAIVE_VERSION}/\${FILE_NAME}\n \ tar xf \${FILE_NAME} && ldd ./\$(echo \$FILE_NAME | rev | cut -b 8- | rev)/naive\n \ - [ \$? -eq 0 ] && cp ./\$(echo \$FILE_NAME | rev | cut -b 8- | rev)/naive /tmp/ && break\ndone < list.dat" > naiveproxy.sh -RUN sh naiveproxy.sh + [ \$? -eq 0 ] && cp ./\$(echo \$FILE_NAME | rev | cut -b 8- | rev)/naive /tmp/ && break\ndone < list.dat" > naiveproxy.sh && \ + sh naiveproxy.sh COPY --from=build-base /apk/ /apk/ RUN /apk/build-base && strip /tmp/naive COPY --from=caddy /tmp/caddy /tmp/ # Compile open-snell -FROM ${GO17} AS snell -ENV SNELL_VERSION="v3.0.1" -RUN wget https://github.com/icpz/open-snell/archive/refs/tags/${SNELL_VERSION}.tar.gz -RUN tar xf ${SNELL_VERSION}.tar.gz && mv ./open-snell-*/ ./open-snell/ -WORKDIR ./open-snell/ +FROM ${GO17_IMG} AS snell +ENV SNELL_VERSION="3.0.1" +RUN wget https://github.com/icpz/open-snell/archive/refs/tags/v${SNELL_VERSION}.tar.gz && \ + tar xf v${SNELL_VERSION}.tar.gz +WORKDIR ./open-snell-${SNELL_VERSION}/ RUN go mod download -x RUN env CGO_ENABLED=0 go build -v -trimpath -ldflags \ - "-s -w -X 'github.com/icpz/open-snell/constants.Version=${SNELL_VERSION}'" ./cmd/snell-client -RUN env CGO_ENABLED=0 go build -v -trimpath -ldflags \ - "-s -w -X 'github.com/icpz/open-snell/constants.Version=${SNELL_VERSION}'" ./cmd/snell-server -RUN mv ./snell-client ./snell-server /tmp/ + "-s -w -X 'github.com/icpz/open-snell/constants.Version=${SNELL_VERSION}'" ./cmd/snell-client && \ + env CGO_ENABLED=0 go build -v -trimpath -ldflags \ + "-s -w -X 'github.com/icpz/open-snell/constants.Version=${SNELL_VERSION}'" ./cmd/snell-server && \ + mv ./snell-client ./snell-server /tmp/ COPY --from=upx /upx/ /usr/ RUN upx -9 /tmp/snell-* # Compile hysteria -FROM ${GO17} AS hysteria +FROM ${GO17_IMG} AS hysteria ENV HYSTERIA_VERSION="v1.1.0" RUN apk add git RUN git clone https://github.com/HyNetwork/hysteria.git @@ -418,74 +418,76 @@ RUN git checkout ${HYSTERIA_VERSION} && go mod download -x RUN env CGO_ENABLED=0 go build -v -o hysteria -trimpath -ldflags "-s -w \ -X 'main.appVersion=$(git describe --tags)' \ -X 'main.appCommit=$(git rev-parse HEAD)' \ - -X 'main.appDate=$(date "+%F %T")'" ./cmd -RUN mv ./hysteria /tmp/ + -X 'main.appDate=$(date "+%F %T")'" ./cmd && \ + mv ./hysteria /tmp/ COPY --from=upx /upx/ /usr/ RUN upx -9 /tmp/hysteria # Compile relaybaton -FROM golang:1.14-alpine3.13 AS relaybaton -ENV RELAYBATON_VERSION="v0.6.0" +FROM ${GO14_IMG} AS relaybaton +ENV RELAYBATON_VERSION="0.6.0" RUN apk add build-base git perl rsync -RUN wget https://github.com/iyouport-org/relaybaton/archive/refs/tags/${RELAYBATON_VERSION}.tar.gz -RUN tar xf ${RELAYBATON_VERSION}.tar.gz && cd ./relaybaton-*/ && go mod download -x -RUN cd ./relaybaton-*/ && make && mv ./bin/relaybaton /tmp/ +RUN wget https://github.com/iyouport-org/relaybaton/archive/refs/tags/v${RELAYBATON_VERSION}.tar.gz && \ + tar xf v${RELAYBATON_VERSION}.tar.gz +WORKDIR ./relaybaton-${RELAYBATON_VERSION}/ +RUN go mod download -x +RUN make && mv ./bin/relaybaton /tmp/ COPY --from=upx /upx/ /usr/ RUN upx -9 /tmp/relaybaton # Compile pingtunnel -FROM ${GO18} AS pingtunnel +FROM ${GO18_IMG} AS pingtunnel RUN apk add git RUN git clone https://github.com/esrrhs/pingtunnel.git RUN env GO111MODULE=off go get -v github.com/esrrhs/pingtunnel/... WORKDIR ./pingtunnel/ -RUN env GO111MODULE=off CGO_ENABLED=0 go build -v -ldflags="-s -w" -RUN mv ./pingtunnel /tmp/ +RUN env GO111MODULE=off CGO_ENABLED=0 go build -v -ldflags="-s -w" && \ + mv ./pingtunnel /tmp/ COPY --from=upx /upx/ /usr/ RUN upx -9 /tmp/pingtunnel # Compile wireproxy -FROM ${GO17} AS wireproxy -ENV WIREPROXY_VERSION="v1.0.3" -RUN wget https://github.com/octeep/wireproxy/archive/refs/tags/${WIREPROXY_VERSION}.tar.gz -RUN tar xf ${WIREPROXY_VERSION}.tar.gz && mv ./wireproxy-*/ ./wireproxy/ -WORKDIR ./wireproxy/ +FROM ${GO17_IMG} AS wireproxy +ENV WIREPROXY_VERSION="1.0.3" +RUN wget https://github.com/octeep/wireproxy/archive/refs/tags/v${WIREPROXY_VERSION}.tar.gz && \ + tar xf v${WIREPROXY_VERSION}.tar.gz +WORKDIR ./wireproxy-${WIREPROXY_VERSION}/ RUN go mod download -x -RUN env CGO_ENABLED=0 go build -v -trimpath -ldflags "-s -w" ./cmd/wireproxy -RUN mv ./wireproxy /tmp/ +RUN env CGO_ENABLED=0 go build -v -trimpath -ldflags "-s -w" ./cmd/wireproxy && \ + mv ./wireproxy /tmp/ COPY --from=upx /upx/ /usr/ RUN upx -9 /tmp/wireproxy # Compile dnsproxy -FROM ${GO18} AS dnsproxy -ENV DNSPROXY_VERSION="v0.43.1" -RUN wget https://github.com/AdguardTeam/dnsproxy/archive/refs/tags/${DNSPROXY_VERSION}.tar.gz -RUN tar xf ${DNSPROXY_VERSION}.tar.gz && mv ./dnsproxy-*/ ./dnsproxy/ -WORKDIR ./dnsproxy/ +FROM ${GO18_IMG} AS dnsproxy +ENV DNSPROXY_VERSION="0.43.1" +RUN wget https://github.com/AdguardTeam/dnsproxy/archive/refs/tags/v${DNSPROXY_VERSION}.tar.gz && \ + tar xf v${DNSPROXY_VERSION}.tar.gz +WORKDIR ./dnsproxy-${DNSPROXY_VERSION}/ RUN go mod download -x -RUN env CGO_ENABLED=0 go build -v -trimpath -ldflags "-X main.VersionString=${DNSPROXY_VERSION} -s -w" -RUN mv ./dnsproxy /tmp/ +RUN env CGO_ENABLED=0 go build -v -trimpath -ldflags "-X main.VersionString=${DNSPROXY_VERSION} -s -w" && \ + mv ./dnsproxy /tmp/ COPY --from=upx /upx/ /usr/ RUN upx -9 /tmp/dnsproxy # Compile mad -FROM ${GO16} AS mad -ENV MAD_VERSION="v20210401" -RUN wget https://github.com/txthinking/mad/archive/refs/tags/${MAD_VERSION}.tar.gz -RUN tar xf ${MAD_VERSION}.tar.gz && mv ./mad-*/ ./mad/ -WORKDIR ./mad/ +FROM ${GO16_IMG} AS mad +ENV MAD_VERSION="20210401" +RUN wget https://github.com/txthinking/mad/archive/refs/tags/v${MAD_VERSION}.tar.gz && \ + tar xf v${MAD_VERSION}.tar.gz +WORKDIR ./mad-${MAD_VERSION}/ RUN go mod download -x -RUN env CGO_ENABLED=0 go build -v -ldflags="-s -w" ./cli/mad -RUN mv ./mad /tmp/ +RUN env CGO_ENABLED=0 go build -v -ldflags="-s -w" ./cli/mad && \ + mv ./mad /tmp/ COPY --from=upx /upx/ /usr/ RUN upx -9 /tmp/mad # Combine all release -FROM ${PYTHON} AS asset +FROM ${PYTHON_IMG} AS asset COPY --from=python-pkg /packages.tar.gz / -RUN \ - PACKAGE_DIR="/asset/usr/local/lib/$(ls /usr/local/lib/ | grep ^python)" && \ - mkdir -p ${PACKAGE_DIR}/ && tar xf /packages.tar.gz -C ${PACKAGE_DIR}/ +ARG PYTHON="3.10" +RUN mkdir -p /asset/usr/local/lib/python${PYTHON}/site-packages/ && \ + tar xf /packages.tar.gz -C /asset/usr/local/lib/python${PYTHON}/site-packages/ COPY --from=openssl /tmp/libcrypto.so* /asset/lib/ COPY --from=shadowsocks /release/ /asset/usr/bin/ COPY --from=plugin /release/ /asset/usr/bin/ @@ -504,13 +506,13 @@ COPY --from=pingtunnel /tmp/pingtunnel /asset/usr/bin/ COPY --from=wireproxy /tmp/wireproxy /asset/usr/bin/ COPY --from=dnsproxy /tmp/dnsproxy /asset/usr/bin/ COPY --from=mad /tmp/mad /asset/usr/bin/ +COPY . /asset/usr/local/share/ProxyC/ # Release docker image -FROM ${PYTHON} +FROM ${PYTHON_IMG} RUN apk add --no-cache boost-program_options c-ares \ ca-certificates glib libev libsodium libstdc++ mbedtls pcre && \ ln -s /usr/local/share/ProxyC/main.py /usr/bin/proxyc COPY --from=asset /asset / -COPY . /usr/local/share/ProxyC/ EXPOSE 7839 CMD ["proxyc"] From 30f8bccc8e43370f69830f5f76082db01c59f419 Mon Sep 17 00:00:00 2001 From: dnomd343 Date: Wed, 3 Aug 2022 16:21:29 +0800 Subject: [PATCH 4/4] build: optimize the installation of build-base --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index a760e8b..cf82d47 100644 --- a/Dockerfile +++ b/Dockerfile @@ -22,7 +22,7 @@ FROM ${ALPINE_IMG} AS build-base WORKDIR /apk/ RUN apk add build-base | grep -oE 'Installing \S+' | cut -b 12- > ./build-base RUN chmod +x ./build-base && cat ./build-base | xargs -n1 apk fetch && \ - sed -i 's/^/apk add \/apk\/&/g;s/$/&-*.apk/g;1i\#!/bin/sh' ./build-base + sed -i 's/^/ \/apk\/&/g;s/$/&-*.apk/g;1i\apk add' ./build-base && sed -i ':a;N;s/\n//g;ba' ./build-base # Compile gevent FROM ${PYTHON_IMG} AS gevent