@cloudbase/manager-node 5.8.1 → 5.8.3

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.
Files changed (34) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/lib/context.js +2 -1
  3. package/lib/database/index.js +11 -6
  4. package/lib/deploy/DeployOrchestrator.js +30 -16
  5. package/lib/deploy/FunctionDeployer.js +269 -39
  6. package/lib/deploy/StaticDeployer.js +7 -1
  7. package/lib/deploy/function/builders/cloud.js +45 -348
  8. package/lib/deploy/function/cloud-build-service.js +2 -16
  9. package/lib/deploy/function/config-guard.js +42 -32
  10. package/lib/deploy/function/enterprise-tcr.js +194 -0
  11. package/lib/deploy/function/image-tag.js +31 -0
  12. package/lib/deploy/function/local-builder.js +170 -25
  13. package/lib/deploy/function/personal-tcr.js +153 -0
  14. package/lib/deploy/types.js +11 -0
  15. package/lib/hosting/index.js +27 -0
  16. package/lib/index.js +4 -3
  17. package/lib/projectValidator/index.js +22 -20
  18. package/lib/utils/cloud-api-request.js +26 -2
  19. package/package.json +2 -2
  20. package/types/context.d.ts +17 -3
  21. package/types/database/index.d.ts +1 -0
  22. package/types/deploy/DeployOrchestrator.d.ts +10 -0
  23. package/types/deploy/FunctionDeployer.d.ts +20 -2
  24. package/types/deploy/StaticDeployer.d.ts +11 -0
  25. package/types/deploy/function/builders/cloud.d.ts +6 -39
  26. package/types/deploy/function/enterprise-tcr.d.ts +32 -0
  27. package/types/deploy/function/image-tag.d.ts +10 -0
  28. package/types/deploy/function/local-builder.d.ts +35 -6
  29. package/types/deploy/function/personal-tcr.d.ts +35 -0
  30. package/types/deploy/types.d.ts +34 -8
  31. package/types/hosting/index.d.ts +13 -0
  32. package/types/index.d.ts +5 -0
  33. package/types/projectValidator/index.d.ts +3 -2
  34. package/types/utils/cloud-api-request.d.ts +3 -2
@@ -0,0 +1,32 @@
1
+ import { INormalizedHttpCloudConfig, INormalizedHttpLocalConfig } from '../types';
2
+ type EnterpriseBuildConfig = INormalizedHttpCloudConfig | INormalizedHttpLocalConfig;
3
+ export interface ITcrApiService {
4
+ call: (options: {
5
+ Action: string;
6
+ Param: Record<string, unknown>;
7
+ }) => Promise<any>;
8
+ }
9
+ export interface IEnterpriseTcrTarget {
10
+ registryId: string;
11
+ registry: string;
12
+ namespace: string;
13
+ repository: string;
14
+ imageRepository: string;
15
+ }
16
+ export interface IEnterpriseTcrCredential {
17
+ username: string;
18
+ token: string;
19
+ }
20
+ export declare function prepareEnterpriseTcrTarget(config: EnterpriseBuildConfig, options: {
21
+ envId: string;
22
+ region: string;
23
+ service: ITcrApiService;
24
+ }): Promise<{
25
+ config: EnterpriseBuildConfig;
26
+ target: IEnterpriseTcrTarget;
27
+ }>;
28
+ export declare function createEnterpriseTcrCredential(service: ITcrApiService, registryId: string): Promise<IEnterpriseTcrCredential>;
29
+ export declare function createTcrApiService(environment: {
30
+ getCommonService: (serviceType: string, serviceVersion: string) => ITcrApiService;
31
+ }): ITcrApiService;
32
+ export {};
@@ -0,0 +1,10 @@
1
+ export interface IResolveImageTagOptions {
2
+ explicitTag?: string;
3
+ cwd: string;
4
+ now?: () => number;
5
+ readGitShortSha?: (cwd: string) => Promise<string | undefined>;
6
+ }
7
+ /**
8
+ * 生成镜像 tag:显式配置优先,其次 Git short SHA,最后回退到毫秒时间戳。
9
+ */
10
+ export declare function resolveImageTag(options: IResolveImageTagOptions): Promise<string>;
@@ -2,25 +2,54 @@ import { INormalizedHttpLocalConfig } from '../types';
2
2
  export interface ILocalBuildResult {
3
3
  imageUri: string;
4
4
  imageDigest?: string;
5
+ buildDurationMs: number;
6
+ pushDurationMs: number;
7
+ durationMs: number;
5
8
  }
