@rakay-technology/kraft 0.7.4 → 0.7.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/README.md +1 -11
- package/dist/bare-JM3EX7S4.js +27 -0
- package/dist/{chunk-EW4PHKB2.js → chunk-2UQFOUSZ.js} +8 -8
- package/dist/{chunk-WYNM7L22.js → chunk-2Y62WP2D.js} +2 -2
- package/dist/{chunk-N4OALTFK.js → chunk-3RCXJZJD.js} +1 -1
- package/dist/{chunk-PZVKPCKE.js → chunk-4UITBYUK.js} +5 -5
- package/dist/{chunk-DM3PKWDC.js → chunk-7UKBMDUF.js} +9 -9
- package/dist/{chunk-MNV2QFHW.js → chunk-BN23UUSF.js} +1 -1
- package/dist/{chunk-I2TOOF2A.js → chunk-CO6FAYLO.js} +1 -1
- package/dist/{chunk-AJ4QZLZ2.js → chunk-DFVWR6JM.js} +2 -2
- package/dist/{chunk-S3QBGGVP.js → chunk-DI54Y66N.js} +3 -3
- package/dist/{chunk-HMJUFZK7.js → chunk-DJNKEVZ7.js} +1 -1
- package/dist/{chunk-JSCZT76F.js → chunk-GABTH5TU.js} +10 -8
- package/dist/{chunk-XVKUFMIB.js → chunk-HFOE2IXZ.js} +1 -1
- package/dist/{chunk-RFOBMHQ7.js → chunk-JK7KKBXI.js} +4 -4
- package/dist/{chunk-XGCG4MD5.js → chunk-K24SBFI2.js} +1 -1
- package/dist/{chunk-TAML5WMA.js → chunk-MC4X55BW.js} +3 -3
- package/dist/chunk-ND23EK7Y.js +81645 -0
- package/dist/{chunk-PNNXWA2A.js → chunk-OZUFHE2T.js} +255 -104
- package/dist/{chunk-YZUKHG3S.js → chunk-PCOTSRS4.js} +3 -3
- package/dist/{chunk-MOLPYPVH.js → chunk-SPKRI7MF.js} +6 -6
- package/dist/{chunk-THTEUDBC.js → chunk-TVURAFJ5.js} +13 -13
- package/dist/{chunk-Y7PVJUXJ.js → chunk-VFPLICBX.js} +6 -6
- package/dist/{chunk-BQMFIXHI.js → chunk-XBGSR22I.js} +5 -5
- package/dist/{chunk-OFXBNFNL.js → chunk-YY5DEAZI.js} +2 -2
- package/dist/{chunk-PNRPKRJU.js → chunk-ZNVAHQRY.js} +6 -6
- package/dist/{chunk-YRSZPVMB.js → chunk-ZQJU5CTZ.js} +1 -1
- package/dist/{detect-676SNZK4.js → detect-N4HFQZ6Y.js} +4 -4
- package/dist/{docker-GOT3Q7DJ.js → docker-DU7JA2AK.js} +8 -8
- package/dist/{docker-edge-executor-VO6JHHW2.js → docker-edge-executor-MPIPQHNF.js} +7 -7
- package/dist/{edge-import-NFCHIW7G.js → edge-import-YDPEIQDU.js} +22 -22
- package/dist/{edge-preflight-QUJ757C6.js → edge-preflight-TT2777R5.js} +13 -13
- package/dist/{ensure-container-edge-Q7IZXHGM.js → ensure-container-edge-T5WRCJSE.js} +11 -11
- package/dist/{executor-GKXKN52K.js → executor-ZWF2J7GS.js} +6 -6
- package/dist/{host-channel-preflight-Z6HYSPKO.js → host-channel-preflight-Z4QG7Q44.js} +22 -22
- package/dist/index.js +343 -89
- package/dist/{local-executor-OMMDKXCM.js → local-executor-W3O5HDLM.js} +3 -3
- package/dist/{nginx-VITTWZZU.js → nginx-XLDZIG4E.js} +9 -9
- package/dist/node-bootstrap.js +72 -37
- package/dist/{openresty-lua-6I3Z6PEQ.js → openresty-lua-ZNE6IBYU.js} +7 -7
- package/dist/{privilege-UQAI2HV4.js → privilege-IMARWVU2.js} +5 -5
- package/dist/server/index.js +58812 -772
- package/dist/{setup-JWKZIECM.js → setup-I3MTOIPW.js} +12 -12
- package/dist/{ssh-client-NWQVRCV7.js → ssh-client-LOCZTEUC.js} +2 -2
- package/dist/{up-P5DMQ5YO.js → up-IADNO7AY.js} +25 -25
- package/package.json +1 -1
- package/dist/bare-HL2GUYE2.js +0 -27
- package/dist/chunk-PVOWHIND.js +0 -26781
|
@@ -9,14 +9,14 @@ import {
|
|
|
9
9
|
internalPost,
|
|
10
10
|
mintBareInternalToken,
|
|
11
11
|
waitHealthy
|
|
12
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-JK7KKBXI.js";
|
|
13
13
|
import {
|
|
14
14
|
completeHostEdge,
|
|
15
15
|
markStoppedProxyImported,
|
|
16
16
|
planAndApplyHostEdge,
|
|
17
17
|
previewHostEdge,
|
|
18
18
|
rollbackHostEdge
|
|
19
|
-
} from "./chunk-
|
|
19
|
+
} from "./chunk-4UITBYUK.js";
|
|
20
20
|
import {
|
|
21
21
|
DEFAULT_REPO,
|
|
22
22
|
PORTS_FILE,
|
|
@@ -43,11 +43,11 @@ import {
|
|
|
43
43
|
resolvePorts,
|
|
44
44
|
sourceBuildDir,
|
|
45
45
|
verifyHostChannel
|
|
46
|
-
} from "./chunk-
|
|
46
|
+
} from "./chunk-GABTH5TU.js";
|
|
47
47
|
import {
|
|
48
48
|
startUnitHint,
|
|
49
49
|
thisHost
|
|
50
|
-
} from "./chunk-
|
|
50
|
+
} from "./chunk-2UQFOUSZ.js";
|
|
51
51
|
import {
|
|
52
52
|
AUTH_SECRET_FILE,
|
|
53
53
|
DATA_DIR,
|
|
@@ -59,16 +59,16 @@ import {
|
|
|
59
59
|
import {
|
|
60
60
|
edgeCrashReason,
|
|
61
61
|
edgeIsBroken
|
|
62
|
-
} from "./chunk-
|
|
62
|
+
} from "./chunk-PCOTSRS4.js";
|
|
63
63
|
import {
|
|
64
64
|
LocalExecutor
|
|
65
|
-
} from "./chunk-
|
|
65
|
+
} from "./chunk-HFOE2IXZ.js";
|
|
66
66
|
import {
|
|
67
67
|
EDGE_CONTAINER_NAME
|
|
68
|
-
} from "./chunk-
|
|
68
|
+
} from "./chunk-3RCXJZJD.js";
|
|
69
69
|
import {
|
|
70
70
|
isValidEmail
|
|
71
|
-
} from "./chunk-
|
|
71
|
+
} from "./chunk-ND23EK7Y.js";
|
|
72
72
|
|
|
73
73
|
// src/commands/up.ts
|
|
74
74
|
import { Command } from "commander";
|
|
@@ -78,27 +78,150 @@ import { spawn } from "child_process";
|
|
|
78
78
|
import { randomBytes } from "crypto";
|
|
79
79
|
import {
|
|
80
80
|
createWriteStream as createWriteStream2,
|
|
81
|
-
existsSync as
|
|
82
|
-
mkdirSync as
|
|
83
|
-
readFileSync as
|
|
84
|
-
writeFileSync as
|
|
81
|
+
existsSync as existsSync5,
|
|
82
|
+
mkdirSync as mkdirSync6,
|
|
83
|
+
readFileSync as readFileSync4,
|
|
84
|
+
writeFileSync as writeFileSync5
|
|
85
85
|
} from "fs";
|
|
86
|
-
import { dirname as dirname2, join as
|
|
86
|
+
import { dirname as dirname2, join as join6 } from "path";
|
|
87
87
|
import { fileURLToPath } from "url";
|
|
88
88
|
|
|
89
89
|
// src/lib/dashboard.ts
|
|
90
|
-
import { spawnSync } from "child_process";
|
|
91
|
-
import { existsSync, mkdirSync as
|
|
92
|
-
import { join as
|
|
90
|
+
import { spawnSync as spawnSync2 } from "child_process";
|
|
91
|
+
import { existsSync as existsSync2, mkdirSync as mkdirSync3, rmSync as rmSync2, writeFileSync as writeFileSync2 } from "fs";
|
|
92
|
+
import { join as join3 } from "path";
|
|
93
93
|
|
|
94
94
|
// src/lib/cache.ts
|
|
95
95
|
import { createHash } from "crypto";
|
|
96
|
-
import { createReadStream, createWriteStream, mkdirSync } from "fs";
|
|
97
|
-
import { dirname, join } from "path";
|
|
98
|
-
|
|
99
|
-
|
|
96
|
+
import { createReadStream, createWriteStream, mkdirSync as mkdirSync2 } from "fs";
|
|
97
|
+
import { dirname, join as join2 } from "path";
|
|
98
|
+
|
|
99
|
+
// src/lib/github-auth.ts
|
|
100
|
+
import {
|
|
101
|
+
mkdirSync,
|
|
102
|
+
readFileSync,
|
|
103
|
+
rmSync,
|
|
104
|
+
writeFileSync
|
|
105
|
+
} from "fs";
|
|
106
|
+
import { homedir } from "os";
|
|
107
|
+
import { join } from "path";
|
|
108
|
+
import { spawnSync } from "child_process";
|
|
109
|
+
var GITHUB_TOKEN_FILENAME = ".github-token";
|
|
110
|
+
function githubTokenFile(dir = OS_DIR) {
|
|
111
|
+
return join(dir, GITHUB_TOKEN_FILENAME);
|
|
112
|
+
}
|
|
113
|
+
function envGithubToken() {
|
|
114
|
+
return process.env.GITHUB_TOKEN?.trim() || process.env.GH_TOKEN?.trim() || void 0;
|
|
115
|
+
}
|
|
116
|
+
function readStoredGithubToken(dir = OS_DIR) {
|
|
117
|
+
try {
|
|
118
|
+
const raw = readFileSync(githubTokenFile(dir), "utf8").trim();
|
|
119
|
+
return raw || null;
|
|
120
|
+
} catch {
|
|
121
|
+
return null;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
function githubToken(dir = OS_DIR) {
|
|
125
|
+
return envGithubToken() ?? readStoredGithubToken(dir) ?? void 0;
|
|
126
|
+
}
|
|
127
|
+
function githubAuthHeaders(dir) {
|
|
128
|
+
const token = dir === void 0 ? githubToken() : githubToken(dir);
|
|
129
|
+
return token ? { Authorization: `Bearer ${token}` } : {};
|
|
130
|
+
}
|
|
131
|
+
function githubTokenSource(dir = OS_DIR) {
|
|
132
|
+
if (envGithubToken()) return "env";
|
|
133
|
+
if (readStoredGithubToken(dir)) return "stored";
|
|
134
|
+
return null;
|
|
135
|
+
}
|
|
136
|
+
function storeGithubToken(token, dir = OS_DIR) {
|
|
137
|
+
mkdirSync(dir, { recursive: true, mode: 448 });
|
|
138
|
+
writeFileSync(githubTokenFile(dir), `${token.trim()}
|
|
139
|
+
`, { mode: 384 });
|
|
140
|
+
}
|
|
141
|
+
function clearGithubToken(dir = OS_DIR) {
|
|
142
|
+
try {
|
|
143
|
+
rmSync(githubTokenFile(dir), { force: true });
|
|
144
|
+
return true;
|
|
145
|
+
} catch {
|
|
146
|
+
return false;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
function maskToken(token) {
|
|
150
|
+
const t = token.trim();
|
|
151
|
+
if (t.length <= 8) return `${t.slice(0, 2)}\u2026`;
|
|
152
|
+
const prefix = t.split("_")[0];
|
|
153
|
+
return `${prefix}_\u2026${t.slice(-4)}`;
|
|
154
|
+
}
|
|
155
|
+
async function validateGithubToken(token) {
|
|
156
|
+
try {
|
|
157
|
+
const res = await fetch("https://api.github.com/rate_limit", {
|
|
158
|
+
headers: {
|
|
159
|
+
Accept: "application/vnd.github+json",
|
|
160
|
+
"User-Agent": "kraft-cli",
|
|
161
|
+
Authorization: `Bearer ${token.trim()}`
|
|
162
|
+
},
|
|
163
|
+
signal: AbortSignal.timeout(1e4)
|
|
164
|
+
});
|
|
165
|
+
return { valid: res.ok, status: res.status };
|
|
166
|
+
} catch {
|
|
167
|
+
return { valid: false, status: 0 };
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
async function checkRepoReleases(token, repo) {
|
|
171
|
+
try {
|
|
172
|
+
const res = await fetch(
|
|
173
|
+
`https://api.github.com/repos/${repo}/releases/latest`,
|
|
174
|
+
{
|
|
175
|
+
headers: {
|
|
176
|
+
Accept: "application/vnd.github+json",
|
|
177
|
+
"User-Agent": "kraft-cli",
|
|
178
|
+
Authorization: `Bearer ${token.trim()}`
|
|
179
|
+
},
|
|
180
|
+
signal: AbortSignal.timeout(1e4)
|
|
181
|
+
}
|
|
182
|
+
);
|
|
183
|
+
if (!res.ok) return { reachable: false, tag: null, status: res.status };
|
|
184
|
+
const data = await res.json();
|
|
185
|
+
return { reachable: true, tag: data.tag_name ?? null, status: res.status };
|
|
186
|
+
} catch {
|
|
187
|
+
return { reachable: false, tag: null, status: 0 };
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
function dockerHasAuthFor(host) {
|
|
191
|
+
try {
|
|
192
|
+
const raw = readFileSync(join(homedir(), ".docker", "config.json"), "utf8");
|
|
193
|
+
const cfg = JSON.parse(raw);
|
|
194
|
+
return !!cfg.auths?.[host];
|
|
195
|
+
} catch {
|
|
196
|
+
return false;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
function dockerAvailable() {
|
|
200
|
+
try {
|
|
201
|
+
return spawnSync("docker", ["--version"], { stdio: "ignore" }).status === 0;
|
|
202
|
+
} catch {
|
|
203
|
+
return false;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
function dockerLogin(host, username, token) {
|
|
207
|
+
try {
|
|
208
|
+
const r = spawnSync(
|
|
209
|
+
"docker",
|
|
210
|
+
["login", host, "-u", username, "--password-stdin"],
|
|
211
|
+
{ input: token, encoding: "utf8" }
|
|
212
|
+
);
|
|
213
|
+
const detail = `${r.stdout ?? ""}${r.stderr ?? ""}`.trim();
|
|
214
|
+
return { ok: r.status === 0, detail };
|
|
215
|
+
} catch (e) {
|
|
216
|
+
return { ok: false, detail: e.message };
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
// src/lib/cache.ts
|
|
221
|
+
var CACHE_DIR = join2(OS_DIR, "cache");
|
|
222
|
+
var RELEASES_DIR = join2(CACHE_DIR, "releases");
|
|
100
223
|
function releaseDir(tag) {
|
|
101
|
-
return
|
|
224
|
+
return join2(RELEASES_DIR, tag);
|
|
102
225
|
}
|
|
103
226
|
function parseSha256(content) {
|
|
104
227
|
const token = content.trim().split(/\s+/)[0]?.toLowerCase();
|
|
@@ -111,9 +234,11 @@ async function hashFile(path) {
|
|
|
111
234
|
return hash.digest("hex");
|
|
112
235
|
}
|
|
113
236
|
async function downloadToFile(url, dest, onProgress) {
|
|
114
|
-
const res = await fetch(url, {
|
|
237
|
+
const res = await fetch(url, {
|
|
238
|
+
headers: { "User-Agent": "kraft-cli", ...githubAuthHeaders() }
|
|
239
|
+
});
|
|
115
240
|
if (!res.ok || !res.body) throw new Error(`HTTP ${res.status} for ${url}`);
|
|
116
|
-
|
|
241
|
+
mkdirSync2(dirname(dest), { recursive: true });
|
|
117
242
|
const total = Number(res.headers.get("content-length")) || 0;
|
|
118
243
|
const hash = createHash("sha256");
|
|
119
244
|
const file = createWriteStream(dest);
|
|
@@ -152,29 +277,43 @@ function formatBytes(n) {
|
|
|
152
277
|
}
|
|
153
278
|
|
|
154
279
|
// src/lib/github-releases.ts
|
|
155
|
-
var
|
|
156
|
-
|
|
157
|
-
|
|
280
|
+
var DEFAULT_GITHUB_REPO = "rakay-technology/kraft";
|
|
281
|
+
function githubRepo() {
|
|
282
|
+
return process.env.KRAFT_GITHUB_REPO?.trim() || DEFAULT_GITHUB_REPO;
|
|
283
|
+
}
|
|
284
|
+
var RELEASES = `https://github.com/${DEFAULT_GITHUB_REPO}/releases`;
|
|
285
|
+
function releasesPage() {
|
|
286
|
+
return `https://github.com/${githubRepo()}/releases`;
|
|
287
|
+
}
|
|
288
|
+
function latestApiUrl() {
|
|
289
|
+
return `https://api.github.com/repos/${githubRepo()}/releases/latest`;
|
|
290
|
+
}
|
|
291
|
+
function privateRepoHint(status) {
|
|
292
|
+
return ` (HTTP ${status} \u2014 for a PRIVATE repo set KRAFT_GITHUB_REPO=<owner/repo> and GITHUB_TOKEN (or GH_TOKEN) with Contents:read, then re-run)`;
|
|
293
|
+
}
|
|
158
294
|
async function resolveLatestTag() {
|
|
159
|
-
const res = await fetch(
|
|
295
|
+
const res = await fetch(latestApiUrl(), {
|
|
160
296
|
headers: {
|
|
161
297
|
Accept: "application/vnd.github+json",
|
|
162
|
-
"User-Agent": "kraft-cli"
|
|
298
|
+
"User-Agent": "kraft-cli",
|
|
299
|
+
...githubAuthHeaders()
|
|
163
300
|
},
|
|
164
301
|
signal: AbortSignal.timeout(1e4)
|
|
165
302
|
});
|
|
166
303
|
if (!res.ok)
|
|
167
|
-
throw new Error(
|
|
304
|
+
throw new Error(
|
|
305
|
+
`GitHub latest-release lookup failed for ${githubRepo()}` + (res.status === 401 || res.status === 403 || res.status === 404 ? privateRepoHint(res.status) : `: HTTP ${res.status}`)
|
|
306
|
+
);
|
|
168
307
|
const data = await res.json();
|
|
169
308
|
if (!data.tag_name) throw new Error("Latest release has no tag_name");
|
|
170
309
|
return data.tag_name;
|
|
171
310
|
}
|
|
172
311
|
function assetUrl(tag, name) {
|
|
173
|
-
return `${
|
|
312
|
+
return `${releasesPage()}/download/${tag}/${name}`;
|
|
174
313
|
}
|
|
175
314
|
async function fetchSidecar(url) {
|
|
176
315
|
const res = await fetch(url, {
|
|
177
|
-
headers: { "User-Agent": "kraft-cli" },
|
|
316
|
+
headers: { "User-Agent": "kraft-cli", ...githubAuthHeaders() },
|
|
178
317
|
signal: AbortSignal.timeout(15e3)
|
|
179
318
|
});
|
|
180
319
|
if (res.status === 404) return null;
|
|
@@ -187,20 +326,20 @@ async function expectedSha256(tag, name) {
|
|
|
187
326
|
}
|
|
188
327
|
|
|
189
328
|
// src/lib/dashboard.ts
|
|
190
|
-
var DASHBOARD_CACHE =
|
|
329
|
+
var DASHBOARD_CACHE = join3(CACHE_DIR, "dashboard");
|
|
191
330
|
function assetName(tag) {
|
|
192
331
|
return `kraft-dashboard-${tag}.tar.gz`;
|
|
193
332
|
}
|
|
194
333
|
function resolveDashboardEntry(cwd) {
|
|
195
|
-
const wrapped =
|
|
196
|
-
return
|
|
334
|
+
const wrapped = join3(cwd, "standalone-server.mjs");
|
|
335
|
+
return existsSync2(wrapped) ? wrapped : join3(cwd, "server.js");
|
|
197
336
|
}
|
|
198
337
|
async function ensureDashboard(opts = {}) {
|
|
199
338
|
const override = process.env.KRAFT_DASHBOARD_DIR?.trim();
|
|
200
339
|
if (override) {
|
|
201
|
-
const cwd =
|
|
202
|
-
const serverJs =
|
|
203
|
-
if (!
|
|
340
|
+
const cwd = join3(override, "apps", "dashboard");
|
|
341
|
+
const serverJs = join3(cwd, "server.js");
|
|
342
|
+
if (!existsSync2(serverJs)) {
|
|
204
343
|
throw new Error(
|
|
205
344
|
`KRAFT_DASHBOARD_DIR=${override} but ${serverJs} is missing \u2014 build the dashboard standalone first (see docs).`
|
|
206
345
|
);
|
|
@@ -221,17 +360,17 @@ async function ensureDashboard(opts = {}) {
|
|
|
221
360
|
}
|
|
222
361
|
}
|
|
223
362
|
async function fetchBundle(tag, onProgress) {
|
|
224
|
-
const dir =
|
|
225
|
-
const cwd =
|
|
226
|
-
const serverJs =
|
|
227
|
-
const marker =
|
|
228
|
-
if (
|
|
363
|
+
const dir = join3(DASHBOARD_CACHE, tag);
|
|
364
|
+
const cwd = join3(dir, "apps", "dashboard");
|
|
365
|
+
const serverJs = join3(cwd, "server.js");
|
|
366
|
+
const marker = join3(dir, ".extracted");
|
|
367
|
+
if (existsSync2(marker) && existsSync2(serverJs)) {
|
|
229
368
|
return { tag, entry: resolveDashboardEntry(cwd), cwd };
|
|
230
369
|
}
|
|
231
|
-
|
|
232
|
-
|
|
370
|
+
rmSync2(dir, { recursive: true, force: true });
|
|
371
|
+
mkdirSync3(dir, { recursive: true });
|
|
233
372
|
const name = assetName(tag);
|
|
234
|
-
const tarball =
|
|
373
|
+
const tarball = join3(dir, name);
|
|
235
374
|
const { sha256 } = await downloadToFile(
|
|
236
375
|
assetUrl(tag, name),
|
|
237
376
|
tarball,
|
|
@@ -244,12 +383,12 @@ async function fetchBundle(tag, onProgress) {
|
|
|
244
383
|
);
|
|
245
384
|
}
|
|
246
385
|
if (expected !== sha256) {
|
|
247
|
-
|
|
386
|
+
rmSync2(dir, { recursive: true, force: true });
|
|
248
387
|
throw new Error(
|
|
249
388
|
`Dashboard bundle checksum mismatch (expected ${expected}, got ${sha256}).`
|
|
250
389
|
);
|
|
251
390
|
}
|
|
252
|
-
const untar =
|
|
391
|
+
const untar = spawnSync2("tar", ["-xzf", tarball, "-C", dir], {
|
|
253
392
|
stdio: "inherit"
|
|
254
393
|
});
|
|
255
394
|
if (untar.status !== 0) {
|
|
@@ -257,32 +396,32 @@ async function fetchBundle(tag, onProgress) {
|
|
|
257
396
|
"Failed to extract the dashboard bundle (is `tar` available?)."
|
|
258
397
|
);
|
|
259
398
|
}
|
|
260
|
-
|
|
261
|
-
if (!
|
|
399
|
+
rmSync2(tarball, { force: true });
|
|
400
|
+
if (!existsSync2(serverJs)) {
|
|
262
401
|
throw new Error(
|
|
263
402
|
`Dashboard bundle extracted but ${serverJs} is missing (unexpected layout).`
|
|
264
403
|
);
|
|
265
404
|
}
|
|
266
|
-
|
|
405
|
+
writeFileSync2(marker, `${tag}
|
|
267
406
|
`);
|
|
268
407
|
return { tag, entry: resolveDashboardEntry(cwd), cwd };
|
|
269
408
|
}
|
|
270
409
|
|
|
271
410
|
// src/lib/service.ts
|
|
272
|
-
import { spawnSync as
|
|
411
|
+
import { spawnSync as spawnSync3 } from "child_process";
|
|
273
412
|
import {
|
|
274
|
-
existsSync as
|
|
275
|
-
mkdirSync as
|
|
276
|
-
writeFileSync as
|
|
277
|
-
rmSync as
|
|
413
|
+
existsSync as existsSync4,
|
|
414
|
+
mkdirSync as mkdirSync5,
|
|
415
|
+
writeFileSync as writeFileSync4,
|
|
416
|
+
rmSync as rmSync3
|
|
278
417
|
} from "fs";
|
|
279
|
-
import { homedir } from "os";
|
|
280
|
-
import { join as
|
|
418
|
+
import { homedir as homedir2 } from "os";
|
|
419
|
+
import { join as join5, resolve } from "path";
|
|
281
420
|
|
|
282
421
|
// src/lib/cli-install.ts
|
|
283
|
-
import { existsSync as
|
|
284
|
-
import { join as
|
|
285
|
-
var MARKER =
|
|
422
|
+
import { existsSync as existsSync3, mkdirSync as mkdirSync4, readFileSync as readFileSync2, writeFileSync as writeFileSync3 } from "fs";
|
|
423
|
+
import { join as join4 } from "path";
|
|
424
|
+
var MARKER = join4(OS_DIR, "cli-install.json");
|
|
286
425
|
function parseCliInstall(raw) {
|
|
287
426
|
try {
|
|
288
427
|
const obj = JSON.parse(raw);
|
|
@@ -291,7 +430,7 @@ function parseCliInstall(raw) {
|
|
|
291
430
|
return {
|
|
292
431
|
method: "tarball",
|
|
293
432
|
tag: obj.tag,
|
|
294
|
-
launcher: typeof obj.launcher === "string" ? obj.launcher :
|
|
433
|
+
launcher: typeof obj.launcher === "string" ? obj.launcher : join4(OS_DIR, "bin", "kraft"),
|
|
295
434
|
runtime: obj.runtime === "vendored" ? "vendored" : "system"
|
|
296
435
|
};
|
|
297
436
|
} catch {
|
|
@@ -299,29 +438,29 @@ function parseCliInstall(raw) {
|
|
|
299
438
|
}
|
|
300
439
|
}
|
|
301
440
|
function readCliInstall() {
|
|
302
|
-
if (!
|
|
441
|
+
if (!existsSync3(MARKER)) return null;
|
|
303
442
|
try {
|
|
304
|
-
return parseCliInstall(
|
|
443
|
+
return parseCliInstall(readFileSync2(MARKER, "utf8"));
|
|
305
444
|
} catch {
|
|
306
445
|
return null;
|
|
307
446
|
}
|
|
308
447
|
}
|
|
309
448
|
function writeCliInstall(info) {
|
|
310
|
-
|
|
311
|
-
|
|
449
|
+
mkdirSync4(OS_DIR, { recursive: true });
|
|
450
|
+
writeFileSync3(MARKER, `${JSON.stringify(info, null, 2)}
|
|
312
451
|
`);
|
|
313
452
|
}
|
|
314
453
|
|
|
315
454
|
// src/lib/service.ts
|
|
316
|
-
var HOME =
|
|
317
|
-
var KRAFT_BIN =
|
|
455
|
+
var HOME = homedir2();
|
|
456
|
+
var KRAFT_BIN = join5(OS_DIR, "bin");
|
|
318
457
|
var MAC_LABEL = IS_ALT_HOME ? "io.kraft-dev.up" : "io.kraft.up";
|
|
319
|
-
var MAC_PLIST =
|
|
458
|
+
var MAC_PLIST = join5(HOME, "Library", "LaunchAgents", `${MAC_LABEL}.plist`);
|
|
320
459
|
var SYSTEMD_NAME = IS_ALT_HOME ? "kraft-dev" : "kraft";
|
|
321
460
|
var WIN_TASK = IS_ALT_HOME ? "KraftDev" : "Kraft";
|
|
322
461
|
function selfInvocation() {
|
|
323
462
|
const cli = readCliInstall();
|
|
324
|
-
if (cli?.method === "tarball" &&
|
|
463
|
+
if (cli?.method === "tarball" && existsSync4(cli.launcher)) {
|
|
325
464
|
return { runtime: cli.launcher, args: [] };
|
|
326
465
|
}
|
|
327
466
|
const runtime = process.execPath;
|
|
@@ -348,7 +487,7 @@ function runArgv(flags) {
|
|
|
348
487
|
return [runtime, ...args, ...upArgs(flags)];
|
|
349
488
|
}
|
|
350
489
|
function run(cmd, args) {
|
|
351
|
-
const r =
|
|
490
|
+
const r = spawnSync3(cmd, args, { encoding: "utf8" });
|
|
352
491
|
return {
|
|
353
492
|
ok: r.status === 0,
|
|
354
493
|
out: `${r.stdout ?? ""}${r.stderr ?? ""}`.trim()
|
|
@@ -395,7 +534,7 @@ function serviceEnv() {
|
|
|
395
534
|
function plist(flags) {
|
|
396
535
|
const argv = runArgv(flags);
|
|
397
536
|
const items = argv.map((a) => ` <string>${xmlEscape(a)}</string>`).join("\n");
|
|
398
|
-
const runtimeBin = readCliInstall()?.method === "tarball" ? KRAFT_BIN :
|
|
537
|
+
const runtimeBin = readCliInstall()?.method === "tarball" ? KRAFT_BIN : join5(HOME, ".bun/bin");
|
|
399
538
|
const path = [
|
|
400
539
|
"/opt/homebrew/bin",
|
|
401
540
|
"/usr/local/bin",
|
|
@@ -417,8 +556,8 @@ ${items}
|
|
|
417
556
|
</array>
|
|
418
557
|
<key>RunAtLoad</key><true/>
|
|
419
558
|
<key>KeepAlive</key><true/>
|
|
420
|
-
<key>StandardOutPath</key><string>${
|
|
421
|
-
<key>StandardErrorPath</key><string>${
|
|
559
|
+
<key>StandardOutPath</key><string>${join5(LOG_DIR, "up.log")}</string>
|
|
560
|
+
<key>StandardErrorPath</key><string>${join5(LOG_DIR, "up.err.log")}</string>
|
|
422
561
|
<key>EnvironmentVariables</key>
|
|
423
562
|
<dict><key>PATH</key><string>${path}</string>${extraEnv}</dict>
|
|
424
563
|
</dict>
|
|
@@ -469,7 +608,7 @@ function preview(flags) {
|
|
|
469
608
|
if (kind === "systemd-user")
|
|
470
609
|
return {
|
|
471
610
|
kind,
|
|
472
|
-
path:
|
|
611
|
+
path: join5(HOME, ".config/systemd/user", `${SYSTEMD_NAME}.service`),
|
|
473
612
|
content: systemdUnit(flags)
|
|
474
613
|
};
|
|
475
614
|
if (kind === "systemd-system")
|
|
@@ -483,15 +622,15 @@ function preview(flags) {
|
|
|
483
622
|
return { kind, path: "", content: "" };
|
|
484
623
|
}
|
|
485
624
|
function installAndStart(flags) {
|
|
486
|
-
|
|
625
|
+
mkdirSync5(LOG_DIR, { recursive: true });
|
|
487
626
|
const kind = detectKind();
|
|
488
627
|
if (kind === "launchd") {
|
|
489
|
-
|
|
628
|
+
mkdirSync5(join5(HOME, "Library", "LaunchAgents"), { recursive: true });
|
|
490
629
|
run("launchctl", [
|
|
491
630
|
"bootout",
|
|
492
631
|
`gui/${process.getuid?.() ?? ""}/${MAC_LABEL}`
|
|
493
632
|
]);
|
|
494
|
-
|
|
633
|
+
writeFileSync4(MAC_PLIST, plist(flags));
|
|
495
634
|
const uid = String(process.getuid?.() ?? "");
|
|
496
635
|
let r = run("launchctl", ["bootstrap", `gui/${uid}`, MAC_PLIST]);
|
|
497
636
|
if (!r.ok) r = run("launchctl", ["load", "-w", MAC_PLIST]);
|
|
@@ -500,11 +639,11 @@ function installAndStart(flags) {
|
|
|
500
639
|
}
|
|
501
640
|
if (kind === "systemd-user" || kind === "systemd-system") {
|
|
502
641
|
const sysArgs = kind === "systemd-user" ? ["--user"] : [];
|
|
503
|
-
const unitPath = kind === "systemd-user" ?
|
|
504
|
-
|
|
642
|
+
const unitPath = kind === "systemd-user" ? join5(HOME, ".config/systemd/user", `${SYSTEMD_NAME}.service`) : `/etc/systemd/system/${SYSTEMD_NAME}.service`;
|
|
643
|
+
mkdirSync5(unitPath.slice(0, unitPath.lastIndexOf("/")), {
|
|
505
644
|
recursive: true
|
|
506
645
|
});
|
|
507
|
-
|
|
646
|
+
writeFileSync4(unitPath, systemdUnit(flags));
|
|
508
647
|
run("systemctl", [...sysArgs, "daemon-reload"]);
|
|
509
648
|
const r = run("systemctl", [...sysArgs, "enable", "--now", SYSTEMD_NAME]);
|
|
510
649
|
if (!r.ok) throw new Error(`systemctl enable failed: ${r.out}`);
|
|
@@ -544,7 +683,7 @@ function installAndStart(flags) {
|
|
|
544
683
|
function restart() {
|
|
545
684
|
const kind = detectKind();
|
|
546
685
|
if (kind === "launchd") {
|
|
547
|
-
if (!
|
|
686
|
+
if (!existsSync4(MAC_PLIST))
|
|
548
687
|
return { restarted: false, detail: "no launchd agent installed" };
|
|
549
688
|
const uid = String(process.getuid?.() ?? "");
|
|
550
689
|
const r = run("launchctl", ["kickstart", "-k", `gui/${uid}/${MAC_LABEL}`]);
|
|
@@ -566,8 +705,8 @@ function restart() {
|
|
|
566
705
|
}
|
|
567
706
|
if (kind === "systemd-user" || kind === "systemd-system") {
|
|
568
707
|
const sysArgs = kind === "systemd-user" ? ["--user"] : [];
|
|
569
|
-
const unitPath = kind === "systemd-user" ?
|
|
570
|
-
if (!
|
|
708
|
+
const unitPath = kind === "systemd-user" ? join5(HOME, ".config/systemd/user", `${SYSTEMD_NAME}.service`) : `/etc/systemd/system/${SYSTEMD_NAME}.service`;
|
|
709
|
+
if (!existsSync4(unitPath))
|
|
571
710
|
return { restarted: false, detail: "no systemd unit installed" };
|
|
572
711
|
const r = run("systemctl", [...sysArgs, "restart", SYSTEMD_NAME]);
|
|
573
712
|
return {
|
|
@@ -587,16 +726,16 @@ function serviceStatus() {
|
|
|
587
726
|
if (kind === "launchd") {
|
|
588
727
|
return {
|
|
589
728
|
kind,
|
|
590
|
-
installed:
|
|
729
|
+
installed: existsSync4(MAC_PLIST),
|
|
591
730
|
running: launchdPid() != null
|
|
592
731
|
};
|
|
593
732
|
}
|
|
594
733
|
if (kind === "systemd-user" || kind === "systemd-system") {
|
|
595
734
|
const sysArgs = kind === "systemd-user" ? ["--user"] : [];
|
|
596
|
-
const unitPath = kind === "systemd-user" ?
|
|
735
|
+
const unitPath = kind === "systemd-user" ? join5(HOME, ".config/systemd/user", `${SYSTEMD_NAME}.service`) : `/etc/systemd/system/${SYSTEMD_NAME}.service`;
|
|
597
736
|
return {
|
|
598
737
|
kind,
|
|
599
|
-
installed:
|
|
738
|
+
installed: existsSync4(unitPath),
|
|
600
739
|
running: run("systemctl", [...sysArgs, "is-active", SYSTEMD_NAME]).out.trim() === "active"
|
|
601
740
|
};
|
|
602
741
|
}
|
|
@@ -636,13 +775,13 @@ function stop() {
|
|
|
636
775
|
"bootout",
|
|
637
776
|
`gui/${process.getuid?.() ?? ""}/${MAC_LABEL}`
|
|
638
777
|
]);
|
|
639
|
-
if (
|
|
778
|
+
if (existsSync4(MAC_PLIST)) rmSync3(MAC_PLIST, { force: true });
|
|
640
779
|
result = { kind, detail: `launchd agent ${MAC_LABEL} stopped + removed` };
|
|
641
780
|
} else if (kind === "systemd-user" || kind === "systemd-system") {
|
|
642
781
|
const sysArgs = kind === "systemd-user" ? ["--user"] : [];
|
|
643
782
|
run("systemctl", [...sysArgs, "disable", "--now", SYSTEMD_NAME]);
|
|
644
|
-
const unitPath = kind === "systemd-user" ?
|
|
645
|
-
if (
|
|
783
|
+
const unitPath = kind === "systemd-user" ? join5(HOME, ".config/systemd/user", `${SYSTEMD_NAME}.service`) : `/etc/systemd/system/${SYSTEMD_NAME}.service`;
|
|
784
|
+
if (existsSync4(unitPath)) rmSync3(unitPath, { force: true });
|
|
646
785
|
run("systemctl", [...sysArgs, "daemon-reload"]);
|
|
647
786
|
result = {
|
|
648
787
|
kind,
|
|
@@ -1150,13 +1289,13 @@ function normalizePublicUrl(raw) {
|
|
|
1150
1289
|
return url;
|
|
1151
1290
|
}
|
|
1152
1291
|
var DIST_DIR = dirname2(fileURLToPath(import.meta.url));
|
|
1153
|
-
var SERVER_DIR =
|
|
1292
|
+
var SERVER_DIR = join6(DIST_DIR, "server");
|
|
1154
1293
|
function ensureAuthSecret() {
|
|
1155
1294
|
const path = AUTH_SECRET_FILE;
|
|
1156
|
-
if (
|
|
1157
|
-
|
|
1295
|
+
if (existsSync5(path)) return readFileSync4(path, "utf8").trim();
|
|
1296
|
+
mkdirSync6(OS_DIR, { recursive: true, mode: 448 });
|
|
1158
1297
|
const secret = randomBytes(32).toString("hex");
|
|
1159
|
-
|
|
1298
|
+
writeFileSync5(path, secret, { mode: 384 });
|
|
1160
1299
|
return secret;
|
|
1161
1300
|
}
|
|
1162
1301
|
var upCommand = new Command("up").description(
|
|
@@ -1657,8 +1796,8 @@ async function runForeground(opts, source) {
|
|
|
1657
1796
|
apiArgs = ["run", "src/index.ts"];
|
|
1658
1797
|
apiCwd = source.apiDir;
|
|
1659
1798
|
} else {
|
|
1660
|
-
const serverEntry =
|
|
1661
|
-
if (!
|
|
1799
|
+
const serverEntry = join6(SERVER_DIR, "index.js");
|
|
1800
|
+
if (!existsSync5(serverEntry)) {
|
|
1662
1801
|
console.error(
|
|
1663
1802
|
chalk2.red("\n Bundled server not found in this install.") + chalk2.dim(
|
|
1664
1803
|
"\n Reinstall with `kraft update` (or `npm i -g @rakay-technology/kraft`).\n"
|
|
@@ -1677,9 +1816,9 @@ async function runForeground(opts, source) {
|
|
|
1677
1816
|
const publicUrl = effectivePublicUrl(opts.publicUrl);
|
|
1678
1817
|
const managedEdge = Boolean(opts.managedEdge && publicUrl);
|
|
1679
1818
|
const dataDir = opts.dataDir || DATA_DIR;
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
const instanceLogPath =
|
|
1819
|
+
mkdirSync6(dataDir, { recursive: true });
|
|
1820
|
+
mkdirSync6(LOG_DIR, { recursive: true });
|
|
1821
|
+
const instanceLogPath = join6(LOG_DIR, "instance.log");
|
|
1683
1822
|
const instanceLog = createWriteStream2(instanceLogPath, { flags: "w" });
|
|
1684
1823
|
const env = {
|
|
1685
1824
|
...process.env,
|
|
@@ -1707,10 +1846,10 @@ async function runForeground(opts, source) {
|
|
|
1707
1846
|
BETTER_AUTH_SECRET: ensureAuthSecret()
|
|
1708
1847
|
};
|
|
1709
1848
|
if (!source) {
|
|
1710
|
-
env.KRAFT_MIGRATIONS_DIR =
|
|
1711
|
-
env.KRAFT_PGLITE_ASSETS_DIR =
|
|
1712
|
-
const engineDir =
|
|
1713
|
-
if (
|
|
1849
|
+
env.KRAFT_MIGRATIONS_DIR = join6(SERVER_DIR, "migrations");
|
|
1850
|
+
env.KRAFT_PGLITE_ASSETS_DIR = join6(SERVER_DIR, "pglite");
|
|
1851
|
+
const engineDir = join6(SERVER_DIR, "engine");
|
|
1852
|
+
if (existsSync5(engineDir)) env.MAIL_SERVER_ENGINE_DIR = engineDir;
|
|
1714
1853
|
}
|
|
1715
1854
|
env.KRAFT_REQUIRE_AUTH = "true";
|
|
1716
1855
|
env.INTERNAL_TOKEN = mintBareInternalToken();
|
|
@@ -1803,7 +1942,7 @@ async function runForeground(opts, source) {
|
|
|
1803
1942
|
const uiSpinner = ora("Preparing the dashboard\u2026").start();
|
|
1804
1943
|
try {
|
|
1805
1944
|
const bundle = await ensureDashboard({
|
|
1806
|
-
tag: source ? "local" : opts.uiVersion || `v${"0.7.
|
|
1945
|
+
tag: source ? "local" : opts.uiVersion || `v${"0.7.6"}`,
|
|
1807
1946
|
onProgress: (received, total) => {
|
|
1808
1947
|
if (total) {
|
|
1809
1948
|
uiSpinner.text = `Downloading dashboard\u2026 ${Math.round(received / total * 100)}%`;
|
|
@@ -1920,6 +2059,17 @@ async function runForeground(opts, source) {
|
|
|
1920
2059
|
}
|
|
1921
2060
|
|
|
1922
2061
|
export {
|
|
2062
|
+
readStoredGithubToken,
|
|
2063
|
+
githubToken,
|
|
2064
|
+
githubTokenSource,
|
|
2065
|
+
storeGithubToken,
|
|
2066
|
+
clearGithubToken,
|
|
2067
|
+
maskToken,
|
|
2068
|
+
validateGithubToken,
|
|
2069
|
+
checkRepoReleases,
|
|
2070
|
+
dockerHasAuthFor,
|
|
2071
|
+
dockerAvailable,
|
|
2072
|
+
dockerLogin,
|
|
1923
2073
|
CACHE_DIR,
|
|
1924
2074
|
RELEASES_DIR,
|
|
1925
2075
|
releaseDir,
|
|
@@ -1927,7 +2077,8 @@ export {
|
|
|
1927
2077
|
hashFile,
|
|
1928
2078
|
downloadToFile,
|
|
1929
2079
|
formatBytes,
|
|
1930
|
-
|
|
2080
|
+
githubRepo,
|
|
2081
|
+
releasesPage,
|
|
1931
2082
|
resolveLatestTag,
|
|
1932
2083
|
assetUrl,
|
|
1933
2084
|
fetchSidecar,
|
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
describeProcess,
|
|
7
7
|
probeListeningPort,
|
|
8
8
|
waitForPortFree
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-2Y62WP2D.js";
|
|
10
10
|
import {
|
|
11
11
|
EDGE_CONTAINER_NAME,
|
|
12
12
|
classifyProxy,
|
|
@@ -16,11 +16,11 @@ import {
|
|
|
16
16
|
resolveContainerPublishingPort,
|
|
17
17
|
stopContainerDurably,
|
|
18
18
|
tryExec
|
|
19
|
-
} from "./chunk-
|
|
19
|
+
} from "./chunk-3RCXJZJD.js";
|
|
20
20
|
import {
|
|
21
21
|
AppError,
|
|
22
22
|
shellQuote
|
|
23
|
-
} from "./chunk-
|
|
23
|
+
} from "./chunk-ND23EK7Y.js";
|
|
24
24
|
|
|
25
25
|
// ../../packages/adapters/src/system/proxy/detect.ts
|
|
26
26
|
var EDGE_PORTS = [80, 443];
|