@xfe-repo/bff-app 1.0.0

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/.eslintrc.js ADDED
@@ -0,0 +1,12 @@
1
+ /** @type {import("eslint").Linter.Config} */
2
+ module.exports = {
3
+ root: true,
4
+ extends: ['@xfe-repo/eslint-config/turbo.js'],
5
+ env: {
6
+ browser: true,
7
+ node: true,
8
+ },
9
+ parserOptions: {
10
+ project: './tsconfig.json',
11
+ },
12
+ }
package/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # `@xfe-repo/bff-app`
2
+
3
+ bff 框架基础库
package/bin/index.js ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env node
2
+ require('../dist/cli.js');
3
+
4
+
5
+
@@ -0,0 +1,184 @@
1
+ kind: pipeline
2
+ type: kubernetes
3
+ name: deploy
4
+
5
+ metadata:
6
+ namespace: cicd
7
+
8
+ trigger:
9
+ event:
10
+ - custom
11
+ - tag
12
+
13
+ steps:
14
+ - name: install
15
+ pull: if-not-exists
16
+ image: xhj-prod-registry-vpc.cn-hangzhou.cr.aliyuncs.com/xhj-image-common/node-cicd:20.17.0
17
+ volumes:
18
+ - name: node-modules-runtime
19
+ path: /drone/src/node_modules
20
+ commands:
21
+ - pnpm config set registry https://registry.npmmirror.com
22
+ - pnpm install --production
23
+
24
+ - name: build
25
+ pull: if-not-exists
26
+ image: xhj-prod-registry-vpc.cn-hangzhou.cr.aliyuncs.com/xhj-image-common/node-cicd:20.17.0
27
+ volumes:
28
+ - name: node-modules-ci
29
+ path: /drone/src/node_modules
30
+ commands:
31
+ - pnpm config set registry https://registry.npmmirror.com
32
+ - pnpm install
33
+ - pnpm build
34
+
35
+ - name: image-build
36
+ image: xhj-prod-registry-vpc.cn-hangzhou.cr.aliyuncs.com/image-common/kaniko:latest
37
+ pull: always
38
+ volumes:
39
+ - name: node-modules-runtime
40
+ path: /drone/src/node_modules
41
+ settings:
42
+ registry: xhj-prod-registry-vpc.cn-hangzhou.cr.aliyuncs.com
43
+ username:
44
+ from_secret: username
45
+ password:
46
+ from_secret: password
47
+ dockerfile: deploy/Dockerfile
48
+ repo_path: xhj-prod-registry-vpc.cn-hangzhou.cr.aliyuncs.com/xhj-image/
49
+ repo_name: ${DRONE_REPO}
50
+ tags:
51
+ - ${CI_COMMIT_SHA}
52
+ - latest
53
+
54
+ - name: pre-deploy
55
+ image: xhj-prod-registry-vpc.cn-hangzhou.cr.aliyuncs.com/xhj-image-common/deploy-helm:latest
56
+ environment:
57
+ SAAS_K8S_CONFIG:
58
+ from_secret: saas-k8s-config
59
+ INFRA_K8S_CONFIG:
60
+ from_secret: infra-k8s-config
61
+ commands:
62
+ # 将环境类型写入values.yaml
63
+ - appName="`echo ${DRONE_REPO//\//-}`"
64
+ - sed -i "s/<<APP_NAME>>/$appName/g" deploy/helm/values.yaml
65
+ - sed -i "s/<<CI_COMMIT_SHA>>/$CI_COMMIT_SHA/g" deploy/helm/values.yaml
66
+ - sed -i "s/<<TAG_CONTENT>>/$DRONE_TAG/g" deploy/helm/values.yaml
67
+ - sed -i "s/<<REPO_NAME>>/$DRONE_REPO_NAME/g" deploy/helm/values.yaml
68
+ # 展示values.yaml
69
+ - cat deploy/helm/values.yaml
70
+
71
+ - name: deploy-to-test
72
+ image: xhj-prod-registry-vpc.cn-hangzhou.cr.aliyuncs.com/xhj-image-common/deploy-helm:latest
73
+ environment:
74
+ SAAS_K8S_CONFIG:
75
+ from_secret: saas-k8s-config
76
+ commands:
77
+ - echo "$SAAS_K8S_CONFIG" > saas_config
78
+ - export KUBECONFIG=$PWD/saas_config
79
+ - cp deploy/helm/values.yaml deploy/helm/values.test.yaml
80
+ - sed -i "s/<<ENV_TYPE>>/test/g" deploy/helm/values.test.yaml
81
+ - sed -i "s/<<APP_PREFIX>>/-$HOST_PREFIX/g" deploy/helm/values.test.yaml
82
+ - sed -i "s/<<HOST_PREFIX>>/$HOST_PREFIX/g" deploy/helm/values.test.yaml
83
+ - cat deploy/helm/values.test.yaml
84
+ - chartName="${DRONE_REPO//\//-}-$HOST_PREFIX"
85
+ - echo "$chartName"
86
+ - sed -i "s/deployment/$chartName/g" deploy/helm/Chart.yaml
87
+ - sed -i "s/1.0.0/0.0.0-$CI_COMMIT_SHA/g" deploy/helm/Chart.yaml
88
+ - helm upgrade --install "$chartName" deploy/helm -f deploy/helm/values.test.yaml --namespace deployment-test --create-namespace --history-max 5
89
+ when:
90
+ event:
91
+ - custom
92
+
93
+ - name: deploy-to-stage
94
+ image: xhj-prod-registry-vpc.cn-hangzhou.cr.aliyuncs.com/xhj-image-common/deploy-helm:latest
95
+ environment:
96
+ SAAS_K8S_CONFIG:
97
+ from_secret: saas-k8s-config
98
+ commands:
99
+ - echo "$SAAS_K8S_CONFIG" > saas_config
100
+ - cp deploy/helm/values.yaml deploy/helm/values.stage.yaml
101
+ - sed -i "s/<<ENV_TYPE>>/stage/g" deploy/helm/values.stage.yaml
102
+ - sed -i "s/<<APP_PREFIX>>/-stage/g" deploy/helm/values.stage.yaml
103
+ - sed -i "s/<<HOST_PREFIX>>/stage/g" deploy/helm/values.stage.yaml
104
+ - cat deploy/helm/values.stage.yaml
105
+ - helm template deploy/helm --values deploy/helm/values.stage.yaml --set replicas=1
106
+ - helm template deploy/helm --values deploy/helm/values.stage.yaml --set replicas=1|kubectl --kubeconfig=saas_config apply -f -
107
+ when:
108
+ ref:
109
+ include:
110
+ - refs/tags/stage-*
111
+
112
+ - name: deploy-to-prod
113
+ image: xhj-prod-registry-vpc.cn-hangzhou.cr.aliyuncs.com/xhj-image-common/deploy-helm:latest
114
+ environment:
115
+ SAAS_K8S_CONFIG:
116
+ from_secret: saas-k8s-config
117
+ commands:
118
+ - echo "$SAAS_K8S_CONFIG" > saas_config
119
+ - cp deploy/helm/values.yaml deploy/helm/values.prod.yaml
120
+ - sed -i "s/<<ENV_TYPE>>/prod/g" deploy/helm/values.prod.yaml
121
+ - sed -i "s/<<APP_PREFIX>>//g" deploy/helm/values.prod.yaml
122
+ - sed -i "s/<<HOST_PREFIX>>//g" deploy/helm/values.prod.yaml
123
+ - cat deploy/helm/values.prod.yaml
124
+ - helm template deploy/helm --values deploy/helm/values.prod.yaml
125
+ - helm template deploy/helm --values deploy/helm/values.prod.yaml|kubectl --kubeconfig=saas_config apply -f -
126
+ when:
127
+ ref:
128
+ include:
129
+ - refs/tags/release-*
130
+
131
+ - name: deploy-to-test-stable
132
+ image: xhj-prod-registry-vpc.cn-hangzhou.cr.aliyuncs.com/xhj-image-common/deploy-helm:latest
133
+ environment:
134
+ SAAS_K8S_CONFIG:
135
+ from_secret: saas-k8s-config
136
+ commands:
137
+ - echo "$SAAS_K8S_CONFIG" > saas_config
138
+ - cp deploy/helm/values.yaml deploy/helm/values.test.yaml
139
+ - sed -i "s/<<ENV_TYPE>>/test/g" deploy/helm/values.test.yaml
140
+ - sed -i "s/<<APP_PREFIX>>/-stable/g" deploy/helm/values.test.yaml
141
+ - sed -i "s/<<HOST_PREFIX>>/*/g" deploy/helm/values.test.yaml
142
+ - cat deploy/helm/values.test.yaml
143
+ - helm template deploy/helm --values deploy/helm/values.test.yaml
144
+ - helm template deploy/helm --values deploy/helm/values.test.yaml|kubectl --kubeconfig=saas_config apply -f -
145
+ when:
146
+ ref:
147
+ include:
148
+ - refs/tags/release-*
149
+
150
+ volumes:
151
+ - name: node-modules-ci
152
+ host:
153
+ path: /var/lib/node/${DRONE_REPO_NAME}-node-modules-ci-v20-v2
154
+ - name: node-modules-runtime
155
+ host:
156
+ path: /var/lib/node/${DRONE_REPO_NAME}-node-modules-runtime-v20-v2
157
+
158
+ image_pull_secrets:
159
+ - docker-key
160
+
161
+ ---
162
+ kind: secret
163
+ name: saas-k8s-config
164
+ get:
165
+ path: saas-k8s-config
166
+ name: config
167
+ ---
168
+ kind: secret
169
+ name: docker-key
170
+ get:
171
+ path: docker-key
172
+ name: config
173
+ ---
174
+ kind: secret
175
+ name: username
176
+ get:
177
+ path: docker-auth
178
+ name: username
179
+ ---
180
+ kind: secret
181
+ name: password
182
+ get:
183
+ path: docker-auth
184
+ name: password
@@ -0,0 +1,16 @@
1
+ FROM xhj-prod-registry-vpc.cn-hangzhou.cr.aliyuncs.com/xhj-image-common/node-runtime:20.17.0
2
+
3
+ WORKDIR /code/www/deploy/webroot/app/current
4
+
5
+ COPY dist ./dist
6
+
7
+ COPY node_modules ./node_modules
8
+
9
+ COPY deploy/ecosystem.config.js ./deploy/ecosystem.config.js
10
+
11
+ COPY static ./static
12
+
13
+ ENV PATH=$PATH:/code/www/deploy/webroot/app/current/node_modules/pm2/bin
14
+
15
+ CMD ["pm2-runtime", "start", "./deploy/ecosystem.config.js"]
16
+
@@ -0,0 +1,8 @@
1
+ apiVersion: v1
2
+ name: deployment
3
+ description: A Helm chart for xfe
4
+
5
+ type: application
6
+
7
+ version: 1.0.0
8
+ appVersion: 1.0.0
@@ -0,0 +1,75 @@
1
+ {{- if $.Values.enableDebug }}
2
+ apiVersion: apps/v1
3
+ kind: Deployment
4
+ metadata:
5
+ name: {{ $.Values.app }}-debug
6
+ namespace: {{ include "tpl.namespace" . }}
7
+ annotations:
8
+ kubernetes.io/change-cause: {{ or $.Values.tagContent $.Values.commitSHA }}
9
+ spec:
10
+ strategy:
11
+ type: RollingUpdate
12
+ rollingUpdate:
13
+ maxSurge: 2
14
+ maxUnavailable: 50%
15
+ replicas: 1
16
+ selector:
17
+ matchLabels:
18
+ app: {{ $.Values.app }}
19
+ template:
20
+ metadata:
21
+ labels:
22
+ app: {{ $.Values.app }}
23
+ spec:
24
+ imagePullSecrets:
25
+ - name: {{ $.Values.imagePullSecret }}
26
+ containers:
27
+ - name: server
28
+ imagePullPolicy: Always
29
+ image: "{{ $.Values.image }}"
30
+ resources:
31
+ requests:
32
+ cpu: "0.5"
33
+ memory: "800Mi"
34
+ limits:
35
+ cpu: "4"
36
+ memory: "2G"
37
+ startupProbe:
38
+ initialDelaySeconds: 10
39
+ periodSeconds: 3
40
+ timeoutSeconds: 2
41
+ successThreshold: 1
42
+ failureThreshold: 10
43
+ httpGet:
44
+ path: /heartbeatCheck
45
+ port: {{ $.Values.appPort }}
46
+ readinessProbe:
47
+ initialDelaySeconds: 5
48
+ periodSeconds: 5
49
+ timeoutSeconds: 2
50
+ successThreshold: 1
51
+ failureThreshold: 3
52
+ httpGet:
53
+ path: /heartbeatCheck
54
+ port: {{ $.Values.appPort }}
55
+ env:
56
+ {{ if $.Values.hostPrefix }}
57
+ - name: HOST_PREFIX
58
+ value: "{{ $.Values.hostPrefix }}"
59
+ {{ end }}
60
+ - name: ALIYUN_OSS_INTERNAL
61
+ value: "1"
62
+ - name: ENABLE_DEBUG
63
+ value: "true"
64
+ envFrom:
65
+ - configMapRef:
66
+ name: "app-common-config"
67
+ volumeMounts:
68
+ - mountPath: /var/log
69
+ subPath: {{ $.Values.repoName }}/{{ $.Values.app |replace "airent-web-" "" }}
70
+ name: log
71
+ volumes:
72
+ - name: log
73
+ hostPath:
74
+ path: /var/log
75
+ {{ end }}
@@ -0,0 +1,79 @@
1
+ apiVersion: apps/v1
2
+ kind: Deployment
3
+ metadata:
4
+ name: {{ $.Values.app }}
5
+ namespace: {{ include "tpl.namespace" . }}
6
+ annotations:
7
+ kubernetes.io/change-cause: {{ or $.Values.tagContent $.Values.commitSHA }}
8
+ spec:
9
+ strategy:
10
+ type: RollingUpdate
11
+ rollingUpdate:
12
+ maxSurge: 2
13
+ maxUnavailable: 50%
14
+ replicas: {{ if eq $.Values.envType "prod" }} 6 {{ else }} 1 {{ end }}
15
+ selector:
16
+ matchLabels:
17
+ app: {{ $.Values.app }}
18
+ template:
19
+ metadata:
20
+ labels:
21
+ app: {{ $.Values.app }}
22
+ spec:
23
+ imagePullSecrets:
24
+ - name: {{ $.Values.imagePullSecret }}
25
+ containers:
26
+ - name: server
27
+ imagePullPolicy: Always
28
+ image: "{{ $.Values.image }}"
29
+ resources:
30
+ requests:
31
+ cpu: "0.5"
32
+ memory: "800Mi"
33
+ limits:
34
+ cpu: "4"
35
+ memory: "2G"
36
+ startupProbe:
37
+ initialDelaySeconds: 10
38
+ periodSeconds: 3
39
+ timeoutSeconds: 2
40
+ successThreshold: 1
41
+ failureThreshold: 10
42
+ httpGet:
43
+ path: /heartbeatCheck
44
+ port: {{ $.Values.appPort }}
45
+ readinessProbe:
46
+ initialDelaySeconds: 5
47
+ periodSeconds: 5
48
+ timeoutSeconds: 2
49
+ successThreshold: 1
50
+ failureThreshold: 3
51
+ httpGet:
52
+ path: /heartbeatCheck
53
+ port: {{ $.Values.appPort }}
54
+ livenessProbe:
55
+ initialDelaySeconds: 5
56
+ periodSeconds: 5
57
+ timeoutSeconds: 2
58
+ failureThreshold: 5
59
+ httpGet:
60
+ path: /heartbeatCheck
61
+ port: {{ $.Values.appPort }}
62
+ env:
63
+ {{ if $.Values.hostPrefix }}
64
+ - name: HOST_PREFIX
65
+ value: "{{ $.Values.hostPrefix }}"
66
+ {{ end }}
67
+ - name: ALIYUN_OSS_INTERNAL
68
+ value: "1"
69
+ envFrom:
70
+ - configMapRef:
71
+ name: "app-common-config"
72
+ volumeMounts:
73
+ - mountPath: /var/log
74
+ subPath: {{ $.Values.repoName }}/{{ $.Values.app |replace "airent-web-" "" }}
75
+ name: log
76
+ volumes:
77
+ - name: log
78
+ hostPath:
79
+ path: /var/log
@@ -0,0 +1,16 @@
1
+ # bff对 user的缓存处理为 memoryCache时,同一用户多次请求接口,可能会落到不同的pod返回的用户缓存数据不一致
2
+ # 此处根据IP规则配置,控制同一IP路由的负载均衡 dr 落到固定的同一台pod
3
+ {{- if and (eq $.Values.envType "prod") $.Values.enableDestinationRule }}
4
+ apiVersion: networking.istio.io/v1beta1
5
+ kind: DestinationRule
6
+ metadata:
7
+ name: {{ $.Values.app }}-dr
8
+ namespace: {{ include "tpl.namespace" . }}
9
+ spec:
10
+ host: {{ $.Values.app }}
11
+ trafficPolicy:
12
+ loadBalancer:
13
+ consistentHash:
14
+ useSourceIp: true
15
+ # httpHeaderName: usertoken
16
+ {{ end }}
@@ -0,0 +1,12 @@
1
+ apiVersion: v1
2
+ kind: Service
3
+ metadata:
4
+ name: {{ $.Values.app }}
5
+ namespace: {{ include "tpl.namespace" . }}
6
+ spec:
7
+ selector:
8
+ app: {{ $.Values.app }}
9
+ ports:
10
+ - port: 80
11
+ name: http
12
+ targetPort: {{ $.Values.appPort }}
@@ -0,0 +1,3 @@
1
+ {{- define "tpl.namespace" -}}
2
+ {{ if eq $.Values.envType "dev" }} deployment-dev {{ else if eq $.Values.envType "test" }} deployment-test {{ else if eq $.Values.envType "stage" }} deployment-stage {{ else if eq $.Values.envType "beta" }} deployment-beta {{ else if eq $.Values.envType "prod" }} deployment-prod {{ else if eq $.Values.envType "apitest" }} ci-apitest {{ else }} deployment-test {{ end }}
3
+ {{- end -}}
@@ -0,0 +1,36 @@
1
+ apiVersion: networking.istio.io/v1alpha3
2
+ kind: VirtualService
3
+ metadata:
4
+ name: {{ $.Values.app }}-vs
5
+ namespace: {{ include "tpl.namespace" . }}
6
+ spec:
7
+ hosts:
8
+ {{- $host := (get $.Values.hosts $.Values.envType) }}
9
+ {{- range $host }}
10
+ - "{{ . }}"
11
+ {{- end }}
12
+ gateways:
13
+ {{- range $.Values.gateways }}
14
+ - {{ . }}
15
+ {{- end }}
16
+ http:
17
+ - match:
18
+ - uri:
19
+ prefix: /
20
+ route:
21
+ - destination:
22
+ host: {{ $.Values.app }}
23
+ port:
24
+ number: 80
25
+ corsPolicy:
26
+ allowMethods:
27
+ - GET
28
+ - POST
29
+ - PUT
30
+ - PATCH
31
+ - DELETE
32
+ allowOrigin:
33
+ - eshetang.com
34
+ - zhixiangyao.com
35
+ ---
36
+
@@ -0,0 +1,26 @@
1
+ imagePullSecret: 'docker-image-cr-pull-vpc'
2
+ app: '<<APP_NAME>><<APP_PREFIX>>'
3
+ image: 'xhj-prod-registry-vpc.cn-hangzhou.cr.aliyuncs.com/xhj-image/<<APP_NAME>>:<<CI_COMMIT_SHA>>'
4
+ tagContent: '<<TAG_CONTENT>>'
5
+ commitSHA: '<<CI_COMMIT_SHA>>'
6
+ envType: '<<ENV_TYPE>>'
7
+ hostPrefix: '<<HOST_PREFIX>>'
8
+ # 兼容kibana统一搜集,后期待移除优化
9
+ repoName: '<<REPO_NAME>>'
10
+ appPort: 6003
11
+ # 是否启用DestinationRule配置
12
+ enableDestinationRule: false
13
+ # 是否启用debug部署配置
14
+ enableDebug: false
15
+ hosts:
16
+ test:
17
+ - '<<HOST_PREFIX>>.bff-s.t.eshetang.com'
18
+ - '<<HOST_PREFIX>>.s.t.eshetang.com'
19
+ stage:
20
+ - stage.bff-s.t.eshetang.com
21
+ - stage.s.t.eshetang.com
22
+ prod:
23
+ - bff.eshetang.com
24
+ - s.eshetang.com
25
+ gateways:
26
+ - common-gateway-eshetang