6
9
  export interface IExecResult {
7
10
  ok: boolean;
8
11
  stdout: string;
9
12
  stderr: string;
10
13
  }
14
+ export interface ILocalCommandOptions {
15
+ env?: NodeJS.ProcessEnv;
16
+ input?: string;
17
+ }
11
18
  /** 可注入依赖:命令执行与文件系统检查 */
12
19
  export interface ILocalBuilderDeps {
13
- runCommand: (command: string, args: string[]) => Promise<IExecResult>;
20
+ runCommand: (command: string, args: string[], options?: ILocalCommandOptions) => Promise<IExecResult>;
14
21
  existsSync: (target: string) => boolean;
15
22
  isDirectory: (target: string) => boolean;
16
23
  isFile: (target: string) => boolean;
17
24
  }
25
+ /** 本地镜像构建阶段结果 */
26
+ export interface ILocalImageBuildResult {
27
+ imageUri: string;
28
+ buildDurationMs: number;
29
+ }
30
+ export interface ILocalBuilderOptions {
31
+ deps?: ILocalBuilderDeps;
32
+ commandOptions?: ILocalCommandOptions;
33
+ }
34
+ /** 本地构建镜像,不执行推送。 */
35
+ export declare function buildLocalImage(config: INormalizedHttpLocalConfig, onLog?: (line: string) => void, options?: ILocalBuilderOptions): Promise<ILocalImageBuildResult>;
36
+ /** 推送已构建镜像,并尽力查询远端 digest。 */
37
+ export declare function pushLocalImage(imageUri: string, onLog?: (line: string) => void, options?: ILocalBuilderOptions): Promise<{
38
+ imageDigest?: string;
39
+ pushDurationMs: number;
40
+ }>;
41
+ export declare function loginDockerRegistry(registry: string, credential: {
42
+ username: string;
43
+ secret: string;
44
+ }, options?: ILocalBuilderOptions): Promise<void>;
45
+ export declare function createTemporaryDockerConfig(): {
46
+ env: NodeJS.ProcessEnv;
47
+ cleanup: () => void;
48
+ };
18
49
  /**
19
- * 本地构建镜像并推送到目标仓库
50
+ * 本地构建镜像并推送到目标仓库。
20
51
  *
21
- * @param config 规范化的 local 部署配置
22
- * @param onLog 可选日志回调,用于透出构建输出(不含凭证)
23
- * @param deps 可注入依赖,默认真实命令与 fs;测试可传 mock
24
- * @returns 最终镜像引用与 digest
52
+ * 保留组合入口以兼容已有调用;需要实时阶段进度的编排器应分别调用
53
+ * buildLocalImage 与 pushLocalImage。
25
54
  */
26
55
  export declare function buildAndPushImage(config: INormalizedHttpLocalConfig, onLog?: (line: string) => void, deps?: ILocalBuilderDeps): Promise<ILocalBuildResult>;
@@ -0,0 +1,35 @@
1
+ import { Environment } from '../../environment';
2
+ export declare const DEFAULT_PERSONAL_TCR_REGISTRY = "ccr.ccs.tencentyun.com";
3
+ export interface IPersonalTcrService {
4
+ ensurePushTarget: (options: {
5
+ namespace: string;
6
+ repository: string;
7
+ ensureNamespace?: boolean;
8
+ ensureRepository?: boolean;
9
+ }) => Promise<void>;
10
+ cleanupTags: (options: {
11
+ namespace: string;
12
+ repository: string;
13
+ retain?: number;
14
+ }) => Promise<void>;
15
+ }
16
+ export declare class PersonalTcrService implements IPersonalTcrService {
17
+ private readonly request;
18
+ constructor(environment: Environment);
19
+ ensurePushTarget(options: {
20
+ namespace: string;
21
+ repository: string;
22
+ ensureNamespace?: boolean;
23
+ ensureRepository?: boolean;
24
+ }): Promise<void>;
25
+ cleanupTags(options: {
26
+ namespace: string;
27
+ repository: string;
28
+ retain?: number;
29
+ }): Promise<void>;
30
+ private namespaceExists;
31
+ private repositoryExists;
32
+ private createIgnoringExisting;
33
+ private listAllTags;
34
+ }
35
+ export declare function createPersonalTcrService(environment: Environment): IPersonalTcrService;
@@ -22,7 +22,7 @@ export type DeployActionKind = 'create' | 'update' | 'replace' | 'noop';
22
22
  /** 部署计划中的细粒度操作 */
