File size: 1,778 Bytes
0fa2f2e
 
 
ea5b12c
0fa2f2e
 
 
 
 
 
 
ea5b12c
0fa2f2e
 
 
b70d391
0fa2f2e
b70d391
0fa2f2e
a2c9b98
 
 
 
 
 
8fbddbd
 
 
ea5b12c
0fa2f2e
ea5b12c
 
2d12cc3
ea5b12c
0fa2f2e
 
a2c9b98
0fa2f2e
ea5b12c
a2c9b98
 
0fa2f2e
ea5b12c
a2c9b98
0fa2f2e
ea5b12c
a2c9b98
b865c24
0fa2f2e
a2c9b98
0fa2f2e
ea5b12c
 
0fa2f2e
ea5b12c
a2c9b98
ea5b12c
 
 
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
# --- Stage 1: Build Go Application ---
FROM golang:1.21-alpine AS build

# Alpine 需要这些依赖来编译
RUN apk add --no-cache build-base

WORKDIR /app

# 复制 Go 源代码
COPY *.go ./

# 编译 Go 应用
RUN CGO_ENABLED=0 GOOS=linux go build -ldflags="-s -w" -o /main main.go

# --- Stage 2: Final Runtime Image ---
FROM alpine:latest

RUN apk add --no-cache python3 py3-pip curl tar gzip bash jq ca-certificates

RUN adduser -D -u 1000 user
RUN mkdir -p /home/user/data && chown -R user:user /home/user/data

ENV HOME=/home/user \
    PATH=/home/user/.local/bin:$PATH 
WORKDIR $HOME/app
ENV VIRTUAL_ENV=$HOME/venv
RUN python3 -m venv $VIRTUAL_ENV
ENV PATH="$VIRTUAL_ENV/bin:$PATH"
# 安装系统依赖

# 安装 Python 依赖 (!!! 确认你的脚本用的是 webdav3 !!!)
# 如果你用了我上次给的脚本,应该是 webdav3
RUN pip install --no-cache-dir requests webdavclient3 
# 如果你确定用的是 webdavclient3,那就改成 webdavclient3,但要确保脚本也对应修改

# 从构建阶段复制编译好的 Go 应用
COPY --from=build /main $HOME/app/main

# 复制后台同步脚本和入口点脚本
COPY --chown=user sync_data.sh $HOME/app/sync_data.sh
COPY --chown=user entrypoint.sh $HOME/app/entrypoint.sh

# 创建用于存储文件的目录
RUN mkdir $HOME/app/files

# 赋予脚本执行权限 (Go 应用也需要)
RUN chmod +x $HOME/app/main $HOME/app/sync_data.sh $HOME/app/entrypoint.sh
RUN chown -R user:user /home/user
# 切换到非 root 用户
USER user

# 端口暴露 (Hugging Face 会处理)
EXPOSE 3456 

# 设置入口点脚本
ENTRYPOINT ["/home/user/app/entrypoint.sh"]

# CMD ["/app/main"] # 如果 entrypoint.sh 负责启动 sync_data.sh,可以让 CMD 启动 Go 应用
# 或者 entrypoint.sh 负责启动所有进程