@cloudbase/manager-node 5.6.8 → 5.7.0-beta.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/CHANGELOG.md +6 -0
- package/lib/cloudApp/index.js +12 -3
- package/lib/deploy/DatabaseDeployer.js +238 -0
- package/lib/deploy/DeployOrchestrator.js +564 -0
- package/lib/deploy/FunctionDeployer.js +611 -0
- package/lib/deploy/GatewayDeployer.js +522 -0
- package/lib/deploy/StateStore.js +327 -0
- package/lib/deploy/StaticDeployer.js +289 -0
- package/lib/deploy/domain.js +39 -0
- package/lib/deploy/framework.js +105 -0
- package/lib/deploy/function/artifact.js +207 -0
- package/lib/deploy/function/builders/cloud.js +454 -0
- package/lib/deploy/function/cam-preflight.js +157 -0
- package/lib/deploy/function/cloud-build-service.js +170 -0
- package/lib/deploy/function/config-guard.js +588 -0
- package/lib/deploy/function/docker-preflight.js +87 -0
- package/lib/deploy/function/image-preflight.js +164 -0
- package/lib/deploy/function/local-builder.js +110 -0
- package/lib/deploy/function/planner.js +282 -0
- package/lib/deploy/function/preflight.js +264 -0
- package/lib/deploy/types.js +99 -0
- package/lib/environment.js +11 -0
- package/lib/hosting/index.js +4 -1
- package/lib/index.js +31 -0
- package/lib/projectValidator/index.js +375 -0
- package/lib/projectValidator/types.js +2 -0
- package/lib/storage/index.js +6 -7
- package/lib/utils/index.js +41 -1
- package/package.json +2 -1
- package/types/cloudApp/index.d.ts +4 -0
- package/types/cloudApp/types.d.ts +87 -6
- package/types/deploy/DatabaseDeployer.d.ts +70 -0
- package/types/deploy/DeployOrchestrator.d.ts +150 -0
- package/types/deploy/FunctionDeployer.d.ts +158 -0
- package/types/deploy/GatewayDeployer.d.ts +175 -0
- package/types/deploy/StateStore.d.ts +170 -0
- package/types/deploy/StaticDeployer.d.ts +104 -0
- package/types/deploy/domain.d.ts +17 -0
- package/types/deploy/framework.d.ts +23 -0
- package/types/deploy/function/artifact.d.ts +40 -0
- package/types/deploy/function/builders/cloud.d.ts +110 -0
- package/types/deploy/function/cam-preflight.d.ts +51 -0
- package/types/deploy/function/cloud-build-service.d.ts +10 -0
- package/types/deploy/function/config-guard.d.ts +41 -0
- package/types/deploy/function/docker-preflight.d.ts +17 -0
- package/types/deploy/function/image-preflight.d.ts +21 -0
- package/types/deploy/function/local-builder.d.ts +26 -0
- package/types/deploy/function/planner.d.ts +15 -0
- package/types/deploy/function/preflight.d.ts +9 -0
- package/types/deploy/types.d.ts +429 -0
- package/types/env/type.d.ts +4 -4
- package/types/environment.d.ts +7 -0
- package/types/function/types.d.ts +15 -0
- package/types/hosting/index.d.ts +6 -0
- package/types/index.d.ts +18 -0
- package/types/interfaces/function.interface.d.ts +1 -1
- package/types/projectValidator/index.d.ts +24 -0
- package/types/projectValidator/types.d.ts +26 -0
- package/types/storage/index.d.ts +6 -0
- package/types/utils/index.d.ts +13 -0
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.createCloudBuildService = createCloudBuildService;
|
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
|
8
|
+
const os_1 = __importDefault(require("os"));
|
|
9
|
+
const path_1 = __importDefault(require("path"));
|
|
10
|
+
const error_1 = require("../../error");
|
|
11
|
+
const utils_1 = require("../../utils");
|
|
12
|
+
const http_request_1 = require("../../utils/http-request");
|
|
13
|
+
const types_1 = require("../types");
|
|
14
|
+
/**
|
|
15
|
+
* 基于 CloudAppService 的云端构建能力适配器
|
|
16
|
+
*
|
|
17
|
+
* 将 CloudApp custom 构建相关的 API/IO 逐一映射为 CloudImageBuilder 所需的
|
|
18
|
+
* ICloudBuildService 接口,使builder 与具体传输/网络实现解耦、便于测试替换。
|
|
19
|
+
*
|
|
20
|
+
* 步骤对应构建方案「阶段 A」(https://iwiki.woa.com/p/4020519533):
|
|
21
|
+
* - packContext:打包源码目录为临时 ZIP(复用 compressToZip)
|
|
22
|
+
* - getCosInfo:DescribeCloudAppCosInfo(DeployType:custom)取上传凭证与UnixTimestamp
|
|
23
|
+
* - uploadZip:PUT 上传到 COS,携带服务端返回的全部 UploadHeaders
|
|
24
|
+
* - createBuild:CreateCloudApp(DeployType:custom)触发容器内 build+push
|
|
25
|
+
* - getVersionStatus:DescribeCloudAppVersion 查询分步状态与产物
|
|
26
|
+
*/
|
|
27
|
+
const CUSTOM_DEPLOY_TYPE = 'custom';
|
|
28
|
+
const CUSTOM_BUILD_TYPE = 'zip';
|
|
29
|
+
/** 云端构建打包默认忽略项,避免上传无关文件或本地环境密钥 */
|
|
30
|
+
const DEFAULT_IGNORE = [
|
|
31
|
+
'node_modules/**',
|
|
32
|
+
'.git/**',
|
|
33
|
+
'.DS_Store',
|
|
34
|
+
'**/.DS_Store',
|
|
35
|
+
'**/.env',
|
|
36
|
+
// 保留 .env.example/.env.sample/.env.template,其余 .env.* 默认视为本地环境密钥
|
|
37
|
+
'**/.env.!(example|sample|template)'
|
|
38
|
+
];
|
|
39
|
+
/**
|
|
40
|
+
* 由CloudAppService 构造 ICloudBuildService实现
|
|
41
|
+
*/
|
|
42
|
+
function createCloudBuildService(cloudApp, options = {}) {
|
|
43
|
+
const ignore = [...DEFAULT_IGNORE, ...(options.ignore || [])];
|
|
44
|
+
return {
|
|
45
|
+
async packContext(cwd, extraEntries) {
|
|
46
|
+
if (!fs_1.default.existsSync(cwd) || !fs_1.default.statSync(cwd).isDirectory()) {
|
|
47
|
+
throw new error_1.CloudBaseError(`构建上下文目录不存在或不是目录:${cwd}`, {
|
|
48
|
+
code: types_1.FUNCTION_DEPLOY_ERROR.BUILD_CONTEXT_INVALID
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
const zipPath = path_1.default.join(os_1.default.tmpdir(), `fn-cloud-build-${Date.now()}-${Math.random().toString(36).slice(2)}.zip`);
|
|
52
|
+
const injectedEntries = (extraEntries || []).map(entry => ({
|
|
53
|
+
zipPath: entry.zipPath.replace(/\\/g, '/').replace(/^\.\//, ''),
|
|
54
|
+
content: entry.content,
|
|
55
|
+
mode: entry.mode
|
|
56
|
+
}));
|
|
57
|
+
// 源码中若存在与 SDK 注入文件同名的路径,必须从 glob 中排除,
|
|
58
|
+
// 避免 ZIP 出现重复 entry 后由解压顺序决定最终执行内容。
|
|
59
|
+
const contextIgnore = [
|
|
60
|
+
...ignore,
|
|
61
|
+
...injectedEntries.map(entry => entry.zipPath)
|
|
62
|
+
];
|
|
63
|
+
// 把 SDK 注入的辅助文件(如 push 脚本)随源码一起打进zip,
|
|
64
|
+
// 通过临时文件注入,绝不写入用户源码目录。
|
|
65
|
+
try {
|
|
66
|
+
await (0, utils_1.compressToZip)({
|
|
67
|
+
dirPath: cwd,
|
|
68
|
+
outputPath: zipPath,
|
|
69
|
+
ignore: contextIgnore,
|
|
70
|
+
extraEntries: injectedEntries
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
catch (error) {
|
|
74
|
+
try {
|
|
75
|
+
if (fs_1.default.existsSync(zipPath)) {
|
|
76
|
+
fs_1.default.unlinkSync(zipPath);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
catch (_a) {
|
|
80
|
+
// 清理未完成的临时 ZIP 失败不覆盖原始打包错误
|
|
81
|
+
}
|
|
82
|
+
const original = error instanceof Error ? error : new Error(String(error));
|
|
83
|
+
throw new error_1.CloudBaseError(`打包云端构建上下文失败:${original.message}`, {
|
|
84
|
+
code: types_1.FUNCTION_DEPLOY_ERROR.BUILD_CONTEXT_INVALID,
|
|
85
|
+
original
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
return zipPath;
|
|
89
|
+
},
|
|
90
|
+
async getCosInfo(serviceName) {
|
|
91
|
+
const res = await cloudApp.describeCosInfo({
|
|
92
|
+
deployType: CUSTOM_DEPLOY_TYPE,
|
|
93
|
+
serviceName,
|
|
94
|
+
suffix: '.zip'
|
|
95
|
+
});
|
|
96
|
+
return {
|
|
97
|
+
uploadUrl: res.UploadUrl,
|
|
98
|
+
uploadHeaders: (res.UploadHeaders || []).map(h => ({
|
|
99
|
+
key: h.Key,
|
|
100
|
+
value: h.Value
|
|
101
|
+
})),
|
|
102
|
+
unixTimestamp: res.UnixTimestamp
|
|
103
|
+
};
|
|
104
|
+
},
|
|
105
|
+
async uploadZip(cosInfo, zipPath) {
|
|
106
|
+
const zipBuffer = fs_1.default.readFileSync(zipPath);
|
|
107
|
+
// 必须携带服务端返回的全部 UploadHeaders,缺失会导致 COS 鉴权失败
|
|
108
|
+
const headers = { 'Content-Type': 'application/zip' };
|
|
109
|
+
for (const h of cosInfo.uploadHeaders) {
|
|
110
|
+
headers[h.key] = h.value;
|
|
111
|
+
}
|
|
112
|
+
const response = await (0, http_request_1.fetchStream)(cosInfo.uploadUrl, {
|
|
113
|
+
method: 'PUT',
|
|
114
|
+
body: zipBuffer,
|
|
115
|
+
headers
|
|
116
|
+
});
|
|
117
|
+
if (!response.ok) {
|
|
118
|
+
let detail = '';
|
|
119
|
+
try {
|
|
120
|
+
const text = await response.text();
|
|
121
|
+
detail = text ? ` - ${text.substring(0, 500)}` : '';
|
|
122
|
+
}
|
|
123
|
+
catch (_a) {
|
|
124
|
+
// 解析响应体失败不影响主错误抛出
|
|
125
|
+
}
|
|
126
|
+
throw new error_1.CloudBaseError(`上传源码到 COS 失败:${response.status} ${response.statusText}${detail}`, { code: types_1.FUNCTION_DEPLOY_ERROR.CLOUD_UPLOAD_FAILED });
|
|
127
|
+
}
|
|
128
|
+
},
|
|
129
|
+
async createBuild(input) {
|
|
130
|
+
const res = await cloudApp.createApp({
|
|
131
|
+
deployType: CUSTOM_DEPLOY_TYPE,
|
|
132
|
+
serviceName: input.serviceName,
|
|
133
|
+
buildType: CUSTOM_BUILD_TYPE,
|
|
134
|
+
source: {
|
|
135
|
+
type: CUSTOM_BUILD_TYPE,
|
|
136
|
+
// 原样回填 DescribeCloudAppCosInfo 返回的时间戳,指向刚上传的源码包
|
|
137
|
+
cosTimestamp: input.cosTimestamp,
|
|
138
|
+
cosSuffix: '.zip'
|
|
139
|
+
},
|
|
140
|
+
env: input.env,
|
|
141
|
+
secrets: input.secrets,
|
|
142
|
+
customSteps: input.customSteps
|
|
143
|
+
});
|
|
144
|
+
return { buildId: res.BuildId, versionName: res.VersionName, requestId: res.RequestId };
|
|
145
|
+
},
|
|
146
|
+
async getVersionStatus(serviceName, versionName) {
|
|
147
|
+
const res = await cloudApp.describeAppVersion({
|
|
148
|
+
deployType: CUSTOM_DEPLOY_TYPE,
|
|
149
|
+
serviceName,
|
|
150
|
+
versionName
|
|
151
|
+
});
|
|
152
|
+
return {
|
|
153
|
+
status: res.Status,
|
|
154
|
+
steps: res.Steps,
|
|
155
|
+
artifacts: res.Artifacts,
|
|
156
|
+
requestId: res.RequestId
|
|
157
|
+
};
|
|
158
|
+
},
|
|
159
|
+
async cleanup(zipPath) {
|
|
160
|
+
if (zipPath && fs_1.default.existsSync(zipPath)) {
|
|
161
|
+
fs_1.default.unlinkSync(zipPath);
|
|
162
|
+
}
|
|
163
|
+
},
|
|
164
|
+
delay(ms) {
|
|
165
|
+
return new Promise(resolve => {
|
|
166
|
+
setTimeout(resolve, ms);
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
}
|