23
23
  export type DeployOperation = 'create-function' | 'update-code' | 'update-config' | 'replace-function' | 'configure-access' | 'configure-gateway';
24
24
  /** 统一进度阶段 */
25
- export type DeployStage = 'validate' | 'preflight' | 'plan' | 'pack' | 'upload' | 'build' | 'push' | 'deploy-function' | 'wait-active' | 'configure-access' | 'configure-gateway' | 'done';
25
+ export type DeployStage = 'validate' | 'preflight' | 'plan' | 'pack' | 'upload' | 'login' | 'build' | 'push' | 'deploy-function' | 'wait-active' | 'configure-access' | 'configure-gateway' | 'done';
26
26
  /** 单项检查结论 */
27
27
  export type CheckStatus = 'pass' | 'warn' | 'fail';
28
28
  /**
@@ -94,6 +94,17 @@ export declare const FUNCTION_DEPLOY_ERROR: {
94
94
  readonly BUILD_ARG_INVALID: "BUILD_ARG_INVALID";
95
95
  readonly CLOUD_REGISTRY_CREDENTIAL_MISSING: "CLOUD_REGISTRY_CREDENTIAL_MISSING";
96
96
  readonly CLOUD_REGISTRY_CREDENTIAL_INVALID: "CLOUD_REGISTRY_CREDENTIAL_INVALID";
97
+ readonly TCR_REGION_MISSING: "TCR_REGION_MISSING";
98
+ readonly TCR_INSTANCE_DISCOVERY_FAILED: "TCR_INSTANCE_DISCOVERY_FAILED";
99
+ readonly TCR_INSTANCE_NOT_FOUND: "TCR_INSTANCE_NOT_FOUND";
100
+ readonly TCR_INSTANCE_AMBIGUOUS: "TCR_INSTANCE_AMBIGUOUS";
101
+ readonly TCR_INSTANCE_INVALID: "TCR_INSTANCE_INVALID";
102
+ readonly TCR_NAMESPACE_INVALID: "TCR_NAMESPACE_INVALID";
103
+ readonly TCR_NAMESPACE_QUERY_FAILED: "TCR_NAMESPACE_QUERY_FAILED";
104
+ readonly TCR_NAMESPACE_CREATE_FAILED: "TCR_NAMESPACE_CREATE_FAILED";
105
+ readonly TCR_TOKEN_CREATE_FAILED: "TCR_TOKEN_CREATE_FAILED";
106
+ readonly TCR_TOKEN_INVALID: "TCR_TOKEN_INVALID";
107
+ readonly TCR_DOCKER_LOGIN_FAILED: "TCR_DOCKER_LOGIN_FAILED";
97
108
  readonly GATEWAY_PATH_INVALID: "GATEWAY_PATH_INVALID";
98
109
  readonly LOCAL_FALLBACK_INVALID: "LOCAL_FALLBACK_INVALID";
99
110
  readonly PREFLIGHT_CODE_PATH_MISSING: "PREFLIGHT_CODE_PATH_MISSING";
@@ -243,7 +254,7 @@ export interface IHttpZipDeployConfig extends IHttpFunctionDeployCommon, ILocalC
243
254
  */
244
255
  installDependency?: boolean | 'TRUE' | 'FALSE';
245
256
  }
