fix web deploy artifact source
This commit is contained in:
@@ -10,7 +10,6 @@ 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 = 'caches/genarrative-build/web-artifacts'
|
||||
}
|
||||
|
||||
parameters {
|
||||
@@ -25,9 +24,6 @@ pipeline {
|
||||
string(name: 'RELEASE_ROOT', defaultValue: '/opt/genarrative/releases', description: '生产 release 根目录')
|
||||
string(name: 'CURRENT_LINK', defaultValue: '/opt/genarrative/current', description: '当前版本软链接')
|
||||
string(name: 'WEB_LINK', defaultValue: '/srv/genarrative/web', description: 'Nginx 静态站点软链接')
|
||||
booleanParam(name: 'SYNC_WEB_ARTIFACT_FROM_BUILD_HOST', defaultValue: true, description: 'release 目标本地缺少 Web 大包时,是否通过 rsync 从构建机内网拉取')
|
||||
string(name: 'WEB_ARTIFACT_SYNC_HOST', defaultValue: 'genarrative-build-internal', description: 'rsync 源 SSH Host,通常来自 release 服务器上 Jenkins 运行用户的 ~/.ssh/config')
|
||||
string(name: 'WEB_ARTIFACT_SYNC_SSH_CONFIG', defaultValue: '', description: '可选,rsync 使用的 ssh config 绝对路径;留空使用当前用户默认 ~/.ssh/config')
|
||||
}
|
||||
|
||||
stages {
|
||||
@@ -103,7 +99,7 @@ pipeline {
|
||||
copyArtifacts(
|
||||
projectName: params.BUILD_JOB_NAME,
|
||||
selector: specific(params.BUILD_NUMBER_TO_DEPLOY),
|
||||
filter: "build/${params.BUILD_VERSION}/web.tar.gz.sha256,build/${params.BUILD_VERSION}/release-manifest.json,build/${params.BUILD_VERSION}/web-artifact-pointer.txt",
|
||||
filter: "build/${params.BUILD_VERSION}/web.tar.gz,build/${params.BUILD_VERSION}/web.tar.gz.sha256,build/${params.BUILD_VERSION}/release-manifest.json",
|
||||
target: '.',
|
||||
fingerprintArtifacts: true
|
||||
)
|
||||
@@ -111,53 +107,10 @@ pipeline {
|
||||
bash -lc '
|
||||
set -euo pipefail
|
||||
|
||||
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}"
|
||||
sync_ssh_config="${WEB_ARTIFACT_SYNC_SSH_CONFIG:-}"
|
||||
|
||||
if [[ "${DEPLOY_TARGET:-development}" == "release" && "${sync_enabled}" == "true" ]]; then
|
||||
if [[ -z "${sync_host}" ]]; then
|
||||
echo "[web-deploy] release 目标需要同步 Web 大包,但 WEB_ARTIFACT_SYNC_HOST 为空。" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "[web-deploy] release 目标本地缓存缺少 Web 大包,尝试从 ${sync_host} 同步: ${artifact_dir}"
|
||||
if ! command -v rsync >/dev/null 2>&1; then
|
||||
echo "[web-deploy] 当前 release agent 缺少 rsync,请先安装 rsync 或预先挂载 Web 产物目录。" >&2
|
||||
exit 1
|
||||
fi
|
||||
mkdir -p "${artifact_dir}"
|
||||
|
||||
rsync_args=(-av --progress)
|
||||
if [[ -n "${sync_ssh_config}" ]]; then
|
||||
rsync_args+=(-e "ssh -F ${sync_ssh_config}")
|
||||
fi
|
||||
|
||||
rsync "${rsync_args[@]}" "${sync_host}:${artifact_dir}/" "${artifact_dir}/"
|
||||
fi
|
||||
fi
|
||||
|
||||
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
|
||||
exit 1
|
||||
fi
|
||||
|
||||
mkdir -p "build/${BUILD_VERSION}"
|
||||
cp -f "${artifact_dir}/web.tar.gz" "build/${BUILD_VERSION}/web.tar.gz"
|
||||
if [[ -f "${artifact_dir}/web.tar.gz.sha256" ]]; then
|
||||
cp -f "${artifact_dir}/web.tar.gz.sha256" "build/${BUILD_VERSION}/web.tar.gz.sha256"
|
||||
fi
|
||||
if [[ -f "${artifact_dir}/release-manifest.json" ]]; then
|
||||
cp -f "${artifact_dir}/release-manifest.json" "build/${BUILD_VERSION}/release-manifest.json"
|
||||
fi
|
||||
echo "[web-deploy] 已从构建机本地目录获取 Web 大包: ${artifact_dir}"
|
||||
test -f "build/${BUILD_VERSION}/web.tar.gz"
|
||||
test -f "build/${BUILD_VERSION}/web.tar.gz.sha256"
|
||||
test -f "build/${BUILD_VERSION}/release-manifest.json"
|
||||
echo "[web-deploy] 已从 Jenkins 构建归档获取 Web 发布包: build/${BUILD_VERSION}/web.tar.gz"
|
||||
'
|
||||
'''
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user