@dazhicheng/common 1.0.32 → 1.0.35
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.gitlab-ci.yml +14 -4
- package/Dockerfile +6 -3
- package/docker-entrypoint.sh +21 -0
- package/nginx_dev.conf +32 -1
- package/nginx_test.conf +34 -1
- package/package.json +2 -1
- package/sync-common.mjs +1 -0
package/.gitlab-ci.yml
CHANGED
|
@@ -23,17 +23,27 @@ variables:
|
|
|
23
23
|
paths:
|
|
24
24
|
- dist/
|
|
25
25
|
- nginx_*.conf
|
|
26
|
+
- docker-entrypoint.sh
|
|
27
|
+
- Dockerfile
|
|
26
28
|
expire_in: 1 day
|
|
27
29
|
|
|
28
30
|
# 部署锚点(通用脚本直接写在这里,不需要项目覆盖) -------------------------
|
|
31
|
+
# 使用 named volume 持久化静态资源:发版时合并新构建并保留旧 hashed 文件,
|
|
32
|
+
# 使已打开的旧页面仍能懒加载到旧入口资源。
|
|
29
33
|
.deploy_template: &deploy_template
|
|
30
34
|
stage: deploy
|
|
31
35
|
image: docker:26.1.4
|
|
32
36
|
script:
|
|
37
|
+
- docker volume create ${IMAGE_NAME}-assets || true
|
|
33
38
|
- docker build --build-arg NODE_ENV=$NODE_ENV -t $IMAGE_NAME:latest .
|
|
34
39
|
- docker stop $IMAGE_NAME || true
|
|
35
40
|
- docker rm $IMAGE_NAME || true
|
|
36
|
-
-
|
|
41
|
+
- >
|
|
42
|
+
docker run -d --name $IMAGE_NAME --restart always
|
|
43
|
+
-p $HOST_PORT:$CONTAINER_PORT
|
|
44
|
+
-v ${IMAGE_NAME}-assets:/usr/share/nginx/html
|
|
45
|
+
-e ASSET_RETENTION_DAYS=14
|
|
46
|
+
$IMAGE_NAME:latest
|
|
37
47
|
- docker image prune -f || true
|
|
38
48
|
|
|
39
49
|
# MR 验证 -----------------------------------------------------------------
|
|
@@ -42,7 +52,7 @@ variables:
|
|
|
42
52
|
variables:
|
|
43
53
|
NODE_ENV: dev
|
|
44
54
|
rules:
|
|
45
|
-
- if: $CI_PIPELINE_SOURCE == "merge_request_event" && $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "develop"
|
|
55
|
+
- if: $CI_PIPELINE_SOURCE == "merge_request_event" && ($CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "develop" || $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "test" || $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "release" || $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "sit")
|
|
46
56
|
|
|
47
57
|
MR 构建验证:
|
|
48
58
|
stage: MR_TEST
|
|
@@ -53,7 +63,7 @@ MR 构建验证:
|
|
|
53
63
|
- docker build --build-arg NODE_ENV=dev -t mr-test:mr-$CI_MERGE_REQUEST_IID .
|
|
54
64
|
- docker images | grep mr-test
|
|
55
65
|
rules:
|
|
56
|
-
- if: $CI_PIPELINE_SOURCE == "merge_request_event" && $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "develop"
|
|
66
|
+
- if: $CI_PIPELINE_SOURCE == "merge_request_event" && ($CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "develop" || $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "test" || $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "release" || $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "sit")
|
|
57
67
|
|
|
58
68
|
# 项目级 deploy jobs 注入点 ------------------------------------------------
|
|
59
69
|
构建_dev:
|
|
@@ -109,4 +119,4 @@ MR 构建验证:
|
|
|
109
119
|
NODE_ENV: test
|
|
110
120
|
<<<测试环境发版_107>>>
|
|
111
121
|
only: [test]
|
|
112
|
-
<<<deploy_jobs>>>
|
|
122
|
+
<<<deploy_jobs>>>
|
package/Dockerfile
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
|
|
2
1
|
FROM nginx:stable
|
|
3
2
|
ARG NODE_ENV=dev
|
|
4
3
|
COPY "nginx_${NODE_ENV}.conf" /etc/nginx/conf.d/default.conf
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
# 构建产物放到镜像内固定目录;运行时由 entrypoint 合并到持久卷,保留历史 hashed 资源
|
|
5
|
+
COPY dist/ /app/dist/
|
|
6
|
+
COPY docker-entrypoint.sh /docker-entrypoint.sh
|
|
7
|
+
RUN chmod +x /docker-entrypoint.sh
|
|
8
|
+
ENTRYPOINT ["/docker-entrypoint.sh"]
|
|
9
|
+
CMD ["nginx", "-g", "daemon off;"]
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
#!/bin/sh
|
|
2
|
+
set -e
|
|
3
|
+
|
|
4
|
+
HTML_ROOT=/usr/share/nginx/html
|
|
5
|
+
DIST_ROOT=/app/dist
|
|
6
|
+
# 保留最近 N 天的历史 hashed 资源,供已打开旧页面继续懒加载
|
|
7
|
+
ASSET_RETENTION_DAYS="${ASSET_RETENTION_DAYS:-14}"
|
|
8
|
+
|
|
9
|
+
mkdir -p "$HTML_ROOT"
|
|
10
|
+
|
|
11
|
+
# 合并拷贝:覆盖同名文件(如 index.html),保留卷中已有、本次构建不含的旧 chunk
|
|
12
|
+
if [ -d "$DIST_ROOT" ]; then
|
|
13
|
+
cp -a "$DIST_ROOT"/. "$HTML_ROOT"/
|
|
14
|
+
fi
|
|
15
|
+
|
|
16
|
+
# 清理过期静态资源,避免磁盘无限增长(不影响未过期的旧入口)
|
|
17
|
+
if [ -d "$HTML_ROOT/assets" ]; then
|
|
18
|
+
find "$HTML_ROOT/assets" -type f -mtime "+${ASSET_RETENTION_DAYS}" -delete 2>/dev/null || true
|
|
19
|
+
fi
|
|
20
|
+
|
|
21
|
+
exec "$@"
|
package/nginx_dev.conf
CHANGED
|
@@ -28,9 +28,40 @@ server {
|
|
|
28
28
|
root /usr/share/nginx/html;
|
|
29
29
|
index index.html;
|
|
30
30
|
|
|
31
|
+
# 带 hash 的构建资源:长缓存;缺失时返回 404(禁止回退成 index.html,避免把 HTML 当 JS)
|
|
32
|
+
location /assets/ {
|
|
33
|
+
try_files $uri =404;
|
|
34
|
+
expires 1y;
|
|
35
|
+
add_header Cache-Control "public, max-age=31536000, immutable" always;
|
|
36
|
+
|
|
37
|
+
# CORS 配置
|
|
38
|
+
add_header 'Access-Control-Allow-Origin' '*' always;
|
|
39
|
+
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS' always;
|
|
40
|
+
add_header 'Access-Control-Allow-Headers' 'Content-Type, Authorization' always;
|
|
41
|
+
<<<assets_CORS配置>>>
|
|
42
|
+
gzip_static on;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
# 入口 HTML:禁止缓存,确保新开/刷新拿到最新入口
|
|
46
|
+
location = /index.html {
|
|
47
|
+
add_header Cache-Control "no-cache, no-store, must-revalidate" always;
|
|
48
|
+
add_header Pragma "no-cache" always;
|
|
49
|
+
add_header Expires "0" always;
|
|
50
|
+
|
|
51
|
+
# CORS 配置
|
|
52
|
+
add_header 'Access-Control-Allow-Origin' '*' always;
|
|
53
|
+
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS' always;
|
|
54
|
+
add_header 'Access-Control-Allow-Headers' 'Content-Type, Authorization' always;
|
|
55
|
+
<<<index_html_CORS配置>>>
|
|
56
|
+
}
|
|
57
|
+
|
|
31
58
|
location / {
|
|
32
59
|
try_files $uri $uri/ /index.html;
|
|
33
|
-
|
|
60
|
+
add_header Cache-Control "no-cache" always;
|
|
61
|
+
add_header 'Access-Control-Allow-Origin' '*' always;
|
|
62
|
+
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS' always;
|
|
63
|
+
add_header 'Access-Control-Allow-Headers' 'Content-Type, Authorization' always;
|
|
64
|
+
<<<index_CORS配置>>>
|
|
34
65
|
}
|
|
35
66
|
|
|
36
67
|
location /dev-api/ {
|
package/nginx_test.conf
CHANGED
|
@@ -27,9 +27,42 @@ server {
|
|
|
27
27
|
root /usr/share/nginx/html;
|
|
28
28
|
index index.html;
|
|
29
29
|
|
|
30
|
+
# 带 hash 的构建资源:长缓存;缺失时返回 404(禁止回退成 index.html,避免把 HTML 当 JS)
|
|
31
|
+
location /assets/ {
|
|
32
|
+
try_files $uri =404;
|
|
33
|
+
expires 1y;
|
|
34
|
+
add_header Cache-Control "public, max-age=31536000, immutable" always;
|
|
35
|
+
|
|
36
|
+
# CORS 配置
|
|
37
|
+
add_header 'Access-Control-Allow-Origin' '*' always;
|
|
38
|
+
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS' always;
|
|
39
|
+
add_header 'Access-Control-Allow-Headers' 'Content-Type, Authorization' always;
|
|
40
|
+
<<<assets_CORS配置>>>
|
|
41
|
+
gzip_static on;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
# 入口 HTML:禁止缓存,确保新开/刷新拿到最新入口
|
|
45
|
+
location = /index.html {
|
|
46
|
+
add_header Cache-Control "no-cache, no-store, must-revalidate" always;
|
|
47
|
+
add_header Pragma "no-cache" always;
|
|
48
|
+
add_header Expires "0" always;
|
|
49
|
+
|
|
50
|
+
# CORS 配置
|
|
51
|
+
add_header 'Access-Control-Allow-Origin' '*' always;
|
|
52
|
+
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS' always;
|
|
53
|
+
add_header 'Access-Control-Allow-Headers' 'Content-Type, Authorization' always;
|
|
54
|
+
<<<index_html_CORS配置>>>
|
|
55
|
+
}
|
|
56
|
+
|
|
30
57
|
location / {
|
|
31
58
|
try_files $uri $uri/ /index.html;
|
|
32
|
-
|
|
59
|
+
add_header Cache-Control "no-cache" always;
|
|
60
|
+
|
|
61
|
+
# CORS 配置
|
|
62
|
+
add_header 'Access-Control-Allow-Origin' '*' always;
|
|
63
|
+
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS' always;
|
|
64
|
+
add_header 'Access-Control-Allow-Headers' 'Content-Type, Authorization' always;
|
|
65
|
+
<<<index_CORS配置>>>
|
|
33
66
|
}
|
|
34
67
|
|
|
35
68
|
location /test-api/ {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dazhicheng/common",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.35",
|
|
4
4
|
"description": "共享配置文件",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"types": "./src/types/index.d.ts",
|
|
@@ -24,6 +24,7 @@
|
|
|
24
24
|
"eslint.config.mjs.txt",
|
|
25
25
|
"tsconfig.json",
|
|
26
26
|
"Dockerfile",
|
|
27
|
+
"docker-entrypoint.sh",
|
|
27
28
|
"nginx_dev.conf",
|
|
28
29
|
"nginx_test.conf",
|
|
29
30
|
"sync-common.mjs",
|