sagacloud 0.2.0 → 0.3.1
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/index.js
CHANGED
|
@@ -6,7 +6,6 @@ import pc8 from "picocolors";
|
|
|
6
6
|
|
|
7
7
|
// src/commands/auth.ts
|
|
8
8
|
import crypto from "crypto";
|
|
9
|
-
import { execFile } from "child_process";
|
|
10
9
|
import http from "http";
|
|
11
10
|
import os2 from "os";
|
|
12
11
|
import * as p from "@clack/prompts";
|
|
@@ -21,11 +20,20 @@ import { parse as parseJsonc, printParseErrorCode } from "jsonc-parser";
|
|
|
21
20
|
import { z } from "zod";
|
|
22
21
|
var DEFAULT_API_BASE_URL = "https://app.sagasoft.xyz";
|
|
23
22
|
var DEFAULT_PANEL_BASE_URL = "https://app.sagasoft.xyz";
|
|
23
|
+
var SagaCloudDomainEntrySchema = z.union([
|
|
24
|
+
z.string().min(1),
|
|
25
|
+
z.object({
|
|
26
|
+
fqdn: z.string().min(1),
|
|
27
|
+
primary: z.boolean().optional(),
|
|
28
|
+
mode: z.enum(["auto", "saga_root", "saga_subdomain", "custom_external"]).optional()
|
|
29
|
+
})
|
|
30
|
+
]);
|
|
24
31
|
var SagaCloudJsoncSchema = z.object({
|
|
25
32
|
$schema: z.string().optional(),
|
|
33
|
+
app_name: z.string().min(1).optional(),
|
|
26
34
|
name: z.string().min(1).optional(),
|
|
27
35
|
site_id: z.string().optional(),
|
|
28
|
-
type: z.enum(["static", "spa", "php", "node", "nextjs"]).optional(),
|
|
36
|
+
type: z.enum(["static", "html", "spa", "php", "node", "nextjs"]).optional(),
|
|
29
37
|
base_directory: z.string().optional(),
|
|
30
38
|
install_command: z.string().optional(),
|
|
31
39
|
build_command: z.string().optional(),
|
|
@@ -33,9 +41,25 @@ var SagaCloudJsoncSchema = z.object({
|
|
|
33
41
|
start_command: z.string().optional(),
|
|
34
42
|
port: z.union([z.number().int().min(1).max(65535), z.string()]).optional(),
|
|
35
43
|
spa_fallback: z.boolean().optional(),
|
|
36
|
-
|
|
44
|
+
healthcheck_path: z.string().optional(),
|
|
45
|
+
domains: z.array(SagaCloudDomainEntrySchema).optional(),
|
|
46
|
+
cdn: z.object({
|
|
47
|
+
enabled: z.boolean().optional(),
|
|
48
|
+
waf: z.boolean().optional(),
|
|
49
|
+
purge_on_deploy: z.boolean().optional()
|
|
50
|
+
}).optional(),
|
|
51
|
+
resources: z.object({
|
|
52
|
+
memory: z.union([z.string(), z.number()]).optional(),
|
|
53
|
+
cpus: z.union([z.string(), z.number()]).optional()
|
|
54
|
+
}).optional(),
|
|
55
|
+
env_file: z.string().optional(),
|
|
37
56
|
ignore: z.array(z.string()).optional(),
|
|
38
|
-
vars: z.record(z.union([z.string(), z.number(), z.boolean()])).optional()
|
|
57
|
+
vars: z.record(z.union([z.string(), z.number(), z.boolean()])).optional(),
|
|
58
|
+
deploy: z.object({
|
|
59
|
+
detach: z.boolean().optional(),
|
|
60
|
+
force_rebuild: z.boolean().optional(),
|
|
61
|
+
sync_domains: z.boolean().optional()
|
|
62
|
+
}).optional()
|
|
39
63
|
});
|
|
40
64
|
function getAuthDir() {
|
|
41
65
|
return path.join(os.homedir(), ".config", "sagacloud");
|
|
@@ -260,12 +284,102 @@ async function exchangeCliCode(apiUrl, code) {
|
|
|
260
284
|
return parsed.message || parsed;
|
|
261
285
|
}
|
|
262
286
|
|
|
263
|
-
// src/
|
|
264
|
-
|
|
287
|
+
// src/lib/browser.ts
|
|
288
|
+
import { execFile } from "child_process";
|
|
289
|
+
async function openBrowser(url) {
|
|
265
290
|
const cmd = process.platform === "darwin" ? "open" : process.platform === "win32" ? "cmd" : "xdg-open";
|
|
266
291
|
const args = process.platform === "win32" ? ["/c", "start", "", url] : [url];
|
|
267
|
-
|
|
292
|
+
return await new Promise((resolve) => {
|
|
293
|
+
let settled = false;
|
|
294
|
+
const finish = (ok) => {
|
|
295
|
+
if (settled) return;
|
|
296
|
+
settled = true;
|
|
297
|
+
resolve(ok);
|
|
298
|
+
};
|
|
299
|
+
try {
|
|
300
|
+
const child = execFile(cmd, args, (err) => {
|
|
301
|
+
finish(!err);
|
|
302
|
+
});
|
|
303
|
+
child.once("error", () => finish(false));
|
|
304
|
+
setTimeout(() => {
|
|
305
|
+
if (child.exitCode === null) {
|
|
306
|
+
child.unref();
|
|
307
|
+
finish(true);
|
|
308
|
+
}
|
|
309
|
+
}, 400);
|
|
310
|
+
} catch {
|
|
311
|
+
finish(false);
|
|
312
|
+
}
|
|
313
|
+
});
|
|
314
|
+
}
|
|
315
|
+
function isHeadlessOrRemoteShell() {
|
|
316
|
+
if (!process.stdin.isTTY) return true;
|
|
317
|
+
if (process.env.SSH_CONNECTION || process.env.SSH_TTY || process.env.SSH_CLIENT) return true;
|
|
318
|
+
if (process.platform === "linux" && !process.env.DISPLAY && !process.env.WAYLAND_DISPLAY) {
|
|
319
|
+
return true;
|
|
320
|
+
}
|
|
321
|
+
return false;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
// src/commands/auth.ts
|
|
325
|
+
async function authenticateWithToken(rawToken, apiUrl, panelUrl) {
|
|
326
|
+
const spin = p.spinner();
|
|
327
|
+
spin.start("Verifying SagaCloud API token...");
|
|
328
|
+
const client = new SagaCloudClient({ token: rawToken.trim(), apiUrl });
|
|
329
|
+
const info = await client.rpc("saga_cloud.api.cli_auth.get_cli_session_info");
|
|
330
|
+
writeAuthProfile({
|
|
331
|
+
token: rawToken.trim(),
|
|
332
|
+
apiUrl,
|
|
333
|
+
panelUrl,
|
|
334
|
+
user: info.user,
|
|
335
|
+
tenant: info.tenant,
|
|
336
|
+
tenantName: info.tenant_name,
|
|
337
|
+
tokenName: info.token_name
|
|
338
|
+
});
|
|
339
|
+
spin.stop(`Authenticated as ${pc.green(info.user)} (Workspace: ${pc.cyan(info.tenant_name)})`);
|
|
340
|
+
}
|
|
341
|
+
async function promptManualLogin(apiUrl, panelBase, tryOpenBrowser) {
|
|
342
|
+
const manualUrl = new URL(`${panelBase}/hosting/cli-auth`);
|
|
343
|
+
manualUrl.searchParams.set("mode", "manual");
|
|
344
|
+
manualUrl.searchParams.set("device", os2.hostname());
|
|
345
|
+
console.log(pc.bold("Manual CLI authorization (SSH / headless / container):"));
|
|
346
|
+
console.log(`1. Open this URL in any browser:
|
|
347
|
+
${pc.cyan(manualUrl.toString())}`);
|
|
348
|
+
console.log(`2. Click ${pc.bold("Authorize CLI Access")} and copy the one-time code (or an ${pc.dim("sc_live_...")} API token).
|
|
349
|
+
`);
|
|
350
|
+
if (tryOpenBrowser) {
|
|
351
|
+
await openBrowser(manualUrl.toString());
|
|
352
|
+
}
|
|
353
|
+
const pasted = await p.password({
|
|
354
|
+
message: "Paste authorization code or sc_live_... token",
|
|
355
|
+
validate(val) {
|
|
356
|
+
if (!val || !val.trim()) return "Authorization code or token is required.";
|
|
357
|
+
}
|
|
268
358
|
});
|
|
359
|
+
if (p.isCancel(pasted)) {
|
|
360
|
+
p.cancel("Login cancelled.");
|
|
361
|
+
process.exit(1);
|
|
362
|
+
}
|
|
363
|
+
const secret = String(pasted).trim();
|
|
364
|
+
if (secret.startsWith("sc_live_")) {
|
|
365
|
+
await authenticateWithToken(secret, apiUrl, panelBase);
|
|
366
|
+
return;
|
|
367
|
+
}
|
|
368
|
+
const spin = p.spinner();
|
|
369
|
+
spin.start("Exchanging one-time authorization code...");
|
|
370
|
+
const exchanged = await exchangeCliCode(apiUrl, secret);
|
|
371
|
+
writeAuthProfile({
|
|
372
|
+
token: exchanged.token,
|
|
373
|
+
apiUrl,
|
|
374
|
+
panelUrl: panelBase,
|
|
375
|
+
user: exchanged.user,
|
|
376
|
+
tenant: exchanged.tenant,
|
|
377
|
+
tenantName: exchanged.tenant_name,
|
|
378
|
+
tokenName: exchanged.token_name
|
|
379
|
+
});
|
|
380
|
+
spin.stop(
|
|
381
|
+
`Logged in as ${pc.green(exchanged.user)} \xB7 Workspace: ${pc.cyan(exchanged.tenant_name)} (${pc.dim(exchanged.token_prefix)}...)`
|
|
382
|
+
);
|
|
269
383
|
}
|
|
270
384
|
function escapeHtml(value) {
|
|
271
385
|
return value.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">").replaceAll('"', """).replaceAll("'", "'");
|
|
@@ -398,23 +512,15 @@ function renderCallbackHtml(opts) {
|
|
|
398
512
|
</html>`;
|
|
399
513
|
}
|
|
400
514
|
function registerAuthCommands(program2) {
|
|
401
|
-
program2.command("login").description("Authenticate CLI via browser approval or --token").option("--token <token>", "Store an existing sc_live_... API token directly").option("--url <apiUrl>", "SagaCloud API base URL", DEFAULT_API_BASE_URL).option("--panel-url <panelUrl>", "SagaCloud Dashboard URL for browser login", DEFAULT_PANEL_BASE_URL).action(async (opts) => {
|
|
515
|
+
program2.command("login").description("Authenticate CLI via browser approval, manual code paste, or --token").option("--token <token>", "Store an existing sc_live_... API token directly").option("--manual", "Prompt to paste an authorization code or token instead of waiting for 127.0.0.1 callback", false).option("--no-browser", "Do not launch a local browser automatically").option("--url <apiUrl>", "SagaCloud API base URL", DEFAULT_API_BASE_URL).option("--panel-url <panelUrl>", "SagaCloud Dashboard URL for browser login", DEFAULT_PANEL_BASE_URL).action(async (opts) => {
|
|
402
516
|
const apiUrl = (opts.url || DEFAULT_API_BASE_URL).replace(/\/+$/, "");
|
|
517
|
+
const panelBase = (opts.panelUrl || DEFAULT_PANEL_BASE_URL).replace(/\/+$/, "");
|
|
403
518
|
if (opts.token) {
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
token: opts.token.trim(),
|
|
410
|
-
apiUrl,
|
|
411
|
-
panelUrl: opts.panelUrl,
|
|
412
|
-
user: info.user,
|
|
413
|
-
tenant: info.tenant,
|
|
414
|
-
tenantName: info.tenant_name,
|
|
415
|
-
tokenName: info.token_name
|
|
416
|
-
});
|
|
417
|
-
spin2.stop(`Authenticated as ${pc.green(info.user)} (Workspace: ${pc.cyan(info.tenant_name)})`);
|
|
519
|
+
await authenticateWithToken(opts.token, apiUrl, opts.panelUrl);
|
|
520
|
+
return;
|
|
521
|
+
}
|
|
522
|
+
if (opts.manual || opts.browser === false || isHeadlessOrRemoteShell()) {
|
|
523
|
+
await promptManualLogin(apiUrl, panelBase, Boolean(opts.browser !== false && !isHeadlessOrRemoteShell()));
|
|
418
524
|
return;
|
|
419
525
|
}
|
|
420
526
|
const state = crypto.randomBytes(24).toString("hex");
|
|
@@ -425,7 +531,6 @@ function registerAuthCommands(program2) {
|
|
|
425
531
|
throw new Error("Could not bind local loopback port for login.");
|
|
426
532
|
}
|
|
427
533
|
const callbackUrl = `http://127.0.0.1:${addr.port}/callback`;
|
|
428
|
-
const panelBase = (opts.panelUrl || DEFAULT_PANEL_BASE_URL).replace(/\/+$/, "");
|
|
429
534
|
const authUrl = new URL(`${panelBase}/hosting/cli-auth`);
|
|
430
535
|
authUrl.searchParams.set("callback", callbackUrl);
|
|
431
536
|
authUrl.searchParams.set("state", state);
|
|
@@ -434,7 +539,13 @@ function registerAuthCommands(program2) {
|
|
|
434
539
|
console.log(`If your browser doesn't open, visit:
|
|
435
540
|
${pc.cyan(authUrl.toString())}
|
|
436
541
|
`);
|
|
437
|
-
openBrowser(authUrl.toString());
|
|
542
|
+
const opened = await openBrowser(authUrl.toString());
|
|
543
|
+
if (!opened) {
|
|
544
|
+
server.close();
|
|
545
|
+
console.log(pc.yellow("No working local browser opener detected; switching to manual authorization mode.\n"));
|
|
546
|
+
await promptManualLogin(apiUrl, panelBase, false);
|
|
547
|
+
return;
|
|
548
|
+
}
|
|
438
549
|
const code = await new Promise((resolve, reject) => {
|
|
439
550
|
const timeout = setTimeout(() => {
|
|
440
551
|
server.close();
|
|
@@ -505,6 +616,7 @@ function registerAuthCommands(program2) {
|
|
|
505
616
|
);
|
|
506
617
|
});
|
|
507
618
|
program2.command("logout").description("Revoke active CLI token on server and remove local credentials").action(async () => {
|
|
619
|
+
const envToken = process.env.SAGACLOUD_TOKEN?.trim();
|
|
508
620
|
const profile = readAuthProfile();
|
|
509
621
|
if (!profile) {
|
|
510
622
|
console.log(pc.yellow("No local CLI credentials found."));
|
|
@@ -518,6 +630,13 @@ function registerAuthCommands(program2) {
|
|
|
518
630
|
}
|
|
519
631
|
clearAuthProfile();
|
|
520
632
|
console.log(pc.green(`Logged out and removed ${getAuthFilePath()}`));
|
|
633
|
+
if (envToken) {
|
|
634
|
+
console.log(
|
|
635
|
+
pc.yellow(
|
|
636
|
+
"Warning: SAGACLOUD_TOKEN is set in your shell environment and its token was just revoked. Run `unset SAGACLOUD_TOKEN` in your terminal."
|
|
637
|
+
)
|
|
638
|
+
);
|
|
639
|
+
}
|
|
521
640
|
});
|
|
522
641
|
program2.command("whoami").description("Display active CLI user, workspace, and token scopes").action(async () => {
|
|
523
642
|
const client = new SagaCloudClient();
|
|
@@ -774,28 +893,32 @@ async function streamRuntimeLogs(client, siteId, lines = 100, follow = false) {
|
|
|
774
893
|
void stop().then(() => process.exit(0));
|
|
775
894
|
});
|
|
776
895
|
let ticks = 0;
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
const current = (res.logs || "").split(/\r?\n/).filter(Boolean);
|
|
782
|
-
if (previousLines.length === 0) {
|
|
783
|
-
for (const ln of current) console.log(ln);
|
|
784
|
-
} else {
|
|
785
|
-
const lastPrev = previousLines[previousLines.length - 1];
|
|
786
|
-
const matchIdx = current.lastIndexOf(lastPrev);
|
|
787
|
-
const added = matchIdx >= 0 ? current.slice(matchIdx + 1) : current;
|
|
788
|
-
for (const ln of added) console.log(ln);
|
|
789
|
-
}
|
|
790
|
-
previousLines = current;
|
|
791
|
-
ticks += 1;
|
|
792
|
-
if (ticks % 5 === 0) {
|
|
793
|
-
await client.rpc("saga_cloud.api.hosting.heartbeat_site_log_stream", {
|
|
794
|
-
method: "POST",
|
|
795
|
-
body: { site_id: siteId }
|
|
896
|
+
try {
|
|
897
|
+
while (running) {
|
|
898
|
+
const res = await client.rpc("saga_cloud.api.hosting.get_site_logs", {
|
|
899
|
+
query: { site_id: siteId, lines }
|
|
796
900
|
});
|
|
901
|
+
const current = (res.logs || "").split(/\r?\n/).filter(Boolean);
|
|
902
|
+
if (previousLines.length === 0) {
|
|
903
|
+
for (const ln of current) console.log(ln);
|
|
904
|
+
} else {
|
|
905
|
+
const lastPrev = previousLines[previousLines.length - 1];
|
|
906
|
+
const matchIdx = current.lastIndexOf(lastPrev);
|
|
907
|
+
const added = matchIdx >= 0 ? current.slice(matchIdx + 1) : current;
|
|
908
|
+
for (const ln of added) console.log(ln);
|
|
909
|
+
}
|
|
910
|
+
previousLines = current;
|
|
911
|
+
ticks += 1;
|
|
912
|
+
if (ticks % 5 === 0) {
|
|
913
|
+
await client.rpc("saga_cloud.api.hosting.heartbeat_site_log_stream", {
|
|
914
|
+
method: "POST",
|
|
915
|
+
body: { site_id: siteId }
|
|
916
|
+
});
|
|
917
|
+
}
|
|
918
|
+
await new Promise((r) => setTimeout(r, 2500));
|
|
797
919
|
}
|
|
798
|
-
|
|
920
|
+
} finally {
|
|
921
|
+
await stop();
|
|
799
922
|
}
|
|
800
923
|
}
|
|
801
924
|
|
|
@@ -818,22 +941,52 @@ var ALWAYS_IGNORED = [
|
|
|
818
941
|
".env",
|
|
819
942
|
".env.*",
|
|
820
943
|
"sagacloud.jsonc",
|
|
821
|
-
"sagacloud.json"
|
|
944
|
+
"sagacloud.json",
|
|
945
|
+
".sagacloudignore"
|
|
822
946
|
];
|
|
823
|
-
|
|
947
|
+
var STATIC_NON_WEB_IGNORES = [
|
|
948
|
+
"**/*.d.ts",
|
|
949
|
+
"**/*.d.mts",
|
|
950
|
+
"**/*.d.cts",
|
|
951
|
+
"*.d.ts",
|
|
952
|
+
"*.d.mts",
|
|
953
|
+
"*.d.cts",
|
|
954
|
+
".editorconfig",
|
|
955
|
+
".gitignore",
|
|
956
|
+
".gitattributes",
|
|
957
|
+
".browserslistrc",
|
|
958
|
+
".npmrc",
|
|
959
|
+
".prettierrc",
|
|
960
|
+
".prettierignore",
|
|
961
|
+
".eslintrc",
|
|
962
|
+
".eslintignore",
|
|
963
|
+
".stylelintrc"
|
|
964
|
+
];
|
|
965
|
+
async function createArchiveFromDirectory(targetDir, extraOrOptions = [], includeGitignoreArg = false) {
|
|
824
966
|
if (!fs3.existsSync(targetDir) || !fs3.statSync(targetDir).isDirectory()) {
|
|
825
967
|
throw new Error(`Directory not found: ${targetDir}`);
|
|
826
968
|
}
|
|
969
|
+
const opts = Array.isArray(extraOrOptions) ? { extraIgnorePatterns: extraOrOptions, includeGitignore: includeGitignoreArg } : extraOrOptions;
|
|
827
970
|
const ig = ignore().add(ALWAYS_IGNORED);
|
|
828
|
-
if (
|
|
829
|
-
ig.add(
|
|
971
|
+
if (opts.staticSiteFilter) {
|
|
972
|
+
ig.add(STATIC_NON_WEB_IGNORES);
|
|
830
973
|
}
|
|
831
|
-
if (
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
974
|
+
if (opts.extraIgnorePatterns && opts.extraIgnorePatterns.length > 0) {
|
|
975
|
+
ig.add(opts.extraIgnorePatterns);
|
|
976
|
+
}
|
|
977
|
+
const searchDirs = Array.from(
|
|
978
|
+
/* @__PURE__ */ new Set([targetDir, ...opts.projectRootDir ? [opts.projectRootDir] : []])
|
|
979
|
+
);
|
|
980
|
+
for (const baseDir of searchDirs) {
|
|
981
|
+
const sagaIgnore = path3.join(baseDir, ".sagacloudignore");
|
|
982
|
+
if (fs3.existsSync(sagaIgnore)) {
|
|
983
|
+
ig.add(fs3.readFileSync(sagaIgnore, "utf8"));
|
|
984
|
+
}
|
|
985
|
+
}
|
|
986
|
+
if (opts.includeGitignore) {
|
|
987
|
+
const gitIgnore = path3.join(targetDir, ".gitignore");
|
|
988
|
+
if (fs3.existsSync(gitIgnore)) {
|
|
989
|
+
ig.add(fs3.readFileSync(gitIgnore, "utf8"));
|
|
837
990
|
}
|
|
838
991
|
}
|
|
839
992
|
return await new Promise((resolve, reject) => {
|
|
@@ -867,31 +1020,147 @@ async function createArchiveFromDirectory(targetDir, extraIgnorePatterns = [], i
|
|
|
867
1020
|
}
|
|
868
1021
|
|
|
869
1022
|
// src/commands/deploy.ts
|
|
1023
|
+
async function resolveWranglerStyleTargetSite(client, optsSite, configuredName, jsonc, link) {
|
|
1024
|
+
if (optsSite) return optsSite;
|
|
1025
|
+
if (jsonc?.site_id) return jsonc.site_id;
|
|
1026
|
+
const targetName = (configuredName || "").trim();
|
|
1027
|
+
if (targetName) {
|
|
1028
|
+
if (link?.site_id && link.site_name && link.site_name.trim().toLowerCase() === targetName.toLowerCase()) {
|
|
1029
|
+
return link.site_id;
|
|
1030
|
+
}
|
|
1031
|
+
const listRes = await client.rpc("saga_cloud.api.hosting.list_sites", {
|
|
1032
|
+
query: { limit: 100 }
|
|
1033
|
+
});
|
|
1034
|
+
const matched = (listRes.sites || []).find(
|
|
1035
|
+
(s) => (s.site_name || "").trim().toLowerCase() === targetName.toLowerCase()
|
|
1036
|
+
);
|
|
1037
|
+
return matched ? matched.name : "";
|
|
1038
|
+
}
|
|
1039
|
+
return link?.site_id || "";
|
|
1040
|
+
}
|
|
870
1041
|
function parseDotEnvText(raw) {
|
|
1042
|
+
const trimmed = raw.trim();
|
|
1043
|
+
if (trimmed.startsWith("[")) {
|
|
1044
|
+
const parsed = JSON.parse(trimmed);
|
|
1045
|
+
return parsed.filter((r) => Boolean(r?.key)).map((r) => ({
|
|
1046
|
+
key: String(r.key).trim(),
|
|
1047
|
+
value: String(r.value ?? ""),
|
|
1048
|
+
isBuildTime: r.is_build_time
|
|
1049
|
+
}));
|
|
1050
|
+
}
|
|
871
1051
|
const rows = [];
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
1052
|
+
const lines = raw.split(/\r?\n/);
|
|
1053
|
+
for (let i = 0; i < lines.length; i += 1) {
|
|
1054
|
+
let line = lines[i].trim();
|
|
1055
|
+
if (!line || line.startsWith("#")) continue;
|
|
1056
|
+
if (/^export\s+/i.test(line)) {
|
|
1057
|
+
line = line.replace(/^export\s+/i, "").trim();
|
|
1058
|
+
}
|
|
1059
|
+
const eq = line.indexOf("=");
|
|
876
1060
|
if (eq <= 0) continue;
|
|
877
|
-
const key =
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
1061
|
+
const key = line.slice(0, eq).trim();
|
|
1062
|
+
const rawVal = line.slice(eq + 1).trimStart();
|
|
1063
|
+
let val = "";
|
|
1064
|
+
if (rawVal.startsWith('"') || rawVal.startsWith("'")) {
|
|
1065
|
+
const quote = rawVal[0];
|
|
1066
|
+
let buf = rawVal.slice(1);
|
|
1067
|
+
while (true) {
|
|
1068
|
+
let closeIdx = -1;
|
|
1069
|
+
for (let j = 0; j < buf.length; j += 1) {
|
|
1070
|
+
if (buf[j] === "\\" && quote === '"' && j + 1 < buf.length) {
|
|
1071
|
+
j += 1;
|
|
1072
|
+
continue;
|
|
1073
|
+
}
|
|
1074
|
+
if (buf[j] === quote) {
|
|
1075
|
+
closeIdx = j;
|
|
1076
|
+
break;
|
|
1077
|
+
}
|
|
1078
|
+
}
|
|
1079
|
+
if (closeIdx !== -1 || i + 1 >= lines.length) {
|
|
1080
|
+
val = closeIdx !== -1 ? buf.slice(0, closeIdx) : buf;
|
|
1081
|
+
if (quote === '"') {
|
|
1082
|
+
val = val.replaceAll("\\n", "\n").replaceAll('\\"', '"').replaceAll("\\\\", "\\");
|
|
1083
|
+
}
|
|
1084
|
+
break;
|
|
1085
|
+
}
|
|
1086
|
+
i += 1;
|
|
1087
|
+
buf += `
|
|
1088
|
+
${lines[i]}`;
|
|
1089
|
+
}
|
|
1090
|
+
} else {
|
|
1091
|
+
const hashIdx = rawVal.indexOf(" #");
|
|
1092
|
+
val = (hashIdx !== -1 ? rawVal.slice(0, hashIdx) : rawVal).trim();
|
|
881
1093
|
}
|
|
882
1094
|
if (key) rows.push({ key, value: val });
|
|
883
1095
|
}
|
|
884
1096
|
return rows;
|
|
885
1097
|
}
|
|
1098
|
+
function normalizeConfiguredDomains(entries) {
|
|
1099
|
+
if (!entries?.length) return [];
|
|
1100
|
+
const out = [];
|
|
1101
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1102
|
+
for (const item of entries) {
|
|
1103
|
+
const raw = typeof item === "string" ? { fqdn: item } : item;
|
|
1104
|
+
const fqdn = (raw.fqdn || "").replace(/^https?:\/\//i, "").split("/")[0].trim().toLowerCase().replace(/\.+$/, "");
|
|
1105
|
+
if (!fqdn || seen.has(fqdn)) continue;
|
|
1106
|
+
seen.add(fqdn);
|
|
1107
|
+
out.push({ fqdn, primary: Boolean(raw.primary), mode: raw.mode || "auto" });
|
|
1108
|
+
}
|
|
1109
|
+
return out;
|
|
1110
|
+
}
|
|
1111
|
+
async function reconcileConfiguredDomains(client, site, specs) {
|
|
1112
|
+
if (specs.length === 0) return site;
|
|
1113
|
+
let latestSite = site;
|
|
1114
|
+
const attached = new Set((latestSite.domains || []).map((d) => (d.fqdn || "").toLowerCase()));
|
|
1115
|
+
for (const spec of specs) {
|
|
1116
|
+
if (attached.has(spec.fqdn)) {
|
|
1117
|
+
if (spec.primary && (latestSite.domain || "").toLowerCase() !== spec.fqdn) {
|
|
1118
|
+
const upRes = await client.rpc("saga_cloud.api.hosting.update_site_domain", {
|
|
1119
|
+
method: "POST",
|
|
1120
|
+
body: { site_id: latestSite.name, fqdn: spec.fqdn, make_primary: true }
|
|
1121
|
+
});
|
|
1122
|
+
latestSite = upRes.site || latestSite;
|
|
1123
|
+
}
|
|
1124
|
+
continue;
|
|
1125
|
+
}
|
|
1126
|
+
const addRes = await client.rpc("saga_cloud.api.hosting.add_site_domain", {
|
|
1127
|
+
method: "POST",
|
|
1128
|
+
body: {
|
|
1129
|
+
site_id: latestSite.name,
|
|
1130
|
+
domain_mode: spec.mode,
|
|
1131
|
+
custom_fqdn: spec.fqdn,
|
|
1132
|
+
make_primary: spec.primary
|
|
1133
|
+
}
|
|
1134
|
+
});
|
|
1135
|
+
latestSite = addRes.site || latestSite;
|
|
1136
|
+
attached.add(spec.fqdn);
|
|
1137
|
+
const added = addRes.added_domain || (latestSite.domains || []).find((d) => d.fqdn.toLowerCase() === spec.fqdn);
|
|
1138
|
+
if (added?.dns_auto_configured) {
|
|
1139
|
+
console.log(pc3.green(`\u2713 Domain ${spec.fqdn} attached with automatic DNS + Edge SSL (${added.domain_mode})`));
|
|
1140
|
+
} else if (added?.cname_target) {
|
|
1141
|
+
console.log(pc3.yellow(`\u25D0 External domain ${spec.fqdn} attached \u2014 point CNAME -> ${pc3.cyan(added.cname_target)}, then run: sagacloud domains verify ${spec.fqdn}`));
|
|
1142
|
+
} else {
|
|
1143
|
+
console.log(pc3.green(`\u2713 Domain ${spec.fqdn} attached`));
|
|
1144
|
+
}
|
|
1145
|
+
}
|
|
1146
|
+
return latestSite;
|
|
1147
|
+
}
|
|
886
1148
|
function registerDeployCommands(program2) {
|
|
887
|
-
program2.command("deploy").alias("up").description("Deploy local static/SPA output, Express/Node source, or Git site to SagaCloud").option("--site <siteId>", "Target Site ID (overrides .sagacloud/project.json)").option("--name <siteName>", "Site name when creating a new site").option("--dir <outputDir>", "Pre-built static output directory (e.g. ./dist)").option("--build", "Run local build command before packaging static output").option("--no-build", "Skip running local build command").option("--static", "Deploy as static HTML/PHP site").option("--spa", "Deploy as Single Page App (Nginx try_files /index.html)").option("--node", "Deploy as Node.js / Express / SSR application").option("--port <port>", "Listening HTTP port for Node.js app"
|
|
1149
|
+
program2.command("deploy").alias("up").description("Deploy local static/SPA output, Express/Node source, or Git site to SagaCloud").option("--site <siteId>", "Target Site ID (overrides .sagacloud/project.json)").option("--name <siteName>", "Site name when creating a new site").option("--dir <outputDir>", "Pre-built static output directory (e.g. ./dist)").option("--build", "Run local build command before packaging static output").option("--no-build", "Skip running local build command").option("--static", "Deploy as static HTML/PHP site").option("--spa", "Deploy as Single Page App (Nginx try_files /index.html)").option("--node", "Deploy as Node.js / Express / SSR application").option("--port <port>", "Listening HTTP port for Node.js app").option("--start <cmd>", "Start command for Node.js app").option("--git", "Trigger remote Git redeploy instead of uploading local files").option("--force", "Bypass build cache on remote rebuild", false).option("--with-env <file>", "Load and push .env file variables before building").option("--detach", "Queue deployment and exit without streaming build logs", false).option("--yes", "Skip interactive prompts", false).action(
|
|
888
1150
|
async (opts) => {
|
|
889
1151
|
const cwd = process.cwd();
|
|
890
1152
|
const client = new SagaCloudClient();
|
|
891
1153
|
const { config: jsonc } = readRepoJsoncConfig(cwd);
|
|
892
1154
|
const link = readLocalLink(cwd);
|
|
893
1155
|
const detected = detectProject(cwd);
|
|
894
|
-
const
|
|
1156
|
+
const configuredName = (opts.name || jsonc?.app_name || jsonc?.name || "").trim() || void 0;
|
|
1157
|
+
const existingSiteId = await resolveWranglerStyleTargetSite(
|
|
1158
|
+
client,
|
|
1159
|
+
opts.site,
|
|
1160
|
+
configuredName,
|
|
1161
|
+
jsonc,
|
|
1162
|
+
link
|
|
1163
|
+
);
|
|
895
1164
|
if (opts.git) {
|
|
896
1165
|
const targetId = resolveActiveSiteId(cwd, existingSiteId);
|
|
897
1166
|
const spin2 = p2.spinner();
|
|
@@ -927,7 +1196,7 @@ function registerDeployCommands(program2) {
|
|
|
927
1196
|
runtimeVariant = jsonc.type;
|
|
928
1197
|
} else {
|
|
929
1198
|
siteType = "static";
|
|
930
|
-
runtimeVariant = jsonc.type === "static" || jsonc.type === "spa" && jsonc.spa_fallback === false ? "html" : jsonc.type;
|
|
1199
|
+
runtimeVariant = jsonc.type === "static" || jsonc.type === "html" || jsonc.type === "spa" && jsonc.spa_fallback === false ? "html" : jsonc.type;
|
|
931
1200
|
}
|
|
932
1201
|
} else if (link?.site_type) {
|
|
933
1202
|
siteType = link.site_type;
|
|
@@ -948,40 +1217,105 @@ function registerDeployCommands(program2) {
|
|
|
948
1217
|
}
|
|
949
1218
|
const spin = p2.spinner();
|
|
950
1219
|
spin.start(`Packaging ${siteType === "node" ? "Node.js source" : outputRel}...`);
|
|
951
|
-
const archive = await createArchiveFromDirectory(
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
siteType === "
|
|
955
|
-
|
|
1220
|
+
const archive = await createArchiveFromDirectory(uploadDir, {
|
|
1221
|
+
extraIgnorePatterns: jsonc?.ignore || [],
|
|
1222
|
+
includeGitignore: siteType === "node" || path4.resolve(uploadDir) === path4.resolve(cwd),
|
|
1223
|
+
staticSiteFilter: siteType === "static",
|
|
1224
|
+
projectRootDir: cwd
|
|
1225
|
+
});
|
|
956
1226
|
spin.stop(
|
|
957
1227
|
`Packaged ${archive.fileCount} files (${(archive.sizeBytes / 1024).toFixed(1)} KB)`
|
|
958
1228
|
);
|
|
1229
|
+
if (archive.fileCount === 0) {
|
|
1230
|
+
throw new Error(
|
|
1231
|
+
`No deployable files found in '${outputRel}'. Check your output directory or ignore patterns.`
|
|
1232
|
+
);
|
|
1233
|
+
}
|
|
959
1234
|
const uploadSpin = p2.spinner();
|
|
960
1235
|
uploadSpin.start("Uploading bundle to SagaCloud...");
|
|
961
|
-
const zipName = `${(jsonc?.name || path4.basename(cwd) || "bundle").replace(/[^a-z0-9-]+/gi, "-")}.zip`;
|
|
1236
|
+
const zipName = `${(jsonc?.app_name || jsonc?.name || path4.basename(cwd) || "bundle").replace(/[^a-z0-9-]+/gi, "-")}.zip`;
|
|
962
1237
|
const uploaded = await client.uploadBundle(archive.buffer, zipName, siteType);
|
|
963
1238
|
uploadSpin.stop(`Uploaded (${uploaded.detected_entry})`);
|
|
964
1239
|
const mergedVars = /* @__PURE__ */ new Map();
|
|
965
1240
|
if (jsonc?.vars) {
|
|
966
1241
|
for (const [k, v] of Object.entries(jsonc.vars)) {
|
|
967
|
-
mergedVars.set(k, String(v));
|
|
1242
|
+
mergedVars.set(k, { value: String(v) });
|
|
968
1243
|
}
|
|
969
1244
|
}
|
|
970
|
-
|
|
971
|
-
|
|
1245
|
+
const envFilesToLoad = [jsonc?.env_file, opts.withEnv].filter((f) => Boolean(f));
|
|
1246
|
+
for (const relEnv of envFilesToLoad) {
|
|
1247
|
+
const envPath = path4.resolve(cwd, relEnv);
|
|
972
1248
|
if (!fs4.existsSync(envPath)) throw new Error(`Env file not found: ${envPath}`);
|
|
973
1249
|
for (const item of parseDotEnvText(fs4.readFileSync(envPath, "utf8"))) {
|
|
974
|
-
mergedVars.set(item.key, item.value);
|
|
1250
|
+
mergedVars.set(item.key, { value: item.value, isBuildTime: item.isBuildTime });
|
|
975
1251
|
}
|
|
976
1252
|
}
|
|
977
|
-
const envPayload = Array.from(mergedVars.entries()).map(([key,
|
|
1253
|
+
const envPayload = Array.from(mergedVars.entries()).map(([key, item]) => ({
|
|
978
1254
|
key,
|
|
979
|
-
value,
|
|
980
|
-
is_build_time: siteType === "static"
|
|
1255
|
+
value: item.value,
|
|
1256
|
+
is_build_time: item.isBuildTime ?? siteType === "static"
|
|
981
1257
|
}));
|
|
1258
|
+
const forceRebuild = opts.force || Boolean(jsonc?.deploy?.force_rebuild);
|
|
1259
|
+
const detachMode = opts.detach || Boolean(jsonc?.deploy?.detach);
|
|
1260
|
+
const domainSpecs = jsonc?.deploy?.sync_domains === false ? [] : normalizeConfiguredDomains(jsonc?.domains);
|
|
982
1261
|
let targetSite;
|
|
983
1262
|
let dep;
|
|
984
1263
|
if (existingSiteId) {
|
|
1264
|
+
const settingsPatch = {
|
|
1265
|
+
site_id: existingSiteId
|
|
1266
|
+
};
|
|
1267
|
+
let hasSettingsUpdate = false;
|
|
1268
|
+
if (siteType === "node") {
|
|
1269
|
+
const nextPort = opts.port || (jsonc?.port !== void 0 ? String(jsonc.port) : "");
|
|
1270
|
+
if (nextPort) {
|
|
1271
|
+
settingsPatch.ports_exposes = nextPort;
|
|
1272
|
+
hasSettingsUpdate = true;
|
|
1273
|
+
}
|
|
1274
|
+
const nextStart = opts.start || jsonc?.start_command;
|
|
1275
|
+
if (nextStart) {
|
|
1276
|
+
settingsPatch.start_command = nextStart;
|
|
1277
|
+
hasSettingsUpdate = true;
|
|
1278
|
+
}
|
|
1279
|
+
if (jsonc?.install_command !== void 0) {
|
|
1280
|
+
settingsPatch.install_command = jsonc.install_command;
|
|
1281
|
+
hasSettingsUpdate = true;
|
|
1282
|
+
}
|
|
1283
|
+
if (jsonc?.build_command !== void 0) {
|
|
1284
|
+
settingsPatch.build_command = jsonc.build_command;
|
|
1285
|
+
hasSettingsUpdate = true;
|
|
1286
|
+
}
|
|
1287
|
+
} else {
|
|
1288
|
+
if (opts.spa || opts.static || jsonc?.spa_fallback !== void 0) {
|
|
1289
|
+
settingsPatch.is_spa = runtimeVariant === "spa" ? 1 : 0;
|
|
1290
|
+
hasSettingsUpdate = true;
|
|
1291
|
+
}
|
|
1292
|
+
if (opts.dir || jsonc?.output_dir) {
|
|
1293
|
+
settingsPatch.publish_directory = outputRel;
|
|
1294
|
+
hasSettingsUpdate = true;
|
|
1295
|
+
}
|
|
1296
|
+
}
|
|
1297
|
+
if (jsonc?.base_directory !== void 0) {
|
|
1298
|
+
settingsPatch.base_directory = jsonc.base_directory;
|
|
1299
|
+
hasSettingsUpdate = true;
|
|
1300
|
+
}
|
|
1301
|
+
if (jsonc?.healthcheck_path !== void 0) {
|
|
1302
|
+
settingsPatch.healthcheck_path = jsonc.healthcheck_path;
|
|
1303
|
+
hasSettingsUpdate = true;
|
|
1304
|
+
}
|
|
1305
|
+
if (jsonc?.resources?.memory !== void 0) {
|
|
1306
|
+
settingsPatch.limits_memory = String(jsonc.resources.memory);
|
|
1307
|
+
hasSettingsUpdate = true;
|
|
1308
|
+
}
|
|
1309
|
+
if (jsonc?.resources?.cpus !== void 0) {
|
|
1310
|
+
settingsPatch.limits_cpus = String(jsonc.resources.cpus);
|
|
1311
|
+
hasSettingsUpdate = true;
|
|
1312
|
+
}
|
|
1313
|
+
if (hasSettingsUpdate) {
|
|
1314
|
+
await client.rpc("saga_cloud.api.hosting.update_site_settings", {
|
|
1315
|
+
method: "POST",
|
|
1316
|
+
body: settingsPatch
|
|
1317
|
+
});
|
|
1318
|
+
}
|
|
985
1319
|
if (envPayload.length > 0) {
|
|
986
1320
|
await client.rpc("saga_cloud.api.hosting.save_site_envs", {
|
|
987
1321
|
method: "POST",
|
|
@@ -996,7 +1330,7 @@ function registerDeployCommands(program2) {
|
|
|
996
1330
|
method: "POST",
|
|
997
1331
|
body: {
|
|
998
1332
|
site_id: existingSiteId,
|
|
999
|
-
force_rebuild:
|
|
1333
|
+
force_rebuild: forceRebuild !== false,
|
|
1000
1334
|
new_zip_file_url: uploaded.file_url
|
|
1001
1335
|
}
|
|
1002
1336
|
}
|
|
@@ -1005,15 +1339,32 @@ function registerDeployCommands(program2) {
|
|
|
1005
1339
|
query: { site_id: existingSiteId, limit: 1 }
|
|
1006
1340
|
})).site;
|
|
1007
1341
|
dep = res.deployment;
|
|
1342
|
+
if (!link || link.site_id !== targetSite.name || link.site_name !== targetSite.site_name) {
|
|
1343
|
+
writeLocalLink(
|
|
1344
|
+
{
|
|
1345
|
+
site_id: targetSite.name,
|
|
1346
|
+
site_name: targetSite.site_name,
|
|
1347
|
+
tenant_id: link?.tenant_id,
|
|
1348
|
+
site_type: siteType,
|
|
1349
|
+
runtime_variant: runtimeVariant,
|
|
1350
|
+
output_dir: siteType === "static" ? outputRel : ""
|
|
1351
|
+
},
|
|
1352
|
+
cwd
|
|
1353
|
+
);
|
|
1354
|
+
}
|
|
1008
1355
|
depSpin.stop(`Deployment v${dep.version_number} queued for ${targetSite.domain}`);
|
|
1009
1356
|
} else {
|
|
1010
|
-
const
|
|
1011
|
-
const
|
|
1012
|
-
|
|
1357
|
+
const fallbackFolderName = path4.basename(cwd).toLowerCase().replace(/[^a-z0-9-]+/g, "-").replace(/^-|-$/g, "") || "sagacloud-app";
|
|
1358
|
+
const defaultName = configuredName || fallbackFolderName;
|
|
1359
|
+
let siteName = defaultName;
|
|
1360
|
+
if (!configuredName && !opts.yes) {
|
|
1361
|
+
const nameAns = await p2.text({
|
|
1013
1362
|
message: `Create new ${siteType.toUpperCase()} site name`,
|
|
1014
1363
|
initialValue: defaultName
|
|
1015
|
-
})
|
|
1016
|
-
|
|
1364
|
+
});
|
|
1365
|
+
if (p2.isCancel(nameAns)) process.exit(1);
|
|
1366
|
+
siteName = String(nameAns);
|
|
1367
|
+
}
|
|
1017
1368
|
const createSpin = p2.spinner();
|
|
1018
1369
|
createSpin.start(`Creating ${siteType} site '${siteName}'...`);
|
|
1019
1370
|
const res = await client.rpc(
|
|
@@ -1028,9 +1379,15 @@ function registerDeployCommands(program2) {
|
|
|
1028
1379
|
zip_file_url: uploaded.file_url,
|
|
1029
1380
|
is_spa: runtimeVariant === "spa",
|
|
1030
1381
|
ports_exposes: siteType === "node" ? String(opts.port || jsonc?.port || detected.port || "3000") : "80",
|
|
1382
|
+
base_directory: jsonc?.base_directory || "",
|
|
1031
1383
|
install_command: jsonc?.install_command || "",
|
|
1032
1384
|
build_command: siteType === "node" ? jsonc?.build_command || detected.buildCommand || "" : "",
|
|
1033
1385
|
start_command: siteType === "node" ? opts.start || jsonc?.start_command || detected.startCommand || "npm start" : "",
|
|
1386
|
+
healthcheck_path: jsonc?.healthcheck_path || "",
|
|
1387
|
+
cdn_enabled: jsonc?.cdn?.enabled,
|
|
1388
|
+
waf_enabled: jsonc?.cdn?.waf,
|
|
1389
|
+
limits_memory: jsonc?.resources?.memory !== void 0 ? String(jsonc.resources.memory) : "",
|
|
1390
|
+
limits_cpus: jsonc?.resources?.cpus !== void 0 ? String(jsonc.resources.cpus) : "",
|
|
1034
1391
|
publish_directory: siteType === "static" ? outputRel : "",
|
|
1035
1392
|
env_vars: envPayload.length > 0 ? envPayload : void 0
|
|
1036
1393
|
}
|
|
@@ -1042,6 +1399,7 @@ function registerDeployCommands(program2) {
|
|
|
1042
1399
|
writeLocalLink(
|
|
1043
1400
|
{
|
|
1044
1401
|
site_id: targetSite.name,
|
|
1402
|
+
site_name: targetSite.site_name,
|
|
1045
1403
|
tenant_id: info.tenant,
|
|
1046
1404
|
site_type: siteType,
|
|
1047
1405
|
runtime_variant: runtimeVariant,
|
|
@@ -1051,7 +1409,10 @@ function registerDeployCommands(program2) {
|
|
|
1051
1409
|
);
|
|
1052
1410
|
createSpin.stop(`Created ${targetSite.name} -> ${pc3.cyan(targetSite.live_url || targetSite.domain)}`);
|
|
1053
1411
|
}
|
|
1054
|
-
if (
|
|
1412
|
+
if (domainSpecs.length > 0) {
|
|
1413
|
+
targetSite = await reconcileConfiguredDomains(client, targetSite, domainSpecs);
|
|
1414
|
+
}
|
|
1415
|
+
if (detachMode || !dep.deployment_uuid) {
|
|
1055
1416
|
console.log(pc3.dim(`Deployment ${dep.name} queued. Check progress with: sagacloud logs`));
|
|
1056
1417
|
return;
|
|
1057
1418
|
}
|
|
@@ -1127,21 +1488,55 @@ function registerEnvCommands(program2) {
|
|
|
1127
1488
|
);
|
|
1128
1489
|
console.log(pc4.green(`Synced ${res.envs?.length || 0} variables from ${filePath}. Redeploy to apply changes.`));
|
|
1129
1490
|
});
|
|
1130
|
-
env.command("pull [filePath]").description("Download remote environment variables to a local file").option("--site <siteId>", "Site ID").action(async (filePath = ".env.local", opts) => {
|
|
1491
|
+
env.command("pull [filePath]").description("Download remote environment variables to a local file").option("--site <siteId>", "Site ID").option("--json", "Write JSON including is_build_time metadata", false).action(async (filePath = ".env.local", opts) => {
|
|
1131
1492
|
const siteId = resolveActiveSiteId(process.cwd(), opts.site);
|
|
1132
1493
|
const client = new SagaCloudClient();
|
|
1133
1494
|
const res = await client.rpc("saga_cloud.api.hosting.get_site_envs", {
|
|
1134
1495
|
query: { site_id: siteId }
|
|
1135
1496
|
});
|
|
1497
|
+
const envs = res.envs || [];
|
|
1136
1498
|
const outPath = path5.resolve(process.cwd(), filePath);
|
|
1137
|
-
|
|
1499
|
+
if (opts.json) {
|
|
1500
|
+
fs5.writeFileSync(
|
|
1501
|
+
outPath,
|
|
1502
|
+
`${JSON.stringify(
|
|
1503
|
+
envs.map((e) => ({
|
|
1504
|
+
key: e.key,
|
|
1505
|
+
value: e.value ?? "",
|
|
1506
|
+
is_build_time: Boolean(e.is_build_time)
|
|
1507
|
+
})),
|
|
1508
|
+
null,
|
|
1509
|
+
2
|
|
1510
|
+
)}
|
|
1511
|
+
`,
|
|
1512
|
+
{ mode: 384 }
|
|
1513
|
+
);
|
|
1514
|
+
console.log(pc4.green(`Wrote ${envs.length} variables (JSON with metadata) to ${filePath}`));
|
|
1515
|
+
return;
|
|
1516
|
+
}
|
|
1517
|
+
const buildTimeKeys = [];
|
|
1518
|
+
const lines = [];
|
|
1519
|
+
for (const item of envs) {
|
|
1138
1520
|
const val = String(item.value ?? "");
|
|
1139
|
-
const needsQuotes = /[\s#'"]/.test(val);
|
|
1140
|
-
|
|
1141
|
-
|
|
1521
|
+
const needsQuotes = /[\s#'"\\]/.test(val);
|
|
1522
|
+
const formatted = `${item.key}=${needsQuotes ? JSON.stringify(val) : val}`;
|
|
1523
|
+
if (item.is_build_time) {
|
|
1524
|
+
buildTimeKeys.push(item.key);
|
|
1525
|
+
lines.push(`# build-time`, formatted);
|
|
1526
|
+
} else {
|
|
1527
|
+
lines.push(formatted);
|
|
1528
|
+
}
|
|
1529
|
+
}
|
|
1142
1530
|
fs5.writeFileSync(outPath, `${lines.join("\n")}
|
|
1143
1531
|
`, { mode: 384 });
|
|
1144
|
-
console.log(pc4.green(`Wrote ${
|
|
1532
|
+
console.log(pc4.green(`Wrote ${envs.length} variables to ${filePath}`));
|
|
1533
|
+
if (buildTimeKeys.length > 0) {
|
|
1534
|
+
console.log(
|
|
1535
|
+
pc4.dim(
|
|
1536
|
+
`Note: ${buildTimeKeys.length} build-time variable(s) (${buildTimeKeys.join(", ")}); use \`env pull --json\` to preserve flags cleanly.`
|
|
1537
|
+
)
|
|
1538
|
+
);
|
|
1539
|
+
}
|
|
1145
1540
|
});
|
|
1146
1541
|
env.command("set <pairs...>").description("Set one or more KEY=VALUE variables").option("--site <siteId>", "Site ID").option("--build-time", "Mark variables as build-time", false).action(async (pairs, opts) => {
|
|
1147
1542
|
const siteId = resolveActiveSiteId(process.cwd(), opts.site);
|
|
@@ -1206,7 +1601,10 @@ function registerOpsCommands(program2) {
|
|
|
1206
1601
|
console.log(pc5.yellow("No deployments found for this site."));
|
|
1207
1602
|
return;
|
|
1208
1603
|
}
|
|
1209
|
-
await streamBuildUntilDone(client, siteId, targetDep);
|
|
1604
|
+
const finalStatus = await streamBuildUntilDone(client, siteId, targetDep);
|
|
1605
|
+
if (finalStatus !== "finished") {
|
|
1606
|
+
process.exit(1);
|
|
1607
|
+
}
|
|
1210
1608
|
}
|
|
1211
1609
|
);
|
|
1212
1610
|
program2.command("deployments").description("List deployment version history for a site").option("--site <siteId>", "Site ID").option("--limit <limit>", "Rows to fetch", "15").action(async (opts) => {
|
|
@@ -1216,12 +1614,14 @@ function registerOpsCommands(program2) {
|
|
|
1216
1614
|
"saga_cloud.api.hosting.list_deployments",
|
|
1217
1615
|
{ query: { site_id: siteId, limit: Number(opts.limit || 15) } }
|
|
1218
1616
|
);
|
|
1219
|
-
const table = new Table3({ head: ["Version", "ID", "
|
|
1617
|
+
const table = new Table3({ head: ["Version", "ID", "Channel", "By", "Status", "Live", "Rollback", "Created"] });
|
|
1220
1618
|
for (const d of res.deployments || []) {
|
|
1619
|
+
const chan = d.cli_token_name ? `${(d.trigger_channel || "cli").toUpperCase()} (${d.cli_token_name})` : (d.trigger_channel || d.trigger_type).toUpperCase();
|
|
1221
1620
|
table.push([
|
|
1222
1621
|
`v${d.version_number}`,
|
|
1223
1622
|
d.name,
|
|
1224
|
-
|
|
1623
|
+
chan,
|
|
1624
|
+
d.triggered_by || "-",
|
|
1225
1625
|
d.status === "finished" ? pc5.green(d.status) : d.status === "failed" ? pc5.red(d.status) : d.status,
|
|
1226
1626
|
d.is_active ? pc5.green("ACTIVE") : "-",
|
|
1227
1627
|
d.can_instant_rollback ? "Yes" : "-",
|
|
@@ -1233,25 +1633,20 @@ function registerOpsCommands(program2) {
|
|
|
1233
1633
|
program2.command("rollback <versionOrId>").description("Roll back site to a previous version (e.g. `v2` or deployment ID)").option("--site <siteId>", "Site ID").action(async (versionOrId, opts) => {
|
|
1234
1634
|
const siteId = resolveActiveSiteId(process.cwd(), opts.site);
|
|
1235
1635
|
const client = new SagaCloudClient();
|
|
1236
|
-
|
|
1237
|
-
const vMatch =
|
|
1238
|
-
|
|
1239
|
-
const ver = Number(vMatch[1]);
|
|
1240
|
-
const list = await client.rpc(
|
|
1241
|
-
"saga_cloud.api.hosting.list_deployments",
|
|
1242
|
-
{ query: { site_id: siteId, limit: 50 } }
|
|
1243
|
-
);
|
|
1244
|
-
const found = (list.deployments || []).find((d) => d.version_number === ver);
|
|
1245
|
-
if (!found) throw new Error(`Version v${ver} not found.`);
|
|
1246
|
-
depId = found.name;
|
|
1247
|
-
}
|
|
1636
|
+
const raw = versionOrId.trim();
|
|
1637
|
+
const vMatch = raw.match(/^v?(\d+)$/i);
|
|
1638
|
+
const rollbackBody = vMatch ? { site_id: siteId, target_version: Number(vMatch[1]) } : { site_id: siteId, target_deployment_id: raw };
|
|
1248
1639
|
const res = await client.rpc(
|
|
1249
1640
|
"saga_cloud.api.hosting.rollback_site",
|
|
1250
|
-
{ method: "POST", body:
|
|
1641
|
+
{ method: "POST", body: rollbackBody }
|
|
1251
1642
|
);
|
|
1252
1643
|
console.log(pc5.green(`Queued rollback v${res.deployment.version_number} (${res.rollback_mode || "instant"})`));
|
|
1253
1644
|
if (res.deployment.deployment_uuid) {
|
|
1254
|
-
await streamBuildUntilDone(client, siteId, res.deployment.deployment_uuid);
|
|
1645
|
+
const finalStatus = await streamBuildUntilDone(client, siteId, res.deployment.deployment_uuid);
|
|
1646
|
+
if (finalStatus !== "finished") {
|
|
1647
|
+
console.log(pc5.red(`\u2717 Rollback v${res.deployment.version_number} ${finalStatus}`));
|
|
1648
|
+
process.exit(1);
|
|
1649
|
+
}
|
|
1255
1650
|
}
|
|
1256
1651
|
});
|
|
1257
1652
|
const domains = program2.command("domains").description("Manage custom domains & Edge SSL");
|
|
@@ -1273,20 +1668,24 @@ function registerOpsCommands(program2) {
|
|
|
1273
1668
|
}
|
|
1274
1669
|
console.log(table.toString());
|
|
1275
1670
|
});
|
|
1276
|
-
domains.command("add <
|
|
1671
|
+
domains.command("add <fqdns...>").description("Attach one or more owned SagaCloud or custom external domains").option("--site <siteId>", "Site ID").option("--primary", "Set the last added domain as primary live URL", false).action(async (fqdns, opts) => {
|
|
1277
1672
|
const siteId = resolveActiveSiteId(process.cwd(), opts.site);
|
|
1278
1673
|
const client = new SagaCloudClient();
|
|
1279
|
-
|
|
1280
|
-
"
|
|
1281
|
-
|
|
1674
|
+
for (let i = 0; i < fqdns.length; i += 1) {
|
|
1675
|
+
const cleanFqdn = fqdns[i].replace(/^https?:\/\//i, "").split("/")[0].trim().toLowerCase().replace(/\.+$/, "");
|
|
1676
|
+
const makePrimary = Boolean(opts.primary) && i === fqdns.length - 1;
|
|
1677
|
+
const res = await client.rpc("saga_cloud.api.hosting.add_site_domain", {
|
|
1282
1678
|
method: "POST",
|
|
1283
|
-
body: { site_id: siteId, domain_mode: "
|
|
1679
|
+
body: { site_id: siteId, domain_mode: "auto", custom_fqdn: cleanFqdn, make_primary: makePrimary }
|
|
1680
|
+
});
|
|
1681
|
+
const added = res.added_domain || (res.site.domains || []).find((d) => d.fqdn.toLowerCase() === cleanFqdn);
|
|
1682
|
+
console.log(pc5.green(`Added ${cleanFqdn} to ${res.site.site_name}`));
|
|
1683
|
+
if (added?.dns_auto_configured) {
|
|
1684
|
+
console.log(pc5.green(`\u2713 Automatic workspace DNS + Edge SSL configured (${added.domain_mode})`));
|
|
1685
|
+
} else if (added?.cname_target) {
|
|
1686
|
+
console.log(`Point DNS CNAME: ${pc5.bold(cleanFqdn)} -> ${pc5.cyan(added.cname_target)}`);
|
|
1687
|
+
console.log(pc5.dim(`Then verify SSL with: sagacloud domains verify ${cleanFqdn}`));
|
|
1284
1688
|
}
|
|
1285
|
-
);
|
|
1286
|
-
console.log(pc5.green(`Added ${fqdn} to ${res.site.site_name}`));
|
|
1287
|
-
if (res.added_domain?.cname_target) {
|
|
1288
|
-
console.log(`Point DNS CNAME: ${pc5.bold(fqdn)} -> ${pc5.cyan(res.added_domain.cname_target)}`);
|
|
1289
|
-
console.log(pc5.dim(`Then verify SSL with: sagacloud domains verify ${fqdn}`));
|
|
1290
1689
|
}
|
|
1291
1690
|
});
|
|
1292
1691
|
domains.command("verify <fqdn>").description("Verify DNS CNAME and issue Edge SSL").option("--site <siteId>", "Site ID").action(async (fqdn, opts) => {
|
|
@@ -1344,6 +1743,38 @@ function registerOpsCommands(program2) {
|
|
|
1344
1743
|
const ci = program2.command("ci").description("CI/CD helpers");
|
|
1345
1744
|
ci.command("init").description("Generate .github/workflows/sagacloud.yml").action(() => {
|
|
1346
1745
|
const cwd = process.cwd();
|
|
1746
|
+
const detected = detectProject(cwd);
|
|
1747
|
+
const { config: jsonc } = readRepoJsoncConfig(cwd);
|
|
1748
|
+
const hasPackageJson = fs6.existsSync(path6.join(cwd, "package.json"));
|
|
1749
|
+
const hasLockfile = fs6.existsSync(path6.join(cwd, "package-lock.json"));
|
|
1750
|
+
const buildCmd = (jsonc?.build_command || detected.buildCommand || "").trim();
|
|
1751
|
+
const siteType = jsonc?.type === "node" || jsonc?.type === "nextjs" ? "node" : jsonc?.type ? "static" : detected.siteType;
|
|
1752
|
+
const outDir = jsonc?.output_dir || detected.outputDir || ".";
|
|
1753
|
+
const steps = [" - uses: actions/checkout@v4"];
|
|
1754
|
+
if (hasPackageJson && (siteType === "static" || Boolean(buildCmd))) {
|
|
1755
|
+
steps.push(
|
|
1756
|
+
" - uses: actions/setup-node@v4",
|
|
1757
|
+
" with:",
|
|
1758
|
+
" node-version: 22",
|
|
1759
|
+
` - run: ${hasLockfile ? "npm ci" : "npm install"}`
|
|
1760
|
+
);
|
|
1761
|
+
if (buildCmd && siteType === "static") {
|
|
1762
|
+
steps.push(` - run: ${buildCmd}`);
|
|
1763
|
+
}
|
|
1764
|
+
}
|
|
1765
|
+
let deployCmd = "npx sagacloud deploy --yes";
|
|
1766
|
+
if (siteType === "node") {
|
|
1767
|
+
deployCmd = "npx sagacloud deploy --node --yes";
|
|
1768
|
+
} else if (outDir && outDir !== ".") {
|
|
1769
|
+
deployCmd = `npx sagacloud deploy --dir ${outDir} --no-build --yes`;
|
|
1770
|
+
} else {
|
|
1771
|
+
deployCmd = "npx sagacloud deploy --no-build --yes";
|
|
1772
|
+
}
|
|
1773
|
+
steps.push(
|
|
1774
|
+
` - run: ${deployCmd}`,
|
|
1775
|
+
" env:",
|
|
1776
|
+
" SAGACLOUD_TOKEN: ${{ secrets.SAGACLOUD_TOKEN }}"
|
|
1777
|
+
);
|
|
1347
1778
|
const wfDir = path6.join(cwd, ".github", "workflows");
|
|
1348
1779
|
fs6.mkdirSync(wfDir, { recursive: true });
|
|
1349
1780
|
const outPath = path6.join(wfDir, "sagacloud.yml");
|
|
@@ -1356,15 +1787,7 @@ function registerOpsCommands(program2) {
|
|
|
1356
1787
|
" deploy:",
|
|
1357
1788
|
" runs-on: ubuntu-latest",
|
|
1358
1789
|
" steps:",
|
|
1359
|
-
|
|
1360
|
-
" - uses: actions/setup-node@v4",
|
|
1361
|
-
" with:",
|
|
1362
|
-
" node-version: 22",
|
|
1363
|
-
" - run: npm ci",
|
|
1364
|
-
" - run: npm run build",
|
|
1365
|
-
" - run: npx sagacloud deploy --no-build --yes",
|
|
1366
|
-
" env:",
|
|
1367
|
-
" SAGACLOUD_TOKEN: ${{ secrets.SAGACLOUD_TOKEN }}",
|
|
1790
|
+
...steps,
|
|
1368
1791
|
""
|
|
1369
1792
|
].join("\n");
|
|
1370
1793
|
fs6.writeFileSync(outPath, yml);
|
|
@@ -1375,7 +1798,6 @@ function registerOpsCommands(program2) {
|
|
|
1375
1798
|
// src/commands/project.ts
|
|
1376
1799
|
import fs7 from "fs";
|
|
1377
1800
|
import path7 from "path";
|
|
1378
|
-
import { execFile as execFile2 } from "child_process";
|
|
1379
1801
|
import * as p4 from "@clack/prompts";
|
|
1380
1802
|
import Table4 from "cli-table3";
|
|
1381
1803
|
import pc6 from "picocolors";
|
|
@@ -1385,10 +1807,11 @@ function registerProjectCommands(program2) {
|
|
|
1385
1807
|
const res = await client.rpc("saga_cloud.api.hosting.list_sites", {
|
|
1386
1808
|
query: { site_type: opts.type, limit: 100 }
|
|
1387
1809
|
});
|
|
1388
|
-
const table = new Table4({ head: ["Site ID", "Name", "Type", "Status", "Live URL"] });
|
|
1810
|
+
const table = new Table4({ head: ["Site ID", "Name", "Type", "Status", "Last Deploy", "Live URL"] });
|
|
1389
1811
|
for (const s of res.sites || []) {
|
|
1390
1812
|
const statusColor = s.status === "Online" ? pc6.green(s.status) : s.status === "Failed" ? pc6.red(s.status) : pc6.yellow(s.status);
|
|
1391
|
-
|
|
1813
|
+
const actor = s.last_deployed_by ? `${(s.last_deploy_channel || "web").toUpperCase()} \xB7 ${s.last_deployed_by}` : "-";
|
|
1814
|
+
table.push([s.name, s.site_name, `${s.site_type}/${s.runtime_variant}`, statusColor, actor, s.live_url || s.domain]);
|
|
1392
1815
|
}
|
|
1393
1816
|
console.log(table.toString());
|
|
1394
1817
|
});
|
|
@@ -1419,6 +1842,7 @@ function registerProjectCommands(program2) {
|
|
|
1419
1842
|
const detected = detectProject(process.cwd());
|
|
1420
1843
|
const linkPath = writeLocalLink({
|
|
1421
1844
|
site_id: details.site.name,
|
|
1845
|
+
site_name: details.site.site_name,
|
|
1422
1846
|
tenant_id: info.tenant,
|
|
1423
1847
|
site_type: details.site.site_type,
|
|
1424
1848
|
runtime_variant: details.site.runtime_variant,
|
|
@@ -1455,16 +1879,21 @@ function registerProjectCommands(program2) {
|
|
|
1455
1879
|
const jsoncLines = [
|
|
1456
1880
|
"{",
|
|
1457
1881
|
` // Auto-detected: ${detected.frameworkLabel}`,
|
|
1458
|
-
` "
|
|
1459
|
-
` "type": ${JSON.stringify(detected.runtimeVariant)},`,
|
|
1882
|
+
` "app_name": ${JSON.stringify(siteName)},`,
|
|
1883
|
+
` "type": ${JSON.stringify(detected.runtimeVariant === "html" ? "static" : detected.runtimeVariant)},`,
|
|
1460
1884
|
...detected.buildCommand ? [` "build_command": ${JSON.stringify(detected.buildCommand)},`] : [],
|
|
1461
1885
|
...detected.siteType === "static" ? [
|
|
1462
1886
|
` "output_dir": ${JSON.stringify(outDir || ".")},`,
|
|
1463
1887
|
` "spa_fallback": ${detected.runtimeVariant === "spa"},`
|
|
1464
1888
|
] : [
|
|
1465
1889
|
` "start_command": ${JSON.stringify(startCmd)},`,
|
|
1466
|
-
` "port": ${port}
|
|
1890
|
+
` "port": ${port},`,
|
|
1891
|
+
` // "healthcheck_path": "/health",`
|
|
1467
1892
|
],
|
|
1893
|
+
` // Add owned SagaCloud domains or external domains to auto-attach on deploy:`,
|
|
1894
|
+
` // "domains": ["app.example.com"],`,
|
|
1895
|
+
` // "env_file": ".env.production",`,
|
|
1896
|
+
` "cdn": { "enabled": true, "waf": false, "purge_on_deploy": true },`,
|
|
1468
1897
|
` "ignore": ["node_modules", ".git", ".env*", "tests"]`,
|
|
1469
1898
|
"}",
|
|
1470
1899
|
""
|
|
@@ -1480,12 +1909,14 @@ function registerProjectCommands(program2) {
|
|
|
1480
1909
|
query: { site_id: siteId, limit: 5 }
|
|
1481
1910
|
});
|
|
1482
1911
|
const s = res.site;
|
|
1483
|
-
|
|
1484
|
-
console.log(`${pc6.bold("
|
|
1485
|
-
console.log(`${pc6.bold("
|
|
1486
|
-
console.log(`${pc6.bold("
|
|
1487
|
-
console.log(`${pc6.bold("
|
|
1488
|
-
console.log(`${pc6.bold("
|
|
1912
|
+
const deployActor = s.last_deployed_by ? `${s.last_deployed_by} (${(s.last_deploy_channel || "web").toUpperCase()})` : "-";
|
|
1913
|
+
console.log(`${pc6.bold("Site:")} ${s.site_name} (${s.name})`);
|
|
1914
|
+
console.log(`${pc6.bold("Type:")} ${s.site_type} / ${s.runtime_variant} (${s.source_type})`);
|
|
1915
|
+
console.log(`${pc6.bold("Status:")} ${s.status}`);
|
|
1916
|
+
console.log(`${pc6.bold("Live URL:")} ${s.live_url || s.domain}`);
|
|
1917
|
+
console.log(`${pc6.bold("SSL / CDN:")} SSL=${s.ssl_status || "-"} \xB7 EdgeCDN=${s.cdn_enabled ? "On" : "Off"} \xB7 Shield=${s.waf_enabled ? "On" : "Off"}`);
|
|
1918
|
+
console.log(`${pc6.bold("Deployed:")} ${s.last_deployed_at || "-"}`);
|
|
1919
|
+
console.log(`${pc6.bold("Deployed By:")} ${deployActor}`);
|
|
1489
1920
|
});
|
|
1490
1921
|
program2.command("open").description("Open site Live URL in browser").option("--site <siteId>", "Site ID").action(async (opts) => {
|
|
1491
1922
|
const siteId = resolveActiveSiteId(process.cwd(), opts.site);
|
|
@@ -1495,10 +1926,10 @@ function registerProjectCommands(program2) {
|
|
|
1495
1926
|
});
|
|
1496
1927
|
const url = res.site.live_url || `https://${res.site.domain}`;
|
|
1497
1928
|
console.log(`Opening ${pc6.cyan(url)}`);
|
|
1498
|
-
const
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
}
|
|
1929
|
+
const opened = await openBrowser(url);
|
|
1930
|
+
if (!opened) {
|
|
1931
|
+
console.log(pc6.yellow("Browser opener is unavailable in this environment; open the URL above manually."));
|
|
1932
|
+
}
|
|
1502
1933
|
});
|
|
1503
1934
|
}
|
|
1504
1935
|
|
|
@@ -1611,7 +2042,7 @@ function registerSkillCommands(program2) {
|
|
|
1611
2042
|
|
|
1612
2043
|
// src/index.ts
|
|
1613
2044
|
var program = new Command();
|
|
1614
|
-
program.name("sagacloud").description("SagaCloud CLI \u2014 deploy Static, SPA, Express & Node.js apps cleanly").version("0.
|
|
2045
|
+
program.name("sagacloud").description("SagaCloud CLI \u2014 deploy Static, SPA, Express & Node.js apps cleanly").version("0.3.1");
|
|
1615
2046
|
registerAuthCommands(program);
|
|
1616
2047
|
registerProjectCommands(program);
|
|
1617
2048
|
registerDeployCommands(program);
|
package/package.json
CHANGED
|
@@ -90,7 +90,7 @@ sagacloud deploy --git --force --site <site_id>
|
|
|
90
90
|
- `sagacloud env push .env.production` (always run `sagacloud deploy` afterward to apply changes)
|
|
91
91
|
- `sagacloud env pull .env.local`
|
|
92
92
|
- **Rollback instant or source version:** `sagacloud deployments` → `sagacloud rollback v2`
|
|
93
|
-
- **Custom domains & Edge SSL:** `sagacloud domains add app.example.com`
|
|
93
|
+
- **Custom domains & Edge SSL:** `sagacloud domains add app.example.com [second.example.com]` (`mode: "auto"` detects owned workspace domains automatically vs external CNAME targets; configure `"domains"` array in `sagacloud.jsonc` for additive merge on `deploy`), or verify SSL with `sagacloud domains verify app.example.com`
|
|
94
94
|
- **Purge Edge CDN cache:** `sagacloud purge`
|
|
95
95
|
- **Container power control:** `sagacloud start | stop | restart`
|
|
96
96
|
- **Generate GitHub Actions workflow:** `sagacloud ci init` (creates `.github/workflows/sagacloud.yml` expecting `secrets.SAGACLOUD_TOKEN`)
|
|
@@ -6,7 +6,7 @@ Place `sagacloud.jsonc` (or `sagacloud.json`) in the root of your repository. Tr
|
|
|
6
6
|
|
|
7
7
|
| Field | Type | Description |
|
|
8
8
|
| --- | --- | --- |
|
|
9
|
-
| `name` | `string` | Default site
|
|
9
|
+
| `app_name` (or `name`) | `string` | Default site/app name when creating a new site |
|
|
10
10
|
| `site_id` | `string` | Explicit target Site ID (`site_...`) if not using `.sagacloud/project.json` |
|
|
11
11
|
| `type` | `"static" \| "spa" \| "php" \| "node" \| "nextjs"` | Runtime mode override |
|
|
12
12
|
| `base_directory` | `string` | Optional monorepo subdirectory |
|
|
@@ -16,9 +16,14 @@ Place `sagacloud.jsonc` (or `sagacloud.json`) in the root of your repository. Tr
|
|
|
16
16
|
| `start_command` | `string` | Start command for Node/SSR runtime (e.g. `npm start`, `node server.js`) |
|
|
17
17
|
| `port` | `number \| string` | Listening HTTP port inside Node container (default `3000`) |
|
|
18
18
|
| `spa_fallback` | `boolean` | When `true`, unknown routes rewrite to `/index.html` (`type: "spa"`) |
|
|
19
|
-
| `
|
|
19
|
+
| `healthcheck_path` | `string` | Optional HTTP health check path for Node/SSR apps |
|
|
20
|
+
| `domains` | `(string \| { fqdn, primary?, mode? })[]` | Multiple domains to auto-attach safely on deploy (`mode`: `auto` \| `saga_root` \| `saga_subdomain` \| `custom_external`) |
|
|
21
|
+
| `cdn` | `{ enabled?, waf?, purge_on_deploy? }` | Edge CDN / WAF toggles for new sites |
|
|
22
|
+
| `resources` | `{ memory?, cpus? }` | Container resource limits (e.g. `"512m"`, `"1"`) |
|
|
23
|
+
| `env_file` | `string` | Default `.env` file synced cleanly during `sagacloud deploy` |
|
|
20
24
|
| `ignore` | `string[]` | Extra glob patterns excluded from upload archive (`node_modules`, `.git`, `.env*`, `.sagacloud`, `sagacloud.json*` are always excluded) |
|
|
21
|
-
| `vars` | `Record<string, string \| number \| boolean>` | Non-secret environment variables pushed automatically on `sagacloud deploy` |
|
|
25
|
+
| `vars` | `Record<string, string \| number \| boolean>` | Non-secret environment variables pushed automatically on `sagacloud deploy` (merged, never wipes dashboard secrets) |
|
|
26
|
+
| `deploy` | `{ detach?, force_rebuild?, sync_domains? }` | Default deploy command behavior |
|
|
22
27
|
|
|
23
28
|
## Auto-Detection Defaults
|
|
24
29
|
|