@infly/libs 2.6.0 → 2.7.0
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 +18 -0
- package/adapters/vue2/project-preview.js +9 -16
- package/adapters/webpack/auto-export.js +53 -52
- package/bin/cli.js +3 -2
- package/build/build-dist/index.js +34 -44
- package/build/build-utils/command.js +58 -57
- package/build/build-utils/deps.js +28 -28
- package/build/build-utils/git.js +246 -254
- package/build/build-utils/preview.js +79 -78
- package/build/build-utils/webhook.js +135 -135
- package/build/docker/deployment/health-check.sh +5 -1
- package/build/docker/deployment/release.sh +5 -1
- package/build/docker/docker-build-push.js +20 -21
- package/build/docker/release-docker.js +5 -4
- package/build/docker/release-paths.js +30 -30
- package/build/docker/release-validation.js +51 -7
- package/build/docker/target-image.js +44 -6
- package/build/docker/target-release.js +540 -527
- package/build/project-files.js +47 -47
- package/cli/progress.js +4 -11
- package/cli/terminal-style.js +40 -0
- package/core/async/concurrency.js +29 -29
- package/package.json +1 -1
- package/script/git-automation/check-packages.js +5 -12
- package/script/git-automation/git-clone.js +6 -5
- package/script/git-automation/git-configure.js +3 -3
- package/script/git-automation/git-submodule.js +3 -2
- package/script/git-automation/git-utils.js +59 -59
- package/script/git-automation/index.js +813 -828
- package/script/git-automation/submodule-utils.js +16 -16
- package/workspace/config.js +144 -144
|
@@ -1,13 +1,37 @@
|
|
|
1
|
+
const { formatTerminalMessage } = require("../../cli/terminal-style");
|
|
1
2
|
const os = require("node:os");
|
|
2
3
|
const path = require("node:path");
|
|
3
4
|
const { prepareMinimalMonorepoContext } = require("./minimal-context");
|
|
4
5
|
const { prepareProjectInstallContext, prepareStandaloneInstallContext } = require("./project-install");
|
|
5
6
|
const { createReleaseId, createBuildProvenance } = require("./release-identity");
|
|
6
7
|
const { confinedPath, inside } = require("./release-paths");
|
|
8
|
+
const { createBuildTimestampPlugin } = require("../vite");
|
|
9
|
+
|
|
10
|
+
function resolveBuildSecrets(secrets = [], { env, projectDir, io }) {
|
|
11
|
+
return secrets.map(({ id, fileEnv, defaultFile }) => {
|
|
12
|
+
const override = env[fileEnv];
|
|
13
|
+
const source = override || defaultFile;
|
|
14
|
+
if (typeof source !== "string" || !source.trim() || /[,\r\n\0"]/.test(source)) {
|
|
15
|
+
throw new Error(`请通过 ${fileEnv} 提供 ${id} 的构建密钥文件路径`);
|
|
16
|
+
}
|
|
17
|
+
const file = path.resolve(projectDir, source);
|
|
18
|
+
try {
|
|
19
|
+
const stat = io.statSync(file);
|
|
20
|
+
if (!stat.isFile() || stat.size === 0) throw new Error();
|
|
21
|
+
io.accessSync(file, io.constants.R_OK);
|
|
22
|
+
} catch {
|
|
23
|
+
if (!override && defaultFile) {
|
|
24
|
+
throw new Error(`缺少可读的 ${id} 构建配置。请将文件放到部署仓的 ${defaultFile},或通过 ${fileEnv} 指定路径`);
|
|
25
|
+
}
|
|
26
|
+
throw new Error(`无法读取 ${fileEnv} 指定的 ${id} 构建密钥文件`);
|
|
27
|
+
}
|
|
28
|
+
return `type=file,id=${id},src=${file}`;
|
|
29
|
+
});
|
|
30
|
+
}
|
|
7
31
|
|
|
8
32
|
function buildTargetImage(item, {
|
|
9
33
|
target, configuration, projectDir, publicSnapshots, resources, verifyFrozen,
|
|
10
|
-
io, run, capture, log, dependencies, buildExecutableSpawn,
|
|
34
|
+
io, run, capture, log, dependencies, buildExecutableSpawn, secrets = [],
|
|
11
35
|
}) {
|
|
12
36
|
const { sourceDir, commit } = item.frozen;
|
|
13
37
|
let tempRoot;
|
|
@@ -27,7 +51,7 @@ function buildTargetImage(item, {
|
|
|
27
51
|
}
|
|
28
52
|
if (item.source) {
|
|
29
53
|
const sourceLabel = item.name === "backend" ? "后端" : (item.label || item.name);
|
|
30
|
-
log(
|
|
54
|
+
log(formatTerminalMessage("success", `${sourceLabel}构建分支:${item.source.branch}`));
|
|
31
55
|
}
|
|
32
56
|
const buildStrategy = item.buildStrategy || "artifact";
|
|
33
57
|
const componentReleaseContext = item.releaseContext;
|
|
@@ -104,6 +128,10 @@ function buildTargetImage(item, {
|
|
|
104
128
|
...(buildStrategy === "source" ? { BUILD_MODE: componentReleaseContext.mode, PROJECT_DIR: buildProjectDir } : {}),
|
|
105
129
|
...(item.projectInstall && componentReleaseContext.mode === "standalone" ? { REFRESH_INTERNAL: true } : {}),
|
|
106
130
|
};
|
|
131
|
+
if (item.buildTimestampArg) {
|
|
132
|
+
const timestamp = createBuildTimestampPlugin({ timestamp: dependencies.now?.() });
|
|
133
|
+
effectiveBuildArgs[item.buildTimestampArg] = timestamp.transformIndexHtml()[0].attrs.content;
|
|
134
|
+
}
|
|
107
135
|
let provenance;
|
|
108
136
|
const releaseId = item.releaseIdentity ? createReleaseId(commit, dependencies.releaseToken?.()) : commit;
|
|
109
137
|
if (item.releaseIdentity) {
|
|
@@ -146,10 +174,12 @@ function buildTargetImage(item, {
|
|
|
146
174
|
const buildOptions = ["buildx", "build", "--load", "--file", dockerfile];
|
|
147
175
|
if (item.platform) buildOptions.push("--platform", item.platform);
|
|
148
176
|
if (item.target) buildOptions.push("--target", item.target);
|
|
177
|
+
if (item.noCacheFilter) buildOptions.push("--no-cache-filter", item.noCacheFilter.join(","));
|
|
178
|
+
for (const secret of secrets) buildOptions.push("--secret", secret);
|
|
149
179
|
for (const [key, value] of Object.entries(effectiveBuildArgs)) {
|
|
150
180
|
buildOptions.push("--build-arg", `${key}=${value}`);
|
|
151
181
|
}
|
|
152
|
-
|
|
182
|
+
const dockerArgs = [...buildOptions,
|
|
153
183
|
"--label", `org.opencontainers.image.revision=${commit}`, "--label", `org.opencontainers.image.version=${releaseId}`,
|
|
154
184
|
...(sourceAuthor ? ["--label", `com.infly.source.author=${sourceAuthor}`] : []),
|
|
155
185
|
...(sourceMessage ? ["--label", `com.infly.source.message=${sourceMessage}`] : []),
|
|
@@ -157,13 +187,21 @@ function buildTargetImage(item, {
|
|
|
157
187
|
...(workspaceRevision ? ["--label", `com.infly.workspace.revision=${workspaceRevision}`] : []),
|
|
158
188
|
...(configuration ? ["--label", `com.infly.deployment.revision=${configuration.commit}`] : []),
|
|
159
189
|
"--label", `com.infly.platform=${target}`, "--tag", image,
|
|
160
|
-
...(latestImage ? ["--tag", latestImage] : []), context]
|
|
190
|
+
...(latestImage ? ["--tag", latestImage] : []), context];
|
|
191
|
+
try {
|
|
192
|
+
run("docker", dockerArgs, { cwd: projectDir });
|
|
193
|
+
} catch (error) {
|
|
194
|
+
// 子进程异常包含完整 argv;错误摘要不透出密钥文件路径。
|
|
195
|
+
if (secrets.length) throw new Error(`${item.name} Docker 构建失败,请检查上方 Buildx 输出`);
|
|
196
|
+
throw error;
|
|
197
|
+
}
|
|
161
198
|
if (capture("docker", ["image", "inspect", "--format", '{{ index .Config.Labels "org.opencontainers.image.revision" }}', image]) !== commit) {
|
|
162
199
|
throw new Error(`${item.name} 镜像 revision 校验失败`);
|
|
163
200
|
}
|
|
164
201
|
if (item.check) {
|
|
165
202
|
const hosts = (item.check.addHosts || []).flatMap((host) => ["--add-host", host]);
|
|
166
|
-
|
|
203
|
+
const network = item.check.network ? ["--network", item.check.network] : [];
|
|
204
|
+
run("docker", ["run", "--rm", ...network, ...hosts, "--entrypoint", item.check.entrypoint, image, ...item.check.args], { cwd: projectDir });
|
|
167
205
|
}
|
|
168
206
|
return { commit, image, latestImage, releaseId, provenance };
|
|
169
207
|
}
|
|
@@ -186,4 +224,4 @@ function finishTargetImage(item, { commit, image, latestImage, releaseId, proven
|
|
|
186
224
|
return { component: item.name, commit, image, latestImage, ...(channelImage ? { channelImage } : {}), pushed: false, ...identity };
|
|
187
225
|
}
|
|
188
226
|
|
|
189
|
-
module.exports = { buildTargetImage, finishTargetImage };
|
|
227
|
+
module.exports = { buildTargetImage, finishTargetImage, resolveBuildSecrets };
|