@dazhicheng/common 1.0.13 → 1.0.15
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 +31 -58
- package/Dockerfile +5 -35
- package/package.json +1 -1
package/.gitlab-ci.yml
CHANGED
|
@@ -1,74 +1,47 @@
|
|
|
1
1
|
stages:
|
|
2
|
+
- build
|
|
2
3
|
- MR_TEST
|
|
3
|
-
-
|
|
4
|
-
- test
|
|
5
|
-
- sit
|
|
4
|
+
- deploy
|
|
6
5
|
|
|
7
6
|
variables:
|
|
8
7
|
DOCKER_BUILDKIT: 1
|
|
9
8
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
- MR_TEST
|
|
9
|
+
# 构建锚点 ----------------------------------------------------------------
|
|
10
|
+
.build_template: &build_template
|
|
11
|
+
stage: build
|
|
12
|
+
image: node:20-alpine
|
|
15
13
|
script:
|
|
16
|
-
|
|
17
|
-
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
14
|
+
- npm install -g pnpm
|
|
15
|
+
- pnpm install
|
|
16
|
+
- pnpm "build:${NODE_ENV}"
|
|
17
|
+
artifacts:
|
|
18
|
+
paths:
|
|
19
|
+
- dist/
|
|
20
|
+
expire_in: 1 day
|
|
22
21
|
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
# 部署锚点(通用脚本直接写在这里,不需要项目覆盖) -------------------------
|
|
23
|
+
.deploy_template: &deploy_template
|
|
24
|
+
stage: deploy
|
|
25
25
|
image: docker:20.10.20
|
|
26
|
-
tags:
|
|
27
|
-
- develop
|
|
28
|
-
resource_group: deploy-develop # 重点
|
|
29
26
|
script:
|
|
30
|
-
|
|
31
|
-
|
|
27
|
+
- docker build --build-arg NODE_ENV=$NODE_ENV -t $IMAGE_NAME:latest .
|
|
28
|
+
- docker stop $IMAGE_NAME || true
|
|
29
|
+
- docker rm $IMAGE_NAME || true
|
|
30
|
+
- docker run -d --name $IMAGE_NAME --restart always -p $HOST_PORT:$CONTAINER_PORT $IMAGE_NAME:latest
|
|
32
31
|
- docker image prune -f || true
|
|
33
|
-
only:
|
|
34
|
-
- develop
|
|
35
32
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
tags:
|
|
40
|
-
- develop_107
|
|
41
|
-
resource_group: deploy-develop_107 # 重点
|
|
42
|
-
script:
|
|
43
|
-
<<<script_开发环境发版_107>>>
|
|
44
|
-
# 清理悬空镜像
|
|
45
|
-
- docker image prune -f || true
|
|
46
|
-
only:
|
|
47
|
-
- develop
|
|
48
|
-
|
|
49
|
-
# 测试环境 -----------------------------------------------------------------------------------------------
|
|
50
|
-
测试环境发版:
|
|
51
|
-
stage: test
|
|
33
|
+
# MR 验证 -----------------------------------------------------------------
|
|
34
|
+
MR 构建验证:
|
|
35
|
+
stage: MR_TEST
|
|
52
36
|
image: docker:20.10.20
|
|
53
37
|
tags:
|
|
54
|
-
-
|
|
55
|
-
|
|
38
|
+
- MR_TEST
|
|
39
|
+
needs: [构建_dev]
|
|
56
40
|
script:
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
- test
|
|
41
|
+
- docker build --build-arg NODE_ENV=dev -t mr-test:mr-$CI_MERGE_REQUEST_IID .
|
|
42
|
+
- docker images | grep mr-test
|
|
43
|
+
rules:
|
|
44
|
+
- if: $CI_PIPELINE_SOURCE == "merge_request_event" && $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "develop"
|
|
62
45
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
image: docker:20.10.20
|
|
66
|
-
tags:
|
|
67
|
-
- test_107
|
|
68
|
-
resource_group: deploy-test_107 # 重点
|
|
69
|
-
script:
|
|
70
|
-
<<<script_测试环境发版_107>>>
|
|
71
|
-
# 清理悬空镜像
|
|
72
|
-
- docker image prune -f || true
|
|
73
|
-
only:
|
|
74
|
-
- test
|
|
46
|
+
# 项目级 deploy jobs 注入点 ------------------------------------------------
|
|
47
|
+
<<<deploy_jobs>>>
|
package/Dockerfile
CHANGED
|
@@ -1,36 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
FROM
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
# 安装 pnpm 并配置镜像源
|
|
7
|
-
RUN npm install -g pnpm && \
|
|
8
|
-
pnpm config set registry https://registry.npmmirror.com
|
|
9
|
-
|
|
10
|
-
ARG NODE_ENV=dev
|
|
11
|
-
|
|
12
|
-
# 先复制依赖文件并安装依赖
|
|
13
|
-
COPY package*.json pnpm-lock.yaml* pnpm-workspace.yaml ./
|
|
14
|
-
COPY scripts/sync-common.mjs ./scripts/
|
|
15
|
-
RUN pnpm install
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
# 再复制全部源代码,进行构建
|
|
19
|
-
COPY . .
|
|
20
|
-
# 同步生成文件
|
|
21
|
-
RUN pnpm sync:common
|
|
22
|
-
RUN pnpm "build:${NODE_ENV}"
|
|
23
|
-
|
|
24
|
-
# 阶段 2:部署到 Nginx
|
|
25
|
-
FROM nginx:stable-alpine
|
|
26
|
-
|
|
27
|
-
ARG NODE_ENV=dev
|
|
28
|
-
|
|
29
|
-
# 复制 Nginx 配置
|
|
30
|
-
COPY --from=builder /app/nginx_${NODE_ENV}.conf /etc/nginx/conf.d/default.conf
|
|
31
|
-
|
|
32
|
-
# 复制构建产物
|
|
33
|
-
COPY --from=builder /app/dist /usr/share/nginx/html
|
|
34
|
-
|
|
35
|
-
# 启动 Nginx
|
|
1
|
+
|
|
2
|
+
FROM nginx:stable-alpine
|
|
3
|
+
ARG NODE_ENV=dev
|
|
4
|
+
COPY "nginx_${NODE_ENV}.conf" /etc/nginx/conf.d/default.conf
|
|
5
|
+
COPY dist/ /usr/share/nginx/html
|
|
36
6
|
CMD ["nginx", "-g", "daemon off;"]
|