@cloudbase/cli 1.12.7-alpha.3 → 2.0.1
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/bin/tcb.js +6 -4
- package/lib/commands/run/create.js +6 -1
- package/lib/commands/run/delete.js +6 -1
- package/lib/commands/run/image/common.js +1 -1
- package/lib/commands/run/image/delete.js +5 -0
- package/lib/commands/run/image/download.js +5 -0
- package/lib/commands/run/image/list.js +5 -0
- package/lib/commands/run/image/upload.js +5 -0
- package/lib/commands/run/index.js +1 -0
- package/lib/commands/run/list.js +7 -1
- package/lib/commands/run/service/config.js +112 -0
- package/lib/commands/run/service/create.js +140 -0
- package/lib/commands/run/service/deploy.js +145 -0
- package/lib/commands/run/service/index.js +21 -0
- package/lib/commands/run/service/list.js +115 -0
- package/lib/commands/run/service/update.js +132 -0
- package/lib/commands/run/version/common.js +1 -1
- package/lib/commands/run/version/create.js +5 -0
- package/lib/commands/run/version/delete.js +5 -0
- package/lib/commands/run/version/list.js +5 -0
- package/lib/commands/run/version/modify.js +5 -0
- package/lib/commands/run/version/update.js +5 -0
- package/lib/constant.js +20 -1
- package/lib/help.js +40 -38
- package/lib/run/index.js +1 -0
- package/lib/run/service/common.js +163 -0
- package/lib/run/service/config.js +70 -0
- package/lib/run/service/create.js +67 -0
- package/lib/run/service/deployPackage.js +89 -0
- package/lib/run/service/index.js +23 -0
- package/lib/run/service/list.js +31 -0
- package/lib/run/service/showLogs.js +116 -0
- package/lib/run/service/update.js +83 -0
- package/lib/utils/checkTcbrEnv.js +74 -0
- package/lib/utils/commonParamsCheck.js +48 -0
- package/lib/utils/index.js +3 -0
- package/lib/utils/net/http-request.js +4 -4
- package/lib/utils/tcbrApi/callTcbrApi.js +38 -0
- package/lib/utils/tcbrApi/index.js +17 -0
- package/lib/utils/tcbrApi/tcbr-cloud-api/cloud-api-service.js +268 -0
- package/lib/utils/tcbrApi/tcbr-cloud-api/error.js +17 -0
- package/lib/utils/tcbrApi/tcbr-cloud-api/index.js +17 -0
- package/lib/utils/tcbrApi/tcbr-cloud-api/request.js +40 -0
- package/lib/utils/tcbrApi/tcbr-cloud-api-request.js +61 -0
- package/lib/utils/validator.js +32 -1
- package/package.json +88 -88
- package/src/commands/run/create.ts +9 -2
- package/src/commands/run/delete.ts +8 -2
- package/src/commands/run/image/common.ts +1 -1
- package/src/commands/run/image/delete.ts +8 -1
- package/src/commands/run/image/download.ts +7 -1
- package/src/commands/run/image/list.ts +7 -2
- package/src/commands/run/image/upload.ts +8 -1
- package/src/commands/run/index.ts +2 -1
- package/src/commands/run/list.ts +11 -3
- package/src/commands/run/service/config.ts +81 -0
- package/src/commands/run/service/create.ts +118 -0
- package/src/commands/run/service/deploy.ts +121 -0
- package/src/commands/run/service/index.ts +5 -0
- package/src/commands/run/service/list.ts +94 -0
- package/src/commands/run/service/update.ts +104 -0
- package/src/commands/run/version/common.ts +1 -1
- package/src/commands/run/version/create.ts +8 -1
- package/src/commands/run/version/delete.ts +8 -2
- package/src/commands/run/version/list.ts +7 -1
- package/src/commands/run/version/modify.ts +8 -1
- package/src/commands/run/version/update.ts +8 -1
- package/src/constant.ts +35 -1
- package/src/help.ts +50 -48
- package/src/run/index.ts +2 -1
- package/src/run/service/common.ts +206 -0
- package/src/run/service/config.ts +77 -0
- package/src/run/service/create.ts +52 -0
- package/src/run/service/deployPackage.ts +65 -0
- package/src/run/service/index.ts +7 -0
- package/src/run/service/list.ts +29 -0
- package/src/run/service/showLogs.ts +98 -0
- package/src/run/service/update.ts +81 -0
- package/src/types.ts +128 -2
- package/src/utils/checkTcbrEnv.ts +67 -0
- package/src/utils/commonParamsCheck.ts +65 -0
- package/src/utils/index.ts +5 -1
- package/src/utils/net/http-request.ts +1 -1
- package/src/utils/tcbrApi/callTcbrApi.ts +28 -0
- package/src/utils/tcbrApi/index.ts +1 -0
- package/src/utils/tcbrApi/tcbr-cloud-api/cloud-api-service.ts +363 -0
- package/src/utils/tcbrApi/tcbr-cloud-api/error.ts +30 -0
- package/src/utils/tcbrApi/tcbr-cloud-api/index.ts +1 -0
- package/src/utils/tcbrApi/tcbr-cloud-api/request.ts +28 -0
- package/src/utils/tcbrApi/tcbr-cloud-api-request.ts +66 -0
- package/src/utils/validator.ts +64 -32
- package/types/commands/run/index.d.ts +1 -0
- package/types/commands/run/service/config.d.ts +14 -0
- package/types/commands/run/service/create.d.ts +13 -0
- package/types/commands/run/service/deploy.d.ts +13 -0
- package/types/commands/run/service/index.d.ts +5 -0
- package/types/commands/run/service/list.d.ts +13 -0
- package/types/commands/run/service/update.d.ts +13 -0
- package/types/constant.d.ts +18 -0
- package/types/run/index.d.ts +1 -0
- package/types/run/service/common.d.ts +32 -0
- package/types/run/service/config.d.ts +23 -0
- package/types/run/service/create.d.ts +7 -0
- package/types/run/service/deployPackage.d.ts +11 -0
- package/types/run/service/index.d.ts +7 -0
- package/types/run/service/list.d.ts +2 -0
- package/types/run/service/showLogs.d.ts +2 -0
- package/types/run/service/update.d.ts +2 -0
- package/types/types.d.ts +116 -2
- package/types/utils/checkTcbrEnv.d.ts +3 -0
- package/types/utils/commonParamsCheck.d.ts +3 -0
- package/types/utils/index.d.ts +3 -0
- package/types/utils/tcbrApi/callTcbrApi.d.ts +1 -0
- package/types/utils/tcbrApi/index.d.ts +1 -0
- package/types/utils/tcbrApi/tcbr-cloud-api/cloud-api-service.d.ts +51 -0
- package/types/utils/tcbrApi/tcbr-cloud-api/error.d.ts +20 -0
- package/types/utils/tcbrApi/tcbr-cloud-api/index.d.ts +1 -0
- package/types/utils/tcbrApi/tcbr-cloud-api/request.d.ts +4 -0
- package/types/utils/tcbrApi/tcbr-cloud-api-request.d.ts +9 -0
- package/types/utils/validator.d.ts +4 -0
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
15
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
16
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
17
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
18
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
19
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
20
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
+
exports.ListServiceTcbr = void 0;
|
|
25
|
+
const common_1 = require("../../common");
|
|
26
|
+
const decorators_1 = require("../../../decorators");
|
|
27
|
+
const run_1 = require("../../../run");
|
|
28
|
+
const utils_1 = require("../../../utils");
|
|
29
|
+
const checkTcbrEnv_1 = require("../../../utils/checkTcbrEnv");
|
|
30
|
+
let ListServiceTcbr = class ListServiceTcbr extends common_1.Command {
|
|
31
|
+
get options() {
|
|
32
|
+
return {
|
|
33
|
+
cmd: 'run',
|
|
34
|
+
childCmd: 'service:list',
|
|
35
|
+
options: [
|
|
36
|
+
{
|
|
37
|
+
flags: '-e, --envId <envId>',
|
|
38
|
+
desc: '环境 Id'
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
flags: '-s, --serviceName <serviceName>',
|
|
42
|
+
desc: '服务名'
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
flags: '--json',
|
|
46
|
+
desc: '以 JSON 形式展示结果'
|
|
47
|
+
}
|
|
48
|
+
],
|
|
49
|
+
desc: '展示环境下服务信息'
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
execute(options) {
|
|
53
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
54
|
+
let { envId, serviceName = '' } = options;
|
|
55
|
+
let envCheckType = yield (0, checkTcbrEnv_1.checkTcbrEnv)(envId, true);
|
|
56
|
+
if (envCheckType !== 0) {
|
|
57
|
+
(0, checkTcbrEnv_1.logEnvCheck)(envId, envCheckType);
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
const loading = (0, utils_1.loadingFactory)();
|
|
61
|
+
const head = ['服务名称', '状态', '公网访问', '创建时间', '更新时间'];
|
|
62
|
+
loading.start('正在获取服务列表');
|
|
63
|
+
const serverList = yield (0, run_1.listService)({
|
|
64
|
+
envId: envId
|
|
65
|
+
});
|
|
66
|
+
loading.stop();
|
|
67
|
+
const specificServer = serverList.filter(serverItem => serverItem.ServerName === serviceName);
|
|
68
|
+
if (options.json) {
|
|
69
|
+
console.log(JSON.stringify({
|
|
70
|
+
code: 0,
|
|
71
|
+
errmsg: 'success',
|
|
72
|
+
data: specificServer.length ?
|
|
73
|
+
specificServer
|
|
74
|
+
: serverList
|
|
75
|
+
}, null, 2));
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
if (!serverList.length) {
|
|
79
|
+
console.log('当前环境下没有服务');
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
let tableData;
|
|
83
|
+
if (specificServer.length) {
|
|
84
|
+
tableData = [[
|
|
85
|
+
specificServer[0].ServerName,
|
|
86
|
+
specificServer[0].Status,
|
|
87
|
+
`是 ${(0, utils_1.genClickableLink)(specificServer[0].DefaultDomainName)}`,
|
|
88
|
+
specificServer[0].CreatedTime,
|
|
89
|
+
specificServer[0].UpdateTime
|
|
90
|
+
]];
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
tableData = serverList.map(serverItem => [
|
|
94
|
+
serverItem.ServerName,
|
|
95
|
+
serverItem.Status,
|
|
96
|
+
`是 ${(0, utils_1.genClickableLink)(serverItem.DefaultDomainName)}`,
|
|
97
|
+
serverItem.CreatedTime,
|
|
98
|
+
serverItem.UpdateTime
|
|
99
|
+
]);
|
|
100
|
+
}
|
|
101
|
+
(0, utils_1.printHorizontalTable)(head, tableData);
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
__decorate([
|
|
106
|
+
(0, decorators_1.InjectParams)(),
|
|
107
|
+
__param(0, (0, decorators_1.ArgsOptions)()),
|
|
108
|
+
__metadata("design:type", Function),
|
|
109
|
+
__metadata("design:paramtypes", [Object]),
|
|
110
|
+
__metadata("design:returntype", Promise)
|
|
111
|
+
], ListServiceTcbr.prototype, "execute", null);
|
|
112
|
+
ListServiceTcbr = __decorate([
|
|
113
|
+
(0, common_1.ICommand)()
|
|
114
|
+
], ListServiceTcbr);
|
|
115
|
+
exports.ListServiceTcbr = ListServiceTcbr;
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
15
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
16
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
17
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
18
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
19
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
20
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
+
exports.UpdateServiceTcbr = void 0;
|
|
25
|
+
const common_1 = require("../../common");
|
|
26
|
+
const decorators_1 = require("../../../decorators");
|
|
27
|
+
const run_1 = require("../../../run");
|
|
28
|
+
const utils_1 = require("../../../utils");
|
|
29
|
+
let UpdateServiceTcbr = class UpdateServiceTcbr extends common_1.Command {
|
|
30
|
+
get options() {
|
|
31
|
+
return {
|
|
32
|
+
cmd: 'run',
|
|
33
|
+
childCmd: 'service:deploy',
|
|
34
|
+
options: [
|
|
35
|
+
{
|
|
36
|
+
flags: '--noConfirm',
|
|
37
|
+
desc: '发布前是否跳过二次确认'
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
flags: '--override',
|
|
41
|
+
desc: '缺省的参数是否沿用旧版本配置'
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
flags: '-e, --envId <envId>',
|
|
45
|
+
desc: '环境 Id,必填'
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
flags: '-s, --serviceName <serviceName>',
|
|
49
|
+
desc: '服务名,必填'
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
flags: '--path <path>',
|
|
53
|
+
desc: '本地代码根目录'
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
flags: '--cpu <cpu>',
|
|
57
|
+
desc: '单一实例cpu规格,默认0.5'
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
flags: '--mem <mem>',
|
|
61
|
+
desc: '单一实例内存规格,默认1'
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
flags: '--minNum <minNum>',
|
|
65
|
+
desc: '最小副本数,默认0'
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
flags: '--maxNum <maxNum>',
|
|
69
|
+
desc: '最大副本数,默认50,不能大于50'
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
flags: '--policyDetails <policyDetails>',
|
|
73
|
+
desc: '扩缩容配置,格式为条件类型=条件比例(%),多个条件之间用&隔开,内存条件为mem,cpu条件为cpu,默认内存>60% 或 CPU>60%,即cpu=60&mem=60'
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
flags: '--customLogs <customLogs>',
|
|
77
|
+
desc: '日志采集路径,默认stdout'
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
flags: '--envParams <envParams>',
|
|
81
|
+
desc: '环境变量,格式为xx=a&yy=b,默认为空'
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
flags: '--containerPort <containerPort>',
|
|
85
|
+
desc: '监听端口,必填'
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
flags: '--remark <remark>',
|
|
89
|
+
desc: '版本备注,默认为空'
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
flags: '--dockerfile <dockerfile>',
|
|
93
|
+
desc: 'Dockerfile文件名,默认为 Dockerfile'
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
flags: '--library_image <library_image>',
|
|
97
|
+
desc: '线上镜像仓库的 tag'
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
flags: '--image <image>',
|
|
101
|
+
desc: '镜像标签或ID'
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
flags: '--json',
|
|
105
|
+
desc: '以 JSON 形式展示结果'
|
|
106
|
+
}
|
|
107
|
+
],
|
|
108
|
+
desc: '指定环境和已存在的服务,发布新的应用'
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
execute(options) {
|
|
112
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
113
|
+
let envCheckType = yield (0, utils_1.checkTcbrEnv)(options.envId, true);
|
|
114
|
+
if (envCheckType !== 0) {
|
|
115
|
+
(0, utils_1.logEnvCheck)(options.envId, envCheckType);
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
yield (0, run_1.updateTcbrService)(options);
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
__decorate([
|
|
123
|
+
(0, decorators_1.InjectParams)(),
|
|
124
|
+
__param(0, (0, decorators_1.ArgsOptions)()),
|
|
125
|
+
__metadata("design:type", Function),
|
|
126
|
+
__metadata("design:paramtypes", [Object]),
|
|
127
|
+
__metadata("design:returntype", Promise)
|
|
128
|
+
], UpdateServiceTcbr.prototype, "execute", null);
|
|
129
|
+
UpdateServiceTcbr = __decorate([
|
|
130
|
+
(0, common_1.ICommand)()
|
|
131
|
+
], UpdateServiceTcbr);
|
|
132
|
+
exports.UpdateServiceTcbr = UpdateServiceTcbr;
|
|
@@ -115,6 +115,11 @@ let CreateVersion = class CreateVersion extends common_1.Command {
|
|
|
115
115
|
}
|
|
116
116
|
execute(envId, options) {
|
|
117
117
|
return __awaiter(this, void 0, void 0, function* () {
|
|
118
|
+
let envCheckType = yield (0, utils_1.checkTcbrEnv)(options.envId, false);
|
|
119
|
+
if (envCheckType !== 0) {
|
|
120
|
+
(0, utils_1.logEnvCheck)(envId, envCheckType);
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
118
123
|
let { serviceName = '', path: _path = '', repo: _repo = '', image: _image = '', port: _port = '80', flow: _flow = '0', remark: _remark = '', cpu: _cpu = '0.5', mem: _mem = '1', copy: _copy = '0~50', policy: _policy = 'cpu|60', dockerfile: _dockerfile = 'Dockerfile', log: _log = 'stdout', delay: _delay = '2', env: _env = '' } = options;
|
|
119
124
|
if (!serviceName) {
|
|
120
125
|
throw new error_1.CloudBaseError('必须输入 serviceName');
|
|
@@ -47,6 +47,11 @@ let DeleteVersion = class DeleteVersion extends common_1.Command {
|
|
|
47
47
|
}
|
|
48
48
|
execute(envId, options) {
|
|
49
49
|
return __awaiter(this, void 0, void 0, function* () {
|
|
50
|
+
let envCheckType = yield (0, utils_1.checkTcbrEnv)(options.envId, false);
|
|
51
|
+
if (envCheckType !== 0) {
|
|
52
|
+
(0, utils_1.logEnvCheck)(envId, envCheckType);
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
50
55
|
let { serviceName = '', versionName = '' } = options;
|
|
51
56
|
if (versionName.length === 0 || serviceName.length === 0) {
|
|
52
57
|
throw new error_1.CloudBaseError('必须输入 serviceName 和 versionName');
|
|
@@ -55,6 +55,11 @@ let ListVersion = class ListVersion extends common_1.Command {
|
|
|
55
55
|
}
|
|
56
56
|
execute(envId, options) {
|
|
57
57
|
return __awaiter(this, void 0, void 0, function* () {
|
|
58
|
+
let envCheckType = yield (0, utils_1.checkTcbrEnv)(options.envId, false);
|
|
59
|
+
if (envCheckType !== 0) {
|
|
60
|
+
(0, utils_1.logEnvCheck)(envId, envCheckType);
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
58
63
|
let { limit = 20, offset = 0, serviceName = '' } = options;
|
|
59
64
|
limit = Number(limit);
|
|
60
65
|
offset = Number(offset);
|
|
@@ -110,6 +110,11 @@ let ModifyVersion = class ModifyVersion extends common_1.Command {
|
|
|
110
110
|
}
|
|
111
111
|
execute(envId, options) {
|
|
112
112
|
return __awaiter(this, void 0, void 0, function* () {
|
|
113
|
+
let envCheckType = yield (0, utils_1.checkTcbrEnv)(options.envId, false);
|
|
114
|
+
if (envCheckType !== 0) {
|
|
115
|
+
(0, utils_1.logEnvCheck)(envId, envCheckType);
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
113
118
|
let { serviceName = '', traffic: _traffic = 'FLOW' } = options;
|
|
114
119
|
if (serviceName.length === 0)
|
|
115
120
|
throw new error_1.CloudBaseError('请填入有效云托管服务名');
|
|
@@ -134,6 +134,11 @@ let UpdateVersion = class UpdateVersion extends common_1.Command {
|
|
|
134
134
|
}
|
|
135
135
|
execute(envId, options) {
|
|
136
136
|
return __awaiter(this, void 0, void 0, function* () {
|
|
137
|
+
let envCheckType = yield (0, utils_1.checkTcbrEnv)(options.envId, false);
|
|
138
|
+
if (envCheckType !== 0) {
|
|
139
|
+
(0, utils_1.logEnvCheck)(envId, envCheckType);
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
137
142
|
let { serviceName = '', versionName = '', path: _path = '', repo: _repo = '', image: _image = '', port: _port = '80', flow: _flow = '0', remark: _remark = '', cpu: _cpu = '0.5', mem: _mem = '1', copy: _copy = '0~50', policy: _policy = 'cpu|60', dockerfile: _dockerfile = 'Dockerfile', log: _log = 'stdout', delay: _delay = '2', env: _env = '' } = options;
|
|
138
143
|
if (!serviceName || !versionName) {
|
|
139
144
|
throw new error_1.CloudBaseError('必须输入 serviceName 和 versionName');
|
package/lib/constant.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ConcurrencyTaskStatus = exports.StatusMap = exports.ALL_COMMANDS = exports.STATUS_TEXT = exports.REQUEST_TIMEOUT = exports.DefaultCloudBaseConfig = exports.DefaultFunctionDeployConfig = exports.ConfigItems = void 0;
|
|
3
|
+
exports.DEFAULT_CPU_MEM_SET = exports.CPU_MEM_OPTS = exports.ConcurrencyTaskStatus = exports.StatusMap = exports.ALL_COMMANDS = exports.STATUS_TEXT = exports.REQUEST_TIMEOUT = exports.DefaultCloudBaseConfig = exports.DefaultFunctionDeployConfig = exports.ConfigItems = void 0;
|
|
4
4
|
class ConfigItems {
|
|
5
5
|
}
|
|
6
6
|
exports.ConfigItems = ConfigItems;
|
|
@@ -99,3 +99,22 @@ exports.ConcurrencyTaskStatus = {
|
|
|
99
99
|
InProgress: '进行中',
|
|
100
100
|
Failed: '失败'
|
|
101
101
|
};
|
|
102
|
+
exports.CPU_MEM_OPTS = [
|
|
103
|
+
{ cpu: 0.25, mems: [0.5] },
|
|
104
|
+
{ cpu: 0.5, mems: [1] },
|
|
105
|
+
{ cpu: 1, mems: [2] },
|
|
106
|
+
{ cpu: 2, mems: [4] },
|
|
107
|
+
{ cpu: 4, mems: [8] },
|
|
108
|
+
{ cpu: 8, mems: [16] },
|
|
109
|
+
{ cpu: 16, mems: [32] },
|
|
110
|
+
];
|
|
111
|
+
exports.DEFAULT_CPU_MEM_SET = [
|
|
112
|
+
{
|
|
113
|
+
PolicyType: 'mem',
|
|
114
|
+
PolicyThreshold: 60
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
PolicyType: 'cpu',
|
|
118
|
+
PolicyThreshold: 60
|
|
119
|
+
},
|
|
120
|
+
];
|
package/lib/help.js
CHANGED
|
@@ -6,45 +6,47 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.outputHelpInfo = void 0;
|
|
7
7
|
const chalk_1 = __importDefault(require("chalk"));
|
|
8
8
|
const outputHelpInfo = () => {
|
|
9
|
-
const commands = `
|
|
10
|
-
命令
|
|
11
|
-
|
|
12
|
-
login [options] 登录腾讯云账号
|
|
13
|
-
logout 登出腾讯云账号
|
|
14
|
-
env [cmd] 环境管理操作
|
|
15
|
-
fn [cmd] 操作函数
|
|
16
|
-
framework [cmd] 云开发 Serverless 应用框架操作
|
|
17
|
-
hosting [cmd] 静态托管资源管理操作
|
|
18
|
-
new [appName] [template] 创建新的云开发应用
|
|
19
|
-
open [link] 在浏览器中打开云开发相关连接
|
|
20
|
-
storage [cmd] 云存储资源管理操作
|
|
21
|
-
service [cmd] HTTP
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
--
|
|
28
|
-
|
|
29
|
-
|
|
9
|
+
const commands = `
|
|
10
|
+
命令
|
|
11
|
+
|
|
12
|
+
login [options] 登录腾讯云账号
|
|
13
|
+
logout 登出腾讯云账号
|
|
14
|
+
env [cmd] 环境管理操作
|
|
15
|
+
fn [cmd] 操作函数
|
|
16
|
+
framework [cmd] 云开发 Serverless 应用框架操作
|
|
17
|
+
hosting [cmd] 静态托管资源管理操作
|
|
18
|
+
new [appName] [template] 创建新的云开发应用
|
|
19
|
+
open [link] 在浏览器中打开云开发相关连接
|
|
20
|
+
storage [cmd] 云存储资源管理操作
|
|
21
|
+
service [cmd] HTTP 访问服务管理操作
|
|
22
|
+
run:deprecated [cmd] 云托管环境管理操作 (BAAS 或 RUN 类型环境)
|
|
23
|
+
run [cmd] 云托管环境管理操作 (TCBR 类型环境)`;
|
|
24
|
+
const options = `
|
|
25
|
+
选项
|
|
26
|
+
|
|
27
|
+
--verbose 打印出内部运行信息
|
|
28
|
+
-r, --region <region> 指定环境地域
|
|
29
|
+
--mode <mode> 指定加载 env 文件的环境
|
|
30
|
+
--config-file <path> 指定配置文件路径
|
|
31
|
+
-v, --version 输出当前版本
|
|
30
32
|
-h, --help 查看命令帮助信息`;
|
|
31
|
-
const tips = `
|
|
32
|
-
Tips:
|
|
33
|
-
|
|
34
|
-
${chalk_1.default.gray('–')} 登录
|
|
35
|
-
|
|
36
|
-
${chalk_1.default.cyan('$ tcb login')}
|
|
37
|
-
|
|
38
|
-
${chalk_1.default.gray('–')} 创建新的云开发应用
|
|
39
|
-
|
|
40
|
-
${chalk_1.default.cyan('$ tcb new appName')}
|
|
41
|
-
|
|
42
|
-
${chalk_1.default.gray('–')} 部署云函数
|
|
43
|
-
|
|
44
|
-
${chalk_1.default.cyan('$ tcb fn deploy')}
|
|
45
|
-
|
|
46
|
-
${chalk_1.default.gray('–')} 查看命令使用介绍
|
|
47
|
-
|
|
33
|
+
const tips = `
|
|
34
|
+
Tips:
|
|
35
|
+
|
|
36
|
+
${chalk_1.default.gray('–')} 登录
|
|
37
|
+
|
|
38
|
+
${chalk_1.default.cyan('$ tcb login')}
|
|
39
|
+
|
|
40
|
+
${chalk_1.default.gray('–')} 创建新的云开发应用
|
|
41
|
+
|
|
42
|
+
${chalk_1.default.cyan('$ tcb new appName')}
|
|
43
|
+
|
|
44
|
+
${chalk_1.default.gray('–')} 部署云函数
|
|
45
|
+
|
|
46
|
+
${chalk_1.default.cyan('$ tcb fn deploy')}
|
|
47
|
+
|
|
48
|
+
${chalk_1.default.gray('–')} 查看命令使用介绍
|
|
49
|
+
|
|
48
50
|
${chalk_1.default.cyan('$ tcb fn -h')}`;
|
|
49
51
|
console.log(commands, '\n', options, '\n', tips);
|
|
50
52
|
};
|
package/lib/run/index.js
CHANGED
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.tcbrServiceOptions = exports.mergeEnvParams = exports.parseEnvParams = exports.extractPolicyDetails = exports.convertNumber = exports.describeWxCloudBaseRunReleaseOrder = void 0;
|
|
13
|
+
const utils_1 = require("../../utils");
|
|
14
|
+
const toolbox_1 = require("@cloudbase/toolbox");
|
|
15
|
+
const index_1 = require("./index");
|
|
16
|
+
const __1 = require("..");
|
|
17
|
+
const constant_1 = require("../../constant");
|
|
18
|
+
const tcbService = utils_1.CloudApiService.getInstance('tcb');
|
|
19
|
+
function describeWxCloudBaseRunReleaseOrder(options) {
|
|
20
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
21
|
+
const res = yield tcbService.request('DescribeWxCloudBaseRunReleaseOrder', {
|
|
22
|
+
EnvId: options.envId,
|
|
23
|
+
ServerName: options.serviceName
|
|
24
|
+
});
|
|
25
|
+
return res;
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
exports.describeWxCloudBaseRunReleaseOrder = describeWxCloudBaseRunReleaseOrder;
|
|
29
|
+
const convertNumber = (item) => {
|
|
30
|
+
if (isNaN(Number(item))) {
|
|
31
|
+
throw new toolbox_1.CloudBaseError(`${item} 必须为数字`);
|
|
32
|
+
}
|
|
33
|
+
return Number(item);
|
|
34
|
+
};
|
|
35
|
+
exports.convertNumber = convertNumber;
|
|
36
|
+
const extractPolicyDetails = (policyDetails) => {
|
|
37
|
+
return policyDetails.split('&').map(condition => {
|
|
38
|
+
let [type, threshold] = [condition.split('=')[0], Number(condition.split('=')[1])];
|
|
39
|
+
if (isNaN(threshold) || !['cpu', 'mem'].includes(type)) {
|
|
40
|
+
throw new toolbox_1.CloudBaseError('请输入合法的缩扩容配置');
|
|
41
|
+
}
|
|
42
|
+
return {
|
|
43
|
+
PolicyType: type,
|
|
44
|
+
PolicyThreshold: threshold
|
|
45
|
+
};
|
|
46
|
+
});
|
|
47
|
+
};
|
|
48
|
+
exports.extractPolicyDetails = extractPolicyDetails;
|
|
49
|
+
const parseEnvParams = (envParams) => {
|
|
50
|
+
return envParams.split('&').reduce((acc, cur) => {
|
|
51
|
+
const [key, value] = cur.split('=');
|
|
52
|
+
acc[key] = value;
|
|
53
|
+
return acc;
|
|
54
|
+
}, {});
|
|
55
|
+
};
|
|
56
|
+
exports.parseEnvParams = parseEnvParams;
|
|
57
|
+
const mergeEnvParams = (curEnvParams, preEnvParams) => {
|
|
58
|
+
const curEnv = (0, exports.parseEnvParams)(curEnvParams);
|
|
59
|
+
const preEnv = preEnvParams ? JSON.parse(preEnvParams) : {};
|
|
60
|
+
const curEnvKeys = Object.keys(curEnv);
|
|
61
|
+
Object.entries(preEnv).forEach(([key, value]) => {
|
|
62
|
+
if (!curEnvKeys.includes(key)) {
|
|
63
|
+
curEnv[key] = value;
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
return JSON.stringify(curEnv);
|
|
67
|
+
};
|
|
68
|
+
exports.mergeEnvParams = mergeEnvParams;
|
|
69
|
+
function checkRequiredParams(options) {
|
|
70
|
+
if (!options.envId) {
|
|
71
|
+
throw new toolbox_1.CloudBaseError('必须使用 -e 或 --envId 指定环境ID');
|
|
72
|
+
}
|
|
73
|
+
if (!options.serviceName) {
|
|
74
|
+
throw new toolbox_1.CloudBaseError('必须使用 -s 或 --serviceName 指定服务名');
|
|
75
|
+
}
|
|
76
|
+
if (!options.containerPort) {
|
|
77
|
+
throw new toolbox_1.CloudBaseError('必须使用 --containerPort 指定监听端口号');
|
|
78
|
+
}
|
|
79
|
+
if (!options.isCreated && !options.path) {
|
|
80
|
+
throw new toolbox_1.CloudBaseError('请使用 --path 指定代码根目录');
|
|
81
|
+
}
|
|
82
|
+
if (options.isCreated && !options.path && !options.library_image && !options.image) {
|
|
83
|
+
throw new toolbox_1.CloudBaseError('请使用 --path 指定代码根目录或 --library_image 指定线上镜像 tag ');
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
function tcbrServiceOptions(options, isCreated, defaultOverride, previousServerConfig) {
|
|
87
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
88
|
+
let { noConfirm: _noConfirm = false, override: _override = (defaultOverride || false), envId, serviceName, path, cpu, mem, minNum, maxNum, policyDetails, customLogs, envParams, containerPort, remark, targetDir, dockerfile, image, library_image, json: _json = false } = options;
|
|
89
|
+
checkRequiredParams({
|
|
90
|
+
envId,
|
|
91
|
+
serviceName,
|
|
92
|
+
containerPort,
|
|
93
|
+
isCreated,
|
|
94
|
+
path,
|
|
95
|
+
library_image,
|
|
96
|
+
image
|
|
97
|
+
});
|
|
98
|
+
containerPort = Number(containerPort);
|
|
99
|
+
const DeployInfo = {
|
|
100
|
+
DeployType: library_image || image
|
|
101
|
+
? 'image'
|
|
102
|
+
: 'package',
|
|
103
|
+
DeployRemark: remark || '',
|
|
104
|
+
};
|
|
105
|
+
let { cpuConverted, memConverted, maxNumConverted, minNumConverted } = (0, utils_1.parseOptionalParams)({
|
|
106
|
+
cpu,
|
|
107
|
+
mem,
|
|
108
|
+
maxNum,
|
|
109
|
+
minNum
|
|
110
|
+
});
|
|
111
|
+
const newServiceOptions = {
|
|
112
|
+
ServerName: serviceName,
|
|
113
|
+
EnvId: envId,
|
|
114
|
+
ServerConfig: {
|
|
115
|
+
EnvId: envId,
|
|
116
|
+
MaxNum: (0, utils_1.parseInputParam)(maxNumConverted, _override, exports.convertNumber, previousServerConfig === null || previousServerConfig === void 0 ? void 0 : previousServerConfig.MaxNum, 50),
|
|
117
|
+
MinNum: (0, utils_1.parseInputParam)(minNumConverted, _override, exports.convertNumber, previousServerConfig === null || previousServerConfig === void 0 ? void 0 : previousServerConfig.MinNum, 0),
|
|
118
|
+
BuildDir: (0, utils_1.parseInputParam)(targetDir, _override, null, previousServerConfig === null || previousServerConfig === void 0 ? void 0 : previousServerConfig.BuildDir, '.'),
|
|
119
|
+
Cpu: (0, utils_1.parseInputParam)(cpuConverted, _override, null, previousServerConfig === null || previousServerConfig === void 0 ? void 0 : previousServerConfig.Cpu, 0.5),
|
|
120
|
+
Mem: (0, utils_1.parseInputParam)(memConverted, _override, null, previousServerConfig === null || previousServerConfig === void 0 ? void 0 : previousServerConfig.Mem, 1),
|
|
121
|
+
OpenAccessTypes: ['PUBLIC'],
|
|
122
|
+
ServerName: serviceName,
|
|
123
|
+
InitialDelaySeconds: 2,
|
|
124
|
+
CustomLogs: (0, utils_1.parseInputParam)(customLogs, _override, null, previousServerConfig === null || previousServerConfig === void 0 ? void 0 : previousServerConfig.CustomLogs, 'stdout'),
|
|
125
|
+
CreateTime: (previousServerConfig === null || previousServerConfig === void 0 ? void 0 : previousServerConfig.CreateTime) || (new Date()).toLocaleString().replace(/\//g, '-'),
|
|
126
|
+
PolicyDetails: (0, utils_1.parseInputParam)(policyDetails, _override, exports.extractPolicyDetails, previousServerConfig === null || previousServerConfig === void 0 ? void 0 : previousServerConfig.PolicyDetails, constant_1.DEFAULT_CPU_MEM_SET),
|
|
127
|
+
EnvParams: (0, utils_1.parseInputParam)(envParams, _override, exports.mergeEnvParams, previousServerConfig === null || previousServerConfig === void 0 ? void 0 : previousServerConfig.EnvParams, '', previousServerConfig === null || previousServerConfig === void 0 ? void 0 : previousServerConfig.EnvParams),
|
|
128
|
+
Port: containerPort,
|
|
129
|
+
HasDockerfile: true,
|
|
130
|
+
Dockerfile: dockerfile || 'Dockerfile',
|
|
131
|
+
},
|
|
132
|
+
DeployInfo: Object.assign({}, DeployInfo)
|
|
133
|
+
};
|
|
134
|
+
if (DeployInfo.DeployType === 'package') {
|
|
135
|
+
const { PackageName, PackageVersion } = yield (0, index_1.packageDeploy)({
|
|
136
|
+
envId,
|
|
137
|
+
serviceName,
|
|
138
|
+
filePath: path,
|
|
139
|
+
});
|
|
140
|
+
DeployInfo.PackageName = PackageName;
|
|
141
|
+
DeployInfo.PackageVersion = PackageVersion;
|
|
142
|
+
}
|
|
143
|
+
else if (DeployInfo.DeployType === 'image') {
|
|
144
|
+
const imageList = yield (0, __1.listImage)({
|
|
145
|
+
envId,
|
|
146
|
+
serviceName
|
|
147
|
+
});
|
|
148
|
+
if (library_image) {
|
|
149
|
+
const imageInfo = imageList.find(({ Tag }) => Tag === library_image);
|
|
150
|
+
if (!imageInfo) {
|
|
151
|
+
throw new toolbox_1.CloudBaseError(`镜像 ${library_image} 不存在`);
|
|
152
|
+
}
|
|
153
|
+
DeployInfo.ImageUrl = imageInfo.ImageUrl;
|
|
154
|
+
}
|
|
155
|
+
else {
|
|
156
|
+
throw new toolbox_1.CloudBaseError('暂不支持 --image 参数,请使用 --library_image 指定线上镜像 tag');
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
newServiceOptions.DeployInfo = Object.assign({}, DeployInfo);
|
|
160
|
+
return newServiceOptions;
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
exports.tcbrServiceOptions = tcbrServiceOptions;
|