@getmonoceros/workbench 1.6.7 → 1.6.9
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/dist/bin.js +62 -8
- package/dist/bin.js.map +1 -1
- package/package.json +1 -1
package/dist/bin.js
CHANGED
|
@@ -3,6 +3,54 @@
|
|
|
3
3
|
// src/bin.ts
|
|
4
4
|
import { runMain } from "citty";
|
|
5
5
|
|
|
6
|
+
// src/devcontainer/docker-group-bootstrap.ts
|
|
7
|
+
import { spawnSync } from "child_process";
|
|
8
|
+
import { userInfo } from "os";
|
|
9
|
+
var REEXEC_MARKER = "MONOCEROS_DOCKER_GROUP_REEXEC";
|
|
10
|
+
function bootstrapDockerGroup(opts = {}) {
|
|
11
|
+
const platform = opts.platform ?? process.platform;
|
|
12
|
+
if (platform !== "linux") return;
|
|
13
|
+
const marker = opts.marker ?? process.env[REEXEC_MARKER];
|
|
14
|
+
if (marker === "1") return;
|
|
15
|
+
const probe = opts.runProbe ?? defaultProbe;
|
|
16
|
+
if (probe("docker", ["--version"]) !== 0) return;
|
|
17
|
+
if (probe("docker", ["info"]) === 0) return;
|
|
18
|
+
const username = opts.username ?? userInfo().username;
|
|
19
|
+
if (!isInDockerGroupViaEtcGroup(username, probe)) return;
|
|
20
|
+
const reexec = opts.reexec ?? defaultReexec;
|
|
21
|
+
const exitCode = reexec(process.argv);
|
|
22
|
+
process.exit(exitCode);
|
|
23
|
+
}
|
|
24
|
+
function isInDockerGroupViaEtcGroup(username, probe) {
|
|
25
|
+
const result = spawnSync("getent", ["group", "docker"], {
|
|
26
|
+
encoding: "utf8",
|
|
27
|
+
stdio: ["ignore", "pipe", "ignore"]
|
|
28
|
+
});
|
|
29
|
+
void probe;
|
|
30
|
+
if (result.status !== 0) return false;
|
|
31
|
+
const fields = result.stdout.split(":");
|
|
32
|
+
if (fields.length < 4) return false;
|
|
33
|
+
const members = (fields[3] ?? "").trim().split(",").map((m) => m.trim()).filter(Boolean);
|
|
34
|
+
return members.includes(username);
|
|
35
|
+
}
|
|
36
|
+
function defaultProbe(cmd, args) {
|
|
37
|
+
const result = spawnSync(cmd, [...args], { stdio: "ignore" });
|
|
38
|
+
return result.status ?? 1;
|
|
39
|
+
}
|
|
40
|
+
function defaultReexec(argv) {
|
|
41
|
+
const quoted = argv.map(shellQuote).join(" ");
|
|
42
|
+
const env = { ...process.env, [REEXEC_MARKER]: "1" };
|
|
43
|
+
const result = spawnSync("sg", ["docker", "-c", quoted], {
|
|
44
|
+
stdio: "inherit",
|
|
45
|
+
env
|
|
46
|
+
});
|
|
47
|
+
return result.status ?? 1;
|
|
48
|
+
}
|
|
49
|
+
function shellQuote(arg) {
|
|
50
|
+
if (/^[\w./@:=,+-]+$/.test(arg)) return arg;
|
|
51
|
+
return `'${arg.replace(/'/g, "'\\''")}'`;
|
|
52
|
+
}
|
|
53
|
+
|
|
6
54
|
// src/help.ts
|
|
7
55
|
var ANSI_BOLD = "\x1B[1m";
|
|
8
56
|
var ANSI_UNDERLINE = "\x1B[4m";
|
|
@@ -2804,17 +2852,22 @@ ${sectionLine(label)}
|
|
|
2804
2852
|
);
|
|
2805
2853
|
validateOptions(createOpts);
|
|
2806
2854
|
logger.success(`yml validated ${dim(`(${prettyPath(ymlPath)})`)}`);
|
|
2855
|
+
const hasRepos = (createOpts.repos ?? []).length > 0;
|
|
2856
|
+
const hasContainerGitUser = parsed.config.git?.user !== void 0;
|
|
2857
|
+
const hasDefaultGitUser = globalConfig?.defaults?.git?.user !== void 0;
|
|
2807
2858
|
const idLogger = {
|
|
2808
2859
|
info: logger.info,
|
|
2809
2860
|
warn: logger.warn ?? logger.info
|
|
2810
2861
|
};
|
|
2811
|
-
|
|
2812
|
-
|
|
2813
|
-
|
|
2814
|
-
|
|
2815
|
-
|
|
2816
|
-
|
|
2817
|
-
|
|
2862
|
+
if (hasRepos || hasContainerGitUser || hasDefaultGitUser) {
|
|
2863
|
+
await collectGitIdentity(targetDir, {
|
|
2864
|
+
...opts.identitySpawn ? { spawn: opts.identitySpawn } : {},
|
|
2865
|
+
...opts.identityPrompt ? { prompt: opts.identityPrompt } : {},
|
|
2866
|
+
...parsed.config.git?.user ? { containerOverride: parsed.config.git.user } : {},
|
|
2867
|
+
...globalConfig?.defaults?.git?.user ? { defaults: globalConfig.defaults.git.user } : {},
|
|
2868
|
+
logger: idLogger
|
|
2869
|
+
});
|
|
2870
|
+
}
|
|
2818
2871
|
const hostsToFetch = uniqueHttpsHosts(createOpts.repos ?? []);
|
|
2819
2872
|
const unknownProviderHosts = hostsToFetch.filter((h) => h.provider === "unknown").map((h) => h.host);
|
|
2820
2873
|
if (unknownProviderHosts.length > 0) {
|
|
@@ -2921,7 +2974,7 @@ function warnOnDeprecatedFeatureRefs(containerFeatures, globalConfig, logger) {
|
|
|
2921
2974
|
}
|
|
2922
2975
|
|
|
2923
2976
|
// src/version.ts
|
|
2924
|
-
var CLI_VERSION = true ? "1.6.
|
|
2977
|
+
var CLI_VERSION = true ? "1.6.9" : "dev";
|
|
2925
2978
|
|
|
2926
2979
|
// src/commands/_dispatch.ts
|
|
2927
2980
|
import { consola as consola11 } from "consola";
|
|
@@ -4718,6 +4771,7 @@ var main = defineCommand25({
|
|
|
4718
4771
|
});
|
|
4719
4772
|
|
|
4720
4773
|
// src/bin.ts
|
|
4774
|
+
bootstrapDockerGroup();
|
|
4721
4775
|
consumeInnerArgsFromProcessArgv();
|
|
4722
4776
|
async function entry() {
|
|
4723
4777
|
if (await maybeRenderHelp(process.argv.slice(2), main)) {
|