Merge remote-tracking branch 'origin/Alpha' into Alpha

This commit is contained in:
adlyq 2022-04-28 17:47:29 +08:00
commit 8217db82ce
6 changed files with 130 additions and 16 deletions

56
.github/workflows/docker.yaml vendored Normal file
View File

@ -0,0 +1,56 @@
name: Docker
on: [push]
env:
REGISTRY: docker.io
IMAGE_NAME: '{{ env.DOCKERHUB_ACCOUNT }}/{{ env.DOCKERHUB_REPO }}'
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Setup Docker buildx
uses: docker/setup-buildx-action@v1
# Extract metadata (tags, labels) for Docker
# https://github.com/docker/metadata-action
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v3
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
- name: Log into registry ${{ env.REGISTRY }}
if: github.event_name != 'pull_request'
uses: docker/login-action@v1
with:
registry: ${{ env.REGISTRY }}
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
# Build and push Docker image with Buildx (don't push on PR)
# https://github.com/docker/build-push-action
- name: Build and push Docker image
id: build-and-push
uses: docker/build-push-action@v2
with:
context: .
push: ${{ github.event_name != 'pull_request' }}
platforms: |
linux/386
linux/amd64
linux/arm64/v8
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

View File

@ -1,18 +1,41 @@
FROM golang:alpine as builder
RUN apk add --no-cache make git && \
wget -O /Country.mmdb https://github.com/Dreamacro/maxmind-geoip/releases/latest/download/Country.mmdb
WORKDIR /clash-src
COPY --from=tonistiigi/xx:golang / /
COPY . /clash-src
RUN go mod download && \
make docker && \
mv ./bin/clash-docker /clash
ARG TARGETOS
ARG TARGETARCH
RUN apk add --no-cache make git && \
mkdir /clash-config && \
wget -O /clash-config/Country.mmdb https://raw.githubusercontent.com/Loyalsoldier/geoip/release/Country.mmdb && \
wget -O /clash-config/geosite.dat https://github.com/Loyalsoldier/v2ray-rules-dat/releases/latest/download/geosite.dat && \
wget -O /clash-config/geoip.dat https://github.com/Loyalsoldier/v2ray-rules-dat/releases/latest/download/geoip.dat
WORKDIR /clash-src
COPY . /clash-src
RUN go mod download
RUN /bin/ash -c 'set -ex && \
if [ "$TARGETARCH" == "amd64" ]; then \
GOOS=$TARGETOS GOARCH=$TARGETARCH GOAMD64=v1 make docker && \
mv ./bin/Clash.Meta-docker ./bin/clash-amd64v1 && \
GOOS=$TARGETOS GOARCH=$TARGETARCH GOAMD64=v2 make docker && \
mv ./bin/Clash.Meta-docker ./bin/clash-amd64v2 && \
GOOS=$TARGETOS GOARCH=$TARGETARCH GOAMD64=v3 make docker && \
mv ./bin/Clash.Meta-docker ./bin/clash-amd64v3 && \
ln -s clash-amd64v3 ./bin/clash-amd64v4 && \
mv check_amd64.sh ./bin/ && \
printf "#!/bin/sh\\nsh ./check_amd64.sh\\nexec ./clash-amd64v\$? \$@" > ./bin/clash && \
chmod +x ./bin/check_amd64.sh ./bin/clash; \
else \
GOOS=$TARGETOS GOARCH=$TARGETARCH make docker && \
mv ./bin/Clash.Meta-docker ./bin/clash; \
fi'
FROM alpine:latest
LABEL org.opencontainers.image.source="https://github.com/Dreamacro/clash"
LABEL org.opencontainers.image.source="https://github.com/MetaCubeX/Clash.Meta"
RUN apk add --no-cache ca-certificates tzdata
COPY --from=builder /Country.mmdb /root/.config/clash/
COPY --from=builder /clash /
ENTRYPOINT ["/clash"]
VOLUME ["/root/.config/clash/"]
EXPOSE 7890/tcp
COPY --from=builder /clash-config/ /root/.config/clash/
COPY --from=builder /clash-src/bin/ /
ENTRYPOINT [ "/clash" ]

View File

@ -2,6 +2,7 @@ package inbound
import (
"net"
"net/netip"
C "github.com/Dreamacro/clash/constant"
"github.com/Dreamacro/clash/context"
@ -36,7 +37,13 @@ func NewInner(conn net.Conn, dst string, host string) *context.ConnContext {
if h, port, err := net.SplitHostPort(dst); err == nil {
metadata.DstPort = port
if host == "" {
metadata.Host = h
if ip, err := netip.ParseAddr(h); err == nil {
metadata.DstIP = ip
metadata.AddrType = C.AtypIPv4
if ip.Is6() {
metadata.AddrType = C.AtypIPv6
}
}
}
}

28
check_amd64.sh Normal file
View File

@ -0,0 +1,28 @@
#!/bin/sh
flags=$(grep '^flags\b' </proc/cpuinfo | head -n 1)
flags=" ${flags#*:} "
has_flags () {
for flag; do
case "$flags" in
*" $flag "*) :;;
*) return 1;;
esac
done
}
determine_level () {
level=0
has_flags lm cmov cx8 fpu fxsr mmx syscall sse2 || return 0
level=1
has_flags cx16 lahf_lm popcnt sse4_1 sse4_2 ssse3 || return 0
level=2
has_flags avx avx2 bmi1 bmi2 f16c fma abm movbe xsave || return 0
level=3
has_flags avx512f avx512bw avx512cd avx512dq avx512vl || return 0
level=4
}
determine_level
echo "Your CPU supports amd64-v$level"
return $level

View File

@ -94,8 +94,8 @@ func getRuleProviders(w http.ResponseWriter, r *http.Request) {
}
func updateRuleProvider(w http.ResponseWriter, r *http.Request) {
provider := r.Context().Value(CtxKeyProvider).(*provider.RuleProvider)
if err := (*provider).Update(); err != nil {
provider := r.Context().Value(CtxKeyProvider).(provider.RuleProvider)
if err := provider.Update(); err != nil {
render.Status(r, http.StatusServiceUnavailable)
render.JSON(w, r, newError(err.Error()))
}

View File

@ -45,7 +45,7 @@ func Start(device io.ReadWriter, gateway, portal, broadcast netip.Addr) (*TCP, *
n, err := device.Read(buf)
if err != nil {
log.Warnln("system error:%s", err.Error())
continue
return
}
raw := buf[:n]