USGCC commited on
Commit
46da029
·
verified ·
1 Parent(s): 59e8b67

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +66 -67
Dockerfile CHANGED
@@ -1,70 +1,69 @@
1
- FROM node:19.1.0-alpine3.16
2
-
3
- # 设置应用目录
4
- ARG APP_HOME=/home/node/app
5
-
6
- # 安装系统依赖
7
- RUN apk add --no-cache gcompat tini git python3 py3-pip bash dos2unix findutils tar curl
8
-
9
- # 安装HuggingFace Hub
10
- RUN pip3 install --no-cache-dir huggingface_hub
11
-
12
- # 确保正确处理内核信号
13
- ENTRYPOINT [ "tini", "--" ]
14
-
15
- # 创建应用目录
16
- WORKDIR ${APP_HOME}
17
-
18
- # 设置NODE_ENV为production
19
- ENV NODE_ENV=production
20
-
21
- # 设置登录凭证环境变量
22
- ENV USERNAME="admin"
23
- ENV PASSWORD="password"
24
-
25
- # 克隆官方SillyTavern仓库(最新版本)
26
- RUN git clone https://github.com/HGFpp/SillyTavern.git .
27
-
28
- # 安装依赖
29
- RUN echo "*** 安装npm包 ***" && \
30
- npm install && npm cache clean --force
31
-
32
- # 添加启动脚本和数据同步脚本
33
- COPY launch.sh sync_data.sh ./
34
- RUN chmod +x launch.sh sync_data.sh && \
35
- dos2unix launch.sh sync_data.sh
36
-
37
- # 安装生产依赖
38
- RUN echo "*** 安装生产npm包 ***" && \
39
- npm i --no-audit --no-fund --loglevel=error --no-progress --omit=dev && npm cache clean --force
40
-
41
- # 创建配置目录
42
- RUN mkdir -p "config" || true && \
43
- rm -f "config.yaml" || true && \
44
- ln -s "./config/config.yaml" "config.yaml" || true
45
-
46
- # 清理不必要的文件
47
- RUN echo "*** 清理 ***" && \
48
- mv "./docker/docker-entrypoint.sh" "./" && \
49
- rm -rf "./docker" && \
50
- echo "*** 使docker-entrypoint.sh可执行 ***" && \
51
- chmod +x "./docker-entrypoint.sh" && \
52
- echo "*** 转换行尾为Unix格式 ***" && \
53
- dos2unix "./docker-entrypoint.sh" || true
54
-
55
- # 修改入口脚本,添加自定义启动脚本
56
- RUN sed -i 's/# Start the server/.\/launch.sh/g' docker-entrypoint.sh
57
-
58
- # 创建临时备份目录和数据目录
59
- RUN mkdir -p /tmp/sillytavern_backup && \
60
- mkdir -p ${APP_HOME}/data
61
-
62
- # 设置权限
63
- RUN chmod -R 777 ${APP_HOME} && \
64
- chmod -R 777 /tmp/sillytavern_backup
65
 
66
  # 暴露端口
67
- EXPOSE 8000
 
 
 
 
 
 
68
 
69
- # 启动命令
70
- CMD [ "./docker-entrypoint.sh" ]
 
1
+ # 使用 git 克隆代码
2
+ FROM alpine/git as clone
3
+ WORKDIR /app
4
+ RUN git clone https://github.com/deanxv/chutesAI2api.git
5
+
6
+ # 使用最新的 golang 镜像
7
+ FROM golang:latest
8
+
9
+ # 设置工作目录
10
+ WORKDIR /app/chutesai2api
11
+
12
+ # 从上一阶段复制代码
13
+ COPY --from=clone /app/chutesAI2api .
14
+
15
+ # 创建 index.html
16
+ RUN echo '<!DOCTYPE html>' > index.html && \
17
+ echo '<html>' >> index.html && \
18
+ echo '<head>' >> index.html && \
19
+ echo ' <title>API 运行状态</title>' >> index.html && \
20
+ echo ' <style>' >> index.html && \
21
+ echo ' body { font-family: Arial, sans-serif; display: flex; justify-content: center; align-items: center; height: 100vh; margin: 0; background-color: #f0f2f5; }' >> index.html && \
22
+ echo ' .container { text-align: center; padding: 20px; background-color: white; border-radius: 8px; box-shadow: 0 2px 4px rgba(0,0,0,0.1); }' >> index.html && \
23
+ echo ' .rocket { font-size: 50px; margin-bottom: 10px; }' >> index.html && \
24
+ echo ' .status { font-size: 24px; color: #1a73e8; }' >> index.html && \
25
+ echo ' </style>' >> index.html && \
26
+ echo '</head>' >> index.html && \
27
+ echo '<body>' >> index.html && \
28
+ echo ' <div class="container">' >> index.html && \
29
+ echo ' <div class="rocket">🚀</div>' >> index.html && \
30
+ echo ' <div class="status">API 成功运行</div>' >> index.html && \
31
+ echo ' </div>' >> index.html && \
32
+ echo '</body>' >> index.html && \
33
+ echo '</html>' >> index.html
34
+
35
+ # 修复 go.mod 文件
36
+ RUN sed -i 's/go 1.23.0/go 1.22/' go.mod && \
37
+ sed -i '/toolchain/d' go.mod
38
+
39
+ # 修改 main.go 添加首页路由
40
+ RUN echo 'package main' > main.go && \
41
+ echo 'import (' >> main.go && \
42
+ echo ' "net/http"' >> main.go && \
43
+ echo ')' >> main.go && \
44
+ echo 'func main() {' >> main.go && \
45
+ echo ' http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {' >> main.go && \
46
+ echo ' http.ServeFile(w, r, "index.html")' >> main.go && \
47
+ echo ' })' >> main.go && \
48
+ echo ' http.ListenAndServe(":7860", nil)' >> main.go && \
49
+ echo '}' >> main.go
50
+
51
+ # 设置变量
52
+ ENV TZ=Asia/Shanghai
53
+ ENV PORT=7860
54
+
55
+ # 构建应用
56
+ RUN go mod download
57
+ RUN go build -o main .
 
 
 
 
 
 
 
58
 
59
  # 暴露端口
60
+ EXPOSE 7860
61
+
62
+ # 创建启动脚本
63
+ RUN echo '#!/bin/sh' > start.sh && \
64
+ echo 'echo "API🚀成功运行"' >> start.sh && \
65
+ echo './main' >> start.sh && \
66
+ chmod +x start.sh
67
 
68
+ # 运行启动脚本
69
+ CMD ["./start.sh"]