#!/usr/bin/env bash # ============================================================================= # 01 把 jar / 前端静态资源同步进 jnpf-resources PVC(不打镜像) # ./scripts/01-artifacts.sh # 全量同步(sha 不同才传) # FORCE=1 ./scripts/01-artifacts.sh # 忽略 sha 强制重传 # 产物在 PVC 上的布局(compose 的 /usr/ssw 目录结构照搬): # /persist/admin|wf|report|xxl/app.jar # /persist/dist|datav|public 前端 # /persist/tenant-web 多租户管理中心前端(独立入口 8081) # /persist/jnpf-resources 文件存储根(内置静态资源 + 用户上传,混合目录) # /persist/log resources 纯运行时目录(建好即可,内容自生) # ============================================================================= set -euo pipefail cd "$(dirname "$0")/.." export KUBECONFIG="${KUBECONFIG:-$HOME/.kube/kubeconfig-wuguirong}" NS=wuguirong POD=jnpf-artifact-sync FORCE="${FORCE:-0}" echo "---- 0) 校验本地产物" need() { [ -e "$1" ] || { echo "缺产物: $1"; exit 1; }; } need build/admin/app.jar; need build/workflow/app.jar need build/report/app.jar; need build/xxl/app.jar need build/tenant/app.jar need build/web/dist/index.html; need build/web/datav; need build/web/public # 多租户管理中心前端(jnpf-web-tenant-vue3 的 vite 产物) need build/tenant-web/index.html # 创租户时 jnpf-tenant 会去 spring.file 目录读这个文件建 schema,缺了就建不出租户 need build/tenantApi/JNPF-PostgreSQL.sql echo "---- 1) 起同步 Pod" kubectl -n $NS delete pod $POD --ignore-not-found --wait=true >/dev/null 2>&1 || true kubectl apply -f k8s/00-sync-pod.yaml kubectl -n $NS wait --for=condition=Ready pod/$POD --timeout=180s echo "---- 2) 预建目录(上传/日志等运行时目录,留 0777 便于多 Pod 共享写)" # 只 chmod 我们自己新建的子目录:PVC 根是 provisioner 建的,我们不是 owner,chmod 根会 EPERM kubectl -n $NS exec $POD -- sh -c \ 'mkdir -p admin wf report xxl tenant dist datav public log resources jnpf-resources tenantApi tenant-web \ && chmod 777 admin wf report xxl tenant dist datav public log resources jnpf-resources tenantApi tenant-web \ && ls -1' # name|本地源 items=( "admin/app.jar|build/admin/app.jar" "wf/app.jar|build/workflow/app.jar" "report/app.jar|build/report/app.jar" "xxl/app.jar|build/xxl/app.jar" "tenant/app.jar|build/tenant/app.jar" # 创租户脚本:jnpf-tenant 的 spring.file 指向 /usr/ssw/tenantApi "tenantApi/JNPF-PostgreSQL.sql|build/tenantApi/JNPF-PostgreSQL.sql" "dist|build/web/dist" "datav|build/web/datav" "public|build/web/public" # 多租户管理中心前端:nginx 第二个 server 块(8081)的静态根 "tenant-web|build/tenant-web" ) echo "---- 3) 同步(sha 一致就跳过)" for entry in "${items[@]}"; do dst="${entry%%|*}"; src="${entry#*|}" if [ -d "$src" ]; then # 目录:先比文件数+总字节,差异就整目录重传(前端 dist 有上万小文件,tar 流式最省事) lsum=$(find "$src" -type f -exec stat -f '%z' {} + | awk '{s+=$1; n++} END {print n" "s}') else lsum="$(wc -c <"$src" | tr -d ' ') 1" fi rsum=$(kubectl -n $NS exec $POD -- sh -c \ "if [ -d /persist/$dst ]; then find /persist/$dst -type f -exec stat -c '%s' {} + | awk '{s+=\$1; n++} END {print n\" \"s}'; \ elif [ -f /persist/$dst ]; then echo \$(stat -c '%s' /persist/$dst) 1; \ else echo missing; fi" 2>/dev/null || echo missing) if [ "$FORCE" != "1" ] && [ "$lsum" = "$rsum" ]; then echo " skip ${dst}(已一致:${rsum})" continue fi echo " send $dst 本地=$lsum 远端=$rsum" kubectl -n $NS exec -i $POD -- sh -c "mkdir -p /persist/$(dirname "$dst")" /dev/null)" ]; then have=$(kubectl -n $NS exec $POD -- sh -c \ 'find /persist/jnpf-resources -type f 2>/dev/null | wc -l' 2>/dev/null || echo 0) if [ "$FORCE" != "1" ] && [ "$have" -gt 0 ]; then echo " skip jnpf-resources(远端已有 ${have} 个文件)" else echo " send jnpf-resources(本地 $(find build/jnpf-resources -type f | wc -l | tr -d ' ') 个文件)" tar --no-xattrs -cf - -C build jnpf-resources \ | kubectl -n $NS exec -i $POD -- tar xf - -C /persist fi # 种子 SQL / base_system.f_icon 里图标路径是小写目录名(projectlogo/…),而 # config.*FilePath 配的是驼峰(ProjectLogo);Linux/NFS 大小写敏感,两个都得有。 # 本机 APFS 不敏感没法并存,只能在对端补一份小写副本。 kubectl -n $NS exec $POD -- sh -c \ 'for d in ProjectLogo Avatar AiFile Language AiModelIcon DatabaseIcon UserAvatar; do [ -d "/persist/jnpf-resources/$d" ] || continue low=$(echo "$d" | tr "[:upper:]" "[:lower:]") [ -d "/persist/jnpf-resources/$low" ] || cp -R "/persist/jnpf-resources/$d" "/persist/jnpf-resources/$low" done; chmod -R 777 /persist/jnpf-resources' else echo " warn build/jnpf-resources 为空,跳过(应用中心图标/用户头像会裂图)" fi echo "---- 5) 远端现状" kubectl -n $NS exec $POD -- sh -c 'ls -la /persist; echo; du -sh /persist/* 2>/dev/null | sort -h' echo "---- 6) 清理同步 Pod" kubectl -n $NS delete pod $POD --ignore-not-found --wait=true echo "产物就位。下一步:./scripts/02-seed-db.sh"