@ricsam/r5d-worker 0.0.3 → 0.0.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 +6 -6
- package/dist/cjs/main.cjs +126 -2
- package/dist/cjs/package.json +1 -1
- package/dist/mjs/main.mjs +126 -2
- package/dist/mjs/package.json +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
1
|
# r5d-worker
|
|
2
2
|
|
|
3
|
-
`r5d-worker` connects a local or remote machine to
|
|
3
|
+
`r5d-worker` connects a local or remote machine to r5d.dev so the agent can run host commands through the live worker.
|
|
4
4
|
|
|
5
5
|
```sh
|
|
6
|
-
r5d-worker start
|
|
6
|
+
r5d-worker start --label macos
|
|
7
|
+
r5d-worker --version
|
|
7
8
|
```
|
|
8
9
|
|
|
9
10
|
The worker uses the existing `r5dctl` config file and accepts `R5D_WORKER_TOKEN` or `R5D_API_KEY`. Project checkouts are managed under:
|
|
10
11
|
|
|
11
12
|
```text
|
|
12
|
-
~/.r5d/projects/<
|
|
13
|
+
~/.r5d/projects/<repo-slug>/<branch-name>
|
|
13
14
|
```
|
|
14
15
|
|
|
15
|
-
|
|
16
|
+
Visible branch checkouts use GitHub `origin` remotes. r5d internal sync git metadata lives separately under `~/.r5d/sync`.
|
|
16
17
|
|
|
17
|
-
Worker labels are mandatory and unique per
|
|
18
|
+
Worker labels are mandatory and unique per user. Choose labels that describe host capabilities, such as `macos`, `linux`, `ios`, or `ec2-build`.
|
|
18
19
|
|
|
19
20
|
The agent runs commands through the virtual shell command:
|
|
20
21
|
|
|
21
22
|
```sh
|
|
22
|
-
worker exec macos git pull --ff-only build-it-now main
|
|
23
23
|
worker exec macos docker compose up -d
|
|
24
24
|
worker exec macos bun test
|
|
25
25
|
```
|
package/dist/cjs/main.cjs
CHANGED
|
@@ -29,6 +29,7 @@ var import_node_crypto = require("node:crypto");
|
|
|
29
29
|
var import_node_os2 = require("node:os");
|
|
30
30
|
var import_node_child_process = require("node:child_process");
|
|
31
31
|
const DEFAULT_BASE_URL = "https://r5d.dev";
|
|
32
|
+
const WORKER_PACKAGE_NAME = "@ricsam/r5d-worker";
|
|
32
33
|
const LABEL_RE = /^[A-Za-z0-9][A-Za-z0-9_.-]{0,62}$/;
|
|
33
34
|
const BRANCH_RE = /^[A-Za-z0-9][A-Za-z0-9-]*[A-Za-z0-9]$|^[A-Za-z0-9]$/;
|
|
34
35
|
const DEFAULT_READ_LIMIT = 2e3;
|
|
@@ -37,6 +38,7 @@ const MAX_SYNC_DIFF_BYTES = 5 * 1024 * 1024;
|
|
|
37
38
|
const activeProcesses = /* @__PURE__ */ new Map();
|
|
38
39
|
const activePtys = /* @__PURE__ */ new Map();
|
|
39
40
|
const branchLocks = /* @__PURE__ */ new Map();
|
|
41
|
+
let containerRegistryCredential = null;
|
|
40
42
|
function defaultConfigPath() {
|
|
41
43
|
return import_node_path.default.join(import_node_os.default.homedir(), ".config", "r5d", "r5dctl", "config.json");
|
|
42
44
|
}
|
|
@@ -49,6 +51,7 @@ function defaultSyncRoot() {
|
|
|
49
51
|
function printHelp() {
|
|
50
52
|
process.stdout.write(`Usage:
|
|
51
53
|
r5d-worker start --label <label> [--base-url <url>] [--token <token>] [--api-key <key>]
|
|
54
|
+
r5d-worker --version
|
|
52
55
|
|
|
53
56
|
Options:
|
|
54
57
|
--label <label> Required unique worker label for this user, e.g. macos or ec2-build
|
|
@@ -58,9 +61,53 @@ Options:
|
|
|
58
61
|
--config <path> Config path (default ~/.config/r5d/r5dctl/config.json)
|
|
59
62
|
--project-root <dir> Override projects checkout root (default ~/.r5d/projects)
|
|
60
63
|
--sync-root <dir> Override r5d internal sync git root (default ~/.r5d/sync)
|
|
64
|
+
-v, --version Show r5d-worker version
|
|
61
65
|
-h, --help Show this help
|
|
62
66
|
`);
|
|
63
67
|
}
|
|
68
|
+
function readVersionFile(filePath) {
|
|
69
|
+
try {
|
|
70
|
+
const version = import_node_fs.default.readFileSync(filePath, "utf8").trim();
|
|
71
|
+
return version || null;
|
|
72
|
+
} catch {
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
function readInstalledPackageVersion(packageJsonPath) {
|
|
77
|
+
try {
|
|
78
|
+
const parsed = JSON.parse(import_node_fs.default.readFileSync(packageJsonPath, "utf8"));
|
|
79
|
+
if (parsed.name === WORKER_PACKAGE_NAME && typeof parsed.version === "string" && parsed.version.trim()) {
|
|
80
|
+
return parsed.version.trim();
|
|
81
|
+
}
|
|
82
|
+
} catch {
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
return null;
|
|
86
|
+
}
|
|
87
|
+
function getWorkerVersion() {
|
|
88
|
+
const entrypoint = process.argv[1] ? import_node_path.default.resolve(process.argv[1]) : null;
|
|
89
|
+
let current = entrypoint ? import_node_path.default.dirname(entrypoint) : process.cwd();
|
|
90
|
+
for (let index = 0; index < 12; index += 1) {
|
|
91
|
+
const packageVersion = readInstalledPackageVersion(import_node_path.default.join(current, "package.json"));
|
|
92
|
+
if (packageVersion) {
|
|
93
|
+
return packageVersion;
|
|
94
|
+
}
|
|
95
|
+
const sourceVersion = readVersionFile(import_node_path.default.join(current, "VERSION.txt"));
|
|
96
|
+
if (sourceVersion && import_node_path.default.basename(current) === "binctl-packages") {
|
|
97
|
+
return sourceVersion;
|
|
98
|
+
}
|
|
99
|
+
const parent = import_node_path.default.dirname(current);
|
|
100
|
+
if (parent === current) {
|
|
101
|
+
break;
|
|
102
|
+
}
|
|
103
|
+
current = parent;
|
|
104
|
+
}
|
|
105
|
+
return "unknown";
|
|
106
|
+
}
|
|
107
|
+
function printVersion() {
|
|
108
|
+
process.stdout.write(`r5d-worker ${getWorkerVersion()}
|
|
109
|
+
`);
|
|
110
|
+
}
|
|
64
111
|
function requireValue(value, message) {
|
|
65
112
|
if (!value) {
|
|
66
113
|
throw new Error(message);
|
|
@@ -70,7 +117,8 @@ function requireValue(value, message) {
|
|
|
70
117
|
function parseArgs(argv) {
|
|
71
118
|
const options = {
|
|
72
119
|
configPath: defaultConfigPath(),
|
|
73
|
-
help: false
|
|
120
|
+
help: false,
|
|
121
|
+
version: false
|
|
74
122
|
};
|
|
75
123
|
const rest = [];
|
|
76
124
|
for (let index = 0; index < argv.length; index += 1) {
|
|
@@ -82,6 +130,10 @@ function parseArgs(argv) {
|
|
|
82
130
|
options.help = true;
|
|
83
131
|
continue;
|
|
84
132
|
}
|
|
133
|
+
if (arg === "-v" || arg === "--version") {
|
|
134
|
+
options.version = true;
|
|
135
|
+
continue;
|
|
136
|
+
}
|
|
85
137
|
const readOption = (name) => {
|
|
86
138
|
if (arg === name) {
|
|
87
139
|
index += 1;
|
|
@@ -127,6 +179,9 @@ function parseArgs(argv) {
|
|
|
127
179
|
}
|
|
128
180
|
rest.push(arg);
|
|
129
181
|
}
|
|
182
|
+
if (options.version) {
|
|
183
|
+
return { command: "version", options };
|
|
184
|
+
}
|
|
130
185
|
if (options.help || rest.length === 0) {
|
|
131
186
|
return { command: "help", options };
|
|
132
187
|
}
|
|
@@ -447,6 +502,68 @@ function configureVisibleGitHubAuth(branchPath, remoteUrl, authHeader) {
|
|
|
447
502
|
}
|
|
448
503
|
runGit(["config", `${gitExtraHeaderConfigKey(gitExtraHeaderUrlForRemote(remoteUrl))}`, authHeader], { cwd: branchPath });
|
|
449
504
|
}
|
|
505
|
+
function dockerConfigPath() {
|
|
506
|
+
return import_node_path.default.join(import_node_os.default.homedir(), ".docker", "config.json");
|
|
507
|
+
}
|
|
508
|
+
function containersAuthPath() {
|
|
509
|
+
return import_node_path.default.join(import_node_os.default.homedir(), ".config", "containers", "auth.json");
|
|
510
|
+
}
|
|
511
|
+
function readJsonFile(filePath) {
|
|
512
|
+
if (!import_node_fs.default.existsSync(filePath)) {
|
|
513
|
+
return {};
|
|
514
|
+
}
|
|
515
|
+
try {
|
|
516
|
+
const parsed = JSON.parse(import_node_fs.default.readFileSync(filePath, "utf8"));
|
|
517
|
+
return parsed && typeof parsed === "object" && !Array.isArray(parsed) ? parsed : {};
|
|
518
|
+
} catch {
|
|
519
|
+
return {};
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
function writeRegistryAuthFile(filePath, credential) {
|
|
523
|
+
const config = readJsonFile(filePath);
|
|
524
|
+
const existingAuths = config.auths && typeof config.auths === "object" && !Array.isArray(config.auths) ? config.auths : {};
|
|
525
|
+
const auths = existingAuths;
|
|
526
|
+
auths[credential.registry] = {
|
|
527
|
+
username: credential.username,
|
|
528
|
+
password: credential.password,
|
|
529
|
+
auth: Buffer.from(`${credential.username}:${credential.password}`).toString("base64")
|
|
530
|
+
};
|
|
531
|
+
config.auths = auths;
|
|
532
|
+
import_node_fs.default.mkdirSync(import_node_path.default.dirname(filePath), { recursive: true });
|
|
533
|
+
import_node_fs.default.writeFileSync(filePath, `${JSON.stringify(config, null, 2)}
|
|
534
|
+
`, { mode: 384 });
|
|
535
|
+
import_node_fs.default.chmodSync(filePath, 384);
|
|
536
|
+
}
|
|
537
|
+
function configureContainerRegistryAuth(credential) {
|
|
538
|
+
containerRegistryCredential = credential;
|
|
539
|
+
if (!credential) {
|
|
540
|
+
return;
|
|
541
|
+
}
|
|
542
|
+
writeRegistryAuthFile(dockerConfigPath(), credential);
|
|
543
|
+
writeRegistryAuthFile(containersAuthPath(), credential);
|
|
544
|
+
if (credential.missingScopes.length > 0) {
|
|
545
|
+
process.stderr.write(
|
|
546
|
+
`[r5d-worker] GitHub token is missing GHCR scope(s): ${credential.missingScopes.join(", ")}. Sign in with GitHub again if GHCR push/pull fails.
|
|
547
|
+
`
|
|
548
|
+
);
|
|
549
|
+
} else {
|
|
550
|
+
process.stdout.write(`[r5d-worker] configured GHCR auth for ${credential.username}
|
|
551
|
+
`);
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
function containerRegistryEnv() {
|
|
555
|
+
if (!containerRegistryCredential) {
|
|
556
|
+
return {};
|
|
557
|
+
}
|
|
558
|
+
return {
|
|
559
|
+
R5D_GHCR_REGISTRY: containerRegistryCredential.registry,
|
|
560
|
+
R5D_GHCR_NAMESPACE: containerRegistryCredential.username,
|
|
561
|
+
R5D_GHCR_AUTH_FILE: containersAuthPath(),
|
|
562
|
+
REGISTRY_AUTH_FILE: containersAuthPath(),
|
|
563
|
+
GHCR_REGISTRY: containerRegistryCredential.registry,
|
|
564
|
+
GHCR_NAMESPACE: containerRegistryCredential.username
|
|
565
|
+
};
|
|
566
|
+
}
|
|
450
567
|
function checkoutVisibleBranch(input) {
|
|
451
568
|
const branchExists = tryGit(["show-ref", "--verify", "--quiet", `refs/heads/${input.branchName}`], { cwd: input.branchPath });
|
|
452
569
|
const remoteBranchExists = tryGit(["show-ref", "--verify", "--quiet", `refs/remotes/origin/${input.branchName}`], {
|
|
@@ -888,6 +1005,7 @@ async function executeCommand(input) {
|
|
|
888
1005
|
stderr: "pipe",
|
|
889
1006
|
env: {
|
|
890
1007
|
...process.env,
|
|
1008
|
+
...containerRegistryEnv(),
|
|
891
1009
|
...input.message.env ?? {}
|
|
892
1010
|
}
|
|
893
1011
|
});
|
|
@@ -1134,6 +1252,7 @@ function openPty(input) {
|
|
|
1134
1252
|
cwd: branchPath.branchPath,
|
|
1135
1253
|
env: {
|
|
1136
1254
|
...process.env,
|
|
1255
|
+
...containerRegistryEnv(),
|
|
1137
1256
|
...input.message.env ?? {},
|
|
1138
1257
|
BUILD_IT_NOW_PROJECT_ID: input.projectId,
|
|
1139
1258
|
BUILD_IT_NOW_BRANCH_NAME: input.message.branchName
|
|
@@ -1260,7 +1379,7 @@ async function startWorker(options) {
|
|
|
1260
1379
|
platform: process.platform,
|
|
1261
1380
|
arch: process.arch,
|
|
1262
1381
|
pid: process.pid,
|
|
1263
|
-
version:
|
|
1382
|
+
version: getWorkerVersion(),
|
|
1264
1383
|
projectRoot: projectsRoot
|
|
1265
1384
|
}
|
|
1266
1385
|
};
|
|
@@ -1274,6 +1393,7 @@ async function startWorker(options) {
|
|
|
1274
1393
|
return;
|
|
1275
1394
|
}
|
|
1276
1395
|
if (message.type === "project_manifest") {
|
|
1396
|
+
configureContainerRegistryAuth(message.githubContainerRegistry);
|
|
1277
1397
|
manifestByProjectId.clear();
|
|
1278
1398
|
for (const project of message.projects) {
|
|
1279
1399
|
manifestByProjectId.set(project.projectId, project);
|
|
@@ -1411,6 +1531,10 @@ async function main() {
|
|
|
1411
1531
|
printHelp();
|
|
1412
1532
|
return;
|
|
1413
1533
|
}
|
|
1534
|
+
if (parsed.command === "version") {
|
|
1535
|
+
printVersion();
|
|
1536
|
+
return;
|
|
1537
|
+
}
|
|
1414
1538
|
await startWorker(parsed.options);
|
|
1415
1539
|
}
|
|
1416
1540
|
main().catch((error) => {
|
package/dist/cjs/package.json
CHANGED
package/dist/mjs/main.mjs
CHANGED
|
@@ -6,6 +6,7 @@ import { createHash } from "node:crypto";
|
|
|
6
6
|
import { hostname } from "node:os";
|
|
7
7
|
import { spawn as spawnChildProcess } from "node:child_process";
|
|
8
8
|
const DEFAULT_BASE_URL = "https://r5d.dev";
|
|
9
|
+
const WORKER_PACKAGE_NAME = "@ricsam/r5d-worker";
|
|
9
10
|
const LABEL_RE = /^[A-Za-z0-9][A-Za-z0-9_.-]{0,62}$/;
|
|
10
11
|
const BRANCH_RE = /^[A-Za-z0-9][A-Za-z0-9-]*[A-Za-z0-9]$|^[A-Za-z0-9]$/;
|
|
11
12
|
const DEFAULT_READ_LIMIT = 2e3;
|
|
@@ -14,6 +15,7 @@ const MAX_SYNC_DIFF_BYTES = 5 * 1024 * 1024;
|
|
|
14
15
|
const activeProcesses = /* @__PURE__ */ new Map();
|
|
15
16
|
const activePtys = /* @__PURE__ */ new Map();
|
|
16
17
|
const branchLocks = /* @__PURE__ */ new Map();
|
|
18
|
+
let containerRegistryCredential = null;
|
|
17
19
|
function defaultConfigPath() {
|
|
18
20
|
return path.join(os.homedir(), ".config", "r5d", "r5dctl", "config.json");
|
|
19
21
|
}
|
|
@@ -26,6 +28,7 @@ function defaultSyncRoot() {
|
|
|
26
28
|
function printHelp() {
|
|
27
29
|
process.stdout.write(`Usage:
|
|
28
30
|
r5d-worker start --label <label> [--base-url <url>] [--token <token>] [--api-key <key>]
|
|
31
|
+
r5d-worker --version
|
|
29
32
|
|
|
30
33
|
Options:
|
|
31
34
|
--label <label> Required unique worker label for this user, e.g. macos or ec2-build
|
|
@@ -35,9 +38,53 @@ Options:
|
|
|
35
38
|
--config <path> Config path (default ~/.config/r5d/r5dctl/config.json)
|
|
36
39
|
--project-root <dir> Override projects checkout root (default ~/.r5d/projects)
|
|
37
40
|
--sync-root <dir> Override r5d internal sync git root (default ~/.r5d/sync)
|
|
41
|
+
-v, --version Show r5d-worker version
|
|
38
42
|
-h, --help Show this help
|
|
39
43
|
`);
|
|
40
44
|
}
|
|
45
|
+
function readVersionFile(filePath) {
|
|
46
|
+
try {
|
|
47
|
+
const version = fs.readFileSync(filePath, "utf8").trim();
|
|
48
|
+
return version || null;
|
|
49
|
+
} catch {
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
function readInstalledPackageVersion(packageJsonPath) {
|
|
54
|
+
try {
|
|
55
|
+
const parsed = JSON.parse(fs.readFileSync(packageJsonPath, "utf8"));
|
|
56
|
+
if (parsed.name === WORKER_PACKAGE_NAME && typeof parsed.version === "string" && parsed.version.trim()) {
|
|
57
|
+
return parsed.version.trim();
|
|
58
|
+
}
|
|
59
|
+
} catch {
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
function getWorkerVersion() {
|
|
65
|
+
const entrypoint = process.argv[1] ? path.resolve(process.argv[1]) : null;
|
|
66
|
+
let current = entrypoint ? path.dirname(entrypoint) : process.cwd();
|
|
67
|
+
for (let index = 0; index < 12; index += 1) {
|
|
68
|
+
const packageVersion = readInstalledPackageVersion(path.join(current, "package.json"));
|
|
69
|
+
if (packageVersion) {
|
|
70
|
+
return packageVersion;
|
|
71
|
+
}
|
|
72
|
+
const sourceVersion = readVersionFile(path.join(current, "VERSION.txt"));
|
|
73
|
+
if (sourceVersion && path.basename(current) === "binctl-packages") {
|
|
74
|
+
return sourceVersion;
|
|
75
|
+
}
|
|
76
|
+
const parent = path.dirname(current);
|
|
77
|
+
if (parent === current) {
|
|
78
|
+
break;
|
|
79
|
+
}
|
|
80
|
+
current = parent;
|
|
81
|
+
}
|
|
82
|
+
return "unknown";
|
|
83
|
+
}
|
|
84
|
+
function printVersion() {
|
|
85
|
+
process.stdout.write(`r5d-worker ${getWorkerVersion()}
|
|
86
|
+
`);
|
|
87
|
+
}
|
|
41
88
|
function requireValue(value, message) {
|
|
42
89
|
if (!value) {
|
|
43
90
|
throw new Error(message);
|
|
@@ -47,7 +94,8 @@ function requireValue(value, message) {
|
|
|
47
94
|
function parseArgs(argv) {
|
|
48
95
|
const options = {
|
|
49
96
|
configPath: defaultConfigPath(),
|
|
50
|
-
help: false
|
|
97
|
+
help: false,
|
|
98
|
+
version: false
|
|
51
99
|
};
|
|
52
100
|
const rest = [];
|
|
53
101
|
for (let index = 0; index < argv.length; index += 1) {
|
|
@@ -59,6 +107,10 @@ function parseArgs(argv) {
|
|
|
59
107
|
options.help = true;
|
|
60
108
|
continue;
|
|
61
109
|
}
|
|
110
|
+
if (arg === "-v" || arg === "--version") {
|
|
111
|
+
options.version = true;
|
|
112
|
+
continue;
|
|
113
|
+
}
|
|
62
114
|
const readOption = (name) => {
|
|
63
115
|
if (arg === name) {
|
|
64
116
|
index += 1;
|
|
@@ -104,6 +156,9 @@ function parseArgs(argv) {
|
|
|
104
156
|
}
|
|
105
157
|
rest.push(arg);
|
|
106
158
|
}
|
|
159
|
+
if (options.version) {
|
|
160
|
+
return { command: "version", options };
|
|
161
|
+
}
|
|
107
162
|
if (options.help || rest.length === 0) {
|
|
108
163
|
return { command: "help", options };
|
|
109
164
|
}
|
|
@@ -424,6 +479,68 @@ function configureVisibleGitHubAuth(branchPath, remoteUrl, authHeader) {
|
|
|
424
479
|
}
|
|
425
480
|
runGit(["config", `${gitExtraHeaderConfigKey(gitExtraHeaderUrlForRemote(remoteUrl))}`, authHeader], { cwd: branchPath });
|
|
426
481
|
}
|
|
482
|
+
function dockerConfigPath() {
|
|
483
|
+
return path.join(os.homedir(), ".docker", "config.json");
|
|
484
|
+
}
|
|
485
|
+
function containersAuthPath() {
|
|
486
|
+
return path.join(os.homedir(), ".config", "containers", "auth.json");
|
|
487
|
+
}
|
|
488
|
+
function readJsonFile(filePath) {
|
|
489
|
+
if (!fs.existsSync(filePath)) {
|
|
490
|
+
return {};
|
|
491
|
+
}
|
|
492
|
+
try {
|
|
493
|
+
const parsed = JSON.parse(fs.readFileSync(filePath, "utf8"));
|
|
494
|
+
return parsed && typeof parsed === "object" && !Array.isArray(parsed) ? parsed : {};
|
|
495
|
+
} catch {
|
|
496
|
+
return {};
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
function writeRegistryAuthFile(filePath, credential) {
|
|
500
|
+
const config = readJsonFile(filePath);
|
|
501
|
+
const existingAuths = config.auths && typeof config.auths === "object" && !Array.isArray(config.auths) ? config.auths : {};
|
|
502
|
+
const auths = existingAuths;
|
|
503
|
+
auths[credential.registry] = {
|
|
504
|
+
username: credential.username,
|
|
505
|
+
password: credential.password,
|
|
506
|
+
auth: Buffer.from(`${credential.username}:${credential.password}`).toString("base64")
|
|
507
|
+
};
|
|
508
|
+
config.auths = auths;
|
|
509
|
+
fs.mkdirSync(path.dirname(filePath), { recursive: true });
|
|
510
|
+
fs.writeFileSync(filePath, `${JSON.stringify(config, null, 2)}
|
|
511
|
+
`, { mode: 384 });
|
|
512
|
+
fs.chmodSync(filePath, 384);
|
|
513
|
+
}
|
|
514
|
+
function configureContainerRegistryAuth(credential) {
|
|
515
|
+
containerRegistryCredential = credential;
|
|
516
|
+
if (!credential) {
|
|
517
|
+
return;
|
|
518
|
+
}
|
|
519
|
+
writeRegistryAuthFile(dockerConfigPath(), credential);
|
|
520
|
+
writeRegistryAuthFile(containersAuthPath(), credential);
|
|
521
|
+
if (credential.missingScopes.length > 0) {
|
|
522
|
+
process.stderr.write(
|
|
523
|
+
`[r5d-worker] GitHub token is missing GHCR scope(s): ${credential.missingScopes.join(", ")}. Sign in with GitHub again if GHCR push/pull fails.
|
|
524
|
+
`
|
|
525
|
+
);
|
|
526
|
+
} else {
|
|
527
|
+
process.stdout.write(`[r5d-worker] configured GHCR auth for ${credential.username}
|
|
528
|
+
`);
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
function containerRegistryEnv() {
|
|
532
|
+
if (!containerRegistryCredential) {
|
|
533
|
+
return {};
|
|
534
|
+
}
|
|
535
|
+
return {
|
|
536
|
+
R5D_GHCR_REGISTRY: containerRegistryCredential.registry,
|
|
537
|
+
R5D_GHCR_NAMESPACE: containerRegistryCredential.username,
|
|
538
|
+
R5D_GHCR_AUTH_FILE: containersAuthPath(),
|
|
539
|
+
REGISTRY_AUTH_FILE: containersAuthPath(),
|
|
540
|
+
GHCR_REGISTRY: containerRegistryCredential.registry,
|
|
541
|
+
GHCR_NAMESPACE: containerRegistryCredential.username
|
|
542
|
+
};
|
|
543
|
+
}
|
|
427
544
|
function checkoutVisibleBranch(input) {
|
|
428
545
|
const branchExists = tryGit(["show-ref", "--verify", "--quiet", `refs/heads/${input.branchName}`], { cwd: input.branchPath });
|
|
429
546
|
const remoteBranchExists = tryGit(["show-ref", "--verify", "--quiet", `refs/remotes/origin/${input.branchName}`], {
|
|
@@ -865,6 +982,7 @@ async function executeCommand(input) {
|
|
|
865
982
|
stderr: "pipe",
|
|
866
983
|
env: {
|
|
867
984
|
...process.env,
|
|
985
|
+
...containerRegistryEnv(),
|
|
868
986
|
...input.message.env ?? {}
|
|
869
987
|
}
|
|
870
988
|
});
|
|
@@ -1111,6 +1229,7 @@ function openPty(input) {
|
|
|
1111
1229
|
cwd: branchPath.branchPath,
|
|
1112
1230
|
env: {
|
|
1113
1231
|
...process.env,
|
|
1232
|
+
...containerRegistryEnv(),
|
|
1114
1233
|
...input.message.env ?? {},
|
|
1115
1234
|
BUILD_IT_NOW_PROJECT_ID: input.projectId,
|
|
1116
1235
|
BUILD_IT_NOW_BRANCH_NAME: input.message.branchName
|
|
@@ -1237,7 +1356,7 @@ async function startWorker(options) {
|
|
|
1237
1356
|
platform: process.platform,
|
|
1238
1357
|
arch: process.arch,
|
|
1239
1358
|
pid: process.pid,
|
|
1240
|
-
version:
|
|
1359
|
+
version: getWorkerVersion(),
|
|
1241
1360
|
projectRoot: projectsRoot
|
|
1242
1361
|
}
|
|
1243
1362
|
};
|
|
@@ -1251,6 +1370,7 @@ async function startWorker(options) {
|
|
|
1251
1370
|
return;
|
|
1252
1371
|
}
|
|
1253
1372
|
if (message.type === "project_manifest") {
|
|
1373
|
+
configureContainerRegistryAuth(message.githubContainerRegistry);
|
|
1254
1374
|
manifestByProjectId.clear();
|
|
1255
1375
|
for (const project of message.projects) {
|
|
1256
1376
|
manifestByProjectId.set(project.projectId, project);
|
|
@@ -1388,6 +1508,10 @@ async function main() {
|
|
|
1388
1508
|
printHelp();
|
|
1389
1509
|
return;
|
|
1390
1510
|
}
|
|
1511
|
+
if (parsed.command === "version") {
|
|
1512
|
+
printVersion();
|
|
1513
|
+
return;
|
|
1514
|
+
}
|
|
1391
1515
|
await startWorker(parsed.options);
|
|
1392
1516
|
}
|
|
1393
1517
|
main().catch((error) => {
|
package/dist/mjs/package.json
CHANGED