diff --git a/Dockerfile b/Dockerfile index ec2db44..4e6469a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,15 +1,23 @@ -FROM alpine as asset -COPY ./asset.sh / -RUN apk add curl wget jq && \ - sh /asset.sh +FROM alpine:3.15 as asset +COPY . /tmp/TProxy +ENV XRAY_VERSION="v1.5.3" +RUN \ +apk add curl go git && \ +mkdir -p /tmp/asset/usr/bin/ && mkdir -p /tmp/asset/run/radvd/ && \ +git clone https://github.com/XTLS/Xray-core.git /tmp/Xray-core && \ +cd /tmp/Xray-core/ && git checkout $XRAY_VERSION && \ +env CGO_ENABLED=0 go build -o xray -trimpath -ldflags "-s -w" ./main && \ +mv ./xray /tmp/asset/usr/bin/ && \ +mkdir -p /tmp/asset/etc/xray/asset/ && cd /tmp/asset/etc/xray/asset/ && \ +GEO_VERSION=$(curl -sL "https://api.github.com/repos/Loyalsoldier/v2ray-rules-dat/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/') && \ +wget "https://github.com/Loyalsoldier/v2ray-rules-dat/releases/download/$GEO_VERSION/geoip.dat" && \ +wget "https://github.com/Loyalsoldier/v2ray-rules-dat/releases/download/$GEO_VERSION/geosite.dat" && \ +cd /tmp/asset/etc/xray/ && tar czf asset.tar.gz asset/ && rm -rf asset/ && \ +mv /tmp/TProxy/load.sh /tmp/asset/etc/xray/ && chmod +x /tmp/asset/etc/xray/load.sh && \ +mv /tmp/TProxy/tproxy.sh /tmp/asset/tproxy && chmod +x /tmp/asset/tproxy -FROM alpine -COPY ["./load.sh", "./tproxy.sh", "/etc/xray/"] -COPY --from=asset /tmp/asset/ /etc/xray/asset/ -COPY --from=asset /tmp/xray/xray /usr/bin/ +FROM alpine:3.15 +COPY --from=asset /tmp/asset/ / ENV XRAY_LOCATION_ASSET=/etc/xray/asset -RUN apk add --no-cache iptables ip6tables radvd && \ - mkdir -p /etc/xray/config && \ - mkdir -p /run/radvd/ && \ - mv /etc/xray/tproxy.sh /tproxy +RUN apk add --no-cache iptables ip6tables radvd ENTRYPOINT ["sh","tproxy"] diff --git a/load.sh b/load.sh index cbe33c1..4e7b2bf 100755 --- a/load.sh +++ b/load.sh @@ -5,7 +5,11 @@ CONFIG_DIR="$XRAY_DIR/expose/config" NETWORK_DIR="$XRAY_DIR/expose/network" load_xray_log() { - log_level=$(cat $LOG_DIR/level) + if [ -f "$LOG_DIR/level" ]; then + log_level=$(cat $LOG_DIR/level) + else + log_level="warning" + fi legal=false [ "$log_level" == "debug" ] && legal=true [ "$log_level" == "info" ] && legal=true @@ -317,6 +321,7 @@ mkdir -p $LOG_DIR mkdir -p $ASSET_DIR mkdir -p $CONFIG_DIR mkdir -p $NETWORK_DIR +mkdir -p $XRAY_DIR/config load_xray_log load_xray_inbounds @@ -325,6 +330,7 @@ load_xray_inbounds [ ! -s "$CONFIG_DIR/dns.json" ] && load_xray_dns cp $CONFIG_DIR/*.json $XRAY_DIR/config/ +tar -C $XRAY_DIR -xf $XRAY_DIR/asset.tar.gz [ ! -s "$ASSET_DIR/geoip.dat" ] && cp $XRAY_DIR/asset/geoip.dat $ASSET_DIR/ [ ! -s "$ASSET_DIR/geosite.dat" ] && cp $XRAY_DIR/asset/geosite.dat $ASSET_DIR/ [ ! -s "$ASSET_DIR/update.sh" ] && load_update_script diff --git a/tproxy.sh b/tproxy.sh index 1706600..8333a7e 100755 --- a/tproxy.sh +++ b/tproxy.sh @@ -57,14 +57,13 @@ ipv6_tproxy() { # IPv6 tproxy settings ip6tables -t mangle -A PREROUTING -j XRAY6 } - trap exit_func 2 15 # SIGINT and SIGTERM signal echo "[TProxy] Server start." echo "[TProxy] Init network environment." +sh /etc/xray/load.sh ipv4_tproxy ipv6_tproxy -sh /etc/xray/load.sh echo "[TProxy] Init complete." echo "[TProxy] Running custom script."