clash-linux commited on
Commit
1013a2b
·
verified ·
1 Parent(s): 4787487

Upload 11 files

Browse files
Files changed (2) hide show
  1. Dockerfile +20 -9
  2. app/clash_manager.py +4 -16
Dockerfile CHANGED
@@ -6,12 +6,14 @@ WORKDIR /app
6
 
7
  # 安装系统依赖
8
  # 添加 py3-yaml 直接通过 apk 安装 PyYAML
 
9
  RUN apk add --no-cache \
10
  curl \
11
  ca-certificates \
12
  tzdata \
13
  tar \
14
  gzip \
 
15
  python3-dev \
16
  musl-dev \
17
  libffi-dev \
@@ -38,17 +40,26 @@ RUN echo "Downloading Clash Meta..." && \
38
  echo "Cleaning up Clash Meta download..." && \
39
  rm /tmp/clash-meta.gz
40
 
41
- # 下载并完整解压subconverter
42
- RUN echo "Downloading subconverter..." && \
43
- curl -L -f -o /tmp/subconverter.tar.gz "https://github.com/tindy2013/subconverter/releases/download/v0.7.2/subconverter_linux64.tar.gz" && \
44
- echo "Extracting subconverter archive..." && \
 
 
 
45
  tar -xzf /tmp/subconverter.tar.gz -C ./subconverter --strip-components=1 && \
 
 
 
 
 
 
46
  echo "Setting subconverter permissions..." && \
47
  chmod +x ./subconverter/subconverter && \
48
- echo "Verifying subconverter exists..." && \
49
- test -f ./subconverter/subconverter && \
50
- echo "Cleaning up subconverter download..." && \
51
- rm /tmp/subconverter.tar.gz
52
 
53
  # 复制Python依赖列表
54
  COPY requirements.txt ./
@@ -72,7 +83,7 @@ RUN echo "Installing Python dependencies..." && \
72
  pip install --no-cache-dir -r requirements.txt
73
 
74
  # 可选:删除构建依赖以减小镜像体积
75
- # RUN apk del python3-dev musl-dev libffi-dev yaml-dev
76
 
77
  # 设置环境变量
78
  ENV PYTHONDONTWRITEBYTECODE=1 \
 
6
 
7
  # 安装系统依赖
8
  # 添加 py3-yaml 直接通过 apk 安装 PyYAML
9
+ # 添加 unzip 用于解压源码包
10
  RUN apk add --no-cache \
11
  curl \
12
  ca-certificates \
13
  tzdata \
14
  tar \
15
  gzip \
16
+ unzip \
17
  python3-dev \
18
  musl-dev \
19
  libffi-dev \
 
40
  echo "Cleaning up Clash Meta download..." && \
41
  rm /tmp/clash-meta.gz
42
 
43
+ # 下载并安装subconverter及其配置文件
44
+ ARG SUBVER=v0.7.2
45
+ RUN echo "Downloading subconverter binary..." && \
46
+ curl -L -f -o /tmp/subconverter.tar.gz "https://github.com/tindy2013/subconverter/releases/download/${SUBVER}/subconverter_linux64.tar.gz" && \
47
+ echo "Downloading subconverter source code (for config files)..." && \
48
+ curl -L -f -o /tmp/subconverter_src.zip "https://github.com/tindy2013/subconverter/archive/refs/tags/${SUBVER}.zip" && \
49
+ echo "Extracting subconverter binary..." && \
50
  tar -xzf /tmp/subconverter.tar.gz -C ./subconverter --strip-components=1 && \
51
+ echo "Extracting subconverter config files..." && \
52
+ unzip -j /tmp/subconverter_src.zip "subconverter-${SUBVER}/pref.yml" -d ./subconverter/ && \
53
+ unzip -oq /tmp/subconverter_src.zip "subconverter-${SUBVER}/rules/*" -d ./subconverter/ && \
54
+ # 重命名解压出来的规则目录(如果需要)
55
+ # mv ./subconverter/subconverter-${SUBVER}/rules ./subconverter/rules && \
56
+ # rmdir ./subconverter/subconverter-${SUBVER} || true && \
57
  echo "Setting subconverter permissions..." && \
58
  chmod +x ./subconverter/subconverter && \
59
+ echo "Verifying subconverter binary and config exist..." && \
60
+ test -f ./subconverter/subconverter && test -f ./subconverter/pref.yml && test -d ./subconverter/rules && \
61
+ echo "Cleaning up subconverter downloads..." && \
62
+ rm /tmp/subconverter.tar.gz /tmp/subconverter_src.zip
63
 
64
  # 复制Python依赖列表
65
  COPY requirements.txt ./
 
83
  pip install --no-cache-dir -r requirements.txt
84
 
85
  # 可选:删除构建依赖以减小镜像体积
86
+ # RUN apk del python3-dev musl-dev libffi-dev yaml-dev unzip
87
 
88
  # 设置环境变量
89
  ENV PYTHONDONTWRITEBYTECODE=1 \
app/clash_manager.py CHANGED
@@ -49,27 +49,15 @@ class ClashManager:
49
  if not os.path.exists(self.config_path):
50
  raise FileNotFoundError(f"Clash配置文件未找到: {self.config_path}")
51
 
52
- # 设置Clash命令行参数 (兼容Clash Meta)
53
  cmd = [
54
  self.clash_path,
55
  "-f", self.config_path,
56
- "-d", os.path.dirname(self.config_path)
 
 
57
  ]
58
 
59
- # 为Clash Meta添加额外参数
60
- if "meta" in self.clash_path.lower():
61
- # Clash Meta特有参数
62
- cmd.extend([
63
- "--controller-addr", f"127.0.0.1:{self.api_port}",
64
- # 如果需要可以添加更多Clash Meta特有参数
65
- ])
66
- else:
67
- # 原始Clash参数
68
- cmd.extend([
69
- "-ext-ctl", f"127.0.0.1:{self.api_port}",
70
- "-ext-ui", "" # 禁用外部UI
71
- ])
72
-
73
  # 启动Clash进程
74
  logger.info(f"正在启动Clash Core: {' '.join(cmd)}")
75
  self.clash_process = subprocess.Popen(
 
49
  if not os.path.exists(self.config_path):
50
  raise FileNotFoundError(f"Clash配置文件未找到: {self.config_path}")
51
 
52
+ # 设置Clash命令行参数 (使用 -ext-ctl)
53
  cmd = [
54
  self.clash_path,
55
  "-f", self.config_path,
56
+ "-d", os.path.dirname(self.config_path),
57
+ "-ext-ctl", f"127.0.0.1:{self.api_port}"
58
+ # 不再需要 "-ext-ui", ""
59
  ]
60
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
61
  # 启动Clash进程
62
  logger.info(f"正在启动Clash Core: {' '.join(cmd)}")
63
  self.clash_process = subprocess.Popen(