File size: 4,462 Bytes
0e697fc
 
 
 
 
 
 
f4f961b
05442c1
0e697fc
 
 
 
 
 
 
 
e902fb4
17a46ca
05442c1
f4f961b
 
03d4200
 
3c9b458
03d4200
0e697fc
 
 
 
ac8610d
 
5b7de09
 
 
0e697fc
1095651
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0e697fc
6f17509
 
 
 
4787487
5a8991e
0e697fc
03d4200
 
 
 
6f17509
 
 
 
0e697fc
 
 
 
 
 
 
f4f961b
 
 
e902fb4
f4f961b
17a46ca
5a8991e
de637f1
0e697fc
f4f961b
0e697fc
1095651
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c21bbbc
0e697fc
 
 
 
de637f1
 
 
 
ac8610d
0e697fc
3e9ce57
0e697fc
 
 
 
149033c
0e697fc
ac8610d
1095651
ac8610d
de637f1
99187f2
de637f1
0e697fc
149033c
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# 使用官方Python 3.9 Alpine作为基础镜像(轻量级)
FROM python:3.9-alpine

# 设置工作目录
WORKDIR /app

# 安装系统依赖
# 添加 yaml-dev 提供编译PyYAML所需的libyaml
# 添加 unzip 用于解压 Yacd
RUN apk add --no-cache \
    curl \
    ca-certificates \
    tzdata \
    tar \
    gzip \
    python3-dev \
    musl-dev \
    libffi-dev \
    yaml-dev \
    unzip \
    # 不再需要 py3-yaml
    # py3-yaml \
    # 添加调试工具
    file \
    libc-utils \
    strace

# 设置时区为亚洲/上海
ENV TZ=Asia/Shanghai

# 创建必要的目录并设置权限(构建阶段就设置好权限)
RUN mkdir -p ./clash_core ./subconverter ./data && \
    chmod -R 777 ./data && \
    chmod -R 777 ./clash_core && \
    chmod -R 777 ./subconverter

# 下载并安装Clash Meta,保留原始文件名
RUN echo "Downloading Clash Meta..." && \
    curl -L -f -o /tmp/clash-meta.gz "https://github.com/MetaCubeX/Clash.Meta/releases/download/v1.16.0/clash.meta-linux-amd64-v1.16.0.gz" && \
    echo "Extracting Clash Meta..." && \
    gunzip -c /tmp/clash-meta.gz > ./clash_core/clash.meta-linux-amd64 && \
    echo "Setting Clash Meta permissions..." && \
    chmod +x ./clash_core/clash.meta-linux-amd64 && \
    # 确保Linux可执行属性已设置
    ls -la ./clash_core/clash.meta-linux-amd64 && \
    # 显示文件类型
    file ./clash_core/clash.meta-linux-amd64 && \
    echo "Verifying Clash Meta exists..." && \
    test -f ./clash_core/clash.meta-linux-amd64 && \
    echo "Cleaning up Clash Meta download..." && \
    rm /tmp/clash-meta.gz

# 下载并完整解压subconverter
RUN echo "Downloading subconverter..." && \
    curl -L -f -o /tmp/subconverter.tar.gz "https://github.com/tindy2013/subconverter/releases/download/v0.7.2/subconverter_linux64.tar.gz" && \
    echo "Extracting subconverter archive..." && \
    tar -xzf /tmp/subconverter.tar.gz -C ./subconverter --strip-components=1 && \
    echo "Setting subconverter permissions..." && \
    chmod +x ./subconverter/subconverter && \
    # 确保Linux可执行属性已设置
    ls -la ./subconverter/subconverter && \
    # 显示文件类型
    file ./subconverter/subconverter && \
    echo "Verifying subconverter exists..." && \
    test -f ./subconverter/subconverter && \
    echo "Cleaning up subconverter download..." && \
    rm /tmp/subconverter.tar.gz

# 复制Python依赖列表
COPY requirements.txt ./

# 升级 pip
RUN pip install --upgrade pip

# 安装Cython(用于编译PyYAML)
RUN echo "Installing Cython for PyYAML build..." && \
    pip install --no-cache-dir Cython

# 安装Python依赖(包括PyYAML,现在应该能成功编译了)
RUN echo "Installing Python dependencies..." && \
    pip install --no-cache-dir -r requirements.txt

# 可选:删除构建依赖以减小镜像体积
RUN apk del python3-dev musl-dev libffi-dev yaml-dev

# 下载并准备 Yacd UI 文件 (从 Yacd-meta 的 gh-pages 分支)
RUN echo "Downloading Yacd-meta UI (gh-pages branch)..." && \
    YACD_DIR=/app/app/static/yacd && \
    mkdir -p ${YACD_DIR} && \
    # 下载 gh-pages 分支的 zip 压缩包
    curl -L -f -o /tmp/yacd-gh-pages.zip "https://github.com/MetaCubeX/Yacd-meta/archive/refs/heads/gh-pages.zip" && \
    echo "Extracting Yacd-meta UI (gh-pages)..." && \
    # 解压到临时目录
    unzip -q /tmp/yacd-gh-pages.zip -d /tmp && \
    # 将解压后的 gh-pages 目录下的 *所有内容* 移动到目标位置
    # 注意:解压后的文件夹名通常是 {repo_name}-{branch_name},即 Yacd-meta-gh-pages
    mv /tmp/Yacd-meta-gh-pages/* ${YACD_DIR}/ && \
    echo "Cleaning up Yacd-meta download..." && \
    rm /tmp/yacd-gh-pages.zip && \
    rm -rf /tmp/Yacd-meta-gh-pages

# 设置环境变量
ENV PYTHONDONTWRITEBYTECODE=1 \
    PYTHONUNBUFFERED=1 \
    FLASK_APP=app.main \
    FLASK_ENV=production \
    FLASK_PORT=7860 \
    CLASH_PROXY_PORT=7890 \
    CLASH_API_PORT=9090 \
    PORT=7860

# 复制应用代码和静态文件
COPY app/ ./app/

# 复制启动脚本并赋予执行权限
COPY entrypoint.sh ./
RUN chmod +x ./entrypoint.sh

# 给脚本和二进制文件执行权限 (重复的chmod可能不需要,但在构建阶段设置更安全)
RUN chmod +x ./clash_core/clash.meta-linux-amd64 || true
RUN chmod +x ./subconverter/subconverter || true

# 暴露端口
EXPOSE $FLASK_PORT $CLASH_PROXY_PORT $CLASH_API_PORT

# 使用entrypoint脚本启动应用
ENTRYPOINT ["/app/entrypoint.sh"]