@cloudbase/cli 2.10.0-beta.0 → 2.11.0-beta.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/lib/auth/login.js +51 -65
- package/lib/auth/logout.js +3 -14
- package/lib/commands/account/login.js +136 -149
- package/lib/commands/account/logout.js +3 -14
- package/lib/commands/ag/base.js +203 -0
- package/lib/commands/ag/create.js +301 -0
- package/lib/commands/ag/debug/index.html +699 -0
- package/lib/commands/ag/delete.js +200 -0
- package/lib/commands/ag/deploy.js +185 -0
- package/lib/commands/ag/detail.js +113 -0
- package/lib/commands/ag/index.js +22 -0
- package/lib/commands/ag/list.js +155 -0
- package/lib/commands/ag/run.js +644 -0
- package/lib/commands/ai/index.js +76 -95
- package/lib/commands/cloudfunction/base.js +182 -203
- package/lib/commands/cloudrun/base.js +578 -603
- package/lib/commands/common.js +48 -63
- package/lib/commands/config/delete.js +16 -27
- package/lib/commands/config/get.js +13 -24
- package/lib/commands/config/list.js +16 -27
- package/lib/commands/config/set.js +33 -44
- package/lib/commands/db/base.js +221 -240
- package/lib/commands/env/base.js +36 -49
- package/lib/commands/env/domain.js +79 -94
- package/lib/commands/env/login.js +120 -135
- package/lib/commands/framework/index.js +32 -49
- package/lib/commands/fun/base.js +223 -244
- package/lib/commands/functions/alias/getRoute.js +33 -44
- package/lib/commands/functions/alias/setRoute.js +36 -47
- package/lib/commands/functions/code-download.js +43 -54
- package/lib/commands/functions/code-update.js +23 -34
- package/lib/commands/functions/concurrency/delete.js +11 -22
- package/lib/commands/functions/concurrency/list.js +20 -31
- package/lib/commands/functions/concurrency/set.js +13 -24
- package/lib/commands/functions/config-update.js +30 -41
- package/lib/commands/functions/copy.js +12 -23
- package/lib/commands/functions/delete.js +30 -41
- package/lib/commands/functions/deploy.js +184 -202
- package/lib/commands/functions/detail.js +23 -34
- package/lib/commands/functions/invoke.js +69 -75
- package/lib/commands/functions/layer/bind.js +102 -105
- package/lib/commands/functions/layer/create.js +29 -35
- package/lib/commands/functions/layer/delete.js +42 -48
- package/lib/commands/functions/layer/download.js +52 -58
- package/lib/commands/functions/layer/list.js +44 -50
- package/lib/commands/functions/layer/sort.js +39 -45
- package/lib/commands/functions/list.js +25 -36
- package/lib/commands/functions/log.js +65 -73
- package/lib/commands/functions/run.js +118 -116
- package/lib/commands/functions/trigger-create.js +32 -43
- package/lib/commands/functions/trigger-delete.js +50 -61
- package/lib/commands/functions/version/list.js +29 -40
- package/lib/commands/functions/version/publish.js +11 -22
- package/lib/commands/gateway/create.js +50 -61
- package/lib/commands/gateway/delete.js +38 -49
- package/lib/commands/gateway/domain.js +65 -80
- package/lib/commands/gateway/list.js +31 -42
- package/lib/commands/gateway/switch.js +48 -61
- package/lib/commands/helpers/init.js +226 -249
- package/lib/commands/helpers/new.js +35 -46
- package/lib/commands/helpers/open.js +22 -33
- package/lib/commands/hosting/hosting.js +157 -178
- package/lib/commands/index.js +1 -0
- package/lib/commands/lowcode/app.js +114 -144
- package/lib/commands/lowcode/comps.js +136 -127
- package/lib/commands/lowcode/utils.js +11 -22
- package/lib/commands/pull/pull.js +33 -46
- package/lib/commands/run/delete.js +35 -46
- package/lib/commands/run/image/delete.js +32 -39
- package/lib/commands/run/image/download.js +26 -33
- package/lib/commands/run/image/list.js +41 -48
- package/lib/commands/run/image/upload.js +26 -33
- package/lib/commands/run/list.js +32 -43
- package/lib/commands/run/service/config.js +17 -28
- package/lib/commands/run/service/deploy.js +15 -26
- package/lib/commands/run/service/list.js +48 -59
- package/lib/commands/run/service/update.js +7 -18
- package/lib/commands/run/standalonegateway/create.js +35 -42
- package/lib/commands/run/standalonegateway/destroy.js +23 -30
- package/lib/commands/run/standalonegateway/list.js +19 -26
- package/lib/commands/run/standalonegateway/package.js +31 -38
- package/lib/commands/run/standalonegateway/turn.js +27 -34
- package/lib/commands/run/version/create.js +198 -205
- package/lib/commands/run/version/delete.js +31 -38
- package/lib/commands/run/version/list.js +42 -49
- package/lib/commands/run/version/modify.js +27 -34
- package/lib/commands/run/version/update.js +201 -208
- package/lib/commands/runf/base.js +216 -237
- package/lib/commands/self-update.js +59 -72
- package/lib/commands/smart.js +66 -79
- package/lib/commands/storage/storage.js +192 -219
- package/lib/commands/third/thirdAttach.js +16 -27
- package/lib/commands/utils.js +119 -149
- package/lib/db/index.js +48 -67
- package/lib/decorators/captureError.js +10 -21
- package/lib/decorators/guard.js +11 -22
- package/lib/decorators/injectParams.js +29 -40
- package/lib/decorators/params/common.js +5 -2
- package/lib/decorators/params/index.js +3 -12
- package/lib/env/domain.js +13 -28
- package/lib/env/index.js +25 -44
- package/lib/env/login.js +30 -45
- package/lib/function/alias.js +31 -44
- package/lib/function/base.js +187 -215
- package/lib/function/code.js +8 -19
- package/lib/function/concurrency.js +43 -58
- package/lib/function/create.js +43 -53
- package/lib/function/delete.js +22 -35
- package/lib/function/layer/attach.js +33 -46
- package/lib/function/layer/create.js +34 -45
- package/lib/function/layer/delete.js +5 -16
- package/lib/function/layer/download.js +11 -22
- package/lib/function/layer/list.js +12 -25
- package/lib/function/layer/sort.js +6 -17
- package/lib/function/trigger.js +65 -82
- package/lib/function/update.js +24 -32
- package/lib/function/version.js +29 -42
- package/lib/function/vpc.js +12 -25
- package/lib/gateway/index.js +77 -104
- package/lib/hosting.js +157 -188
- package/lib/run/delete.js +3 -12
- package/lib/run/image/build.js +6 -15
- package/lib/run/image/delete.js +3 -12
- package/lib/run/image/info.js +3 -12
- package/lib/run/image/list.js +6 -15
- package/lib/run/list.js +19 -30
- package/lib/run/repo.js +6 -15
- package/lib/run/service/common.js +160 -173
- package/lib/run/service/config.js +44 -57
- package/lib/run/service/deployPackage.js +33 -44
- package/lib/run/service/list.js +8 -14
- package/lib/run/service/showLogs.js +69 -90
- package/lib/run/service/update.js +50 -63
- package/lib/run/standalonegateway/create.js +3 -12
- package/lib/run/standalonegateway/destroy.js +3 -12
- package/lib/run/standalonegateway/list.js +3 -12
- package/lib/run/standalonegateway/package/list.js +3 -12
- package/lib/run/standalonegateway/turn/off.js +3 -12
- package/lib/run/standalonegateway/turn/on.js +3 -12
- package/lib/run/version/create.js +41 -31
- package/lib/run/version/delete.js +3 -12
- package/lib/run/version/list.js +3 -12
- package/lib/run/version/modify.js +3 -12
- package/lib/run/version/repo.js +6 -15
- package/lib/run/version/update.js +37 -26
- package/lib/storage.js +62 -93
- package/lib/third/index.js +6 -17
- package/lib/utils/ai/banner.js +49 -60
- package/lib/utils/ai/claudeWindows.js +2 -2
- package/lib/utils/ai/config.js +169 -206
- package/lib/utils/ai/ensureFiles.js +6 -17
- package/lib/utils/ai/env.js +16 -27
- package/lib/utils/ai/envLocalManager.js +35 -52
- package/lib/utils/ai/router.js +927 -1005
- package/lib/utils/ai/setup.js +527 -563
- package/lib/utils/auth.js +3 -14
- package/lib/utils/checkTcbrEnv.js +20 -31
- package/lib/utils/cli-table.js +6 -1
- package/lib/utils/config.js +4 -13
- package/lib/utils/dts.js +98 -113
- package/lib/utils/env.js +154 -175
- package/lib/utils/function-packer.js +29 -42
- package/lib/utils/log.js +10 -21
- package/lib/utils/mcp-config-modifier.js +105 -120
- package/lib/utils/net/cloud-api-request.js +15 -23
- package/lib/utils/net/credential.js +26 -39
- package/lib/utils/net/http-request.js +63 -80
- package/lib/utils/net/manager-service.js +22 -35
- package/lib/utils/notice.js +16 -27
- package/lib/utils/output/loading.js +3 -12
- package/lib/utils/parallel.js +32 -43
- package/lib/utils/platform/mac.js +4 -15
- package/lib/utils/platform/port.js +4 -15
- package/lib/utils/prompt/select.js +6 -15
- package/lib/utils/report.js +28 -33
- package/lib/utils/reporter/agree.js +11 -22
- package/lib/utils/reporter/download.js +17 -28
- package/lib/utils/reporter/usage.js +12 -23
- package/lib/utils/store/auth.js +17 -30
- package/lib/utils/store/config.js +11 -25
- package/lib/utils/store/db.js +17 -36
- package/lib/utils/tcbrApi/callTcbrApi.js +19 -28
- package/lib/utils/template-manager.js +215 -242
- package/lib/utils/template.js +81 -96
- package/lib/utils/tools/common.js +45 -56
- package/lib/utils/tools/time.js +5 -16
- package/lib/utils/url.js +10 -4
- package/package.json +2 -2
- package/specs/ag-command/design.md +421 -0
- package/specs/ag-command/doc.md +204 -0
- package/specs/ag-command/requirements.md +173 -0
- package/specs/ag-command/summary.md +174 -0
- package/specs/ag-command/tasks.md +197 -0
- package/specs/ag-command/usage-guide.md +420 -0
- package/tsconfig.json +1 -1
- package/types/commands/ag/base.d.ts +44 -0
- package/types/commands/ag/create.d.ts +25 -0
- package/types/commands/ag/delete.d.ts +32 -0
- package/types/commands/ag/deploy.d.ts +31 -0
- package/types/commands/ag/detail.d.ts +28 -0
- package/types/commands/ag/index.d.ts +6 -0
- package/types/commands/ag/list.d.ts +35 -0
- package/types/commands/ag/run.d.ts +52 -0
- package/types/commands/cloudrun/base.d.ts +10 -0
- package/types/commands/index.d.ts +1 -0
package/lib/run/repo.js
CHANGED
|
@@ -1,31 +1,22 @@
|
|
|
1
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
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.deleteImageRepo = exports.describeImageRepo = void 0;
|
|
13
4
|
const utils_1 = require("../utils");
|
|
14
5
|
const tcbService = utils_1.CloudApiService.getInstance('tcb');
|
|
15
|
-
const describeImageRepo = (options) =>
|
|
16
|
-
const { ImageRepo } =
|
|
6
|
+
const describeImageRepo = async (options) => {
|
|
7
|
+
const { ImageRepo } = await tcbService.request('DescribeCloudBaseRunServer', {
|
|
17
8
|
EnvId: options.envId,
|
|
18
9
|
Limit: options.limit ? options.limit : 100,
|
|
19
10
|
Offset: options.offset ? options.offset : 0,
|
|
20
11
|
ServerName: options.serverName
|
|
21
12
|
});
|
|
22
13
|
return ImageRepo;
|
|
23
|
-
}
|
|
14
|
+
};
|
|
24
15
|
exports.describeImageRepo = describeImageRepo;
|
|
25
|
-
const deleteImageRepo = (options) =>
|
|
26
|
-
const { result } =
|
|
16
|
+
const deleteImageRepo = async (options) => {
|
|
17
|
+
const { result } = await tcbService.request('DeleteCloudBaseRunImageRepo', {
|
|
27
18
|
ImageRepo: options.imageRepo
|
|
28
19
|
});
|
|
29
20
|
return result;
|
|
30
|
-
}
|
|
21
|
+
};
|
|
31
22
|
exports.deleteImageRepo = deleteImageRepo;
|
|
@@ -1,13 +1,4 @@
|
|
|
1
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
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.validateTcrImageURL = exports.getAuthorizedTcrInstance = exports.tcbrServiceOptions = exports.mergeEnvParams = exports.parseEnvParams = exports.extractPolicyDetails = exports.convertNumber = exports.describeWxCloudBaseRunReleaseOrder = exports.describeCloudRunServerDetail = void 0;
|
|
13
4
|
const utils_1 = require("../../utils");
|
|
@@ -19,21 +10,19 @@ const constant_1 = require("../../constant");
|
|
|
19
10
|
const i18n_1 = require("../../i18n");
|
|
20
11
|
const tcbService = utils_1.CloudApiService.getInstance('tcb');
|
|
21
12
|
const tcrCloudApiService = new utils_1.CloudApiService('tcr', {}, '2019-09-24');
|
|
22
|
-
const describeCloudRunServerDetail = (options) =>
|
|
23
|
-
return
|
|
13
|
+
const describeCloudRunServerDetail = async (options) => {
|
|
14
|
+
return await (0, utils_1.callTcbrApi)('DescribeCloudRunServerDetail', {
|
|
24
15
|
EnvId: options.envId,
|
|
25
16
|
ServerName: options.serviceName,
|
|
26
17
|
});
|
|
27
|
-
}
|
|
18
|
+
};
|
|
28
19
|
exports.describeCloudRunServerDetail = describeCloudRunServerDetail;
|
|
29
|
-
function describeWxCloudBaseRunReleaseOrder(options) {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
ServerName: options.serviceName
|
|
34
|
-
});
|
|
35
|
-
return res;
|
|
20
|
+
async function describeWxCloudBaseRunReleaseOrder(options) {
|
|
21
|
+
const res = await tcbService.request('DescribeWxCloudBaseRunReleaseOrder', {
|
|
22
|
+
EnvId: options.envId,
|
|
23
|
+
ServerName: options.serviceName
|
|
36
24
|
});
|
|
25
|
+
return res;
|
|
37
26
|
}
|
|
38
27
|
exports.describeWxCloudBaseRunReleaseOrder = describeWxCloudBaseRunReleaseOrder;
|
|
39
28
|
const convertNumber = (item) => {
|
|
@@ -93,179 +82,177 @@ function checkRequiredParams(options) {
|
|
|
93
82
|
throw new toolbox_1.CloudBaseError((0, i18n_1.t)('请使用 --path 指定代码根目录或 --custom_image 指定 TCR 镜像 URL 或 --library_image 指定线上镜像 tag '));
|
|
94
83
|
}
|
|
95
84
|
}
|
|
96
|
-
function tcbrServiceOptions(options, isCreated, defaultOverride, previousServerConfig) {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
85
|
+
async function tcbrServiceOptions(options, isCreated, defaultOverride, previousServerConfig) {
|
|
86
|
+
let { noConfirm: _noConfirm = false, override: _override = (defaultOverride || false), envId, serviceName, path, cpu, mem, minNum, maxNum, policyDetails, customLogs, envParams, containerPort, remark, targetDir, dockerfile, image, custom_image, library_image, log_type, json: _json = false } = options;
|
|
87
|
+
checkRequiredParams({
|
|
88
|
+
envId,
|
|
89
|
+
serviceName,
|
|
90
|
+
containerPort,
|
|
91
|
+
isCreated,
|
|
92
|
+
path,
|
|
93
|
+
custom_image,
|
|
94
|
+
library_image,
|
|
95
|
+
image
|
|
96
|
+
});
|
|
97
|
+
containerPort = Number(containerPort);
|
|
98
|
+
const deployByImage = Boolean(custom_image || library_image || image);
|
|
99
|
+
const DeployInfo = {
|
|
100
|
+
DeployType: deployByImage ? types_1.DEPLOY_TYPE.IMAGE : types_1.DEPLOY_TYPE.PACKAGE,
|
|
101
|
+
DeployRemark: remark || '',
|
|
102
|
+
ReleaseType: 'FULL'
|
|
103
|
+
};
|
|
104
|
+
let { cpuConverted, memConverted, maxNumConverted, minNumConverted } = (0, utils_1.parseOptionalParams)({
|
|
105
|
+
cpu,
|
|
106
|
+
mem,
|
|
107
|
+
maxNum,
|
|
108
|
+
minNum
|
|
109
|
+
});
|
|
110
|
+
if (log_type && log_type !== "none") {
|
|
111
|
+
throw new toolbox_1.CloudBaseError((0, i18n_1.t)('日志类型 log_type 只能为 none,如需自定义日志,请前往控制台配置'));
|
|
112
|
+
}
|
|
113
|
+
const defaultLogType = "none";
|
|
114
|
+
const newServiceOptions = {
|
|
115
|
+
ServerName: serviceName,
|
|
116
|
+
EnvId: envId,
|
|
117
|
+
ServerConfig: {
|
|
118
|
+
EnvId: envId,
|
|
119
|
+
MaxNum: (0, utils_1.parseInputParam)(maxNumConverted, _override, exports.convertNumber, previousServerConfig === null || previousServerConfig === void 0 ? void 0 : previousServerConfig.MaxNum, 50),
|
|
120
|
+
MinNum: (0, utils_1.parseInputParam)(minNumConverted, _override, exports.convertNumber, previousServerConfig === null || previousServerConfig === void 0 ? void 0 : previousServerConfig.MinNum, 0),
|
|
121
|
+
BuildDir: (0, utils_1.parseInputParam)(targetDir, _override, null, previousServerConfig === null || previousServerConfig === void 0 ? void 0 : previousServerConfig.BuildDir, '.'),
|
|
122
|
+
Cpu: (0, utils_1.parseInputParam)(cpuConverted, _override, null, previousServerConfig === null || previousServerConfig === void 0 ? void 0 : previousServerConfig.Cpu, 0.5),
|
|
123
|
+
Mem: (0, utils_1.parseInputParam)(memConverted, _override, null, previousServerConfig === null || previousServerConfig === void 0 ? void 0 : previousServerConfig.Mem, 1),
|
|
124
|
+
OpenAccessTypes: ['PUBLIC'],
|
|
125
|
+
ServerName: serviceName,
|
|
126
|
+
InitialDelaySeconds: 2,
|
|
127
|
+
CustomLogs: (0, utils_1.parseInputParam)(customLogs, _override, null, previousServerConfig === null || previousServerConfig === void 0 ? void 0 : previousServerConfig.CustomLogs, 'stdout'),
|
|
128
|
+
CreateTime: (previousServerConfig === null || previousServerConfig === void 0 ? void 0 : previousServerConfig.CreateTime) || (new Date()).toLocaleString().replace(/\//g, '-'),
|
|
129
|
+
PolicyDetails: (0, utils_1.parseInputParam)(policyDetails, _override, exports.extractPolicyDetails, previousServerConfig === null || previousServerConfig === void 0 ? void 0 : previousServerConfig.PolicyDetails, constant_1.DEFAULT_CPU_MEM_SET),
|
|
130
|
+
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),
|
|
131
|
+
Port: containerPort,
|
|
132
|
+
HasDockerfile: true,
|
|
133
|
+
Dockerfile: dockerfile || 'Dockerfile',
|
|
134
|
+
LogType: (0, utils_1.parseInputParam)(log_type, _override, null, previousServerConfig === null || previousServerConfig === void 0 ? void 0 : previousServerConfig.LogType, defaultLogType),
|
|
135
|
+
LogSetId: previousServerConfig === null || previousServerConfig === void 0 ? void 0 : previousServerConfig.LogSetId,
|
|
136
|
+
LogTopicId: previousServerConfig === null || previousServerConfig === void 0 ? void 0 : previousServerConfig.LogTopicId,
|
|
137
|
+
LogParseType: previousServerConfig === null || previousServerConfig === void 0 ? void 0 : previousServerConfig.LogParseType,
|
|
138
|
+
},
|
|
139
|
+
DeployInfo: {
|
|
140
|
+
...DeployInfo
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
if (DeployInfo.DeployType === types_1.DEPLOY_TYPE.PACKAGE) {
|
|
144
|
+
const { PackageName, PackageVersion } = await (0, index_1.packageDeploy)({
|
|
100
145
|
envId,
|
|
101
146
|
serviceName,
|
|
102
|
-
|
|
103
|
-
isCreated,
|
|
104
|
-
path,
|
|
105
|
-
custom_image,
|
|
106
|
-
library_image,
|
|
107
|
-
image
|
|
147
|
+
filePath: path,
|
|
108
148
|
});
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
});
|
|
122
|
-
if (log_type && log_type !== "none") {
|
|
123
|
-
throw new toolbox_1.CloudBaseError((0, i18n_1.t)('日志类型 log_type 只能为 none,如需自定义日志,请前往控制台配置'));
|
|
149
|
+
DeployInfo.PackageName = PackageName;
|
|
150
|
+
DeployInfo.PackageVersion = PackageVersion;
|
|
151
|
+
}
|
|
152
|
+
else if (DeployInfo.DeployType === types_1.DEPLOY_TYPE.IMAGE) {
|
|
153
|
+
if (custom_image) {
|
|
154
|
+
const authorizedTcrInstances = await getAuthorizedTcrInstance(envId);
|
|
155
|
+
if (!authorizedTcrInstances) {
|
|
156
|
+
const link = `${utils_1.EUrl.Console}/tcbr/env?/tcbr/env=&envId=${envId}`;
|
|
157
|
+
throw new toolbox_1.CloudBaseError((0, i18n_1.t)('您还未授权 tcr 实例,请先到控制台授权:{{link}}', { link: (0, utils_1.genClickableLink)(link) }));
|
|
158
|
+
}
|
|
159
|
+
await validateTcrImageURL(authorizedTcrInstances, custom_image);
|
|
160
|
+
DeployInfo.ImageUrl = custom_image;
|
|
124
161
|
}
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
ServerName: serviceName,
|
|
128
|
-
EnvId: envId,
|
|
129
|
-
ServerConfig: {
|
|
130
|
-
EnvId: envId,
|
|
131
|
-
MaxNum: (0, utils_1.parseInputParam)(maxNumConverted, _override, exports.convertNumber, previousServerConfig === null || previousServerConfig === void 0 ? void 0 : previousServerConfig.MaxNum, 50),
|
|
132
|
-
MinNum: (0, utils_1.parseInputParam)(minNumConverted, _override, exports.convertNumber, previousServerConfig === null || previousServerConfig === void 0 ? void 0 : previousServerConfig.MinNum, 0),
|
|
133
|
-
BuildDir: (0, utils_1.parseInputParam)(targetDir, _override, null, previousServerConfig === null || previousServerConfig === void 0 ? void 0 : previousServerConfig.BuildDir, '.'),
|
|
134
|
-
Cpu: (0, utils_1.parseInputParam)(cpuConverted, _override, null, previousServerConfig === null || previousServerConfig === void 0 ? void 0 : previousServerConfig.Cpu, 0.5),
|
|
135
|
-
Mem: (0, utils_1.parseInputParam)(memConverted, _override, null, previousServerConfig === null || previousServerConfig === void 0 ? void 0 : previousServerConfig.Mem, 1),
|
|
136
|
-
OpenAccessTypes: ['PUBLIC'],
|
|
137
|
-
ServerName: serviceName,
|
|
138
|
-
InitialDelaySeconds: 2,
|
|
139
|
-
CustomLogs: (0, utils_1.parseInputParam)(customLogs, _override, null, previousServerConfig === null || previousServerConfig === void 0 ? void 0 : previousServerConfig.CustomLogs, 'stdout'),
|
|
140
|
-
CreateTime: (previousServerConfig === null || previousServerConfig === void 0 ? void 0 : previousServerConfig.CreateTime) || (new Date()).toLocaleString().replace(/\//g, '-'),
|
|
141
|
-
PolicyDetails: (0, utils_1.parseInputParam)(policyDetails, _override, exports.extractPolicyDetails, previousServerConfig === null || previousServerConfig === void 0 ? void 0 : previousServerConfig.PolicyDetails, constant_1.DEFAULT_CPU_MEM_SET),
|
|
142
|
-
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),
|
|
143
|
-
Port: containerPort,
|
|
144
|
-
HasDockerfile: true,
|
|
145
|
-
Dockerfile: dockerfile || 'Dockerfile',
|
|
146
|
-
LogType: (0, utils_1.parseInputParam)(log_type, _override, null, previousServerConfig === null || previousServerConfig === void 0 ? void 0 : previousServerConfig.LogType, defaultLogType),
|
|
147
|
-
LogSetId: previousServerConfig === null || previousServerConfig === void 0 ? void 0 : previousServerConfig.LogSetId,
|
|
148
|
-
LogTopicId: previousServerConfig === null || previousServerConfig === void 0 ? void 0 : previousServerConfig.LogTopicId,
|
|
149
|
-
LogParseType: previousServerConfig === null || previousServerConfig === void 0 ? void 0 : previousServerConfig.LogParseType,
|
|
150
|
-
},
|
|
151
|
-
DeployInfo: Object.assign({}, DeployInfo)
|
|
152
|
-
};
|
|
153
|
-
if (DeployInfo.DeployType === types_1.DEPLOY_TYPE.PACKAGE) {
|
|
154
|
-
const { PackageName, PackageVersion } = yield (0, index_1.packageDeploy)({
|
|
162
|
+
else {
|
|
163
|
+
const imageList = await (0, __1.listImage)({
|
|
155
164
|
envId,
|
|
156
|
-
serviceName
|
|
157
|
-
filePath: path,
|
|
165
|
+
serviceName
|
|
158
166
|
});
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
if (custom_image) {
|
|
164
|
-
const authorizedTcrInstances = yield getAuthorizedTcrInstance(envId);
|
|
165
|
-
if (!authorizedTcrInstances) {
|
|
166
|
-
const link = `${utils_1.EUrl.Console}/tcbr/env?/tcbr/env=&envId=${envId}`;
|
|
167
|
-
throw new toolbox_1.CloudBaseError((0, i18n_1.t)('您还未授权 tcr 实例,请先到控制台授权:{{link}}', { link: (0, utils_1.genClickableLink)(link) }));
|
|
167
|
+
if (library_image) {
|
|
168
|
+
const imageInfo = imageList.find(({ Tag }) => Tag === library_image);
|
|
169
|
+
if (!imageInfo) {
|
|
170
|
+
throw new toolbox_1.CloudBaseError((0, i18n_1.t)('镜像 {{image}} 不存在', { image: library_image }));
|
|
168
171
|
}
|
|
169
|
-
|
|
170
|
-
DeployInfo.ImageUrl = custom_image;
|
|
172
|
+
DeployInfo.ImageUrl = imageInfo.ImageUrl;
|
|
171
173
|
}
|
|
172
174
|
else {
|
|
173
|
-
|
|
174
|
-
envId,
|
|
175
|
-
serviceName
|
|
176
|
-
});
|
|
177
|
-
if (library_image) {
|
|
178
|
-
const imageInfo = imageList.find(({ Tag }) => Tag === library_image);
|
|
179
|
-
if (!imageInfo) {
|
|
180
|
-
throw new toolbox_1.CloudBaseError((0, i18n_1.t)('镜像 {{image}} 不存在', { image: library_image }));
|
|
181
|
-
}
|
|
182
|
-
DeployInfo.ImageUrl = imageInfo.ImageUrl;
|
|
183
|
-
}
|
|
184
|
-
else {
|
|
185
|
-
throw new toolbox_1.CloudBaseError((0, i18n_1.t)('暂不支持 --image 参数,请使用 --custom_image 指定 tcr 镜像 URL 或 --library_image 指定线上镜像 tag'));
|
|
186
|
-
}
|
|
175
|
+
throw new toolbox_1.CloudBaseError((0, i18n_1.t)('暂不支持 --image 参数,请使用 --custom_image 指定 tcr 镜像 URL 或 --library_image 指定线上镜像 tag'));
|
|
187
176
|
}
|
|
188
177
|
}
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
178
|
+
}
|
|
179
|
+
newServiceOptions.DeployInfo = {
|
|
180
|
+
...DeployInfo
|
|
181
|
+
};
|
|
182
|
+
return newServiceOptions;
|
|
192
183
|
}
|
|
193
184
|
exports.tcbrServiceOptions = tcbrServiceOptions;
|
|
194
|
-
function getAuthorizedTcrInstance(envId) {
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
EnvId: envId
|
|
198
|
-
});
|
|
199
|
-
return authorizedTcrInstances;
|
|
185
|
+
async function getAuthorizedTcrInstance(envId) {
|
|
186
|
+
let { data: { TcrInstances: authorizedTcrInstances } } = await (0, utils_1.callTcbrApi)('DescribeTcrInstances', {
|
|
187
|
+
EnvId: envId
|
|
200
188
|
});
|
|
189
|
+
return authorizedTcrInstances;
|
|
201
190
|
}
|
|
202
191
|
exports.getAuthorizedTcrInstance = getAuthorizedTcrInstance;
|
|
203
|
-
function validateTcrImageURL(authorizedTcrInstances, imageUrl) {
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
192
|
+
async function validateTcrImageURL(authorizedTcrInstances, imageUrl) {
|
|
193
|
+
const errMsg = (0, i18n_1.t)('镜像URL解析失败,请检查输入的镜像URL是否正确');
|
|
194
|
+
try {
|
|
195
|
+
const host = imageUrl.split('/')[0];
|
|
196
|
+
const namespace = imageUrl.split('/')[1];
|
|
197
|
+
const name = `${namespace}/${imageUrl.split('/')[2].split(':')[0]}`;
|
|
198
|
+
const tag = imageUrl.split('/')[2].split(':')[1];
|
|
199
|
+
const filteredInstances = authorizedTcrInstances === null || authorizedTcrInstances === void 0 ? void 0 : authorizedTcrInstances.filter(({ Domain }) => host === Domain);
|
|
200
|
+
if (!(filteredInstances === null || filteredInstances === void 0 ? void 0 : filteredInstances.length)) {
|
|
201
|
+
throw new toolbox_1.CloudBaseError(errMsg);
|
|
202
|
+
}
|
|
203
|
+
const reposUnderSpecifiedRegistry = [];
|
|
204
|
+
for (const registry of filteredInstances) {
|
|
205
|
+
const repos = [];
|
|
206
|
+
let { Id: registryId, Domain: domain } = registry;
|
|
207
|
+
const limit = 100;
|
|
208
|
+
let curIndex = 1;
|
|
209
|
+
let totalCount = 0;
|
|
210
|
+
do {
|
|
211
|
+
const rsp = await tcrCloudApiService.request('DescribeRepositories', {
|
|
212
|
+
RegistryId: registryId,
|
|
213
|
+
Offset: curIndex,
|
|
214
|
+
Limit: limit
|
|
215
|
+
});
|
|
216
|
+
repos.push(...rsp.RepositoryList);
|
|
217
|
+
curIndex += 1;
|
|
218
|
+
totalCount = rsp.TotalCount;
|
|
219
|
+
} while (repos.length < totalCount);
|
|
220
|
+
reposUnderSpecifiedRegistry.push({ registryId, domain, repos });
|
|
221
|
+
}
|
|
222
|
+
const filteredRepos = [];
|
|
223
|
+
for (const repo of reposUnderSpecifiedRegistry) {
|
|
224
|
+
const { registryId, repos } = repo;
|
|
225
|
+
filteredRepos.push(...repos.filter(({ Name }) => Name === name));
|
|
226
|
+
if (!(filteredRepos === null || filteredRepos === void 0 ? void 0 : filteredRepos.length)) {
|
|
213
227
|
throw new toolbox_1.CloudBaseError(errMsg);
|
|
214
228
|
}
|
|
215
|
-
|
|
216
|
-
for (const registry of filteredInstances) {
|
|
217
|
-
const repos = [];
|
|
218
|
-
let { Id: registryId, Domain: domain } = registry;
|
|
219
|
-
const limit = 100;
|
|
220
|
-
let curIndex = 1;
|
|
221
|
-
let totalCount = 0;
|
|
222
|
-
do {
|
|
223
|
-
const rsp = yield tcrCloudApiService.request('DescribeRepositories', {
|
|
224
|
-
RegistryId: registryId,
|
|
225
|
-
Offset: curIndex,
|
|
226
|
-
Limit: limit
|
|
227
|
-
});
|
|
228
|
-
repos.push(...rsp.RepositoryList);
|
|
229
|
-
curIndex += 1;
|
|
230
|
-
totalCount = rsp.TotalCount;
|
|
231
|
-
} while (repos.length < totalCount);
|
|
232
|
-
reposUnderSpecifiedRegistry.push({ registryId, domain, repos });
|
|
233
|
-
}
|
|
234
|
-
const filteredRepos = [];
|
|
235
|
-
for (const repo of reposUnderSpecifiedRegistry) {
|
|
236
|
-
const { registryId, repos } = repo;
|
|
237
|
-
filteredRepos.push(...repos.filter(({ Name }) => Name === name));
|
|
238
|
-
if (!(filteredRepos === null || filteredRepos === void 0 ? void 0 : filteredRepos.length)) {
|
|
239
|
-
throw new toolbox_1.CloudBaseError(errMsg);
|
|
240
|
-
}
|
|
241
|
-
filteredRepos.forEach(item => { item.registryId = registryId; });
|
|
242
|
-
}
|
|
243
|
-
for (const repoItem of filteredRepos) {
|
|
244
|
-
const { Name, Namespace, registryId } = repoItem;
|
|
245
|
-
const images = [];
|
|
246
|
-
const limit = 100;
|
|
247
|
-
let curIndex = 1;
|
|
248
|
-
let totalCount = 0;
|
|
249
|
-
do {
|
|
250
|
-
const rsp = yield tcrCloudApiService.request('DescribeImages', {
|
|
251
|
-
RegistryId: registryId,
|
|
252
|
-
NamespaceName: Namespace,
|
|
253
|
-
RepositoryName: Name.split(`${Namespace}/`)[1],
|
|
254
|
-
Offset: curIndex,
|
|
255
|
-
Limit: limit
|
|
256
|
-
});
|
|
257
|
-
images.push(...rsp.ImageInfoList);
|
|
258
|
-
curIndex += 1;
|
|
259
|
-
totalCount = rsp.TotalCount;
|
|
260
|
-
} while (images.length < totalCount);
|
|
261
|
-
if (!images.some(({ ImageVersion }) => ImageVersion === tag)) {
|
|
262
|
-
throw new toolbox_1.CloudBaseError(errMsg);
|
|
263
|
-
}
|
|
264
|
-
}
|
|
229
|
+
filteredRepos.forEach(item => { item.registryId = registryId; });
|
|
265
230
|
}
|
|
266
|
-
|
|
267
|
-
|
|
231
|
+
for (const repoItem of filteredRepos) {
|
|
232
|
+
const { Name, Namespace, registryId } = repoItem;
|
|
233
|
+
const images = [];
|
|
234
|
+
const limit = 100;
|
|
235
|
+
let curIndex = 1;
|
|
236
|
+
let totalCount = 0;
|
|
237
|
+
do {
|
|
238
|
+
const rsp = await tcrCloudApiService.request('DescribeImages', {
|
|
239
|
+
RegistryId: registryId,
|
|
240
|
+
NamespaceName: Namespace,
|
|
241
|
+
RepositoryName: Name.split(`${Namespace}/`)[1],
|
|
242
|
+
Offset: curIndex,
|
|
243
|
+
Limit: limit
|
|
244
|
+
});
|
|
245
|
+
images.push(...rsp.ImageInfoList);
|
|
246
|
+
curIndex += 1;
|
|
247
|
+
totalCount = rsp.TotalCount;
|
|
248
|
+
} while (images.length < totalCount);
|
|
249
|
+
if (!images.some(({ ImageVersion }) => ImageVersion === tag)) {
|
|
250
|
+
throw new toolbox_1.CloudBaseError(errMsg);
|
|
251
|
+
}
|
|
268
252
|
}
|
|
269
|
-
}
|
|
253
|
+
}
|
|
254
|
+
catch (e) {
|
|
255
|
+
throw new toolbox_1.CloudBaseError(errMsg);
|
|
256
|
+
}
|
|
270
257
|
}
|
|
271
258
|
exports.validateTcrImageURL = validateTcrImageURL;
|
|
@@ -1,70 +1,57 @@
|
|
|
1
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
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.updateCloudRunServerConfig = exports.tcbrServiceConfigOptions = void 0;
|
|
13
4
|
const toolbox_1 = require("@cloudbase/toolbox");
|
|
14
5
|
const common_1 = require("./common");
|
|
15
6
|
const utils_1 = require("../../utils");
|
|
16
7
|
const i18n_1 = require("../../i18n");
|
|
17
|
-
function tcbrServiceConfigOptions(options) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
serviceName
|
|
35
|
-
});
|
|
36
|
-
if (serviceInfo instanceof Error && serviceInfo['code'] === 'InvalidParameter') {
|
|
37
|
-
throw new toolbox_1.CloudBaseError((0, i18n_1.t)('服务不存在,请检查服务名是否正确或到控制台 {{link}} 创建服务', { link: (0, utils_1.genClickableLink)(`${utils_1.EUrl.Console}/tcbr`) }));
|
|
38
|
-
}
|
|
39
|
-
const { ServerConfig: previousServerConfig } = serviceInfo.data;
|
|
40
|
-
const newServiceOptions = {
|
|
41
|
-
EnvId: envId,
|
|
42
|
-
ServerName: serviceName,
|
|
43
|
-
OpenAccessTypes: previousServerConfig.OpenAccessTypes,
|
|
44
|
-
Cpu: cpuConverted || previousServerConfig.Cpu,
|
|
45
|
-
Mem: memConverted || previousServerConfig.Mem,
|
|
46
|
-
MinNum: minNumConverted || previousServerConfig.MinNum,
|
|
47
|
-
MaxNum: maxNumConverted || previousServerConfig.MaxNum,
|
|
48
|
-
PolicyDetails: policyDetails ? (0, common_1.extractPolicyDetails)(policyDetails) : previousServerConfig.PolicyDetails,
|
|
49
|
-
CustomLogs: customLogs || previousServerConfig.CustomLogs,
|
|
50
|
-
EnvParams: envParams ? (0, common_1.mergeEnvParams)(envParams, previousServerConfig === null || previousServerConfig === void 0 ? void 0 : previousServerConfig.EnvParams) : previousServerConfig.EnvParams,
|
|
51
|
-
InitialDelaySeconds: 2,
|
|
52
|
-
CreateTime: previousServerConfig.CreateTime,
|
|
53
|
-
Port: previousServerConfig.Port,
|
|
54
|
-
HasDockerfile: true,
|
|
55
|
-
Dockerfile: previousServerConfig.Dockerfile,
|
|
56
|
-
BuildDir: previousServerConfig.BuildDir,
|
|
57
|
-
};
|
|
58
|
-
return newServiceOptions;
|
|
8
|
+
async function tcbrServiceConfigOptions(options) {
|
|
9
|
+
let { serviceName, envId, cpu, mem, minNum, maxNum, policyDetails, customLogs, envParams, } = options;
|
|
10
|
+
if (!envId) {
|
|
11
|
+
throw new toolbox_1.CloudBaseError((0, i18n_1.t)('必须使用 -e 或 --envId 指定环境ID'));
|
|
12
|
+
}
|
|
13
|
+
if (!serviceName) {
|
|
14
|
+
throw new toolbox_1.CloudBaseError((0, i18n_1.t)('必须使用 -s 或 --serviceName 指定服务名'));
|
|
15
|
+
}
|
|
16
|
+
let { cpuConverted, memConverted, maxNumConverted, minNumConverted } = (0, utils_1.parseOptionalParams)({
|
|
17
|
+
cpu,
|
|
18
|
+
mem,
|
|
19
|
+
maxNum,
|
|
20
|
+
minNum
|
|
21
|
+
});
|
|
22
|
+
const serviceInfo = await (0, common_1.describeCloudRunServerDetail)({
|
|
23
|
+
envId,
|
|
24
|
+
serviceName
|
|
59
25
|
});
|
|
26
|
+
if (serviceInfo instanceof Error && serviceInfo['code'] === 'InvalidParameter') {
|
|
27
|
+
throw new toolbox_1.CloudBaseError((0, i18n_1.t)('服务不存在,请检查服务名是否正确或到控制台 {{link}} 创建服务', { link: (0, utils_1.genClickableLink)(`${utils_1.EUrl.Console}/tcbr`) }));
|
|
28
|
+
}
|
|
29
|
+
const { ServerConfig: previousServerConfig } = serviceInfo.data;
|
|
30
|
+
const newServiceOptions = {
|
|
31
|
+
EnvId: envId,
|
|
32
|
+
ServerName: serviceName,
|
|
33
|
+
OpenAccessTypes: previousServerConfig.OpenAccessTypes,
|
|
34
|
+
Cpu: cpuConverted || previousServerConfig.Cpu,
|
|
35
|
+
Mem: memConverted || previousServerConfig.Mem,
|
|
36
|
+
MinNum: minNumConverted || previousServerConfig.MinNum,
|
|
37
|
+
MaxNum: maxNumConverted || previousServerConfig.MaxNum,
|
|
38
|
+
PolicyDetails: policyDetails ? (0, common_1.extractPolicyDetails)(policyDetails) : previousServerConfig.PolicyDetails,
|
|
39
|
+
CustomLogs: customLogs || previousServerConfig.CustomLogs,
|
|
40
|
+
EnvParams: envParams ? (0, common_1.mergeEnvParams)(envParams, previousServerConfig === null || previousServerConfig === void 0 ? void 0 : previousServerConfig.EnvParams) : previousServerConfig.EnvParams,
|
|
41
|
+
InitialDelaySeconds: 2,
|
|
42
|
+
CreateTime: previousServerConfig.CreateTime,
|
|
43
|
+
Port: previousServerConfig.Port,
|
|
44
|
+
HasDockerfile: true,
|
|
45
|
+
Dockerfile: previousServerConfig.Dockerfile,
|
|
46
|
+
BuildDir: previousServerConfig.BuildDir,
|
|
47
|
+
};
|
|
48
|
+
return newServiceOptions;
|
|
60
49
|
}
|
|
61
50
|
exports.tcbrServiceConfigOptions = tcbrServiceConfigOptions;
|
|
62
|
-
function updateCloudRunServerConfig(options) {
|
|
63
|
-
return
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
ServerBaseConfig: options.ServerBaseConfig,
|
|
67
|
-
});
|
|
51
|
+
async function updateCloudRunServerConfig(options) {
|
|
52
|
+
return await (0, utils_1.callTcbrApi)('UpdateCloudRunServerConfig', {
|
|
53
|
+
EnvId: options.envId,
|
|
54
|
+
ServerBaseConfig: options.ServerBaseConfig,
|
|
68
55
|
});
|
|
69
56
|
}
|
|
70
57
|
exports.updateCloudRunServerConfig = updateCloudRunServerConfig;
|
|
@@ -22,15 +22,6 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
22
22
|
__setModuleDefault(result, mod);
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
-
});
|
|
33
|
-
};
|
|
34
25
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
35
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
36
27
|
};
|
|
@@ -41,43 +32,41 @@ const fs = __importStar(require("fs"));
|
|
|
41
32
|
const __1 = require("..");
|
|
42
33
|
const toolbox_1 = require("@cloudbase/toolbox");
|
|
43
34
|
const i18n_1 = require("../../i18n");
|
|
44
|
-
function packageDeploy(options) {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
loading.succeed((0, i18n_1.t)('压缩文件完成'));
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
catch (error) {
|
|
62
|
-
if (error.code === 'ENOENT') {
|
|
63
|
-
throw new toolbox_1.CloudBaseError((0, i18n_1.t)('找不到指定文件夹,请检查文件路径是否正确'));
|
|
64
|
-
}
|
|
65
|
-
else {
|
|
66
|
-
throw new toolbox_1.CloudBaseError(error.message);
|
|
67
|
-
}
|
|
35
|
+
async function packageDeploy(options) {
|
|
36
|
+
let { envId, serviceName, filePath, fileToIgnore } = options;
|
|
37
|
+
let { PackageName, PackageVersion, UploadUrl, UploadHeaders } = await (0, __1.createBuild)({
|
|
38
|
+
envId,
|
|
39
|
+
serviceName
|
|
40
|
+
});
|
|
41
|
+
const loading = (0, toolbox_1.loadingFactory)();
|
|
42
|
+
const zipFile = `.tcbr_${serviceName}_${Date.now()}.zip`;
|
|
43
|
+
const dstPath = path_1.default.join(process.cwd(), zipFile);
|
|
44
|
+
try {
|
|
45
|
+
if (fs.statSync(filePath).isDirectory()) {
|
|
46
|
+
loading.start((0, i18n_1.t)('正在压缩文件…'));
|
|
47
|
+
await (0, toolbox_1.zipDir)(filePath, dstPath, fileToIgnore);
|
|
48
|
+
loading.succeed((0, i18n_1.t)('压缩文件完成'));
|
|
68
49
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
}), {
|
|
74
|
-
startTip: (0, i18n_1.t)('\n正在上传代码包...'),
|
|
75
|
-
failTip: (0, i18n_1.t)('上传代码包失败,请稍后重试')
|
|
76
|
-
});
|
|
50
|
+
}
|
|
51
|
+
catch (error) {
|
|
52
|
+
if (error.code === 'ENOENT') {
|
|
53
|
+
throw new toolbox_1.CloudBaseError((0, i18n_1.t)('找不到指定文件夹,请检查文件路径是否正确'));
|
|
77
54
|
}
|
|
78
|
-
|
|
79
|
-
|
|
55
|
+
else {
|
|
56
|
+
throw new toolbox_1.CloudBaseError(error.message);
|
|
80
57
|
}
|
|
81
|
-
}
|
|
58
|
+
}
|
|
59
|
+
try {
|
|
60
|
+
return await (0, toolbox_1.execWithLoading)(async () => {
|
|
61
|
+
await (0, __1.uploadZip)(zipFile, UploadUrl, UploadHeaders[0]);
|
|
62
|
+
return { PackageName, PackageVersion };
|
|
63
|
+
}, {
|
|
64
|
+
startTip: (0, i18n_1.t)('\n正在上传代码包...'),
|
|
65
|
+
failTip: (0, i18n_1.t)('上传代码包失败,请稍后重试')
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
finally {
|
|
69
|
+
await fs.promises.unlink(dstPath);
|
|
70
|
+
}
|
|
82
71
|
}
|
|
83
72
|
exports.packageDeploy = packageDeploy;
|