diff --git a/.github/workflows/build-docker.yml b/.github/workflows/build-docker.yml index dd4fa4f..2b9947e 100644 --- a/.github/workflows/build-docker.yml +++ b/.github/workflows/build-docker.yml @@ -33,7 +33,7 @@ jobs: steps: - uses: actions/checkout@v4 - run: | - source ./tool.sh && build_image app-clash latest docker_app_clash/Dockerfile && push_image + source ./tool.sh && build_image app-clash latest docker_app_clash/clash.Dockerfile && push_image ## Casdoor docker_casdoor: diff --git a/docker_app_clash/Dockerfile b/docker_app_clash/Dockerfile deleted file mode 100644 index bc789d9..0000000 --- a/docker_app_clash/Dockerfile +++ /dev/null @@ -1,13 +0,0 @@ -FROM alpine AS builder - -# https://github.com/haishanh/yacd -WORKDIR /tmp -RUN set -eux \ - && wget https://github.com/haishanh/yacd/archive/gh-pages.zip \ - && unzip ./*.zip && rm -rf *.zip \ - && mv ./* ./ui - -# https://github.com/Dreamacro/clash -FROM dreamacro/clash-premium -COPY --from=builder /tmp/* /root/.config/clash/ui -COPY demo/config.yaml /root/.config/clash/ diff --git a/docker_app_clash/README.md b/docker_app_clash/README.md index e69de29..082f2c0 100644 --- a/docker_app_clash/README.md +++ b/docker_app_clash/README.md @@ -0,0 +1,11 @@ +# Clash / Mihomo + +- mihomo core: https://github.com/MetaCubeX/mihomo/tree/Alpha +- webui matacubexd: https://github.com/MetaCubeX/metacubexd +- webui verge / client: https://clash-verge-rev.github.io + +## Usage + +```shell +docker run -d --name=app-clash -p 57890:57890 -p 59090:59090 qpod/app-clash +``` diff --git a/docker_app_clash/clash.Dockerfile b/docker_app_clash/clash.Dockerfile new file mode 100644 index 0000000..0f89f67 --- /dev/null +++ b/docker_app_clash/clash.Dockerfile @@ -0,0 +1,27 @@ +# Distributed under the terms of the Modified BSD License. + +ARG BASE_NAMESPACE +ARG BASE_IMG_BUILD="go-stack" +ARG BASE_IMG="atom" + + +# Stage 1: build code, both backend and frontend +FROM ${BASE_NAMESPACE:+$BASE_NAMESPACE/}${BASE_IMG_BUILD} as builder + +COPY work/clash /opt/utils/ + +RUN set -eux && source /opt/utils/script-setup-clash.sh \ + && setup_clash && setup_clash_metacubexd && setup_clash_verge \ + && mv /opt/utils/config.yaml /opt/clash/config + + +# Stage 2: runtime image, copy files from builder image +FROM ${BASE_NAMESPACE:+$BASE_NAMESPACE/}${BASE_IMG} + +COPY --from=builder /opt/clash /opt/clash +WORKDIR /opt/clash +RUN set -eux \ + && echo 'export PATH=${PATH}:/opt/clash' >> /etc/profile.d/path-clash.sh \ + && ln -sf /opt/clash/clash /usr/local/bin/ + +CMD ["/opt/clash/clash", "-d", "config"] diff --git a/docker_app_clash/demo/docker-compose.yml b/docker_app_clash/demo/docker-compose.yml index c990c87..886a1fa 100644 --- a/docker_app_clash/demo/docker-compose.yml +++ b/docker_app_clash/demo/docker-compose.yml @@ -1,6 +1,3 @@ -# ref1: https://github.com/Dreamacro/clash/wiki/Run-clash-in-docker -# ref2: https://github.com/Dreamacro/clash/wiki/configuration - services: svc-clash: image: qpod/app-clash @@ -10,6 +7,6 @@ services: - ./config.yaml:/root/.config/clash/config.yaml:ro ports: - "57890:57890" - - "59090:9090" + - "59090:59090" # When your system is Linux, you can use `network_mode: "host"` directly. # network_mode: "host" diff --git a/docker_app_clash/demo/config.yaml b/docker_app_clash/work/clash/config.yaml similarity index 65% rename from docker_app_clash/demo/config.yaml rename to docker_app_clash/work/clash/config.yaml index fbb37d8..f887e96 100644 --- a/docker_app_clash/demo/config.yaml +++ b/docker_app_clash/work/clash/config.yaml @@ -1,11 +1,16 @@ -# https://github.com/Dreamacro/clash/wiki/configuration#all-configuration-options +# ref: https://github.com/MetaCubeX/mihomo/blob/Alpha/docs/config.yaml + mixed-port: 57890 -external-controller: :59090 + +external-controller: 0.0.0.0:59090 +external-ui: /opt/clash/ui-xd +external-ui-name: xd +external-ui-url: "https://github.com/MetaCubeX/metacubexd/archive/refs/heads/gh-pages.zip" + allow-lan: true bind-address: '*' log-level: debug mode: Rule -external-ui: ui rules: - DOMAIN-SUFFIX,local,DIRECT diff --git a/docker_app_clash/work/clash/script-setup-clash.sh b/docker_app_clash/work/clash/script-setup-clash.sh new file mode 100644 index 0000000..8cc0750 --- /dev/null +++ b/docker_app_clash/work/clash/script-setup-clash.sh @@ -0,0 +1,45 @@ +source /opt/utils/script-utils.sh + +setup_clash() { + # Install the latest release: https://github.com/MetaCubeX/mihomo/tree/Alpha + VER_CLASH=$(curl -sL https://github.com/MetaCubeX/mihomo/releases.atom | grep 'releases/tag/v' | head -1 | grep -Po '\d[\d.]+' ) \ + && URL_CLASH="https://github.com/MetaCubeX/mihomo/archive/refs/tags/v$VER_CLASH.tar.gz" \ + && echo "Downloading clash version ${VER_CLASH} from: ${URL_CLASH}" \ + && install_tar_gz $URL_CLASH \ + && mv /opt/mihomo-* /tmp/clash && cd /tmp/clash \ + && export BUILDTIME=$(date -u) \ + && export GOARCH=amd64 && export GOOS=linux && export GOAMD64=v3 && export CGO_ENABLED=0 \ + && opt='-X \"github.com/metacubex/mihomo/constant.Version=${VER_CLASH}\" -X \"github.com/metacubex/mihomo/constant.BuildTime=${BUILDTIME}\" -w -s -buildid=1' \ + && opt=$(eval echo $opt) \ + && cmd="go build -tags with_gvisor -trimpath -o /opt/clash/clash -ldflags '${opt}'" \ + && eval $cmd && /opt/clash/clash -v \ + && echo "@ Version of Clash $(clash -v)" + + mkdir -pv /opt/clash/config \ + && wget -O /opt/clash/config/geoip.metadb https://fastly.jsdelivr.net/gh/MetaCubeX/meta-rules-dat@release/geoip.metadb \ + && wget -O /opt/clash/config/geosite.dat https://fastly.jsdelivr.net/gh/MetaCubeX/meta-rules-dat@release/geosite.dat \ + && wget -O /opt/clash/config/geoip.dat https://fastly.jsdelivr.net/gh/MetaCubeX/meta-rules-dat@release/geoip.dat +} + +setup_clash_metacubexd() { + # Install the latest release: https://github.com/MetaCubeX/metacubexd + VER_XD=$(curl -sL https://github.com/MetaCubeX/metacubexd/releases.atom | grep 'releases/tag/v' | head -1 | grep -Po '\d[\d.]+' ) \ + && URL_XD="https://github.com/MetaCubeX/metacubexd/archive/refs/tags/v$VER_XD.tar.gz" \ + && echo "Downloading XD version ${VER_XD} from: ${URL_XD}" \ + && install_tar_gz $URL_XD \ + && mv /opt/metacubexd-* /tmp/xd && cd /tmp/xd \ + && npx pnpm i && npx pnpm run build && ls -alh \ + && mv /tmp/xd/dist /opt/clash/ui-xd +} + +setup_clash_verge() { + # Install the latest release: https://clash-verge-rev.github.io/index.html + VER_VERGE=$(curl -sL https://github.com/clash-verge-rev/clash-verge-rev/releases.atom | grep 'releases/tag/v' | head -1 | grep -Po '\d[\d.]+' ) \ + && URL_VERGE="https://github.com/clash-verge-rev/clash-verge-rev/archive/refs/tags/v$VER_VERGE.tar.gz" \ + && echo "Downloading clash-verge version ${VER_VERGE} from: ${URL_VERGE}" \ + && install_tar_gz $URL_VERGE \ + && mv /opt/clash-verge-* /tmp/verge && cd /tmp/verge \ + && jq '.homepage = "./ui"' package.json > tmp.$$.json && mv tmp.$$.json package.json \ + && npx pnpm i && npx pnpm run web:build && ls -alh \ + && mv /tmp/verge/dist /opt/clash/ui-verge +}