Skip to content

Commit

Permalink
update clash (#14)
Browse files Browse the repository at this point in the history
* update clash
* fix clash config ui
* update entrypoint
* update clash README
  • Loading branch information
haobibo authored Jun 22, 2024
1 parent c4ff968 commit 4aac095
Show file tree
Hide file tree
Showing 7 changed files with 93 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
13 changes: 0 additions & 13 deletions docker_app_clash/Dockerfile

This file was deleted.

11 changes: 11 additions & 0 deletions docker_app_clash/README.md
Original file line number Diff line number Diff line change
@@ -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
```
27 changes: 27 additions & 0 deletions docker_app_clash/clash.Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
5 changes: 1 addition & 4 deletions docker_app_clash/demo/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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"
Original file line number Diff line number Diff line change
@@ -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
Expand Down
45 changes: 45 additions & 0 deletions docker_app_clash/work/clash/script-setup-clash.sh
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit 4aac095

Please sign in to comment.