diff --git a/.env b/.env index 55dbc16..0ed107c 100644 --- a/.env +++ b/.env @@ -13,3 +13,6 @@ AI_MODEL=GLM-4.7-Flash # 版本更新配置 # 在 OneDev 中创建 Access Token (Settings → Access Tokens → New Token, scope: Read code) ONEDEV_ACCESS_TOKEN=Gtn1krR7tmv4x2c7xLupvW6OqgwWbmanpKonknpQ +REGISTRY_IMAGE=recipe_tool:latest +REPOSITORY_URL=https://git.hanhan.ltd/recipe_tool + diff --git a/docker-compose.yml b/docker-compose.yml index 881309a..eed2f6d 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -20,4 +20,6 @@ services: - AI_BASE_URL=${AI_BASE_URL:-https://api.openai.com/v1} - AI_MODEL=${AI_MODEL:-gpt-3.5-turbo} - ONEDEV_ACCESS_TOKEN=${ONEDEV_ACCESS_TOKEN} + - REGISTRY_IMAGE=${REGISTRY_IMAGE:-recipe_tool:latest} + - REPOSITORY_URL=${REPOSITORY_URL:-https://git.hanhan.ltd/recipe_tool} - GIT_REMOTE_URL=https://git.hanhan.ltd/recipe_tool.git diff --git a/lib/update.ts b/lib/update.ts index 674d9a3..1e500c7 100644 --- a/lib/update.ts +++ b/lib/update.ts @@ -333,16 +333,24 @@ async function checkDockerAvailable(): Promise<{ ok: boolean; message: string }> * 执行 Docker 容器更新 * @param onLog 日志回调 */ -const REGISTRY_IMAGE = "git.hanhan.ltd/recipe_tool/recipe_tool:latest"; - export async function executeUpdate( onLog: LogCallback = noopLog ): Promise<{ success: boolean; message: string }> { const cwd = process.cwd(); // /app(容器内工作目录,含 docker-compose.yml) const token = process.env.ONEDEV_ACCESS_TOKEN || ""; + const repoUrl = process.env.REPOSITORY_URL || "https://git.hanhan.ltd/recipe_tool"; + const registryImage = process.env.REGISTRY_IMAGE || "recipe_tool:latest"; + + // 从 REPOSITORY_URL 提取 registry host 和 project path 以拼出完整镜像地址 + // 例如: https://git.hanhan.ltd/recipe_tool → host=git.hanhan.ltd, path=recipe_tool + // 完整镜像: git.hanhan.ltd/recipe_tool/recipe_tool:latest + const repoUrlObj = new URL(repoUrl); + const registryHost = repoUrlObj.host; + const projectPath = repoUrlObj.pathname.replace(/^\/|\/$/g, ""); + const fullImage = `${registryHost}/${projectPath}/${registryImage}`; consoleLog("执行", "=== 开始执行更新 ==="); - consoleLog("执行", `工作目录: ${cwd}, 镜像: ${REGISTRY_IMAGE}`); + consoleLog("执行", `工作目录: ${cwd}, 镜像: ${fullImage}`); const logLine = (line: string) => onLog(line); @@ -366,7 +374,7 @@ export async function executeUpdate( if (token) { await execAsync( "sh", - ["-c", `echo "${token}" | docker login git.hanhan.ltd -u access-token --password-stdin`], + ["-c", `echo "${token}" | docker login ${registryHost} -u access-token --password-stdin`], "docker-login", { timeout: 15000, onLine: logLine } ); @@ -377,7 +385,7 @@ export async function executeUpdate( onLog("[1/4] 拉取新镜像"); consoleLog("执行", "步骤 1/4 — 拉取镜像"); - await execAsync("docker", ["pull", REGISTRY_IMAGE], "docker-pull", { + await execAsync("docker", ["pull", fullImage], "docker-pull", { timeout: 300000, onLine: logLine, }); @@ -396,6 +404,8 @@ export async function executeUpdate( `AI_BASE_URL=${process.env.AI_BASE_URL || "https://api.openai.com/v1"}`, `AI_MODEL=${process.env.AI_MODEL || "gpt-3.5-turbo"}`, `ONEDEV_ACCESS_TOKEN=${token}`, + `REGISTRY_IMAGE=${registryImage}`, + `REPOSITORY_URL=${repoUrl}`, `GIT_REMOTE_URL=${process.env.GIT_REMOTE_URL || "https://git.hanhan.ltd/recipe_tool.git"}`, ].join("\n"); fs.writeFileSync(path.join(cwd, ".env"), envContent, "utf-8");