@lark-apaas/miaoda-cli 0.1.4-alpha.a655ae4 → 0.1.4-alpha.b2fdfff
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/README.md +1 -1
- package/dist/api/deploy/index.js +2 -1
- package/dist/api/deploy/modern.js +8 -0
- package/dist/services/app/init/template.js +3 -2
- package/dist/services/deploy/modern/atoms/build.js +8 -3
- package/dist/services/deploy/modern/atoms/upload.js +90 -49
- package/dist/services/deploy/modern/pipelines/local.js +1 -1
- package/dist/services/deploy/modern/protocol.js +83 -4
- package/dist/utils/http.js +9 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -54,7 +54,7 @@ miaoda file ls --output json
|
|
|
54
54
|
## 环境变量
|
|
55
55
|
|
|
56
56
|
- `MIAODA_APP_ID`:默认应用 ID,等价于 `--app-id`。
|
|
57
|
-
- `MIAODA_CANARY_HEADER
|
|
57
|
+
- `MIAODA_CANARY_HEADER`:HTTP 请求的 `x-tt-env` 小流量头取值。未设置时默认 `boe_miaoda_doubao`;设为空字符串则不带该头(例:`export MIAODA_CANARY_HEADER=boe_xxx`)。值形如 `ppe_xxx` 时额外带上 `x-use-ppe: 1`。
|
|
58
58
|
|
|
59
59
|
## 输出契约
|
|
60
60
|
|
package/dist/api/deploy/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.NodeStatus = exports.nodeStatusFromText = exports.nodeStatusText = exports.errorJobSchema = exports.deployGetSchema = exports.deployHistorySchema = exports.batchSavePluginInstances = exports.LocalReleaseStatus = exports.getModernLastPublishedVersion = exports.getModernReleaseStatus = exports.createModernRelease = exports.updateLocalRelease = exports.createLocalRelease = exports.preRelease = exports.queryPipelineInstance = exports.getErrorLog = exports.listPipelineInstances = exports.createRelease = void 0;
|
|
3
|
+
exports.NodeStatus = exports.nodeStatusFromText = exports.nodeStatusText = exports.errorJobSchema = exports.deployGetSchema = exports.deployHistorySchema = exports.batchSavePluginInstances = exports.LocalReleaseStatus = exports.getModernLastPublishedVersion = exports.getModernReleaseStatus = exports.createModernRelease = exports.callbackStatic = exports.updateLocalRelease = exports.createLocalRelease = exports.preRelease = exports.queryPipelineInstance = exports.getErrorLog = exports.listPipelineInstances = exports.createRelease = void 0;
|
|
4
4
|
var api_1 = require("./api");
|
|
5
5
|
Object.defineProperty(exports, "createRelease", { enumerable: true, get: function () { return api_1.createRelease; } });
|
|
6
6
|
Object.defineProperty(exports, "listPipelineInstances", { enumerable: true, get: function () { return api_1.listPipelineInstances; } });
|
|
@@ -10,6 +10,7 @@ var modern_1 = require("./modern");
|
|
|
10
10
|
Object.defineProperty(exports, "preRelease", { enumerable: true, get: function () { return modern_1.preRelease; } });
|
|
11
11
|
Object.defineProperty(exports, "createLocalRelease", { enumerable: true, get: function () { return modern_1.createLocalRelease; } });
|
|
12
12
|
Object.defineProperty(exports, "updateLocalRelease", { enumerable: true, get: function () { return modern_1.updateLocalRelease; } });
|
|
13
|
+
Object.defineProperty(exports, "callbackStatic", { enumerable: true, get: function () { return modern_1.callbackStatic; } });
|
|
13
14
|
Object.defineProperty(exports, "createModernRelease", { enumerable: true, get: function () { return modern_1.createRelease; } });
|
|
14
15
|
Object.defineProperty(exports, "getModernReleaseStatus", { enumerable: true, get: function () { return modern_1.getReleaseStatus; } });
|
|
15
16
|
Object.defineProperty(exports, "getModernLastPublishedVersion", { enumerable: true, get: function () { return modern_1.getLastPublishedVersion; } });
|
|
@@ -13,6 +13,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
13
13
|
exports.preRelease = preRelease;
|
|
14
14
|
exports.createLocalRelease = createLocalRelease;
|
|
15
15
|
exports.updateLocalRelease = updateLocalRelease;
|
|
16
|
+
exports.callbackStatic = callbackStatic;
|
|
16
17
|
exports.createRelease = createRelease;
|
|
17
18
|
exports.getReleaseStatus = getReleaseStatus;
|
|
18
19
|
exports.getLastPublishedVersion = getLastPublishedVersion;
|
|
@@ -48,6 +49,13 @@ async function updateLocalRelease(req) {
|
|
|
48
49
|
const url = `/v1/devops/app/${encodeURIComponent(appID)}/local_publish/update_release`;
|
|
49
50
|
await (0, http_1.postInnerApi)(url, body, envelopeOpts('Failed to update local release'));
|
|
50
51
|
}
|
|
52
|
+
// ── callbackStatic(PaaS Storage 静态资源上传完成回调) ──
|
|
53
|
+
/** POST /v1/storage/app/:appID/bucket/:bucketID/object/callbackStatic */
|
|
54
|
+
async function callbackStatic(req) {
|
|
55
|
+
const { appID, bucketID, uploadID } = req;
|
|
56
|
+
const url = `/v1/storage/app/${encodeURIComponent(appID)}/bucket/${encodeURIComponent(bucketID)}/object/callbackStatic`;
|
|
57
|
+
return (0, http_1.postInnerApi)(url, { uploadID }, envelopeOpts('Failed to callback static upload'));
|
|
58
|
+
}
|
|
51
59
|
// ── release(远端部署,B / C 链路;本期不导出,类型骨架已就绪) ──
|
|
52
60
|
/** POST /v1/devops/app/:appID/remote_publish/release */
|
|
53
61
|
async function createRelease(req) {
|
|
@@ -16,11 +16,12 @@ exports.TEMPLATE_PACKAGE_BY_STACK = {
|
|
|
16
16
|
html: '@lark-apaas/coding-template-html',
|
|
17
17
|
};
|
|
18
18
|
exports.SUPPORTED_STACKS = Object.keys(exports.TEMPLATE_PACKAGE_BY_STACK);
|
|
19
|
-
// template/ 内以下划线开头的占位文件名在渲染时改名(npm publish 会把 .gitignore 吞掉,
|
|
20
|
-
// 模板里用 _gitignore 提交,渲染时再改回)。
|
|
19
|
+
// template/ 内以下划线开头的占位文件名在渲染时改名(npm publish 会把 .gitignore / .npmrc 吞掉,
|
|
20
|
+
// 模板里用 _gitignore / _npmrc 提交,渲染时再改回)。
|
|
21
21
|
const RENAME_FILES = {
|
|
22
22
|
_gitignore: '.gitignore',
|
|
23
23
|
'_env.local': '.env.local',
|
|
24
|
+
_npmrc: '.npmrc',
|
|
24
25
|
};
|
|
25
26
|
function renderTemplate(opts) {
|
|
26
27
|
const packageName = exports.TEMPLATE_PACKAGE_BY_STACK[opts.stack];
|
|
@@ -6,13 +6,14 @@ const error_1 = require("../../../../utils/error");
|
|
|
6
6
|
const logger_1 = require("../../../../utils/logger");
|
|
7
7
|
const protocol_1 = require("../protocol");
|
|
8
8
|
/**
|
|
9
|
-
* 给
|
|
9
|
+
* 给 RESOURCE_CDN_PREFIX 补 https:// 协议头:
|
|
10
10
|
* - 已带 http:// 或 https:// → 原样返回
|
|
11
11
|
* - 以 / 开头(绝对路径)→ 原样返回
|
|
12
12
|
* - 不含 dot(看起来不像域名,比如纯路径 app_xxx/2)→ 原样返回
|
|
13
13
|
* - 其它(典型:lf-xxx.bytetos.com/...)→ 前缀 https://
|
|
14
14
|
*
|
|
15
15
|
* template 的 build script 直接拿来当 vite base / asset URL 用,必须是合法 URL。
|
|
16
|
+
* STATIC_CDN_PREFIX 由 runtime 同域提供(相对路径),不走这里。
|
|
16
17
|
*/
|
|
17
18
|
function ensureHttpsScheme(v) {
|
|
18
19
|
if (/^https?:\/\//i.test(v))
|
|
@@ -28,17 +29,21 @@ function ensureHttpsScheme(v) {
|
|
|
28
29
|
* MIAODA_APP_ID / MIAODA_VERSION / MIAODA_STACK
|
|
29
30
|
* MIAODA_RESOURCE_CDN_PREFIX / MIAODA_STATIC_CDN_PREFIX
|
|
30
31
|
*
|
|
31
|
-
*
|
|
32
|
+
* MIAODA_STATIC_CDN_PREFIX 取自 output_static_paas_storage_credential.downloadURLPrefix,
|
|
33
|
+
* 是 runtime 同域相对路径(例如 /app/<appId>/runtime/api/v1/storage/object/<bucket>/),
|
|
34
|
+
* 不补 https scheme,原样注入。顶层 static_cdn_prefix 不再下发。
|
|
35
|
+
*
|
|
32
36
|
* build 失败抛 AppError(execSync 自身会 throw,捕获后包一层加错误码)。
|
|
33
37
|
*/
|
|
34
38
|
function runBuild(opts) {
|
|
39
|
+
const staticCred = (0, protocol_1.parsePaasStorageCredential)((0, protocol_1.requireDataKey)(opts.data, protocol_1.DataKey.OUTPUT_STATIC_PAAS_STORAGE_CREDENTIAL), protocol_1.DataKey.OUTPUT_STATIC_PAAS_STORAGE_CREDENTIAL);
|
|
35
40
|
const buildEnv = {
|
|
36
41
|
...process.env,
|
|
37
42
|
MIAODA_APP_ID: opts.appId,
|
|
38
43
|
MIAODA_VERSION: opts.version,
|
|
39
44
|
MIAODA_STACK: opts.templateKey,
|
|
40
45
|
MIAODA_RESOURCE_CDN_PREFIX: ensureHttpsScheme((0, protocol_1.requireDataKey)(opts.data, protocol_1.DataKey.RESOURCE_CDN_PREFIX)),
|
|
41
|
-
MIAODA_STATIC_CDN_PREFIX:
|
|
46
|
+
MIAODA_STATIC_CDN_PREFIX: staticCred.downloadURLPrefix,
|
|
42
47
|
};
|
|
43
48
|
(0, logger_1.log)('deploy', 'Building...');
|
|
44
49
|
try {
|
|
@@ -8,21 +8,28 @@ const node_fs_1 = __importDefault(require("node:fs"));
|
|
|
8
8
|
const node_os_1 = __importDefault(require("node:os"));
|
|
9
9
|
const node_path_1 = __importDefault(require("node:path"));
|
|
10
10
|
const node_child_process_1 = require("node:child_process");
|
|
11
|
+
const index_1 = require("../../../../api/deploy/index");
|
|
11
12
|
const error_1 = require("../../../../utils/error");
|
|
12
13
|
const logger_1 = require("../../../../utils/logger");
|
|
13
14
|
const constants_1 = require("../constants");
|
|
14
15
|
const protocol_1 = require("../protocol");
|
|
15
16
|
const UPLOAD_PLAN = [
|
|
16
|
-
{ dir: constants_1.OUTPUT_DIR, dataKey: protocol_1.DataKey.OUTPUT_TOS_UPLOAD_CREDENTIAL, required: true },
|
|
17
17
|
{
|
|
18
|
+
kind: 'tos',
|
|
19
|
+
dir: constants_1.OUTPUT_DIR,
|
|
20
|
+
dataKey: protocol_1.DataKey.OUTPUT_TOS_UPLOAD_CREDENTIAL,
|
|
21
|
+
required: true,
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
kind: 'tos',
|
|
18
25
|
dir: constants_1.OUTPUT_RESOURCE_DIR,
|
|
19
26
|
dataKey: protocol_1.DataKey.OUTPUT_RESOURCE_TOS_UPLOAD_CREDENTIAL,
|
|
20
27
|
required: false,
|
|
21
28
|
},
|
|
22
29
|
{
|
|
30
|
+
kind: 'paas_storage',
|
|
23
31
|
dir: constants_1.OUTPUT_STATIC_DIR,
|
|
24
|
-
dataKey: protocol_1.DataKey.
|
|
25
|
-
required: false,
|
|
32
|
+
dataKey: protocol_1.DataKey.OUTPUT_STATIC_PAAS_STORAGE_CREDENTIAL,
|
|
26
33
|
},
|
|
27
34
|
];
|
|
28
35
|
function resolveTosutilPath() {
|
|
@@ -36,33 +43,28 @@ function resolveTosutilPath() {
|
|
|
36
43
|
}
|
|
37
44
|
throw new error_1.AppError('DEPLOY_TOSUTIL_MISSING', 'tosutil is not installed or not in PATH. modern deploy requires sandbox preinstalled tosutil.');
|
|
38
45
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
const
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
const missing = required.filter((k) => typeof c[k] !== 'string' || c[k] === '');
|
|
62
|
-
if (missing.length > 0) {
|
|
63
|
-
throw new error_1.AppError('DEPLOY_CRED_INCOMPLETE', `preRelease.data["${dataKey}"] credential missing fields: ${missing.join(', ')}`);
|
|
64
|
-
}
|
|
65
|
-
return c;
|
|
46
|
+
function tosutilUploadFromTos(cred) {
|
|
47
|
+
return {
|
|
48
|
+
accessKeyID: cred.accessKeyID,
|
|
49
|
+
secretAccessKey: cred.secretAccessKey,
|
|
50
|
+
sessionToken: cred.sessionToken,
|
|
51
|
+
endpoint: cred.endpoint,
|
|
52
|
+
region: cred.region,
|
|
53
|
+
bucket: cred.bucket,
|
|
54
|
+
prefix: cred.prefix,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
function tosutilUploadFromPaasStorage(cred, dataKey) {
|
|
58
|
+
const { bucket, prefix } = (0, protocol_1.parseTosUploadPrefix)(cred.uploadPrefix, dataKey);
|
|
59
|
+
return {
|
|
60
|
+
accessKeyID: cred.accessKeyID,
|
|
61
|
+
secretAccessKey: cred.secretAccessKey,
|
|
62
|
+
sessionToken: cred.sessionToken,
|
|
63
|
+
endpoint: cred.endpoint,
|
|
64
|
+
region: cred.region,
|
|
65
|
+
bucket,
|
|
66
|
+
prefix,
|
|
67
|
+
};
|
|
66
68
|
}
|
|
67
69
|
/**
|
|
68
70
|
* 写一个 tosutil 临时 config 文件,注入 STS 凭证 + endpoint + region。
|
|
@@ -164,42 +166,81 @@ function uploadDirWithCredential(tosutilPath, sourceDir, cred, label) {
|
|
|
164
166
|
throw new error_1.AppError('DEPLOY_UPLOAD_EMPTY', `Upload failed: 0 files uploaded. source=${sourceDir}. Check tosutil credentials and bucket permissions.`);
|
|
165
167
|
}
|
|
166
168
|
}
|
|
169
|
+
function uploadTosTarget(tosutilPath, target, localPath, data) {
|
|
170
|
+
const credRaw = target.required
|
|
171
|
+
? (0, protocol_1.requireDataKey)(data, target.dataKey)
|
|
172
|
+
: (0, protocol_1.optionalDataKey)(data, target.dataKey);
|
|
173
|
+
if (credRaw === undefined) {
|
|
174
|
+
(0, logger_1.debug)(`upload: ${target.dir} exists but no credential configured, skipping`);
|
|
175
|
+
return false;
|
|
176
|
+
}
|
|
177
|
+
const cred = (0, protocol_1.parseTosUploadCredential)(credRaw, target.dataKey);
|
|
178
|
+
(0, logger_1.log)('deploy', `Uploading ${target.dir}...`);
|
|
179
|
+
uploadDirWithCredential(tosutilPath, localPath, tosutilUploadFromTos(cred), target.dir);
|
|
180
|
+
return true;
|
|
181
|
+
}
|
|
182
|
+
function uploadPaasStorageTarget(tosutilPath, target, localPath, data) {
|
|
183
|
+
// 空目录:直接跳过;callbackStatic 也不能调,否则会让后端把"未发生的上传"
|
|
184
|
+
// 误以为已完成。凭证本身 build 阶段已经消费过 downloadURLPrefix,这里不重复要求。
|
|
185
|
+
if (node_fs_1.default.readdirSync(localPath).length === 0) {
|
|
186
|
+
(0, logger_1.debug)(`upload: ${target.dir} is empty, skipping`);
|
|
187
|
+
return undefined;
|
|
188
|
+
}
|
|
189
|
+
const cred = (0, protocol_1.parsePaasStorageCredential)((0, protocol_1.requireDataKey)(data, target.dataKey), target.dataKey);
|
|
190
|
+
(0, logger_1.log)('deploy', `Uploading ${target.dir}...`);
|
|
191
|
+
uploadDirWithCredential(tosutilPath, localPath, tosutilUploadFromPaasStorage(cred, target.dataKey), target.dir);
|
|
192
|
+
return cred;
|
|
193
|
+
}
|
|
167
194
|
/**
|
|
168
|
-
*
|
|
169
|
-
*
|
|
195
|
+
* 上传三类产物。output / output_resource 走 TOS STS 凭证;output_static 走 PaaS Storage
|
|
196
|
+
* 凭证(uploadPrefix 解出 tosutil cp 目的,上传完后再调 callbackStatic 把 uploadID
|
|
197
|
+
* 提交给后端核销):
|
|
170
198
|
* - dist/output (必传) → OUTPUT_TOS_UPLOAD_CREDENTIAL
|
|
171
199
|
* - dist/output_resource (可选) → OUTPUT_RESOURCE_TOS_UPLOAD_CREDENTIAL
|
|
172
|
-
* - dist/output_static (可选) →
|
|
200
|
+
* - dist/output_static (可选) → OUTPUT_STATIC_PAAS_STORAGE_CREDENTIAL + callbackStatic
|
|
173
201
|
*
|
|
174
202
|
* 目录不存在的可选项跳过;output 不存在或凭证缺失抛错。
|
|
175
203
|
*/
|
|
176
|
-
function uploadArtifacts(opts) {
|
|
204
|
+
async function uploadArtifacts(opts) {
|
|
177
205
|
const tosutilPath = resolveTosutilPath();
|
|
178
206
|
const distDir = node_path_1.default.join(opts.projectDir, constants_1.DIST_DIR);
|
|
179
|
-
|
|
207
|
+
const outcome = { uploaded: 0 };
|
|
180
208
|
for (const target of UPLOAD_PLAN) {
|
|
181
209
|
const localPath = node_path_1.default.join(distDir, target.dir);
|
|
182
210
|
const exists = node_fs_1.default.existsSync(localPath);
|
|
183
|
-
if (
|
|
184
|
-
if (
|
|
185
|
-
|
|
211
|
+
if (target.kind === 'tos') {
|
|
212
|
+
if (!exists) {
|
|
213
|
+
if (target.required) {
|
|
214
|
+
throw new error_1.AppError('DEPLOY_NO_BUILD_OUTPUT', `Required directory missing: ${constants_1.DIST_DIR}/${target.dir}`);
|
|
215
|
+
}
|
|
216
|
+
(0, logger_1.debug)(`upload: dir not present, skipping ${target.dir}`);
|
|
217
|
+
continue;
|
|
218
|
+
}
|
|
219
|
+
if (uploadTosTarget(tosutilPath, target, localPath, opts.data)) {
|
|
220
|
+
outcome.uploaded++;
|
|
186
221
|
}
|
|
187
|
-
(0, logger_1.debug)(`upload: dir not present, skipping ${target.dir}`);
|
|
188
222
|
continue;
|
|
189
223
|
}
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
if (credRaw === undefined) {
|
|
194
|
-
(0, logger_1.debug)(`upload: ${target.dir} exists but no credential configured, skipping`);
|
|
224
|
+
// PaaS Storage 分支
|
|
225
|
+
if (!exists) {
|
|
226
|
+
(0, logger_1.debug)(`upload: dir not present, skipping ${target.dir}`);
|
|
195
227
|
continue;
|
|
196
228
|
}
|
|
197
|
-
const cred =
|
|
198
|
-
(
|
|
199
|
-
|
|
200
|
-
|
|
229
|
+
const cred = uploadPaasStorageTarget(tosutilPath, target, localPath, opts.data);
|
|
230
|
+
if (cred) {
|
|
231
|
+
outcome.staticUploaded = cred;
|
|
232
|
+
outcome.uploaded++;
|
|
233
|
+
}
|
|
201
234
|
}
|
|
202
|
-
if (uploaded === 0) {
|
|
235
|
+
if (outcome.uploaded === 0) {
|
|
203
236
|
throw new error_1.AppError('DEPLOY_UPLOAD_EMPTY', 'No artifacts uploaded — check build output.');
|
|
204
237
|
}
|
|
238
|
+
if (outcome.staticUploaded) {
|
|
239
|
+
(0, logger_1.log)('deploy', 'Callbacking static upload...');
|
|
240
|
+
await (0, index_1.callbackStatic)({
|
|
241
|
+
appID: opts.appId,
|
|
242
|
+
bucketID: outcome.staticUploaded.bucketID,
|
|
243
|
+
uploadID: outcome.staticUploaded.uploadID,
|
|
244
|
+
});
|
|
245
|
+
}
|
|
205
246
|
}
|
|
@@ -46,7 +46,7 @@ async function localBuildLocalPublishPipeline(opts) {
|
|
|
46
46
|
const release = await (0, index_1.createLocalRelease)(ctx.appId, pre.version);
|
|
47
47
|
try {
|
|
48
48
|
(0, logger_1.log)('deploy', 'Uploading artifacts...');
|
|
49
|
-
(0, index_1.uploadArtifacts)({ projectDir: ctx.projectDir, data });
|
|
49
|
+
await (0, index_1.uploadArtifacts)({ projectDir: ctx.projectDir, appId: ctx.appId, data });
|
|
50
50
|
const saveResult = await (0, index_1.savePluginInstances)({
|
|
51
51
|
projectDir: ctx.projectDir,
|
|
52
52
|
appId: ctx.appId,
|
|
@@ -3,6 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.DataKey = void 0;
|
|
4
4
|
exports.requireDataKey = requireDataKey;
|
|
5
5
|
exports.optionalDataKey = optionalDataKey;
|
|
6
|
+
exports.parseTosUploadCredential = parseTosUploadCredential;
|
|
7
|
+
exports.parsePaasStorageCredential = parsePaasStorageCredential;
|
|
8
|
+
exports.parseTosUploadPrefix = parseTosUploadPrefix;
|
|
6
9
|
const error_1 = require("../../../utils/error");
|
|
7
10
|
/**
|
|
8
11
|
* modern deploy 对外协议常量集中地(SSOT)。
|
|
@@ -15,9 +18,7 @@ exports.DataKey = {
|
|
|
15
18
|
// ── CDN 前缀(构建期注入到 build env,用于客户端资源访问) ──
|
|
16
19
|
/** dist/output_resource 对应的 CDN 域名前缀 */
|
|
17
20
|
RESOURCE_CDN_PREFIX: 'resource_cdn_prefix',
|
|
18
|
-
|
|
19
|
-
STATIC_CDN_PREFIX: 'static_cdn_prefix',
|
|
20
|
-
// ── TOS 上传凭证(与三个产物目录一一对应,value 为 JSON.stringify 的凭证对象) ──
|
|
21
|
+
// ── TOS 上传凭证(output / output_resource 两条线,value 为 JSON.stringify 的凭证对象) ──
|
|
21
22
|
// 凭证对象形态(camelCase):
|
|
22
23
|
// { accessKeyID, secretAccessKey, sessionToken, endpoint, region, bucket, prefix }
|
|
23
24
|
// CLI 端 JSON.parse 后写 tosutil 临时 config,cp 到 tos://bucket/prefix。
|
|
@@ -25,8 +26,13 @@ exports.DataKey = {
|
|
|
25
26
|
OUTPUT_TOS_UPLOAD_CREDENTIAL: 'output_tos_upload_credential',
|
|
26
27
|
/** dist/output_resource 上传凭证(仅当目录存在时使用) */
|
|
27
28
|
OUTPUT_RESOURCE_TOS_UPLOAD_CREDENTIAL: 'output_resource_tos_upload_credential',
|
|
29
|
+
// ── PaaS Storage 静态资源凭证(dist/output_static 专用) ──
|
|
30
|
+
// 形态:JSON.stringify 后的 PaasStorageCredential(见下方 interface)。
|
|
31
|
+
// 上传走 tosutil(从 uploadPrefix 解析出 bucket/prefix);上传完成后再调
|
|
32
|
+
// callbackStatic(appID, bucketID, uploadID) 把本次上传核销给后端;
|
|
33
|
+
// downloadURLPrefix 替代原 static_cdn_prefix 注入 build env。
|
|
28
34
|
/** dist/output_static 上传凭证(仅当目录存在时使用) */
|
|
29
|
-
|
|
35
|
+
OUTPUT_STATIC_PAAS_STORAGE_CREDENTIAL: 'output_static_paas_storage_credential',
|
|
30
36
|
};
|
|
31
37
|
/** 取必传 key,缺失抛 AppError(带 key 名,便于后端 tcc 配置排查) */
|
|
32
38
|
function requireDataKey(data, key) {
|
|
@@ -41,3 +47,76 @@ function optionalDataKey(data, key) {
|
|
|
41
47
|
const v = data[key];
|
|
42
48
|
return v === undefined || v === '' ? undefined : v;
|
|
43
49
|
}
|
|
50
|
+
const TOS_CREDENTIAL_REQUIRED_FIELDS = [
|
|
51
|
+
'accessKeyID',
|
|
52
|
+
'secretAccessKey',
|
|
53
|
+
'sessionToken',
|
|
54
|
+
'endpoint',
|
|
55
|
+
'region',
|
|
56
|
+
'bucket',
|
|
57
|
+
'prefix',
|
|
58
|
+
];
|
|
59
|
+
const PAAS_STORAGE_CREDENTIAL_REQUIRED_FIELDS = [
|
|
60
|
+
'accessKeyID',
|
|
61
|
+
'secretAccessKey',
|
|
62
|
+
'sessionToken',
|
|
63
|
+
'endpoint',
|
|
64
|
+
'region',
|
|
65
|
+
'uploadPrefix',
|
|
66
|
+
'downloadURLPrefix',
|
|
67
|
+
'uploadID',
|
|
68
|
+
'bucketID',
|
|
69
|
+
];
|
|
70
|
+
function parseCredentialObject(raw, dataKey) {
|
|
71
|
+
let parsed;
|
|
72
|
+
try {
|
|
73
|
+
parsed = JSON.parse(raw);
|
|
74
|
+
}
|
|
75
|
+
catch (err) {
|
|
76
|
+
throw new error_1.AppError('DEPLOY_CRED_INVALID_JSON', `preRelease.data["${dataKey}"] is not valid JSON: ${err.message}`);
|
|
77
|
+
}
|
|
78
|
+
if (typeof parsed !== 'object' || parsed === null) {
|
|
79
|
+
throw new error_1.AppError('DEPLOY_CRED_INVALID_JSON', `preRelease.data["${dataKey}"] is not an object`);
|
|
80
|
+
}
|
|
81
|
+
return parsed;
|
|
82
|
+
}
|
|
83
|
+
function assertStringFields(obj, required, dataKey) {
|
|
84
|
+
const missing = required.filter((k) => {
|
|
85
|
+
const v = obj[k];
|
|
86
|
+
return typeof v !== 'string' || v === '';
|
|
87
|
+
});
|
|
88
|
+
if (missing.length > 0) {
|
|
89
|
+
throw new error_1.AppError('DEPLOY_CRED_INCOMPLETE', `preRelease.data["${dataKey}"] credential missing fields: ${missing.join(', ')}`);
|
|
90
|
+
}
|
|
91
|
+
return obj;
|
|
92
|
+
}
|
|
93
|
+
/** JSON.parse + 字段完整性校验:output / output_resource 凭证 */
|
|
94
|
+
function parseTosUploadCredential(raw, dataKey) {
|
|
95
|
+
const obj = parseCredentialObject(raw, dataKey);
|
|
96
|
+
return assertStringFields(obj, TOS_CREDENTIAL_REQUIRED_FIELDS, dataKey);
|
|
97
|
+
}
|
|
98
|
+
/** JSON.parse + 字段完整性校验:output_static PaaS Storage 凭证 */
|
|
99
|
+
function parsePaasStorageCredential(raw, dataKey) {
|
|
100
|
+
const obj = parseCredentialObject(raw, dataKey);
|
|
101
|
+
return assertStringFields(obj, PAAS_STORAGE_CREDENTIAL_REQUIRED_FIELDS, dataKey);
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* 解析 `tos://<storage-bucket>/<segments...>/` 形态的 uploadPrefix。
|
|
105
|
+
* 返回的 bucket 是 tosutil cp 视角的 TOS 物理 bucket(uploadPrefix 第一段),
|
|
106
|
+
* prefix 是其余路径(不含开头斜杠,保留可能存在的尾部斜杠以贴合 tosutil 习惯)。
|
|
107
|
+
*
|
|
108
|
+
* 注意:这里返回的 bucket 与 PaasStorageCredential.bucketID 不是同一个概念
|
|
109
|
+
* (bucketID 是 PaaS Storage 逻辑 bucket,给 callbackStatic 用)。
|
|
110
|
+
*/
|
|
111
|
+
function parseTosUploadPrefix(uploadPrefix, dataKey) {
|
|
112
|
+
const match = /^tos:\/\/([^/]+)\/(.*)$/.exec(uploadPrefix);
|
|
113
|
+
if (!match) {
|
|
114
|
+
throw new error_1.AppError('DEPLOY_CRED_INCOMPLETE', `preRelease.data["${dataKey}"].uploadPrefix must look like "tos://<bucket>/<prefix>/", got: ${uploadPrefix}`);
|
|
115
|
+
}
|
|
116
|
+
const bucket = match[1];
|
|
117
|
+
const prefix = match[2];
|
|
118
|
+
if (bucket === '' || prefix === '') {
|
|
119
|
+
throw new error_1.AppError('DEPLOY_CRED_INCOMPLETE', `preRelease.data["${dataKey}"].uploadPrefix missing bucket or prefix segment: ${uploadPrefix}`);
|
|
120
|
+
}
|
|
121
|
+
return { bucket, prefix };
|
|
122
|
+
}
|
package/dist/utils/http.js
CHANGED
|
@@ -65,7 +65,12 @@ function createClient(opts) {
|
|
|
65
65
|
* 缺省走这个。MIAODA_CANARY_HEADER 可显式覆盖;设为空字符串则去掉头。
|
|
66
66
|
*/
|
|
67
67
|
const DEFAULT_CANARY_HEADER = 'boe_miaoda_doubao';
|
|
68
|
-
/**
|
|
68
|
+
/**
|
|
69
|
+
* 注入 x-tt-env 小流量头:env 显式设值 > DEFAULT_CANARY_HEADER。
|
|
70
|
+
*
|
|
71
|
+
* 当泳道形如 `ppe_xxx`(PPE 预发环境)时,额外加 `x-use-ppe: 1`;
|
|
72
|
+
* BOE 泳道(`boe_xxx`)只带 x-tt-env,不加该头。
|
|
73
|
+
*/
|
|
69
74
|
function applyCanaryHeader(reqConfig) {
|
|
70
75
|
// env 显式设为空字符串视为"去掉灰度头";未设置时用 DEFAULT_CANARY_HEADER
|
|
71
76
|
const canary = process.env.MIAODA_CANARY_HEADER ?? DEFAULT_CANARY_HEADER;
|
|
@@ -73,6 +78,9 @@ function applyCanaryHeader(reqConfig) {
|
|
|
73
78
|
return reqConfig;
|
|
74
79
|
const headers = new Headers(reqConfig.headers);
|
|
75
80
|
headers.set('x-tt-env', canary);
|
|
81
|
+
if (canary.startsWith('ppe_')) {
|
|
82
|
+
headers.set('x-use-ppe', '1');
|
|
83
|
+
}
|
|
76
84
|
reqConfig.headers = headers;
|
|
77
85
|
return reqConfig;
|
|
78
86
|
}
|