@xcanwin/manyoyo 4.2.4 → 4.2.6
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/lib/image-build.js +27 -6
- package/package.json +1 -1
package/lib/image-build.js
CHANGED
|
@@ -152,21 +152,32 @@ function cleanupGoTmpPath(ctx, tmpGoPath, warnOnError) {
|
|
|
152
152
|
const { YELLOW, NC } = ctx.colors;
|
|
153
153
|
if (!fs.existsSync(tmpGoPath)) return;
|
|
154
154
|
|
|
155
|
+
let cleanupFailed = false;
|
|
155
156
|
try {
|
|
156
157
|
ctx.runCmd('go', ['clean', '-modcache'], {
|
|
157
158
|
stdio: 'inherit',
|
|
158
159
|
ignoreError: true,
|
|
159
160
|
env: { ...process.env, GOPATH: tmpGoPath }
|
|
160
161
|
});
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
} catch (e) {
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
}
|
|
162
|
+
} catch (e) { cleanupFailed = true; }
|
|
163
|
+
try { ctx.runCmd('chmod', ['-R', 'u+w', tmpGoPath], { stdio: 'inherit', ignoreError: true }); } catch (e) { cleanupFailed = true; }
|
|
164
|
+
try { ctx.runCmd('rm', ['-rf', tmpGoPath], { stdio: 'inherit', ignoreError: true }); } catch (e) { cleanupFailed = true; }
|
|
165
|
+
if (cleanupFailed && warnOnError) {
|
|
166
|
+
ctx.log(`${YELLOW}提示: 临时目录清理失败,可手动删除 ${tmpGoPath}${NC}`);
|
|
167
167
|
}
|
|
168
168
|
}
|
|
169
169
|
|
|
170
|
+
function isGoCommandMissing(error) {
|
|
171
|
+
const message = error && error.message ? String(error.message) : '';
|
|
172
|
+
const stderr = error && error.stderr ? String(error.stderr) : '';
|
|
173
|
+
const stdout = error && error.stdout ? String(error.stdout) : '';
|
|
174
|
+
const combined = `${message}\n${stderr}\n${stdout}`.toLowerCase();
|
|
175
|
+
if (error && String(error.code || '').toUpperCase() === 'ENOENT') {
|
|
176
|
+
return /\bgo\b/.test(message.toLowerCase()) || /spawnsync go enoent|spawn go enoent/.test(combined);
|
|
177
|
+
}
|
|
178
|
+
return /spawnsync go enoent|spawn go enoent|go: not found|go: command not found|command not found: go/.test(combined);
|
|
179
|
+
}
|
|
180
|
+
|
|
170
181
|
function resolveGoplsSource(tmpGoPath, arch) {
|
|
171
182
|
const primary = path.join(tmpGoPath, 'bin', `linux_${arch}`, 'gopls');
|
|
172
183
|
if (fs.existsSync(primary)) return primary;
|
|
@@ -209,6 +220,11 @@ function prepareGoplsBuildCache(ctx, cache, imageTool, arch) {
|
|
|
209
220
|
ctx.log(`${GREEN}✓ gopls 下载完成${NC}`);
|
|
210
221
|
cleanupGoTmpPath(ctx, tmpGoPath, true);
|
|
211
222
|
} catch (e) {
|
|
223
|
+
if (isGoCommandMissing(e)) {
|
|
224
|
+
ctx.log(`${YELLOW}提示: 未检测到本机 go,跳过 gopls 本地缓存预下载,将在镜像构建阶段安装${NC}`);
|
|
225
|
+
cleanupGoTmpPath(ctx, tmpGoPath, false);
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
212
228
|
ctx.error(`${RED}错误: gopls 下载失败${NC}`);
|
|
213
229
|
throw e;
|
|
214
230
|
}
|
|
@@ -285,6 +301,10 @@ function buildBuildkitRunArgs(ctx, dockerfilePath, fullImageTag, imageBuildArgs)
|
|
|
285
301
|
const args = [
|
|
286
302
|
'run', '--rm', '--privileged',
|
|
287
303
|
'--network', `host`,
|
|
304
|
+
'-e', `HTTP_PROXY=$HTTP_PROXY`,
|
|
305
|
+
'-e', `HTTPS_PROXY=$HTTPS_PROXY`,
|
|
306
|
+
'-e', `ALL_PROXY=$ALL_PROXY`,
|
|
307
|
+
'-e', `NO_PROXY=$NO_PROXY`,
|
|
288
308
|
'--volume', `${ctx.rootDir}:/workspace`,
|
|
289
309
|
'--entrypoint', 'buildctl-daemonless.sh',
|
|
290
310
|
'docker.io/moby/buildkit:latest',
|
|
@@ -293,6 +313,7 @@ function buildBuildkitRunArgs(ctx, dockerfilePath, fullImageTag, imageBuildArgs)
|
|
|
293
313
|
'--local', 'context=/workspace',
|
|
294
314
|
'--local', 'dockerfile=/workspace',
|
|
295
315
|
'--opt', `filename=${dockerfileRelativePath}`,
|
|
316
|
+
'--opt', 'network=host',
|
|
296
317
|
'--opt', `build-arg:HTTP_PROXY=$HTTP_PROXY`,
|
|
297
318
|
'--opt', `build-arg:HTTPS_PROXY=$HTTPS_PROXY`,
|
|
298
319
|
'--opt', `build-arg:ALL_PROXY=$ALL_PROXY`,
|