chore: add docker workflow
This commit is contained in:
parent
2b8ac19566
commit
701bb3de3c
3 changed files with 122 additions and 12 deletions
59
.github/workflows/docker.yaml
vendored
Normal file
59
.github/workflows/docker.yaml
vendored
Normal file
|
@ -0,0 +1,59 @@
|
||||||
|
name: Docker
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
tags: [ 'v*.*.*' ]
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
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 }}
|
47
Dockerfile
47
Dockerfile
|
@ -1,18 +1,41 @@
|
||||||
FROM golang:alpine as builder
|
FROM golang:alpine as builder
|
||||||
|
|
||||||
RUN apk add --no-cache make git && \
|
ARG TARGETOS
|
||||||
wget -O /Country.mmdb https://github.com/Dreamacro/maxmind-geoip/releases/latest/download/Country.mmdb
|
ARG TARGETARCH
|
||||||
WORKDIR /clash-src
|
|
||||||
COPY --from=tonistiigi/xx:golang / /
|
|
||||||
COPY . /clash-src
|
|
||||||
RUN go mod download && \
|
|
||||||
make docker && \
|
|
||||||
mv ./bin/clash-docker /clash
|
|
||||||
|
|
||||||
|
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
|
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
|
RUN apk add --no-cache ca-certificates tzdata
|
||||||
COPY --from=builder /Country.mmdb /root/.config/clash/
|
|
||||||
COPY --from=builder /clash /
|
VOLUME ["/root/.config/clash/"]
|
||||||
ENTRYPOINT ["/clash"]
|
EXPOSE 7890/tcp
|
||||||
|
|
||||||
|
COPY --from=builder /clash-config/ /root/.config/clash/
|
||||||
|
COPY --from=builder /clash-src/bin/ /
|
||||||
|
ENTRYPOINT [ "/clash" ]
|
28
check_amd64.sh
Normal file
28
check_amd64.sh
Normal 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
|
Loading…
Reference in a new issue