@cloudbase/manager-node 4.10.0 → 4.10.2
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/constant.js
CHANGED
|
@@ -62,5 +62,13 @@ exports.COS_SDK_KEEPALIVE = process.env.COS_SDK_KEEPALIVE;
|
|
|
62
62
|
// SCF 临时 COS 配置(用于函数代码上传)
|
|
63
63
|
exports.SCF_TEMP_COS = {
|
|
64
64
|
APPID: '1253665819',
|
|
65
|
-
|
|
65
|
+
// 区域前缀映射:region -> bucket 前缀
|
|
66
|
+
REGION_PREFIX_MAP: {
|
|
67
|
+
'ap-shanghai': 'sh',
|
|
68
|
+
'ap-guangzhou': 'gz',
|
|
69
|
+
'ap-beijing': 'bj',
|
|
70
|
+
'ap-singapore': 'sg'
|
|
71
|
+
},
|
|
72
|
+
DEFAULT_REGION_PREFIX: 'sh',
|
|
73
|
+
DEFAULT_REGION: 'ap-shanghai'
|
|
66
74
|
};
|
package/lib/function/index.js
CHANGED
|
@@ -23,6 +23,30 @@ function isNodeFunction(runtime) {
|
|
|
23
23
|
// 不严格限制
|
|
24
24
|
return runtime === 'Nodejs10.15' || runtime === 'Nodejs8.9' || (runtime === null || runtime === void 0 ? void 0 : runtime.includes('Nodejs'));
|
|
25
25
|
}
|
|
26
|
+
/**
|
|
27
|
+
* 构建镜像配置对象
|
|
28
|
+
* @param imageConfig 镜像配置
|
|
29
|
+
* @param options 可选配置
|
|
30
|
+
* @param options.includeCommandList 是否包含 CommandList/ArgsList(仅 CreateFunction 支持)
|
|
31
|
+
* @returns 构建好的镜像配置对象
|
|
32
|
+
*/
|
|
33
|
+
function buildImageConfig(imageConfig, options) {
|
|
34
|
+
var _a, _b;
|
|
35
|
+
const { includeCommandList = false } = options || {};
|
|
36
|
+
const config = Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({ ImageType: imageConfig.imageType || 'enterprise', ImageUri: imageConfig.imageUri }, (imageConfig.registryId && { RegistryId: imageConfig.registryId })), (imageConfig.entryPoint && { EntryPoint: imageConfig.entryPoint })), (imageConfig.command && { Command: imageConfig.command })), (imageConfig.args && { Args: imageConfig.args })), (typeof imageConfig.containerImageAccelerate === 'boolean' && {
|
|
37
|
+
ContainerImageAccelerate: imageConfig.containerImageAccelerate
|
|
38
|
+
})), { ImagePort: imageConfig.imagePort || 9000 });
|
|
39
|
+
// CommandList 和 ArgsList 仅在 CreateFunction 时支持
|
|
40
|
+
if (includeCommandList) {
|
|
41
|
+
if ((_a = imageConfig.commandList) === null || _a === void 0 ? void 0 : _a.length) {
|
|
42
|
+
config.CommandList = imageConfig.commandList;
|
|
43
|
+
}
|
|
44
|
+
if ((_b = imageConfig.argsList) === null || _b === void 0 ? void 0 : _b.length) {
|
|
45
|
+
config.ArgsList = imageConfig.argsList;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return config;
|
|
49
|
+
}
|
|
26
50
|
// 解析函数配置,换成请求参数
|
|
27
51
|
function configToParams(options) {
|
|
28
52
|
var _a, _b, _c, _d, _e, _f, _g;
|
|
@@ -106,6 +130,12 @@ function configToParams(options) {
|
|
|
106
130
|
if (func === null || func === void 0 ? void 0 : func.description) {
|
|
107
131
|
params.Description = func.description;
|
|
108
132
|
}
|
|
133
|
+
// 镜像配置(用于镜像部署)
|
|
134
|
+
if (func === null || func === void 0 ? void 0 : func.imageConfig) {
|
|
135
|
+
params.Code = {
|
|
136
|
+
ImageConfig: buildImageConfig(func.imageConfig, { includeCommandList: true })
|
|
137
|
+
};
|
|
138
|
+
}
|
|
109
139
|
return params;
|
|
110
140
|
}
|
|
111
141
|
class FunctionService {
|
|
@@ -161,6 +191,7 @@ class FunctionService {
|
|
|
161
191
|
* @returns {(Promise<IResponseInfo | ICreateFunctionRes>)}
|
|
162
192
|
*/
|
|
163
193
|
async createFunction(funcParam) {
|
|
194
|
+
var _a;
|
|
164
195
|
const { env } = this.getFunctionConfig();
|
|
165
196
|
const { func, functionRootPath, force = false, base64Code, codeSecret, functionPath, deployMode } = funcParam;
|
|
166
197
|
const funcName = func.name;
|
|
@@ -173,13 +204,30 @@ class FunctionService {
|
|
|
173
204
|
Stamp: 'MINI_QCBASE'
|
|
174
205
|
}
|
|
175
206
|
});
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
207
|
+
// 根据部署方式处理 Code 参数
|
|
208
|
+
// 优先使用显式指定的 deployMode,如果未指定但存在 imageConfig 则认为是镜像部署
|
|
209
|
+
const isImageDeploy = deployMode === 'image' || (!deployMode && func.imageConfig);
|
|
210
|
+
if (isImageDeploy) {
|
|
211
|
+
// 镜像部署:Code 参数已在 configToParams 中通过 imageConfig 设置
|
|
212
|
+
if (!((_a = func.imageConfig) === null || _a === void 0 ? void 0 : _a.imageUri)) {
|
|
213
|
+
throw new error_1.CloudBaseError('镜像部署需要配置 imageConfig.imageUri');
|
|
214
|
+
}
|
|
215
|
+
// 镜像部署的特殊配置
|
|
216
|
+
// 镜像函数不需要 Handler
|
|
217
|
+
delete params.Handler;
|
|
218
|
+
// 镜像函数不需要安装依赖
|
|
219
|
+
delete params.InstallDependency;
|
|
220
|
+
}
|
|
221
|
+
else {
|
|
222
|
+
// 代码部署:通过 getCodeParams 获取代码参数
|
|
223
|
+
params.Code = await this.getCodeParams({
|
|
224
|
+
func,
|
|
225
|
+
base64Code,
|
|
226
|
+
functionPath,
|
|
227
|
+
functionRootPath,
|
|
228
|
+
deployMode
|
|
229
|
+
}, params.InstallDependency);
|
|
230
|
+
}
|
|
183
231
|
const { TopicId, LogsetId } = this.getClsServiceConfig();
|
|
184
232
|
params.ClsTopicId = TopicId;
|
|
185
233
|
params.ClsLogsetId = LogsetId;
|
|
@@ -203,13 +251,14 @@ class FunctionService {
|
|
|
203
251
|
const functionExist = e.code === 'ResourceInUse.FunctionName' || e.code === 'ResourceInUse.Function';
|
|
204
252
|
// 已存在同名函数,强制更新
|
|
205
253
|
if (functionExist && force) {
|
|
206
|
-
// 1.
|
|
254
|
+
// 1. 更新函数代码(通过 deployMode 区分镜像部署和代码部署)
|
|
207
255
|
const codeRes = await this.updateFunctionCode({
|
|
208
256
|
func,
|
|
209
257
|
base64Code,
|
|
210
258
|
functionPath,
|
|
211
259
|
functionRootPath,
|
|
212
|
-
codeSecret: codeSecret
|
|
260
|
+
codeSecret: codeSecret,
|
|
261
|
+
deployMode: isImageDeploy ? 'image' : undefined
|
|
213
262
|
});
|
|
214
263
|
// 等待函数状态正常
|
|
215
264
|
await this.waitFunctionActive(funcName, codeSecret);
|
|
@@ -663,9 +712,35 @@ class FunctionService {
|
|
|
663
712
|
* @memberof FunctionService
|
|
664
713
|
*/
|
|
665
714
|
async updateFunctionCode(funcParam) {
|
|
715
|
+
var _a;
|
|
666
716
|
const { func, functionRootPath, base64Code, codeSecret, functionPath, deployMode } = funcParam;
|
|
667
717
|
const funcName = func.name;
|
|
668
718
|
const { env } = this.getFunctionConfig();
|
|
719
|
+
// 镜像部署:使用镜像配置更新函数代码
|
|
720
|
+
if (deployMode === 'image') {
|
|
721
|
+
if (!((_a = func.imageConfig) === null || _a === void 0 ? void 0 : _a.imageUri)) {
|
|
722
|
+
throw new error_1.CloudBaseError('镜像部署需要配置 imageConfig.imageUri');
|
|
723
|
+
}
|
|
724
|
+
const params = {
|
|
725
|
+
FunctionName: funcName,
|
|
726
|
+
EnvId: env,
|
|
727
|
+
Code: {
|
|
728
|
+
ImageConfig: buildImageConfig(func.imageConfig)
|
|
729
|
+
}
|
|
730
|
+
};
|
|
731
|
+
try {
|
|
732
|
+
// 等待函数状态正常
|
|
733
|
+
await this.waitFunctionActive(funcName, codeSecret);
|
|
734
|
+
return await this.tcbService.request('UpdateFunctionCode', params);
|
|
735
|
+
}
|
|
736
|
+
catch (e) {
|
|
737
|
+
throw new error_1.CloudBaseError(`[${funcName}] 函数代码更新失败:${e.message}`, {
|
|
738
|
+
code: e.code,
|
|
739
|
+
requestId: e.requestId
|
|
740
|
+
});
|
|
741
|
+
}
|
|
742
|
+
}
|
|
743
|
+
// 代码部署:原有逻辑
|
|
669
744
|
let installDependency;
|
|
670
745
|
// Node 函数默认安装依赖
|
|
671
746
|
installDependency = isNodeFunction(func.runtime) ? 'TRUE' : 'FALSE';
|
|
@@ -1237,11 +1312,14 @@ class FunctionService {
|
|
|
1237
1312
|
});
|
|
1238
1313
|
const zipFilePath = await packer.compressFiles();
|
|
1239
1314
|
// 3. 初始化 cos 并上传
|
|
1315
|
+
// 根据环境 region 获取对应的 bucket 前缀
|
|
1316
|
+
const region = this.environment.cloudBaseContext.region || constant_1.SCF_TEMP_COS.DEFAULT_REGION;
|
|
1317
|
+
const regionPrefix = constant_1.SCF_TEMP_COS.REGION_PREFIX_MAP[region] || constant_1.SCF_TEMP_COS.DEFAULT_REGION_PREFIX;
|
|
1240
1318
|
const tempCosObjectName = `/${cosDate}/${objectPath}`;
|
|
1241
1319
|
const uploadParams = {
|
|
1242
|
-
Bucket:
|
|
1320
|
+
Bucket: `${regionPrefix}tempcos-${constant_1.SCF_TEMP_COS.APPID}`,
|
|
1243
1321
|
Key: tempCosObjectName,
|
|
1244
|
-
Region:
|
|
1322
|
+
Region: region,
|
|
1245
1323
|
FilePath: zipFilePath,
|
|
1246
1324
|
};
|
|
1247
1325
|
const cos = new cos_nodejs_sdk_v5_1.default({
|
|
@@ -1384,9 +1462,10 @@ class FunctionService {
|
|
|
1384
1462
|
}
|
|
1385
1463
|
// 默认走 COS 上传
|
|
1386
1464
|
console.log(`[${func.name}] 部署方式: COS 上传`);
|
|
1465
|
+
const region = this.environment.cloudBaseContext.region || constant_1.SCF_TEMP_COS.DEFAULT_REGION;
|
|
1387
1466
|
const legacyResult = await this.uploadFunctionZipToCosLegacy(options, installDependency);
|
|
1388
1467
|
return {
|
|
1389
|
-
CosBucketRegion:
|
|
1468
|
+
CosBucketRegion: region,
|
|
1390
1469
|
TempCosObjectName: `/${legacyResult.Key}`
|
|
1391
1470
|
};
|
|
1392
1471
|
}
|
package/package.json
CHANGED
package/types/constant.d.ts
CHANGED
|
@@ -50,5 +50,7 @@ export declare const COS_SDK_PROTOCOL: string;
|
|
|
50
50
|
export declare const COS_SDK_KEEPALIVE: string;
|
|
51
51
|
export declare const SCF_TEMP_COS: {
|
|
52
52
|
APPID: string;
|
|
53
|
-
|
|
53
|
+
REGION_PREFIX_MAP: Record<string, string>;
|
|
54
|
+
DEFAULT_REGION_PREFIX: string;
|
|
55
|
+
DEFAULT_REGION: string;
|
|
54
56
|
};
|
|
@@ -6,7 +6,7 @@ export interface IFunctionCode {
|
|
|
6
6
|
functionRootPath?: string;
|
|
7
7
|
base64Code?: string;
|
|
8
8
|
functionPath?: string;
|
|
9
|
-
deployMode?: 'cos' | 'zip';
|
|
9
|
+
deployMode?: 'cos' | 'zip' | 'image';
|
|
10
10
|
}
|
|
11
11
|
export interface ICreateFunctionParam {
|
|
12
12
|
func: ICloudFunction & {
|
|
@@ -17,7 +17,7 @@ export interface ICreateFunctionParam {
|
|
|
17
17
|
base64Code?: string;
|
|
18
18
|
functionPath?: string;
|
|
19
19
|
codeSecret?: string;
|
|
20
|
-
deployMode?: 'cos' | 'zip';
|
|
20
|
+
deployMode?: 'cos' | 'zip' | 'image';
|
|
21
21
|
}
|
|
22
22
|
export interface IUpdateFunctionCodeParam {
|
|
23
23
|
func: ICloudFunction;
|
|
@@ -25,7 +25,7 @@ export interface IUpdateFunctionCodeParam {
|
|
|
25
25
|
functionRootPath?: string;
|
|
26
26
|
base64Code?: string;
|
|
27
27
|
codeSecret?: string;
|
|
28
|
-
deployMode?: 'cos' | 'zip';
|
|
28
|
+
deployMode?: 'cos' | 'zip' | 'image';
|
|
29
29
|
}
|
|
30
30
|
export interface IUpdateFunctionIncrementalCodeParam {
|
|
31
31
|
func: ICloudFunction;
|
|
@@ -36,7 +36,7 @@ export interface IUpdateFunctionIncrementalCodeParam {
|
|
|
36
36
|
export interface ICreateFunctionRes {
|
|
37
37
|
triggerRes: IResponseInfo;
|
|
38
38
|
configRes: IResponseInfo;
|
|
39
|
-
codeRes
|
|
39
|
+
codeRes?: IResponseInfo;
|
|
40
40
|
}
|
|
41
41
|
export interface IFunctionLayerOptions {
|
|
42
42
|
contentPath?: string;
|
|
@@ -191,22 +191,22 @@ export interface ILayerVersionItem {
|
|
|
191
191
|
LayerVersion: number;
|
|
192
192
|
}
|
|
193
193
|
export interface IFunctionUpdateAttribute {
|
|
194
|
-
Code
|
|
195
|
-
Description
|
|
194
|
+
Code?: IFunctionCode;
|
|
195
|
+
Description?: string;
|
|
196
196
|
FunctionName: string;
|
|
197
|
-
MemorySize
|
|
198
|
-
Timeout
|
|
199
|
-
UseGpu
|
|
200
|
-
Namespace
|
|
201
|
-
Environment
|
|
197
|
+
MemorySize?: number;
|
|
198
|
+
Timeout?: number;
|
|
199
|
+
UseGpu?: 'FALSE' | 'TRUE';
|
|
200
|
+
Namespace?: string;
|
|
201
|
+
Environment?: {
|
|
202
202
|
Variables: IEnvVariable[];
|
|
203
203
|
};
|
|
204
|
-
VpcConfig
|
|
204
|
+
VpcConfig?: {
|
|
205
205
|
VpcId: string;
|
|
206
206
|
SubnetId: string;
|
|
207
207
|
};
|
|
208
208
|
InstallDependency?: 'FALSE' | 'TRUE';
|
|
209
|
-
PublicNetConfig
|
|
209
|
+
PublicNetConfig?: {
|
|
210
210
|
PublicNetStatus: string;
|
|
211
211
|
EipConfig: {
|
|
212
212
|
EipStatus: string;
|
|
@@ -216,4 +216,20 @@ export interface IFunctionUpdateAttribute {
|
|
|
216
216
|
Layers?: ILayerVersionItem[];
|
|
217
217
|
ClsLogsetId?: string;
|
|
218
218
|
ClsTopicId?: string;
|
|
219
|
+
Runtime?: string;
|
|
220
|
+
Handler?: string;
|
|
221
|
+
Role?: string;
|
|
222
|
+
L5Enable?: string | null;
|
|
223
|
+
CodeSecret?: string;
|
|
224
|
+
Type?: string;
|
|
225
|
+
ProtocolType?: string;
|
|
226
|
+
ProtocolParams?: {
|
|
227
|
+
WSParams?: {
|
|
228
|
+
IdleTimeOut?: number;
|
|
229
|
+
};
|
|
230
|
+
};
|
|
231
|
+
InstanceConcurrencyConfig?: {
|
|
232
|
+
DynamicEnabled?: 'FALSE' | 'TRUE';
|
|
233
|
+
MaxConcurrency?: number;
|
|
234
|
+
};
|
|
219
235
|
}
|
|
@@ -21,6 +21,18 @@ export interface LayerVersionSimple {
|
|
|
21
21
|
LayerName: string;
|
|
22
22
|
LayerVersion: number;
|
|
23
23
|
}
|
|
24
|
+
export interface IFunctionImageConfig {
|
|
25
|
+
imageType: 'enterprise' | 'personal';
|
|
26
|
+
imageUri: string;
|
|
27
|
+
registryId?: string;
|
|
28
|
+
entryPoint?: string;
|
|
29
|
+
command?: string;
|
|
30
|
+
args?: string;
|
|
31
|
+
containerImageAccelerate?: boolean;
|
|
32
|
+
imagePort?: number;
|
|
33
|
+
commandList?: string[];
|
|
34
|
+
argsList?: string[];
|
|
35
|
+
}
|
|
24
36
|
export interface ICloudFunction extends ICloudFunctionConfig {
|
|
25
37
|
name: string;
|
|
26
38
|
description?: string;
|
|
@@ -44,6 +56,7 @@ export interface ICloudFunction extends ICloudFunctionConfig {
|
|
|
44
56
|
version: number;
|
|
45
57
|
}[];
|
|
46
58
|
triggers?: ICloudFunctionTrigger[];
|
|
59
|
+
imageConfig?: IFunctionImageConfig;
|
|
47
60
|
}
|
|
48
61
|
export interface ICloudFunctionV2 {
|
|
49
62
|
name: string;
|