246
- /** 个人版 TCR 云端推送凭证,只能通过 CloudApp Secrets 传递密码。 */
257
+ /** 个人版 TCR 推送凭证,local/cloud 均可使用。 */
247
258
  export interface IRegistryCredential {
248
259
  /** 腾讯云账号 ID(UIN),作为个人版 CCR 登录用户名 */
249
260
  username: string;
@@ -258,12 +269,14 @@ export interface IImageBuildTarget {
258
269
  dockerfile?: string;
259
270
  /** 目标镜像仓库实例 ID */
260
271
  registryId?: string;
261
- /** 目标镜像命名空间;个人版 cloud 构建必填,推荐使用 {{env.TCB_TCR_NAMESPACE}} */
272
+ /**
273
+ * 目标镜像命名空间。personal local/cloud 优先使用显式配置;
274
+ * 缺省时使用当前 CloudBase envId。enterprise 可省略并由实例准备逻辑创建或复用。
275
+ */
262
276
  namespace?: string;
263
277
  /**
264
- * 目标镜像仓库路径。
265
- * personal cloud 可省略并默认使用函数名;enterprise cloud 在自动实例发现完成前需提供完整地址;
266
- * local 策略当前需提供可直接 push 的完整 registry/namespace/repository 地址。
278
+ * 目标镜像仓库路径。local/cloud 均可省略并默认使用函数名;
279
+ * manager-node 会结合目标 registry 与 namespace 组装最终推送地址。
267
280
  */
268
281
  repository?: string;
269
282
  /** local 策略的目标镜像 tag;cloud 策略由平台生成,不接受自定义 tag */
@@ -272,10 +285,15 @@ export interface IImageBuildTarget {
272
285
  platform?: string;
273
286
  /** 构建参数,不得写入敏感值 */
274
287
  buildArgs?: Record<string, string>;
275
- /** 个人版 TCR 云端推送凭证;personal + cloud 必填,推荐使用 {{env.*}} */
288
+ /**
289
+ * 个人版 TCR 推送凭证。personal local/cloud 必须由调用方显式提供;
290
+ * manager-node 仅使用该凭证登录,不创建用户、不修改远端密码,也不持久化凭证。
291
+ */
276
292
  registryCredential?: IRegistryCredential;
277
293
  /** 忽略同摘要镜像复用,强制重新构建 */
278
294
  forceBuild?: boolean;
295
+ /** 个人版 TCR 保留的最新镜像标签数量 */
296
+ retainedTags?: number;
279
297
  }
280
298
  /** HTTP 自定义镜像公共配置 */
281
299
  export interface IHttpImageRuntimeCommon extends IHttpFunctionDeployCommon {
@@ -413,16 +431,25 @@ export interface IFunctionDeployPlan {
413
431
  /** 单步执行结果 */
414
432
  export interface IDeployStepResult {
415
433
  stage: DeployStage;
434
+ /** 同一 stage 下的具体步骤名称,例如 Docker 环境检查、镜像仓库权限检查 */
435
+ label?: string;
416
436
  status: 'success' | 'skipped' | 'failed';
417
437
  /** 毫秒 */
418
438
  elapsedTime: number;
419
439
  detail?: string;
440
+ errorCode?: string;
420
441
  }
421
442
  /** 进度事件 */
422
443
  export interface IDeployProgressEvent {
423
444
  stage: DeployStage;
445
+ /** 同一 stage 下的具体步骤名称,例如 Docker 环境检查、镜像仓库权限检查 */
446
+ label?: string;
424
447
  status: 'start' | 'success' | 'skipped' | 'failed';
425
448
  message?: string;
449
+ /** 当前阶段耗时(毫秒),仅 success/failed 时提供 */
450
+ elapsedTime?: number;
451
+ errorCode?: string;
452
+ requestId?: string;
426
453
  }
427
454
  /** 部署结果 */
428
455
  export interface IFunctionDeployResult {
@@ -447,7 +474,6 @@ export interface IFunctionDeployResult {
447
474
  warnings: string[];
448
475
  plan: IFunctionDeployPlan;
449
476
  }
450
- /** 部署选项 */
451
477
  export interface IFunctionDeployOptions {
452
478
  /** 只生成计划,不执行任何变更 */
453
479
  dryRun?: boolean;
@@ -229,6 +229,9 @@ export declare class HostingService {
229
229
  }>;
230
230
  /**
231
231
  * 查询域名状态信息
232
+ *
233
+ * 仅在 CDN 域名(domainType=cdn)或老环境(未返回 domainType)时调用 CDN 接口,
234
+ * 其他域名类型(gateway / eo 等)返回空结果
232
235
  * @param options
233
236
  */
234
237
  tcbCheckResource(options: ICheckSourceOptions): Promise<{
@@ -238,6 +241,9 @@ export declare class HostingService {
238
241
  }>;
239
242
  /**
240
243
  * 域名配置变更
244
+ *
245
+ * 仅在 CDN 域名(domainType=cdn)或老环境(未返回 domainType)时调用 CDN 接口,
246
+ * 其他域名类型(gateway / eo 等)返回空结果
241
247
  * @param options
242
248
  */
243
249
  tcbModifyAttribute(options: IModifyOptions): Promise<{}>;
@@ -263,4 +269,11 @@ export declare class HostingService {
263
269
  * 将 cloudPath 转换成 cloudPath/ 形式
264
270
  */
265
271
  private getCloudKey;
272
+ /**
273
+ * 获取静态托管域名类型(cdn / gateway / eo)
274
+ *
275
+ * 后端通过 DescribeEnvInfo 返回 StaticStorages[0].DomainType,
276
+ * 仅 cdn 或空值(老环境)才允许调用 CDN 相关接口。
277
+ */
278
+ private getStorageDomainType;
266
279
  }
package/types/index.d.ts CHANGED
@@ -6,6 +6,7 @@ import { AgentService } from './agent';
6
6
  import { StorageService } from './storage';
7
7
  import { DatabaseService } from './database';
8
8
  import { LogService } from './log';
9
+ import { CloudApiRequestFn } from './context';
9
10
  import { CommonService } from './common';
10
11
  import { HostingService } from './hosting';
11
12
  import { Environment } from './environment';
@@ -34,6 +35,7 @@ interface CloudBaseConfig {
34
35
  envType?: string;
35
36
  useInternalEndpoint?: boolean;
36
37
  internalEndpointRegion?: string;
38
+ requestFn?: CloudApiRequestFn;
37
39
  }
38
40
  declare class CloudBase {
39
41
  private static cloudBase;
@@ -123,4 +125,7 @@ declare class CloudBase {
123
125
  getManagerConfig(): CloudBaseConfig;
124
126
  get isInternalEndpoint(): Boolean;
125
127
  }
128
+ declare namespace CloudBase {
129
+ type RequestFn = CloudApiRequestFn;
130
+ }
126
131
  export = CloudBase;
@@ -5,8 +5,9 @@ export declare class ProjectValidator {
5
5
  private validateSchema;
6
6
  private validateEnvId;
7
7
  /**
8
- * 个人版 TCR 的 username/password/namespace 必须在 cloudbaserc 中显式声明。
9
- * ConfigParser 已先解析 {{env.*}},因此这里同时承担缺失 env 值的前置校验。
8
+ * 个人版 TCR 的 username/password 必须在 cloudbaserc 中显式声明。
9
+ * namespace/repository 可省略,分别由部署器按 envId/函数名推导。
10
+ * ConfigParser 已先解析 {{env.*}},因此这里同时承担缺失凭证 env 值的前置校验。
10
11
  */
11
12
  private validatePersonalRegistryConfig;
12
13
  private hasPersonalCloudFunction;
@@ -1,4 +1,4 @@
1
- import { CloudBaseContext } from '../context';
1
+ import { CloudBaseContext, CloudApiRequestFn } from '../context';
2
2
  export declare class CloudService {
3
3
  service: string;
4
4
  version: string;
@@ -13,7 +13,8 @@ export declare class CloudService {
13
13
  payload: Record<string, any>;
14
14
  baseParams: Record<string, any>;
15
15
  cloudBaseContext: CloudBaseContext;
16
- constructor(context: CloudBaseContext, service: string, version: string, baseParams?: Record<string, any>);
16
+ private requestFn?;
17
+ constructor(context: CloudBaseContext, service: string, version: string, baseParams?: Record<string, any>, requestFn?: CloudApiRequestFn);
17
18
  get baseUrl(): any;
18
19
  request<T extends {}>(action: string, data?: Record<string, any>, method?: 'POST' | 'GET'): Promise<T>;
19
20
  requestWithSign(): Promise<any>;