diff --git a/.github/workflows/docker.yaml b/.github/workflows/docker.yaml new file mode 100644 index 00000000..ad930bd0 --- /dev/null +++ b/.github/workflows/docker.yaml @@ -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 }} \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 6e67d5d4..498fbd44 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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" ] \ No newline at end of file diff --git a/adapter/inbound/socket.go b/adapter/inbound/socket.go index 5aa90034..28608be9 100644 --- a/adapter/inbound/socket.go +++ b/adapter/inbound/socket.go @@ -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 + } + } } } diff --git a/check_amd64.sh b/check_amd64.sh new file mode 100644 index 00000000..068296d3 --- /dev/null +++ b/check_amd64.sh @@ -0,0 +1,28 @@ +#!/bin/sh +flags=$(grep '^flags\b'