@infly/libs 2.1.3 → 2.1.5
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
CHANGED
|
@@ -89,7 +89,7 @@ infly-libs build:docker --local --cicd-url="https://deploy.example.com/projects/
|
|
|
89
89
|
infly-libs build:docker --local --cicd-url "https://deploy.example.com/projects/admin/"
|
|
90
90
|
```
|
|
91
91
|
|
|
92
|
-
未传 `--cicd-url` 时保持原有输出。参数值必须是合法的 HTTP/HTTPS URL
|
|
92
|
+
未传 `--cicd-url` 时保持原有输出。参数值必须是合法的 HTTP/HTTPS URL,且不能包含用户名、密码或控制字符。配置和显示文本可以使用中文;输出时“发布系统:”与 URL 分为两行,URL 独占一行,并通过 OSC 8 显式超链接把百分号编码后的标准 URL 作为点击目标,避免依赖终端对中文或空格的自动识别。在支持 OSC 8 的终端中可通过 Ctrl + 鼠标左键打开完整地址。
|
|
93
93
|
|
|
94
94
|
需要在推送前验证镜像自身的 Docker `HEALTHCHECK` 时,可启用可选健康门禁:
|
|
95
95
|
|
|
@@ -264,11 +264,15 @@ Windows 本地构建连接 `dockerDesktopLinuxEngine` 失败时,入口尝试
|
|
|
264
264
|
{
|
|
265
265
|
"scripts": {
|
|
266
266
|
"build:prod:docker": "infly-libs docker:release --no-push",
|
|
267
|
-
"release:
|
|
267
|
+
"release:frontend:docker": "infly-libs docker:release --push --components frontend",
|
|
268
|
+
"release:backend:docker": "infly-libs docker:release --push --components backend"
|
|
268
269
|
},
|
|
269
270
|
"infly": {
|
|
270
271
|
"docker": {
|
|
271
272
|
"registry": "registry.example.com",
|
|
273
|
+
"releaseScripts": {
|
|
274
|
+
"backend": "release:backend:docker"
|
|
275
|
+
},
|
|
272
276
|
"targets": {
|
|
273
277
|
"demo": {
|
|
274
278
|
"label": "示例平台",
|
|
@@ -320,7 +324,8 @@ Windows 本地构建连接 `dockerDesktopLinuxEngine` 失败时,入口尝试
|
|
|
320
324
|
|
|
321
325
|
- `files`:从组件源码仓复制到独立临时上下文,仅发送指定产物;配置后 `dockerfile` 相对临时上下文。未配置时 `context`、`dockerfile` 相对组件源码仓。
|
|
322
326
|
- `requiredFiles`:构建前必须存在的源码仓相对路径,例如前端产物的 `index.html`;缺失时停止构建。
|
|
323
|
-
- `source`:可选独立源码仓;从项目目录解析 `directory`,fetch 后使用指定分支的临时 detached worktree
|
|
327
|
+
- `source`:可选独立源码仓;从项目目录解析 `directory`,fetch 后使用指定分支的临时 detached worktree,不切换当前开发分支。缺少源码仓时明确说明未执行构建或推送,打印编号化的 clone、fetch 和重跑步骤,全部构建停止,CLI 返回 2。
|
|
328
|
+
- `releaseScripts`:可选的组件重跑脚本映射。源码仓缺失时优先提示 `pnpm run <脚本> -- --platform ...`;脚本名只允许字母、数字、冒号、点、下划线和连字符。未配置时提示通用 `pnpm exec infly-libs docker:release` 命令。
|
|
324
329
|
- 无 `source` 时构建当前项目,要求干净工作树且 HEAD 等于 `expectedRef`。有 `source` 时校验临时工作树对应的 origin 分支。
|
|
325
330
|
- `check`:可选镜像内校验,使用 `entrypoint`、`args` 数组及 `addHosts` 数组;失败不推送。配置命令具有代码执行权限,应与源码一样评审,不能来自不可信输入。
|
|
326
331
|
- `deployment`:仅用于部署包生成;`ready=false` 会阻止生成。可设置 `lockName`,默认 `.infly-release.lock`。服务归属和 imageEnv 必须唯一。
|
|
@@ -337,7 +342,7 @@ infly-libs docker:bundle --target demo --dry-run
|
|
|
337
342
|
|
|
338
343
|
`--platform` 是 `--target` 的兼容别名;`--config` 读取 JSON 文件,其顶层直接为 docker 配置。CLI 参数优先于项目配置;`--backend-dir` 仅覆盖名为 backend 的组件源码目录。
|
|
339
344
|
|
|
340
|
-
构建成功后逐组件输出完整提交版本、`组件=仓库:<12位提交版本>` 和 `组件_latest=仓库:latest` 机器行;每个组件的一次构建同时生成不可变提交标签与 `latest`,启用推送时先推送不可变标签,再更新 `latest`。全部构建结束后打印 `✅ 完成` 汇总块,明确区分“不可变提交版本”和“最新构建镜像”。可选 `--cicd-url
|
|
345
|
+
构建成功后逐组件输出完整提交版本、`组件=仓库:<12位提交版本>` 和 `组件_latest=仓库:latest` 机器行;每个组件的一次构建同时生成不可变提交标签与 `latest`,启用推送时先推送不可变标签,再更新 `latest`。全部构建结束后打印 `✅ 完成` 汇总块,明确区分“不可变提交版本”和“最新构建镜像”。可选 `--cicd-url`(支持等号和空格两种传参形式)在推送成功后于汇总块尾输出蓝色发布系统链接;“发布系统:”与中文 URL 分为两行,URL 独占一行,OSC 8 显式超链接使用百分号编码后的标准 URL 作为点击目标,确保支持该协议的终端可通过 Ctrl + 鼠标左键完整打开。不传时保持原输出。链接必须是合法 HTTP/HTTPS URL,不含用户名或密码。
|
|
341
346
|
|
|
342
347
|
`docker:bundle` 只生成本地脚本包,不自动部署;输出须是项目内尚不存在的独立子目录。包内包含 config.sh、Compose 覆盖文件和公共 shell 脚本。Jenkins 固定公共包版本后生成,使用既有凭据,调用 `deploy.sh component=repository:commit` 传输并执行。包内仍保留 `promote-image.sh` 供既有 qc 晋升流程兼容使用;低频定制平台直接在本地推送不可变提交标签与 `latest`,Jenkins 不再调用晋升脚本。运行部署脚本会操作服务器,必须由开发者手动触发既定任务。
|
|
343
348
|
|
|
@@ -52,7 +52,10 @@ function formatCicdLink(value) {
|
|
|
52
52
|
throw new Error("--cicd-url 不能包含用户名或密码凭据");
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
-
|
|
55
|
+
// 显示中文地址,同时把标准化 URL 放进 OSC 8 点击目标,避免依赖终端的文本自动识别。
|
|
56
|
+
const hyperlinkStart = `\x1b]8;;${parsedUrl.href}\x1b\\`;
|
|
57
|
+
const hyperlinkEnd = "\x1b]8;;\x1b\\";
|
|
58
|
+
return `发布系统:\n${hyperlinkStart}\x1b[34m${decodeURI(parsedUrl.href)}\x1b[0m${hyperlinkEnd}`;
|
|
56
59
|
}
|
|
57
60
|
|
|
58
61
|
function detectMode({ standalone = false } = {}) {
|
|
@@ -116,6 +116,7 @@ async function runTargetRelease(options = {}, dependencies = {}) {
|
|
|
116
116
|
: JSON.parse(fs.readFileSync(path.join(projectDir, "package.json"), "utf8")).infly?.docker);
|
|
117
117
|
const targets = config?.targets;
|
|
118
118
|
if (!targets || !Object.keys(targets).length) throw new Error("请配置 infly.docker.targets");
|
|
119
|
+
const releaseScripts = config?.releaseScripts || {};
|
|
119
120
|
const log = dependencies.log || console.log;
|
|
120
121
|
const cicdLink = formatCicdLink(options.cicdUrl);
|
|
121
122
|
const target = options.target || await (dependencies.selectOption || selectOption)("请选择构建平台",
|
|
@@ -159,12 +160,19 @@ async function runTargetRelease(options = {}, dependencies = {}) {
|
|
|
159
160
|
if (missing.length) {
|
|
160
161
|
for (const item of missing) {
|
|
161
162
|
const source = item.source;
|
|
163
|
+
const releaseScript = releaseScripts[item.name];
|
|
164
|
+
if (releaseScript && !/^[a-z0-9][a-z0-9:._-]*$/i.test(releaseScript)) {
|
|
165
|
+
throw new Error(`${item.name} releaseScripts 配置无效`);
|
|
166
|
+
}
|
|
162
167
|
log(`未找到 ${item.name} 源码仓: ${source.directory}`);
|
|
163
|
-
log(
|
|
164
|
-
if (source.url) log(`git clone "${source.url}" "${source.directory}"`);
|
|
165
|
-
log(
|
|
168
|
+
log("未执行任何构建或推送。请手动完成以下步骤:");
|
|
169
|
+
if (source.url) log(`1. git clone "${source.url}" "${source.directory}"`);
|
|
170
|
+
log(`${source.url ? "2" : "1"}. git -C "${source.directory}" fetch origin "${source.branch}"`);
|
|
166
171
|
const overrides = `${options.backendDir ? ` --backend-dir "${options.backendDir}"` : ""}${options.config ? ` --config "${options.config}"` : ""}`;
|
|
167
|
-
|
|
172
|
+
const rerun = releaseScript
|
|
173
|
+
? `pnpm run ${releaseScript} -- --platform ${target}${overrides}`
|
|
174
|
+
: `pnpm exec infly-libs docker:release --project-dir "${projectDir}" --target ${target} --components ${components.join(",")}${overrides} ${options.push ? "--push" : "--no-push"}`;
|
|
175
|
+
log(`${source.url ? "3" : "2"}. ${rerun}`);
|
|
168
176
|
}
|
|
169
177
|
return { target, missingSources: missing.map((item) => item.name) };
|
|
170
178
|
}
|
package/cli/select-option.js
CHANGED
|
@@ -65,7 +65,7 @@ async function selectOptions(message, choices, dependencies = {}) {
|
|
|
65
65
|
const prompt = new MultiSelect({
|
|
66
66
|
name: "selections",
|
|
67
67
|
message,
|
|
68
|
-
indicator: { on: "[√
|
|
68
|
+
indicator: { on: "[√]", off: "[ ]" },
|
|
69
69
|
hint: "↑/↓ 移动,空格勾选/取消,回车确认,Ctrl+C 退出(至少选择一项)",
|
|
70
70
|
stdin,
|
|
71
71
|
stdout,
|
|
@@ -87,8 +87,27 @@ async function selectOptions(message, choices, dependencies = {}) {
|
|
|
87
87
|
}
|
|
88
88
|
}
|
|
89
89
|
|
|
90
|
+
async function inputText(message, dependencies = {}) {
|
|
91
|
+
const stdin = dependencies.stdin || process.stdin;
|
|
92
|
+
const stdout = dependencies.stdout || process.stdout;
|
|
93
|
+
if (!stdin.isTTY || !stdout.isTTY) {
|
|
94
|
+
throw new Error(`${message}: interactive input requires a TTY; pass an explicit option.`);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const Input = dependencies.Input || require("enquirer").Input;
|
|
98
|
+
const prompt = new Input({ name: "value", message, stdin, stdout });
|
|
99
|
+
prompt.once("start", makePromptCancellationSafe);
|
|
100
|
+
try {
|
|
101
|
+
return await prompt.run();
|
|
102
|
+
} catch (error) {
|
|
103
|
+
if (!error || error.name === "CancelPromptError" || isReadlineClosedError(error)) return EXIT_SELECTION;
|
|
104
|
+
throw error;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
90
108
|
module.exports = {
|
|
91
109
|
EXIT_SELECTION,
|
|
110
|
+
inputText,
|
|
92
111
|
makePromptCancellationSafe,
|
|
93
112
|
selectOption,
|
|
94
113
|
selectOptions,
|
package/package.json
CHANGED
|
@@ -20,7 +20,7 @@ function runGit(cwd, args, { allowFailure = false } = {}) {
|
|
|
20
20
|
if (result.status !== 0 && allowFailure) {
|
|
21
21
|
const detail = String(result.stderr || result.stdout || "").trim();
|
|
22
22
|
if (detail) {
|
|
23
|
-
process.stderr.write(`[submodule
|
|
23
|
+
process.stderr.write(`[status:submodule] git ${args.join(" ")}: ${detail}\n`);
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
26
|
|