Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 90db243a68 |
@@ -43,3 +43,5 @@ backups/
|
||||
.ci-remote-tags
|
||||
.ci-commits-count
|
||||
.ci-preview-url
|
||||
# 上一版构建的静态资源(部署脚本落盘、只读挂载的运行时目录,不进 git)
|
||||
deploy/legacy-assets/
|
||||
|
||||
+4
-1
@@ -11,7 +11,10 @@
|
||||
|
||||
### Fixed
|
||||
|
||||
- 前端入口的缓存策略:`index.html` 此前没有缓存头,CDN/浏览器会启发式缓存它,于是**页面会一直停在旧构建上**(实测被腾讯云 EdgeOne 卡住:源站已是新包,公网入口仍发旧包,看起来像"新菜单/新页面没上线")。现在 `index.html` 每次回源校验(`no-cache, must-revalidate`)、带内容哈希的 `/assets/` 长缓存(`immutable`),旧哈希资源明确 404 而不是回退成 HTML。
|
||||
- 前端入口与静态资源的缓存语义("新功能看起来没上线"与"页面偶尔裸奔/空白"的根因):
|
||||
- `index.html` 此前**没有缓存头**,CDN/浏览器按启发式缓存它 ⇒ 页面会一直停在旧构建上(实测被腾讯云 EdgeOne 卡住:源站已是新包,公网入口仍发旧包)。现在 `index.html` 每次回源校验(`no-cache, must-revalidate`);
|
||||
- 带内容哈希的 `/assets/` 长缓存(`immutable`),但**未命中时先回退到"上一版构建的资源"目录、再 404**(`deploy/legacy-assets` 由部署脚本在每次重建前落盘并只读挂载):CDN/浏览器仍持有旧 `index.html` 时,它引用的旧 JS/CSS 依旧能取到 ⇒ 不会出现"JS 404 白屏"或"CSS 404 只有文字没样式";
|
||||
- 明确 404 时不再回退成 `index.html`(否则浏览器把 HTML 当 JS 执行,报一堆语法错误)。
|
||||
|
||||
### Security
|
||||
|
||||
|
||||
@@ -211,6 +211,10 @@ services:
|
||||
api:
|
||||
condition: service_healthy
|
||||
read_only: true
|
||||
volumes:
|
||||
# 上一版构建的静态资源(只读,由部署脚本落盘):CDN/浏览器可能还持有旧 index.html,
|
||||
# 让它的旧哈希引用不至于 404 —— 否则页面会空白或"只有文字没样式"。
|
||||
- ./deploy/legacy-assets:/usr/share/nginx/legacy:ro
|
||||
tmpfs:
|
||||
- /tmp
|
||||
- /var/cache/nginx
|
||||
|
||||
@@ -30,6 +30,14 @@ server {
|
||||
location /assets/ {
|
||||
expires 1y;
|
||||
add_header Cache-Control "public, max-age=31536000, immutable";
|
||||
# 当前构建里没有再找**上一版构建**的资源:CDN/浏览器可能还持有旧 index.html,
|
||||
# 它引用的旧哈希文件若直接 404,页面就会空白或"裸奔"(只有文字没样式)。
|
||||
# 旧目录由部署脚本在每次重建前落盘(deploy/legacy-assets,只读挂载)。
|
||||
try_files $uri @legacy;
|
||||
}
|
||||
|
||||
location @legacy {
|
||||
root /usr/share/nginx/legacy;
|
||||
try_files $uri =404;
|
||||
}
|
||||
|
||||
|
||||
@@ -35,6 +35,18 @@ if [ "${#IDENTITY_ARGS[@]}" -lt 6 ]; then
|
||||
fi
|
||||
printf ' %s\n' "${IDENTITY_ARGS[@]}"
|
||||
|
||||
echo "=== 1c. 保留上一版构建的静态资源(CDN/浏览器可能还持有旧 index.html)"
|
||||
# 只保留**当前正在跑的那一版**:旧 index.html 的旧哈希引用仍能取到文件,
|
||||
# 页面不会因为某个 JS/CSS 404 而空白或"裸奔"。目录只读挂载进 web 容器。
|
||||
LEGACY_DIR="deploy/legacy-assets"
|
||||
PREV_WEB_IMAGE=$(docker inspect -f '{{.Image}}' knowledge-governance-p1-web-1 2>/dev/null || true)
|
||||
mkdir -p "$LEGACY_DIR/assets" && chmod 777 "$LEGACY_DIR" "$LEGACY_DIR/assets"
|
||||
if [ -n "$PREV_WEB_IMAGE" ]; then
|
||||
docker run --rm --user 0 --entrypoint sh -v "$PWD/$LEGACY_DIR:/out" "$PREV_WEB_IMAGE" \
|
||||
-c 'cp -a /usr/share/nginx/html/assets/. /out/assets/ 2>/dev/null || true' >/dev/null 2>&1 || true
|
||||
echo " LEGACY_ASSETS=$(ls -1 "$LEGACY_DIR/assets" 2>/dev/null | tr '\n' ' ')"
|
||||
fi
|
||||
|
||||
echo "=== 2. 构建 api"
|
||||
docker build --network host "${PROXY_ARGS[@]}" "${IDENTITY_ARGS[@]}" -f Dockerfile -t knowledge-governance-p1-api:latest . || { echo "API_BUILD_FAILED"; exit 1; }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user