Browse Source

update: build xray-core locally

master
dnomd343 2 years ago
parent
commit
b43979fb5f
  1. 32
      Dockerfile
  2. 8
      load.sh
  3. 3
      tproxy.sh

32
Dockerfile

@ -1,15 +1,23 @@
FROM alpine as asset FROM alpine:3.15 as asset
COPY ./asset.sh / COPY . /tmp/TProxy
RUN apk add curl wget jq && \ ENV XRAY_VERSION="v1.5.3"
sh /asset.sh 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 FROM alpine:3.15
COPY ["./load.sh", "./tproxy.sh", "/etc/xray/"] COPY --from=asset /tmp/asset/ /
COPY --from=asset /tmp/asset/ /etc/xray/asset/
COPY --from=asset /tmp/xray/xray /usr/bin/
ENV XRAY_LOCATION_ASSET=/etc/xray/asset ENV XRAY_LOCATION_ASSET=/etc/xray/asset
RUN apk add --no-cache iptables ip6tables radvd && \ RUN apk add --no-cache iptables ip6tables radvd
mkdir -p /etc/xray/config && \
mkdir -p /run/radvd/ && \
mv /etc/xray/tproxy.sh /tproxy
ENTRYPOINT ["sh","tproxy"] ENTRYPOINT ["sh","tproxy"]

8
load.sh

@ -5,7 +5,11 @@ CONFIG_DIR="$XRAY_DIR/expose/config"
NETWORK_DIR="$XRAY_DIR/expose/network" NETWORK_DIR="$XRAY_DIR/expose/network"
load_xray_log() { 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 legal=false
[ "$log_level" == "debug" ] && legal=true [ "$log_level" == "debug" ] && legal=true
[ "$log_level" == "info" ] && legal=true [ "$log_level" == "info" ] && legal=true
@ -317,6 +321,7 @@ mkdir -p $LOG_DIR
mkdir -p $ASSET_DIR mkdir -p $ASSET_DIR
mkdir -p $CONFIG_DIR mkdir -p $CONFIG_DIR
mkdir -p $NETWORK_DIR mkdir -p $NETWORK_DIR
mkdir -p $XRAY_DIR/config
load_xray_log load_xray_log
load_xray_inbounds load_xray_inbounds
@ -325,6 +330,7 @@ load_xray_inbounds
[ ! -s "$CONFIG_DIR/dns.json" ] && load_xray_dns [ ! -s "$CONFIG_DIR/dns.json" ] && load_xray_dns
cp $CONFIG_DIR/*.json $XRAY_DIR/config/ 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/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/geosite.dat" ] && cp $XRAY_DIR/asset/geosite.dat $ASSET_DIR/
[ ! -s "$ASSET_DIR/update.sh" ] && load_update_script [ ! -s "$ASSET_DIR/update.sh" ] && load_update_script

3
tproxy.sh

@ -57,14 +57,13 @@ ipv6_tproxy() { # IPv6 tproxy settings
ip6tables -t mangle -A PREROUTING -j XRAY6 ip6tables -t mangle -A PREROUTING -j XRAY6
} }
trap exit_func 2 15 # SIGINT and SIGTERM signal trap exit_func 2 15 # SIGINT and SIGTERM signal
echo "[TProxy] Server start." echo "[TProxy] Server start."
echo "[TProxy] Init network environment." echo "[TProxy] Init network environment."
sh /etc/xray/load.sh
ipv4_tproxy ipv4_tproxy
ipv6_tproxy ipv6_tproxy
sh /etc/xray/load.sh
echo "[TProxy] Init complete." echo "[TProxy] Init complete."
echo "[TProxy] Running custom script." echo "[TProxy] Running custom script."

Loading…
Cancel
Save