@winner-fed/winner-deploy 3.0.2 → 3.1.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/README.md +16 -16
- package/package.json +1 -1
- package/src/genDockerPackage.js +10 -4
- package/src/{genZipPackage.js → genWebPackage.js} +47 -49
- package/src/see.js +48 -5
- package/src/utils.js +4 -0
- package/src/winner-deploy.js +33 -26
- package/templates/see/{2.x → bash}/deploy.xml +3 -2
- package/templates/see/bash/scripts/afterInstall.sh +3 -0
- package/templates/see/bash/scripts/install.sh +22 -0
- package/templates/see/bash/scripts/uninstall.sh +15 -0
- package/templates/see/docker/Dockerfile +5 -3
- package/templates/see/docker/deploy.xml +1 -1
- package/templates/see/docker/{template/k8s-deploy-res.yaml → k8s-deploy-res.yaml} +2 -2
- package/templates/see/{1.x → python}/deploy.xml +3 -3
- package/templates/see/{1.x → python}/scripts/afterInstall.py +0 -0
- package/templates/see/{1.x → python}/scripts/install.py +0 -0
- package/templates/see/{1.x → python}/scripts/uninstall.py +0 -0
- package/templates/see/{1.x → python}/scripts/utils.py +0 -0
- package/src/GeneratorSeePackage.js +0 -220
- package/templates/see/1.x/scripts/afterInstall.sh +0 -3
- package/templates/see/1.x/scripts/install.sh +0 -9
- package/templates/see/1.x/scripts/uninstall.sh +0 -6
- package/templates/see/2.x/scripts/afterInstall.sh +0 -3
- package/templates/see/2.x/scripts/install.sh +0 -9
- package/templates/see/2.x/scripts/uninstall.sh +0 -6
package/README.md
CHANGED
|
@@ -1,25 +1,22 @@
|
|
|
1
1
|
# winner-deploy
|
|
2
2
|
|
|
3
|
-
## python 版本脚本兼容性问题
|
|
4
|
-
python2 对应 template/1.x
|
|
5
|
-
|
|
6
3
|
## 功能接口说明
|
|
7
4
|
```javscript
|
|
8
5
|
/**
|
|
9
6
|
* 生成 see 平台部署包
|
|
10
|
-
* @param system {string}
|
|
11
|
-
* @param type {string}
|
|
12
|
-
* @param name {string}
|
|
13
|
-
* @param appType {string}
|
|
14
|
-
* @param version {string}
|
|
15
|
-
* @param configName {string} 配置文件名称,不带有 .js, 默认为 config.local
|
|
16
|
-
* @param templateFunc {function} 自定义变量配置文件, 默认为
|
|
7
|
+
* @param options.system {string} 系统类型, SEE 平台的分组是以系统类型字段纬度来的, 默认为 winner-front
|
|
8
|
+
* @param options.type {string} 应用类型, 外框架 - bizframe | 子系统 - subsystem, 默认为 子系统 - subsystem
|
|
9
|
+
* @param options.name {string} 发布物名称
|
|
10
|
+
* @param options.appType {string} 发布物类型, 默认为 应用名称 - name
|
|
11
|
+
* @param options.version {string} 发布包版本
|
|
12
|
+
* @param options.configName {string} 配置文件名称,不带有 .js, 默认为 config.local
|
|
13
|
+
* @param options.templateFunc {function} 自定义变量配置文件, 默认为
|
|
17
14
|
* function () {
|
|
18
15
|
if (type === 'bizframe') {
|
|
19
16
|
return `./dist/config.local.js`;
|
|
20
17
|
}
|
|
21
18
|
}
|
|
22
|
-
* @param variablesFunc {function} deploy.xml模板变量, 可以动态配置, 默认为
|
|
19
|
+
* @param options.variablesFunc {function} deploy.xml模板变量, 可以动态配置, 默认为
|
|
23
20
|
* function () {
|
|
24
21
|
* const context = process.cwd()
|
|
25
22
|
if (type === 'bizframe') {
|
|
@@ -38,12 +35,15 @@ python2 对应 template/1.x
|
|
|
38
35
|
}
|
|
39
36
|
}
|
|
40
37
|
}
|
|
41
|
-
* @param copyFiles {Array<string>} 不包含在 manifest.json 配置的文件,直接拷贝到 see 包里。文件路径是相对于项目根目录的路径+文件名,比如 dist/子包/version.js,那么 copyFiles: ['version.js']
|
|
42
|
-
* @param description {string} 发布包说明
|
|
43
|
-
* @param seePackageName {string} see发布物的包名,也就是 zip 包的命名,默认为 `${system}-${name}-${version}`
|
|
44
|
-
* @param
|
|
38
|
+
* @param options.copyFiles {Array<string>} 不包含在 manifest.json 配置的文件,直接拷贝到 see 包里。文件路径是相对于项目根目录的路径+文件名,比如 dist/子包/version.js,那么 copyFiles: ['version.js']
|
|
39
|
+
* @param options.description {string} 发布包说明
|
|
40
|
+
* @param options.seePackageName {string} see发布物的包名,也就是 zip 包的命名,默认为 `${system}-${name}-${version}`
|
|
41
|
+
* @param options.seePackageType see 平台发布物包的类型,'web'(默认的) | 'docker'(支持容器化部署的SEE发布物)
|
|
42
|
+
* @param options.dockerImage docker 容器化镜像名,seePackageType 为 docker 生效
|
|
43
|
+
* @param options.scriptsType 脚本类型 'python'(默认的) | 'bash'
|
|
44
|
+
* @param cb {function} 回调函数,用于处理在组装 see 包后,可以自定义执行的动作
|
|
45
45
|
*/
|
|
46
|
-
exports.generateSeePackageZip = function generateSeePackageZip({system, type, name, appType, version, configName, templateFunc, variablesFunc, copyFiles, description}, cb) {
|
|
46
|
+
exports.generateSeePackageZip = function generateSeePackageZip({system, type, name, appType, version, configName, templateFunc, variablesFunc, copyFiles, description, seePackageType, dockerImage, scriptsType}, cb) {
|
|
47
47
|
...
|
|
48
48
|
}
|
|
49
49
|
```
|
package/package.json
CHANGED
package/src/genDockerPackage.js
CHANGED
|
@@ -31,13 +31,18 @@ exports.genDockerPackage = function genDockerPackage (seePackageName, options, h
|
|
|
31
31
|
template,
|
|
32
32
|
variables,
|
|
33
33
|
configName: configFileName,
|
|
34
|
-
description
|
|
34
|
+
description,
|
|
35
|
+
dockerImage = version.indexOf('-') > 0 ? `isee1.0-docker-dev-local/${name}` : `isee1.0-docker-release-local/${name}`
|
|
35
36
|
} = options
|
|
36
37
|
fs.ensureDirSync(tmp)
|
|
37
38
|
|
|
38
39
|
// 项目根目录下 Dockerfile 文件
|
|
39
40
|
fs.ensureDirSync('docker')
|
|
40
|
-
|
|
41
|
+
|
|
42
|
+
// 如果项目根目录下已经存在 Dockerfile,则不进行重新生成
|
|
43
|
+
if (!fs.pathExistsSync(path.resolve(process.cwd(), `docker/Dockerfile`))) {
|
|
44
|
+
fs.outputFileSync(path.resolve(process.cwd(), `docker/Dockerfile`), genDockerfile({ name }));
|
|
45
|
+
}
|
|
41
46
|
|
|
42
47
|
// 缺少 scripts 目录会导致 SEE 平台上传发布物报错
|
|
43
48
|
fs.ensureDirSync(`${tmp}/scripts`);
|
|
@@ -70,13 +75,14 @@ exports.genDockerPackage = function genDockerPackage (seePackageName, options, h
|
|
|
70
75
|
variables,
|
|
71
76
|
description,
|
|
72
77
|
web_app_web_service_name: `${name}-web`,
|
|
73
|
-
dockerImage
|
|
78
|
+
dockerImage
|
|
74
79
|
}))
|
|
75
80
|
|
|
76
81
|
if (handler) {
|
|
77
|
-
handler(() => {
|
|
82
|
+
handler((cb) => {
|
|
78
83
|
genZipPackage(seePackageName, tmp, () => {
|
|
79
84
|
rm.sync(tmp)
|
|
85
|
+
typeof cb === 'function' && cb()
|
|
80
86
|
})
|
|
81
87
|
})
|
|
82
88
|
} else {
|
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
const chalk = require('chalk')
|
|
2
1
|
const fs = require('fs-extra')
|
|
3
2
|
const rm = require('rimraf')
|
|
4
|
-
const GeneratorSeePackage = require('./GeneratorSeePackage')
|
|
5
3
|
|
|
6
|
-
const {
|
|
7
|
-
const { genDeployXml, genScripts, genTemplate } = require('./see')
|
|
4
|
+
const { isWinnerProject, isProProject, genZipPackage } = require('./utils')
|
|
5
|
+
const { genDeployXml, genScripts, genTemplate, genDeployXmlBySh, genScriptsBySh } = require('./see')
|
|
8
6
|
|
|
9
7
|
const tmp = 'tmp'
|
|
10
8
|
|
|
@@ -18,6 +16,7 @@ const tmp = 'tmp'
|
|
|
18
16
|
* @property {options.appType} 发布物类型
|
|
19
17
|
* @property {options.version} 发布包版本
|
|
20
18
|
* @property {options.configName} 配置文件名称 winner - config.local pro - sysconfig
|
|
19
|
+
* @property {options.scriptsType} 脚本类型
|
|
21
20
|
* @param handler
|
|
22
21
|
*/
|
|
23
22
|
exports.genSeePackage = function genSeePackage (seePackageName, options, handler) {
|
|
@@ -30,18 +29,11 @@ exports.genSeePackage = function genSeePackage (seePackageName, options, handler
|
|
|
30
29
|
template,
|
|
31
30
|
variables,
|
|
32
31
|
configName: configFileName,
|
|
33
|
-
description
|
|
32
|
+
description,
|
|
33
|
+
scriptsType
|
|
34
34
|
} = options
|
|
35
35
|
fs.ensureDirSync(tmp)
|
|
36
36
|
fs.ensureDirSync(`${tmp}/scripts`)
|
|
37
|
-
fs.outputFileSync(`./${tmp}/scripts/${name}/utils.py`, genScripts('utils'))
|
|
38
|
-
fs.outputFileSync(`./${tmp}/scripts/${name}/install.py`, genScripts('install', { name, type }))
|
|
39
|
-
fs.outputFileSync(`./${tmp}/scripts/${name}/afterInstall.py`, genScripts('afterInstall', { name }))
|
|
40
|
-
fs.outputFileSync(`./${tmp}/scripts/${name}/uninstall.py`, genScripts('uninstall', {
|
|
41
|
-
name,
|
|
42
|
-
type
|
|
43
|
-
}))
|
|
44
|
-
|
|
45
37
|
// 缺少 template 目录会导致 SEE 平台上传发布物报错
|
|
46
38
|
fs.ensureDirSync(`${tmp}/template`)
|
|
47
39
|
if (isWinnerProject()) {
|
|
@@ -56,21 +48,52 @@ exports.genSeePackage = function genSeePackage (seePackageName, options, handler
|
|
|
56
48
|
fs.outputFileSync(`./${tmp}/template/${name}/${configFileName}.js`, template ? genTemplate(template, variables) : '')
|
|
57
49
|
}
|
|
58
50
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
type
|
|
62
|
-
name,
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
51
|
+
if (scriptsType === 'python') {
|
|
52
|
+
fs.outputFileSync(`./${tmp}/scripts/${name}/utils.py`, genScripts('utils'))
|
|
53
|
+
fs.outputFileSync(`./${tmp}/scripts/${name}/install.py`, genScripts('install', { name, type }))
|
|
54
|
+
fs.outputFileSync(`./${tmp}/scripts/${name}/afterInstall.py`, genScripts('afterInstall', { name }))
|
|
55
|
+
fs.outputFileSync(`./${tmp}/scripts/${name}/uninstall.py`, genScripts('uninstall', {
|
|
56
|
+
name,
|
|
57
|
+
type
|
|
58
|
+
}))
|
|
59
|
+
|
|
60
|
+
fs.outputFileSync(`./${tmp}/deploy.xml`, genDeployXml({
|
|
61
|
+
system,
|
|
62
|
+
type,
|
|
63
|
+
name,
|
|
64
|
+
appType,
|
|
65
|
+
version,
|
|
66
|
+
configFileName,
|
|
67
|
+
variables,
|
|
68
|
+
description
|
|
69
|
+
}))
|
|
70
|
+
} else {
|
|
71
|
+
fs.outputFileSync(`./${tmp}/scripts/${name}/install.sh`, genScriptsBySh('install', { name, type }))
|
|
72
|
+
fs.outputFileSync(`./${tmp}/scripts/${name}/afterInstall.sh`, genScriptsBySh('afterInstall', { name }))
|
|
73
|
+
fs.outputFileSync(`./${tmp}/scripts/${name}/uninstall.sh`, genScriptsBySh('uninstall', {
|
|
74
|
+
name,
|
|
75
|
+
type
|
|
76
|
+
}))
|
|
77
|
+
|
|
78
|
+
fs.outputFileSync(`./${tmp}/deploy.xml`, genDeployXmlBySh({
|
|
79
|
+
system,
|
|
80
|
+
type,
|
|
81
|
+
name,
|
|
82
|
+
appType,
|
|
83
|
+
version,
|
|
84
|
+
configFileName,
|
|
85
|
+
variables,
|
|
86
|
+
description
|
|
87
|
+
}))
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
|
|
69
91
|
|
|
70
92
|
if (handler) {
|
|
71
|
-
handler(() => {
|
|
93
|
+
handler((cb) => {
|
|
72
94
|
genZipPackage(seePackageName, tmp, () => {
|
|
73
95
|
rm.sync(tmp)
|
|
96
|
+
typeof cb === 'function' && cb()
|
|
74
97
|
})
|
|
75
98
|
})
|
|
76
99
|
} else {
|
|
@@ -79,28 +102,3 @@ exports.genSeePackage = function genSeePackage (seePackageName, options, handler
|
|
|
79
102
|
})
|
|
80
103
|
}
|
|
81
104
|
}
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* Legacy function
|
|
85
|
-
*/
|
|
86
|
-
exports.genSeePackage2 = function genSeePackage2 (cb) {
|
|
87
|
-
spinner('开始制作 SEE 发布物,这可能需要花点儿时间...').info()
|
|
88
|
-
|
|
89
|
-
const { see, type, name, version, configFileName } = getProjectConfig()
|
|
90
|
-
|
|
91
|
-
new GeneratorSeePackage(
|
|
92
|
-
{ system: see.systemType, type: see.appType || type, name, version, configFileName },
|
|
93
|
-
'./dist/config.local.js',
|
|
94
|
-
see.variables
|
|
95
|
-
)
|
|
96
|
-
.generate((done) => {
|
|
97
|
-
fs.copySync(`./dist`, `./tmp/dist`)
|
|
98
|
-
done()
|
|
99
|
-
})
|
|
100
|
-
.then((packageName) => {
|
|
101
|
-
spinner(
|
|
102
|
-
`发布物 ${chalk.yellowBright(packageName + '.zip')} 制作完成,您可以在 SEE 平台上传并部署应用!`
|
|
103
|
-
).succeed()
|
|
104
|
-
cb && cb()
|
|
105
|
-
})
|
|
106
|
-
}
|
package/src/see.js
CHANGED
|
@@ -5,6 +5,8 @@ const xml = require('xml')
|
|
|
5
5
|
const babel = require('@babel/core')
|
|
6
6
|
const { unEscapeForXML } = require('./utils')
|
|
7
7
|
|
|
8
|
+
const resolveFile = (file) => path.resolve(__dirname, `../templates/see/${file}`)
|
|
9
|
+
|
|
8
10
|
exports.genDeployXml = function genDeployXml ({
|
|
9
11
|
system,
|
|
10
12
|
type,
|
|
@@ -15,7 +17,7 @@ exports.genDeployXml = function genDeployXml ({
|
|
|
15
17
|
variables = [],
|
|
16
18
|
description
|
|
17
19
|
}) {
|
|
18
|
-
const template = fs.readFileSync(
|
|
20
|
+
const template = fs.readFileSync(resolveFile(`python/deploy.xml`))
|
|
19
21
|
|
|
20
22
|
return tpl(template)({
|
|
21
23
|
system,
|
|
@@ -39,7 +41,7 @@ exports.genDeployXml = function genDeployXml ({
|
|
|
39
41
|
}
|
|
40
42
|
|
|
41
43
|
exports.genScripts = function genScripts (name, options) {
|
|
42
|
-
const template = fs.readFileSync(
|
|
44
|
+
const template = fs.readFileSync(resolveFile(`python/scripts/${name}.py`))
|
|
43
45
|
return tpl(template)(options)
|
|
44
46
|
}
|
|
45
47
|
|
|
@@ -117,7 +119,7 @@ exports.genDockerDeployXml = function genDockerDeployXml ({
|
|
|
117
119
|
web_app_web_service_name,
|
|
118
120
|
dockerImage
|
|
119
121
|
}) {
|
|
120
|
-
const template = fs.readFileSync(
|
|
122
|
+
const template = fs.readFileSync(resolveFile(`docker/deploy.xml`))
|
|
121
123
|
|
|
122
124
|
return tpl(template)({
|
|
123
125
|
system,
|
|
@@ -143,7 +145,7 @@ exports.genDockerDeployXml = function genDockerDeployXml ({
|
|
|
143
145
|
}
|
|
144
146
|
|
|
145
147
|
exports.genK8sDeployRes = function genK8sDeployResYaml (options) {
|
|
146
|
-
const template = fs.readFileSync(
|
|
148
|
+
const template = fs.readFileSync(resolveFile(`docker/k8s-deploy-res.yaml`));
|
|
147
149
|
|
|
148
150
|
return tpl(template, {
|
|
149
151
|
interpolate: /{{([\s\S]+?)}}/g
|
|
@@ -151,7 +153,48 @@ exports.genK8sDeployRes = function genK8sDeployResYaml (options) {
|
|
|
151
153
|
}
|
|
152
154
|
|
|
153
155
|
exports.genDockerfile = function genDockerfile (options) {
|
|
154
|
-
const template = fs.readFileSync(
|
|
156
|
+
const template = fs.readFileSync(resolveFile(`docker/Dockerfile`))
|
|
155
157
|
|
|
156
158
|
return tpl(template)(options)
|
|
157
159
|
}
|
|
160
|
+
|
|
161
|
+
// --------------------------------------------------- bash
|
|
162
|
+
exports.genDeployXmlBySh = function genDeployXmlBySh ({
|
|
163
|
+
system,
|
|
164
|
+
type,
|
|
165
|
+
name,
|
|
166
|
+
appType,
|
|
167
|
+
version,
|
|
168
|
+
configFileName = 'config.local',
|
|
169
|
+
variables = [],
|
|
170
|
+
description
|
|
171
|
+
}) {
|
|
172
|
+
const template = fs.readFileSync(resolveFile(`bash/deploy.xml`));
|
|
173
|
+
|
|
174
|
+
return tpl(template)({
|
|
175
|
+
system,
|
|
176
|
+
type,
|
|
177
|
+
name,
|
|
178
|
+
appType,
|
|
179
|
+
version,
|
|
180
|
+
configFileName,
|
|
181
|
+
variables: (() => {
|
|
182
|
+
return variables
|
|
183
|
+
.map((attr) => {
|
|
184
|
+
const defaultValue = attr.default
|
|
185
|
+
delete attr.default
|
|
186
|
+
const xmlVariable = xml({ field: [{ _attr: attr }, defaultValue] })
|
|
187
|
+
return unEscapeForXML(`${xmlVariable}`)
|
|
188
|
+
})
|
|
189
|
+
.join('\n ')
|
|
190
|
+
})(),
|
|
191
|
+
description
|
|
192
|
+
})
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
exports.genScriptsBySh = function genScriptsBySh (name, options) {
|
|
196
|
+
const template = fs.readFileSync(resolveFile(`bash/scripts/${name}.sh`))
|
|
197
|
+
return tpl(template, {
|
|
198
|
+
interpolate: /{{([\s\S]+?)}}/g
|
|
199
|
+
})(options)
|
|
200
|
+
}
|
package/src/utils.js
CHANGED
package/src/winner-deploy.js
CHANGED
|
@@ -5,7 +5,7 @@ const fs = require('fs-extra')
|
|
|
5
5
|
|
|
6
6
|
const context = process.cwd()
|
|
7
7
|
|
|
8
|
-
const { genSeePackage } = require('./
|
|
8
|
+
const { genSeePackage } = require('./genWebPackage')
|
|
9
9
|
const { genDockerPackage } = require('./genDockerPackage')
|
|
10
10
|
|
|
11
11
|
function genManifest (type, name) {
|
|
@@ -67,8 +67,10 @@ function genManifest (type, name) {
|
|
|
67
67
|
* @param copyFiles {Array<string>} 不包含在 manifest.json 配置的文件,直接拷贝到 see 包里。文件路径是相对于项目根目录的路径+文件名,比如 dist/子包/version.js,那么 copyFiles: ['version.js']
|
|
68
68
|
* @param description {string} 发布包说明
|
|
69
69
|
* @param seePackageName {string} see发布物的包名,也就是 zip 包的命名,默认为 `${system}-${name}-${version}`
|
|
70
|
-
* @param cb {function} 回调函数,用于处理在组装 see 包后,压缩成 zip 包前可以自定义执行的动作
|
|
71
70
|
* @param seePackageType see 平台发布物包的类型,'web'(默认的) | 'docker'(支持容器化部署的SEE发布物)
|
|
71
|
+
* @param dockerImage docker 容器化镜像名,seePackageType 为 docker 生效
|
|
72
|
+
* @param scriptsType 脚本类型 'python' | 'bash'
|
|
73
|
+
* @param cb {function} 回调函数,用于处理在组装 see 包后,可以自定义执行的动作
|
|
72
74
|
*/
|
|
73
75
|
exports.generateSeePackageZip = function generateSeePackageZip ({
|
|
74
76
|
system,
|
|
@@ -82,7 +84,9 @@ exports.generateSeePackageZip = function generateSeePackageZip ({
|
|
|
82
84
|
copyFiles,
|
|
83
85
|
description,
|
|
84
86
|
seePackageName,
|
|
85
|
-
seePackageType = 'web'
|
|
87
|
+
seePackageType = 'web',
|
|
88
|
+
dockerImage,
|
|
89
|
+
scriptsType = 'python'
|
|
86
90
|
}, cb) {
|
|
87
91
|
if (!name || !version) {
|
|
88
92
|
throw new Error('应用名称和应用版本不能缺失~')
|
|
@@ -126,18 +130,17 @@ exports.generateSeePackageZip = function generateSeePackageZip ({
|
|
|
126
130
|
configName,
|
|
127
131
|
template: (templateFunc)(),
|
|
128
132
|
variables: (variablesFunc)(),
|
|
129
|
-
description
|
|
133
|
+
description,
|
|
134
|
+
dockerImage
|
|
130
135
|
},
|
|
131
136
|
done => {
|
|
132
137
|
|
|
133
|
-
// 自定义执行的操作
|
|
134
|
-
typeof cb === 'function' && cb()
|
|
135
|
-
|
|
136
|
-
done()
|
|
137
138
|
console.log()
|
|
138
139
|
ora(
|
|
139
140
|
`docker 容器化部署的 SEE 发布物制作完成,您可以在 SEE 平台上传并部署应用。`
|
|
140
141
|
).succeed()
|
|
142
|
+
|
|
143
|
+
done(cb)
|
|
141
144
|
}
|
|
142
145
|
)
|
|
143
146
|
return;
|
|
@@ -157,23 +160,29 @@ exports.generateSeePackageZip = function generateSeePackageZip ({
|
|
|
157
160
|
description
|
|
158
161
|
},
|
|
159
162
|
done => {
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
163
|
+
if (scriptsType === 'python') {
|
|
164
|
+
const { manifest, manifestJson } = genManifest(type, name)
|
|
165
|
+
// 发布物中的源码部分统一放到 source 目录下
|
|
166
|
+
for (const file in manifestJson) {
|
|
167
|
+
if (manifestJson.hasOwnProperty(file)) {
|
|
168
|
+
const { path, dir } = manifestJson[file]
|
|
169
|
+
|
|
170
|
+
fs.ensureDirSync(`./tmp/source/${dir}`)
|
|
171
|
+
fs.copyFileSync(`./dist/${path}`, `./tmp/source/${path}`)
|
|
172
|
+
}
|
|
168
173
|
}
|
|
169
|
-
}
|
|
170
174
|
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
+
fs.outputJSONSync(
|
|
176
|
+
`./tmp/scripts/${name}/conf/${manifest}`,
|
|
177
|
+
manifestJson
|
|
178
|
+
)
|
|
179
|
+
} else {
|
|
180
|
+
// bash
|
|
181
|
+
fs.ensureDirSync(`./tmp/source`)
|
|
182
|
+
fs.copySync(`./dist`, `./tmp/source`)
|
|
183
|
+
}
|
|
175
184
|
|
|
176
|
-
//
|
|
185
|
+
// 自定义拷贝的文件,直接拷贝到 see 包里
|
|
177
186
|
if (Array.isArray(copyFiles) && copyFiles.length) {
|
|
178
187
|
copyFiles.forEach((file) => {
|
|
179
188
|
// 1. 首先先确保文件目录存在,否则创建
|
|
@@ -183,16 +192,14 @@ exports.generateSeePackageZip = function generateSeePackageZip ({
|
|
|
183
192
|
});
|
|
184
193
|
}
|
|
185
194
|
|
|
186
|
-
// 自定义执行的操作
|
|
187
|
-
typeof cb === 'function' && cb()
|
|
188
|
-
|
|
189
|
-
done()
|
|
190
195
|
console.log()
|
|
191
196
|
ora(
|
|
192
197
|
`发布物制作完成,您可以在 SEE 平台上传并部署应用。注意:${chalk.yellow(
|
|
193
198
|
'子系统发布物的安装目录需要指定到具体的应用目录'
|
|
194
199
|
)}。比如/home/hsiar/hsiar-green/html/。\n`
|
|
195
200
|
).succeed()
|
|
201
|
+
|
|
202
|
+
done(cb)
|
|
196
203
|
}
|
|
197
204
|
)
|
|
198
205
|
}
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
<packType describe="包类型" options="pack:全量包;patch:补丁包">pack</packType>
|
|
5
5
|
<systemType describe="系统类型">${ system }</systemType>
|
|
6
6
|
<appName describe="发布物名称">${ name }</appName>
|
|
7
|
-
<appType describe="发布物类型">${
|
|
7
|
+
<appType describe="发布物类型">${ appType }</appType>
|
|
8
8
|
<appDescribe describe="发布包说明">${ description }</appDescribe>
|
|
9
9
|
<version describe="发布包版本">${ version }</version>
|
|
10
10
|
<group>bizframe</group>
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
</basic>
|
|
13
13
|
<globalConfig describe="系统全局配置" />
|
|
14
14
|
<subSystems describe="子系统集合">
|
|
15
|
-
<system id="${ name }" type="" name="${ name }" mode="cluster" front="">
|
|
15
|
+
<system id="${ name }" type="${ type }" name="${ name }" mode="cluster" front="">
|
|
16
16
|
<scale describe="集群规模" />
|
|
17
17
|
<scripts describe="集群脚本集">
|
|
18
18
|
<script name="beforeInstall" path="" describe="安装前处理"/>
|
|
@@ -29,6 +29,7 @@
|
|
|
29
29
|
<variables describe="集群基本参数">
|
|
30
30
|
<field name="user" label="安装用户" type="input">root</field>
|
|
31
31
|
<field name="workspace" label="前端安装目录" type="input" tooltip="IAR上存放前端根目录">/usr/local/nginx/html</field>
|
|
32
|
+
<field name="isSubsystem" label="是否是子系统" type="select" options="false:主系统;true:子系统" required="true" tooltip="默认主系统">false</field>
|
|
32
33
|
${ variables }
|
|
33
34
|
</variables>
|
|
34
35
|
<config path="./${ name }/${ configFileName }.js" encoding="UTF-8"/>
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
#[install]
|
|
3
|
+
# chmod -R 755 .
|
|
4
|
+
# 拷贝前端工程文件到运行目录
|
|
5
|
+
if [ "${isSubsystem}" = "true" ]; then
|
|
6
|
+
# 子系统执行逻辑
|
|
7
|
+
ls -I tmp | xargs rm -rf
|
|
8
|
+
\cp -rf tmp/source/* ${workspace}/../
|
|
9
|
+
else
|
|
10
|
+
# 主系统执行逻辑
|
|
11
|
+
if [ -d "${workspace}/{{name}}" ]; then
|
|
12
|
+
cd "${workspace}/{{name}}"
|
|
13
|
+
ls | grep "manifest." | xargs rm -rf
|
|
14
|
+
rm -rf frame common static sysconfig.js index.html
|
|
15
|
+
cd -
|
|
16
|
+
fi
|
|
17
|
+
mkdir -p ${workspace}/{{name}}
|
|
18
|
+
\cp -rf tmp/source/* ${workspace}/{{name}}
|
|
19
|
+
fi
|
|
20
|
+
# 扫尾清除
|
|
21
|
+
rm -rf tmp
|
|
22
|
+
exit 0
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
#[uninstall]
|
|
3
|
+
# 删除前端工程文件
|
|
4
|
+
if [ "${isSubsystem}" = "true" ]; then
|
|
5
|
+
# 子系统执行逻辑
|
|
6
|
+
if [ -d "${workspace}" ]; then
|
|
7
|
+
rm -rf ${workspace}
|
|
8
|
+
fi
|
|
9
|
+
else
|
|
10
|
+
# 主系统执行逻辑
|
|
11
|
+
if [ -d "${workspace}/{{name}}" ]; then
|
|
12
|
+
rm -rf ${workspace}/{{name}}
|
|
13
|
+
fi
|
|
14
|
+
fi
|
|
15
|
+
exit 0
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
# Dockerfile用于生成应用镜像,非特殊情况请勿修改
|
|
2
2
|
FROM package.hundsun.com/public-docker-local/freestyle/hswealth/nginx:1.18.0-alpine-see
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
COPY dist /usr/share/nginx/html/hui-pro
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
RUN chmod +x /etc/nginx/* && \
|
|
7
|
+
chmod +x /usr/share/nginx/html/* &&\
|
|
8
|
+
chmod +x /usr/local/bin/*
|
|
7
9
|
|
|
8
|
-
|
|
10
|
+
WORKDIR /usr/share/nginx/html
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
<system id="${ name }" type="" name="${ name }" mode="cluster" front="">
|
|
16
16
|
<variables describe="集群基本参数">
|
|
17
17
|
<field name="user" label="安装用户" type="input">root</field>
|
|
18
|
-
<field name="workspace" label="前端安装目录" type="
|
|
18
|
+
<field name="workspace" label="前端安装目录" type="input" tooltip="IAR上存放前端目录">/home/hsiar/hsiar-green/html</field>
|
|
19
19
|
|
|
20
20
|
<!-- K8S部署配置 -->
|
|
21
21
|
<field name="division_k8s" label="K8S部署配置" type="division" fold="false">
|
|
@@ -57,7 +57,7 @@ spec:
|
|
|
57
57
|
httpGet:
|
|
58
58
|
scheme: HTTP
|
|
59
59
|
port: 80
|
|
60
|
-
path: /
|
|
60
|
+
path: /{{ configFileName }}.js
|
|
61
61
|
initialDelaySeconds: 5
|
|
62
62
|
periodSeconds: 3
|
|
63
63
|
timeoutSeconds: 3
|
|
@@ -67,7 +67,7 @@ spec:
|
|
|
67
67
|
httpGet:
|
|
68
68
|
scheme: HTTP
|
|
69
69
|
port: 80
|
|
70
|
-
path: /
|
|
70
|
+
path: /{{ configFileName }}.js
|
|
71
71
|
initialDelaySeconds: 5
|
|
72
72
|
periodSeconds: 3
|
|
73
73
|
timeoutSeconds: 3
|
|
@@ -8,12 +8,12 @@
|
|
|
8
8
|
<appDescribe describe="发布包说明">${ description }</appDescribe>
|
|
9
9
|
<version describe="发布包版本">${ version }</version>
|
|
10
10
|
<group>bizframe</group>
|
|
11
|
-
<packInEffect describe="影响的主包(只有补丁需要配置,填写主包的版本号)"/>
|
|
11
|
+
<packInEffect describe="影响的主包(只有补丁需要配置,填写主包的版本号)" />
|
|
12
12
|
</basic>
|
|
13
|
-
<globalConfig describe="系统全局配置"/>
|
|
13
|
+
<globalConfig describe="系统全局配置" />
|
|
14
14
|
<subSystems describe="子系统集合">
|
|
15
15
|
<system id="${ name }" type="${ type }" name="${ name }" mode="cluster" front="">
|
|
16
|
-
<scale describe="集群规模"/>
|
|
16
|
+
<scale describe="集群规模" />
|
|
17
17
|
<scripts describe="集群脚本集">
|
|
18
18
|
<script name="beforeInstall" path="" describe="安装前处理"/>
|
|
19
19
|
<script name="install" path="./scripts/${ name }/install.py" describe="部署"/>
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -1,220 +0,0 @@
|
|
|
1
|
-
const fs = require('fs-extra')
|
|
2
|
-
const path = require('path')
|
|
3
|
-
const tpl = require('lodash.template')
|
|
4
|
-
const xml = require('xml')
|
|
5
|
-
const babel = require('@babel/core')
|
|
6
|
-
const archiver = require('archiver')
|
|
7
|
-
const rm = require('rimraf')
|
|
8
|
-
const { unEscapeForXML, isProProject } = require('./utils')
|
|
9
|
-
const resolve = (file) => path.resolve(__dirname, `../templates/see/2.x${file}`)
|
|
10
|
-
|
|
11
|
-
const TypesSupported = ['input', 'select', 'switch', 'smallfile', 'table']
|
|
12
|
-
|
|
13
|
-
const tmp = 'tmp'
|
|
14
|
-
|
|
15
|
-
module.exports = class Generator {
|
|
16
|
-
constructor (packageInfo, sysconfig = './dist/config.local.js', variables = []) {
|
|
17
|
-
const {
|
|
18
|
-
system = 'winner-front',
|
|
19
|
-
type = 'app',
|
|
20
|
-
name = '',
|
|
21
|
-
version = '1.0.0',
|
|
22
|
-
configFileName = 'config.local'
|
|
23
|
-
} = packageInfo
|
|
24
|
-
|
|
25
|
-
this.packageInfo = {
|
|
26
|
-
system,
|
|
27
|
-
type,
|
|
28
|
-
name,
|
|
29
|
-
version,
|
|
30
|
-
configFileName
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
this.templateFile = sysconfig
|
|
34
|
-
this.templateVariables = variables
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
generate (handler, packageName) {
|
|
38
|
-
return new Promise((resolve, reject) => {
|
|
39
|
-
this.packageName = packageName || this.packageInfo.name + '-' + Date.now()
|
|
40
|
-
|
|
41
|
-
fs.ensureDirSync(tmp)
|
|
42
|
-
|
|
43
|
-
try {
|
|
44
|
-
this.genDeployXml()
|
|
45
|
-
this.genScripts()
|
|
46
|
-
this.genTemplate()
|
|
47
|
-
|
|
48
|
-
if (handler) {
|
|
49
|
-
handler(() => this.genPackage(() => resolve(this.packageName)))
|
|
50
|
-
} else {
|
|
51
|
-
this.genPackage(() => resolve(this.packageName))
|
|
52
|
-
}
|
|
53
|
-
} catch (error) {
|
|
54
|
-
return reject(error)
|
|
55
|
-
}
|
|
56
|
-
})
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
genDeployXml () {
|
|
60
|
-
fs.outputFileSync(
|
|
61
|
-
`./${tmp}/deploy.xml`,
|
|
62
|
-
tpl(fs.readFileSync(resolve('/deploy.xml')))({
|
|
63
|
-
...this.packageInfo,
|
|
64
|
-
variables: this.templateVariables
|
|
65
|
-
.map((attr) => this.genXmlField(attr))
|
|
66
|
-
.join('\n ')
|
|
67
|
-
})
|
|
68
|
-
)
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
genXmlField (attr) {
|
|
72
|
-
const genCommonField = (attr) => {
|
|
73
|
-
const { type } = attr
|
|
74
|
-
if (!TypesSupported.includes(type)) return ''
|
|
75
|
-
let {
|
|
76
|
-
label,
|
|
77
|
-
name,
|
|
78
|
-
tooltip = '',
|
|
79
|
-
visible = 'true',
|
|
80
|
-
required = 'false',
|
|
81
|
-
fixed = 'false',
|
|
82
|
-
options = '',
|
|
83
|
-
default: defaultValue
|
|
84
|
-
} = attr
|
|
85
|
-
|
|
86
|
-
if (type === 'table') {
|
|
87
|
-
let { keys = [], columns } = attr
|
|
88
|
-
|
|
89
|
-
// 原来这个字段是 keys,不太好理解,换成 columns,
|
|
90
|
-
// 需要处理兼容问题
|
|
91
|
-
columns = columns || keys
|
|
92
|
-
|
|
93
|
-
defaultValue = columns.map((attr) => genCommonField(attr)).join('\n ')
|
|
94
|
-
} else {
|
|
95
|
-
defaultValue = [defaultValue]
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
const xmlVariable = xml({
|
|
99
|
-
field: [{
|
|
100
|
-
_attr: {
|
|
101
|
-
type,
|
|
102
|
-
label,
|
|
103
|
-
name,
|
|
104
|
-
tooltip,
|
|
105
|
-
visible,
|
|
106
|
-
required,
|
|
107
|
-
fixed,
|
|
108
|
-
options
|
|
109
|
-
}
|
|
110
|
-
}, defaultValue].concat(
|
|
111
|
-
defaultValue
|
|
112
|
-
)
|
|
113
|
-
})
|
|
114
|
-
|
|
115
|
-
return unEscapeForXML(`${xmlVariable}`)
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
return genCommonField(attr)
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
genScripts () {
|
|
122
|
-
fs.ensureDirSync(`${tmp}/scripts`)
|
|
123
|
-
fs.outputFileSync(
|
|
124
|
-
`./${tmp}/scripts/${this.packageInfo.name}/install.sh`,
|
|
125
|
-
tpl(fs.readFileSync(resolve('/scripts/install.sh')))(this.packageInfo)
|
|
126
|
-
)
|
|
127
|
-
fs.outputFileSync(
|
|
128
|
-
`./${tmp}/scripts/${this.packageInfo.name}/uninstall.sh`,
|
|
129
|
-
tpl(fs.readFileSync(resolve('/scripts/uninstall.sh')))(this.packageInfo)
|
|
130
|
-
)
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
genTemplate () {
|
|
134
|
-
const { templateFile, templateVariables } = this
|
|
135
|
-
let { code } = babel.transformFileSync(templateFile, {
|
|
136
|
-
babelrc: false,
|
|
137
|
-
plugins: [
|
|
138
|
-
function seeTemplatePlugin () {
|
|
139
|
-
return {
|
|
140
|
-
visitor: {
|
|
141
|
-
Literal (path) {
|
|
142
|
-
if (path.parentPath.isProperty()) {
|
|
143
|
-
const _match = templateVariables.find(
|
|
144
|
-
(variable) => path.parentPath.get('key').node.name === variable.name
|
|
145
|
-
)
|
|
146
|
-
if (_match) {
|
|
147
|
-
if (path.isStringLiteral()) {
|
|
148
|
-
path.node.value = `$\{${_match.name}\}`
|
|
149
|
-
return
|
|
150
|
-
}
|
|
151
|
-
if (path.isBooleanLiteral()) {
|
|
152
|
-
path.node.type = 'StringLiteral'
|
|
153
|
-
path.node.value = `[NO_QUOTATION_MARKS]$\{${_match.name}\}[NO_QUOTATION_MARKS]`
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
},
|
|
158
|
-
ArrayExpression (path) {
|
|
159
|
-
if (path.parentPath.isProperty()) {
|
|
160
|
-
const _match = templateVariables.find(
|
|
161
|
-
(variable) => path.parentPath.get('key').node.name === variable.name
|
|
162
|
-
)
|
|
163
|
-
if (_match) {
|
|
164
|
-
let value = ''
|
|
165
|
-
|
|
166
|
-
// 目前只支持 [{}, {}] 这种形式的 table
|
|
167
|
-
// keys 表示 Object 元素的 key,value 目前只支持 String 类型
|
|
168
|
-
let { keys = [], columns } = _match
|
|
169
|
-
// 原来这个字段是 keys,不太好理解,换成 columns,需要处理兼容问题
|
|
170
|
-
columns = columns || keys
|
|
171
|
-
if (columns && columns.length) {
|
|
172
|
-
columns.forEach((item) => {
|
|
173
|
-
value += `${item.name}: '$row.${item.name}',` // 双引号会被转义
|
|
174
|
-
})
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
path.node.type = 'StringLiteral'
|
|
178
|
-
path.node.value = `[NO_QUOTATION_MARKS][#foreach($row in $${_match.name}) {${value}}, #end][NO_QUOTATION_MARKS]`
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
],
|
|
186
|
-
retainLines: true
|
|
187
|
-
})
|
|
188
|
-
|
|
189
|
-
// BooleanLiteral 需要在模版中去掉引号
|
|
190
|
-
code = code.replace(/"\[NO_QUOTATION_MARKS](.*)\[NO_QUOTATION_MARKS]"/g, '$1')
|
|
191
|
-
|
|
192
|
-
fs.ensureDirSync(`${tmp}/template`)
|
|
193
|
-
if (isProProject()) {
|
|
194
|
-
fs.outputFileSync(`./${tmp}/template/${this.packageInfo.name}/sysconfig.js`, code)
|
|
195
|
-
return
|
|
196
|
-
}
|
|
197
|
-
fs.outputFileSync(`./${tmp}/template/${this.packageInfo.name}/config.local.js`, code)
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
genPackage (cb) {
|
|
201
|
-
const output = fs.createWriteStream(`${this.packageName}.zip`)
|
|
202
|
-
|
|
203
|
-
output.on('close', function() {
|
|
204
|
-
rm.sync(tmp)
|
|
205
|
-
cb && cb()
|
|
206
|
-
})
|
|
207
|
-
|
|
208
|
-
const archive = archiver('zip', { zlib: { level: 9 } }) // Sets the compression level.
|
|
209
|
-
|
|
210
|
-
archive.on('error', function(error) {
|
|
211
|
-
console.error()
|
|
212
|
-
console.error(error.stack || error)
|
|
213
|
-
error.details && console.error(error.details)
|
|
214
|
-
})
|
|
215
|
-
|
|
216
|
-
archive.pipe(output)
|
|
217
|
-
archive.directory(tmp, false)
|
|
218
|
-
archive.finalize()
|
|
219
|
-
}
|
|
220
|
-
}
|