diff --git a/.hermes/shared-memory/pitfalls.md b/.hermes/shared-memory/pitfalls.md index e6af2a55..c7437277 100644 --- a/.hermes/shared-memory/pitfalls.md +++ b/.hermes/shared-memory/pitfalls.md @@ -1133,7 +1133,7 @@ ## Release Web 产物通过内网 rsync 拉取 -- 现象:`Genarrative-Web-Deploy` 发布到 `release` 目标时,release agent 本地没有 `/var/cache/genarrative-build/web-artifacts////web.tar.gz`,但 Jenkins controller 又只归档轻量元数据,导致发布阶段找不到 Web 大包。 +- 现象:`Genarrative-Web-Deploy` 发布到 `release` 目标时,release agent 本地没有 `$HOME/caches/genarrative-build/web-artifacts////web.tar.gz`,但 Jenkins controller 又只归档轻量元数据,导致发布阶段找不到 Web 大包。 - 原因:Web 大包为了避免从 Linux 构建机拉回 Jenkins controller,默认留在构建机稳定缓存目录;development 目标与构建机同机可直接读取,release 目标是独立机器,需要内网同步。 - 处理:release 服务器的 Jenkins 运行用户配置 SSH Host `genarrative-build-internal` 指向构建机内网地址,`Genarrative-Web-Deploy` 在 `DEPLOY_TARGET=release` 且本地缺少大包时默认执行 `rsync` 拉取同一路径内容;真实内网 IP、用户和私钥路径只放在服务器本机 SSH config,不写入 Jenkinsfile。 - 验证:在 release 服务器上先手工跑通 `rsync -av --progress "genarrative-build-internal:${SRC}/" "${DST}/"`,再运行 Web Deploy;流水线会继续执行 `web.tar.gz.sha256` 校验。 diff --git a/jenkins/Jenkinsfile.production-api-build b/jenkins/Jenkinsfile.production-api-build index 43294be0..9d925de6 100644 --- a/jenkins/Jenkinsfile.production-api-build +++ b/jenkins/Jenkinsfile.production-api-build @@ -12,11 +12,9 @@ pipeline { environment { GIT_REMOTE_URL = 'http://127.0.0.1:3000/GenarrativeAI/Genarrative.git' GIT_REMOTE_FALLBACK_URL = 'https://git.genarrative.world/GenarrativeAI/Genarrative.git' - CARGO_HOME = '/home/dsk/.cache/genarrative-jenkins/api-server/cargo-home' - CARGO_TARGET_DIR = '/home/dsk/.cache/genarrative-jenkins/api-server/cargo-target/prod-release' + GENARRATIVE_API_CACHE_ROOT = 'caches/genarrative-jenkins/api-server' CARGO_INCREMENTAL = '0' RUSTC_WRAPPER = 'sccache' - SCCACHE_DIR = '/home/dsk/.cache/genarrative-jenkins/api-server/sccache' SCCACHE_CACHE_SIZE = '30G' } @@ -80,6 +78,13 @@ pipeline { sh ''' bash -lc ' set -euo pipefail + api_cache_root="${GENARRATIVE_API_CACHE_ROOT:-caches/genarrative-jenkins/api-server}" + if [[ "${api_cache_root}" != /* ]]; then + api_cache_root="${HOME:?HOME 不能为空}/${api_cache_root}" + fi + export CARGO_HOME="${api_cache_root}/cargo-home" + export CARGO_TARGET_DIR="${api_cache_root}/cargo-target/prod-release" + export SCCACHE_DIR="${api_cache_root}/sccache" chmod +x scripts/jenkins-prepare-cargo-env.sh source scripts/jenkins-prepare-cargo-env.sh if ! command -v clang >/dev/null 2>&1 || ! command -v lld >/dev/null 2>&1; then diff --git a/jenkins/Jenkinsfile.production-web-build b/jenkins/Jenkinsfile.production-web-build index d26c65fe..a24bebb1 100644 --- a/jenkins/Jenkinsfile.production-web-build +++ b/jenkins/Jenkinsfile.production-web-build @@ -12,7 +12,7 @@ pipeline { environment { GIT_REMOTE_URL = 'http://127.0.0.1:3000/GenarrativeAI/Genarrative.git' GIT_REMOTE_FALLBACK_URL = 'https://git.genarrative.world/GenarrativeAI/Genarrative.git' - WEB_ARTIFACT_ROOT = '/var/cache/genarrative-build/web-artifacts' + WEB_ARTIFACT_ROOT = 'caches/genarrative-build/web-artifacts' } parameters { @@ -94,7 +94,11 @@ pipeline { bash -lc ' set -euo pipefail - artifact_dir="${WEB_ARTIFACT_ROOT}/${JOB_NAME}/${BUILD_NUMBER}/${EFFECTIVE_BUILD_VERSION}" + web_artifact_root="${WEB_ARTIFACT_ROOT:-caches/genarrative-build/web-artifacts}" + if [[ "${web_artifact_root}" != /* ]]; then + web_artifact_root="${HOME:?HOME 不能为空}/${web_artifact_root}" + fi + artifact_dir="${web_artifact_root}/${JOB_NAME}/${BUILD_NUMBER}/${EFFECTIVE_BUILD_VERSION}" mkdir -p "${artifact_dir}" rm -f "${artifact_dir}/web.tar.gz" "${artifact_dir}/web.tar.gz.sha256" "${artifact_dir}/release-manifest.json" install -m 0644 "build/${EFFECTIVE_BUILD_VERSION}/web.tar.gz" "${artifact_dir}/web.tar.gz" @@ -109,7 +113,7 @@ WEB_ARTIFACT_VERSION=${EFFECTIVE_BUILD_VERSION} EOF echo "[web-build] Web 大包已保存在构建机本地目录: ${artifact_dir}" - find "${WEB_ARTIFACT_ROOT}/${JOB_NAME}" -mindepth 1 -maxdepth 1 -type d -mtime +14 -print -exec rm -rf {} + + find "${web_artifact_root}/${JOB_NAME}" -mindepth 1 -maxdepth 1 -type d -mtime +14 -print -exec rm -rf {} + ' ''' archiveArtifacts artifacts: "build/${env.EFFECTIVE_BUILD_VERSION}/web.tar.gz.sha256,build/${env.EFFECTIVE_BUILD_VERSION}/release-manifest.json,build/${env.EFFECTIVE_BUILD_VERSION}/web-artifact-pointer.txt", fingerprint: false diff --git a/jenkins/Jenkinsfile.production-web-deploy b/jenkins/Jenkinsfile.production-web-deploy index 943ad5c4..7597ec41 100644 --- a/jenkins/Jenkinsfile.production-web-deploy +++ b/jenkins/Jenkinsfile.production-web-deploy @@ -10,7 +10,7 @@ pipeline { environment { GIT_REMOTE_URL = 'http://127.0.0.1:3000/GenarrativeAI/Genarrative.git' GIT_REMOTE_FALLBACK_URL = 'https://git.genarrative.world/GenarrativeAI/Genarrative.git' - WEB_ARTIFACT_ROOT = '/var/cache/genarrative-build/web-artifacts' + WEB_ARTIFACT_ROOT = 'caches/genarrative-build/web-artifacts' } parameters { @@ -111,7 +111,11 @@ pipeline { bash -lc ' set -euo pipefail - artifact_dir="${WEB_ARTIFACT_ROOT}/${BUILD_JOB_NAME}/${BUILD_NUMBER_TO_DEPLOY}/${BUILD_VERSION}" + web_artifact_root="${WEB_ARTIFACT_ROOT:-caches/genarrative-build/web-artifacts}" + if [[ "${web_artifact_root}" != /* ]]; then + web_artifact_root="${HOME:?HOME 不能为空}/${web_artifact_root}" + fi + artifact_dir="${web_artifact_root}/${BUILD_JOB_NAME}/${BUILD_NUMBER_TO_DEPLOY}/${BUILD_VERSION}" if [[ ! -f "${artifact_dir}/web.tar.gz" ]]; then sync_enabled="${SYNC_WEB_ARTIFACT_FROM_BUILD_HOST:-true}" sync_host="${WEB_ARTIFACT_SYNC_HOST:-genarrative-build-internal}" @@ -141,7 +145,7 @@ pipeline { if [[ ! -f "${artifact_dir}/web.tar.gz" ]]; then echo "[web-deploy] 未找到构建机本地 Web 大包: ${artifact_dir}/web.tar.gz" >&2 - echo "[web-deploy] development 目标要求 Web 构建与发布共享同一 Linux 构建/开发部署机;release 目标会默认通过 rsync 从 WEB_ARTIFACT_SYNC_HOST 拉取,也可预先同步或挂载 ${WEB_ARTIFACT_ROOT}。" >&2 + echo "[web-deploy] development 目标要求 Web 构建与发布共享同一 Linux 构建/开发部署机;release 目标会默认通过 rsync 从 WEB_ARTIFACT_SYNC_HOST 拉取,也可预先同步或挂载 ${web_artifact_root}。" >&2 exit 1 fi