黄中银 2 weeks ago
parent
commit
5b79484490
3 changed files with 94 additions and 4 deletions
  1. 0 4
      .gitignore
  2. 26 0
      mixapi/Dockerfile
  3. 68 0
      mixapi/auto_update.sh

+ 0 - 4
.gitignore

@@ -3,11 +3,7 @@
 .gitignore
 .gitignore
 .dockerignore
 .dockerignore
 .gitlab-ci.yml
 .gitlab-ci.yml
-*.sh
 *.bak
 *.bak
 *.log
 *.log
-!samba.sh
-!builder.sh
-!entrypoint.sh
 unbound
 unbound
 nul
 nul

+ 26 - 0
mixapi/Dockerfile

@@ -0,0 +1,26 @@
+# 使用curlimages/curl作为基础镜像(自带curl和sh)
+FROM curlimages/curl:latest
+
+# 切换到root用户进行设置
+USER root
+
+# 设置下载目录
+WORKDIR /app
+
+# 复制更新脚本
+COPY auto_update.sh /app/
+
+# 设置脚本可执行权限
+RUN chmod +x /app/auto_update.sh
+
+# 构建时下载初始版本
+RUN sh /app/auto_update.sh OnlyUpdate
+
+# 暴露3000端口
+EXPOSE 3000
+
+# 设置工作目录
+WORKDIR /data
+
+# 启动命令 - 容器启动时检测更新并启动服务
+CMD ["sh", "/app/auto_update.bash"]

+ 68 - 0
mixapi/auto_update.sh

@@ -0,0 +1,68 @@
+#!/bin/sh
+
+# 自动更新为最新版本
+# 获取最新版本号
+ftag_name=$(curl -ksSL https://api.github.com/repos/aiprodcoder/MIXAPI/releases/latest | sed -n 's/.*"tag_name":[[:space:]]*"\([^"]*\)".*/\1/p')
+
+# 如果获取失败,使用默认版本
+if [ -z "$ftag_name" ]; then
+    echo "无法获取最新版本号,使用默认版本 v1.2"
+    ftag_name="v1.2"
+fi
+
+echo "最新版本: ${ftag_name}"
+
+# 版本标记文件
+VERSION_FILE="/app/version.txt"
+
+# 检查是否需要更新
+if [ -f "$VERSION_FILE" ]; then
+    current_version=$(cat "$VERSION_FILE")
+    echo "当前版本: ${current_version}"
+    if [ "$current_version" = "$ftag_name" ]; then
+        echo "已是最新版本,无需更新"
+    else
+        echo "发现新版本,开始更新..."
+        rm -f /app/mixapi
+    fi
+else
+    echo "首次运行,开始下载..."
+fi
+
+# 如果可执行文件不存在,则下载
+if [ ! -f "/app/mixapi" ]; then
+    # 检测架构
+    arch="$(uname -m)"
+    echo "检测到架构: ${arch}"
+    
+    case "$arch" in
+        'x86_64')
+            download_url="https://github.com/aiprodcoder/MIXAPI/releases/download/${ftag_name}/mixapi-${ftag_name}-linux-amd64"
+            ;;
+        'aarch64')
+            download_url="https://github.com/aiprodcoder/MIXAPI/releases/download/${ftag_name}/mixapi-${ftag_name}-linux-arm64"
+            ;;
+        *)
+            echo "不支持的架构: ${arch}"
+            exit 1
+            ;;
+    esac
+    
+    echo "下载地址: ${download_url}"
+    curl -ksSL -o /app/mixapi "${download_url}"
+    
+    if [ $? -eq 0 ]; then
+        chmod +x /app/mixapi
+        echo "${ftag_name}" > "$VERSION_FILE"
+        echo "下载完成,版本: ${ftag_name}"
+    else
+        echo "下载失败"
+        exit 1
+    fi
+fi
+
+# 如果不是仅更新模式,则启动服务
+if [ "${1}" != "OnlyUpdate" ]; then
+    echo "启动 mixapi 服务..."
+    exec /app/mixapi
+fi