@cardelli/ambit 0.1.4 → 0.2.0
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/esm/cli/commands/create/index.d.ts +2 -0
- package/esm/cli/commands/create/index.d.ts.map +1 -0
- package/esm/cli/commands/create/index.js +292 -0
- package/esm/cli/commands/create/machine.d.ts +33 -0
- package/esm/cli/commands/create/machine.d.ts.map +1 -0
- package/esm/cli/commands/create/machine.js +162 -0
- package/esm/cli/commands/deploy/index.d.ts +2 -0
- package/esm/cli/commands/deploy/index.d.ts.map +1 -0
- package/esm/cli/commands/deploy/index.js +290 -0
- package/esm/cli/commands/deploy/machine.d.ts +52 -0
- package/esm/cli/commands/deploy/machine.d.ts.map +1 -0
- package/esm/cli/commands/deploy/machine.js +116 -0
- package/esm/cli/commands/deploy/modes.d.ts +18 -0
- package/esm/cli/commands/deploy/modes.d.ts.map +1 -0
- package/esm/cli/commands/deploy/modes.js +152 -0
- package/esm/cli/commands/destroy/app.d.ts +2 -0
- package/esm/cli/commands/destroy/app.d.ts.map +1 -0
- package/esm/cli/commands/destroy/app.js +173 -0
- package/esm/cli/commands/destroy/index.d.ts +2 -0
- package/esm/cli/commands/destroy/index.d.ts.map +1 -0
- package/esm/cli/commands/destroy/index.js +63 -0
- package/esm/cli/commands/destroy/network.d.ts +2 -0
- package/esm/cli/commands/destroy/network.d.ts.map +1 -0
- package/esm/cli/commands/destroy/network.js +210 -0
- package/esm/cli/commands/doctor.d.ts.map +1 -0
- package/esm/cli/commands/doctor.js +295 -0
- package/esm/{src/cli → cli}/commands/list.d.ts.map +1 -1
- package/esm/{src/cli → cli}/commands/list.js +39 -54
- package/esm/cli/commands/status.d.ts.map +1 -0
- package/esm/cli/commands/status.js +331 -0
- package/esm/cli/mod.d.ts.map +1 -0
- package/esm/{src/cli → cli}/mod.js +4 -4
- package/esm/deno.d.ts +4 -18
- package/esm/deno.js +5 -19
- package/esm/deps/jsr.io/@std/path/1.1.4/constants.d.ts +1 -1
- package/esm/deps/jsr.io/@zod/zod/4.3.6/src/v4/core/json-schema-generator.d.ts +1 -1
- package/esm/lib/args.d.ts +11 -0
- package/esm/lib/args.d.ts.map +1 -0
- package/esm/lib/args.js +28 -0
- package/esm/lib/cli.d.ts +0 -2
- package/esm/lib/cli.d.ts.map +1 -1
- package/esm/lib/cli.js +41 -27
- package/esm/lib/command.d.ts +21 -49
- package/esm/lib/command.d.ts.map +1 -1
- package/esm/lib/command.js +55 -95
- package/esm/lib/machine.d.ts +11 -0
- package/esm/lib/machine.d.ts.map +1 -0
- package/esm/lib/machine.js +15 -0
- package/esm/lib/output.d.ts +3 -2
- package/esm/lib/output.d.ts.map +1 -1
- package/esm/lib/output.js +25 -11
- package/esm/lib/result.d.ts +18 -7
- package/esm/lib/result.d.ts.map +1 -1
- package/esm/lib/result.js +46 -1
- package/esm/main.d.ts +6 -6
- package/esm/main.d.ts.map +1 -1
- package/esm/main.js +7 -9
- package/esm/providers/fly.d.ts +81 -0
- package/esm/providers/fly.d.ts.map +1 -0
- package/esm/providers/fly.js +372 -0
- package/esm/providers/tailscale.d.ts +31 -0
- package/esm/providers/tailscale.d.ts.map +1 -0
- package/esm/providers/tailscale.js +150 -0
- package/esm/{src/schemas → schemas}/fly.d.ts +1 -11
- package/esm/schemas/fly.d.ts.map +1 -0
- package/esm/{src/schemas → schemas}/fly.js +14 -56
- package/esm/{src/schemas → schemas}/tailscale.d.ts +1 -2
- package/esm/schemas/tailscale.d.ts.map +1 -0
- package/esm/{src/schemas → schemas}/tailscale.js +2 -3
- package/esm/src/{docker/router → router}/Dockerfile +0 -11
- package/esm/src/router/start.sh +101 -0
- package/esm/util/constants.d.ts +13 -0
- package/esm/util/constants.d.ts.map +1 -0
- package/esm/util/constants.js +34 -0
- package/esm/{src → util}/credentials.d.ts +0 -1
- package/esm/util/credentials.d.ts.map +1 -0
- package/esm/{src → util}/credentials.js +3 -5
- package/esm/{src → util}/discovery.d.ts +20 -4
- package/esm/util/discovery.d.ts.map +1 -0
- package/esm/{src → util}/discovery.js +38 -15
- package/esm/util/fly-transforms.d.ts +27 -0
- package/esm/util/fly-transforms.d.ts.map +1 -0
- package/esm/util/fly-transforms.js +87 -0
- package/esm/{src → util}/guard.d.ts +1 -2
- package/esm/util/guard.d.ts.map +1 -0
- package/esm/{src → util}/guard.js +27 -27
- package/esm/util/naming.d.ts +5 -0
- package/esm/util/naming.d.ts.map +1 -0
- package/esm/util/naming.js +12 -0
- package/esm/{src → util}/resolve.d.ts +2 -3
- package/esm/util/resolve.d.ts.map +1 -0
- package/esm/{src → util}/resolve.js +1 -2
- package/esm/util/session.d.ts +16 -0
- package/esm/util/session.d.ts.map +1 -0
- package/esm/util/session.js +19 -0
- package/esm/util/tailscale-local.d.ts +13 -0
- package/esm/util/tailscale-local.d.ts.map +1 -0
- package/esm/util/tailscale-local.js +63 -0
- package/esm/{src → util}/template.d.ts +2 -4
- package/esm/util/template.d.ts.map +1 -0
- package/esm/{src → util}/template.js +14 -17
- package/package.json +1 -43
- package/esm/lib/paths.d.ts +0 -3
- package/esm/lib/paths.d.ts.map +0 -1
- package/esm/lib/paths.js +0 -5
- package/esm/src/cli/commands/create.d.ts +0 -2
- package/esm/src/cli/commands/create.d.ts.map +0 -1
- package/esm/src/cli/commands/create.js +0 -294
- package/esm/src/cli/commands/deploy.d.ts +0 -2
- package/esm/src/cli/commands/deploy.d.ts.map +0 -1
- package/esm/src/cli/commands/deploy.js +0 -426
- package/esm/src/cli/commands/destroy.d.ts +0 -2
- package/esm/src/cli/commands/destroy.d.ts.map +0 -1
- package/esm/src/cli/commands/destroy.js +0 -340
- package/esm/src/cli/commands/doctor.d.ts.map +0 -1
- package/esm/src/cli/commands/doctor.js +0 -141
- package/esm/src/cli/commands/status.d.ts.map +0 -1
- package/esm/src/cli/commands/status.js +0 -152
- package/esm/src/cli/mod.d.ts.map +0 -1
- package/esm/src/credentials.d.ts.map +0 -1
- package/esm/src/discovery.d.ts.map +0 -1
- package/esm/src/docker/router/start.sh +0 -146
- package/esm/src/guard.d.ts.map +0 -1
- package/esm/src/providers/fly.d.ts +0 -70
- package/esm/src/providers/fly.d.ts.map +0 -1
- package/esm/src/providers/fly.js +0 -411
- package/esm/src/providers/tailscale.d.ts +0 -31
- package/esm/src/providers/tailscale.d.ts.map +0 -1
- package/esm/src/providers/tailscale.js +0 -195
- package/esm/src/resolve.d.ts.map +0 -1
- package/esm/src/schemas/config.d.ts +0 -5
- package/esm/src/schemas/config.d.ts.map +0 -1
- package/esm/src/schemas/config.js +0 -22
- package/esm/src/schemas/fly.d.ts.map +0 -1
- package/esm/src/schemas/tailscale.d.ts.map +0 -1
- package/esm/src/template.d.ts.map +0 -1
- /package/esm/{src/cli → cli}/commands/doctor.d.ts +0 -0
- /package/esm/{src/cli → cli}/commands/list.d.ts +0 -0
- /package/esm/{src/cli → cli}/commands/status.d.ts +0 -0
- /package/esm/{src/cli → cli}/mod.d.ts +0 -0
- /package/esm/src/{docker/router → router}/fly.toml +0 -0
|
@@ -1,426 +0,0 @@
|
|
|
1
|
-
// =============================================================================
|
|
2
|
-
// Deploy Command - Safely Deploy a Workload App on a Custom Private Network
|
|
3
|
-
// =============================================================================
|
|
4
|
-
import * as dntShim from "../../../_dnt.shims.js";
|
|
5
|
-
import { parseArgs } from "../../../deps/jsr.io/@std/cli/1.0.28/mod.js";
|
|
6
|
-
import { join } from "../../../deps/jsr.io/@std/path/1.1.4/mod.js";
|
|
7
|
-
import { bold, confirm, fileExists } from "../../../lib/cli.js";
|
|
8
|
-
import { createOutput } from "../../../lib/output.js";
|
|
9
|
-
import { registerCommand } from "../mod.js";
|
|
10
|
-
import { createFlyProvider, FlyDeployError } from "../../providers/fly.js";
|
|
11
|
-
import { findRouterApp } from "../../discovery.js";
|
|
12
|
-
import { resolveOrg } from "../../resolve.js";
|
|
13
|
-
import { assertNotRouter, auditDeploy, scanFlyToml } from "../../guard.js";
|
|
14
|
-
import { fetchTemplate, parseTemplateRef } from "../../template.js";
|
|
15
|
-
// =============================================================================
|
|
16
|
-
// Image Mode
|
|
17
|
-
// =============================================================================
|
|
18
|
-
/**
|
|
19
|
-
* Generate a minimal fly.toml with http_service config for auto start/stop.
|
|
20
|
-
* Written to a temp directory and cleaned up after deploy.
|
|
21
|
-
*/
|
|
22
|
-
const generateServiceToml = (port) => `[http_service]\n` +
|
|
23
|
-
` internal_port = ${port}\n` +
|
|
24
|
-
` auto_stop_machines = "stop"\n` +
|
|
25
|
-
` auto_start_machines = true\n` +
|
|
26
|
-
` min_machines_running = 0\n`;
|
|
27
|
-
/**
|
|
28
|
-
* Parse --main-port value. Returns the port number, or null if "none".
|
|
29
|
-
* Dies on invalid input.
|
|
30
|
-
*/
|
|
31
|
-
const parseMainPort = (raw, out) => {
|
|
32
|
-
if (raw === "none")
|
|
33
|
-
return null;
|
|
34
|
-
const port = Number(raw);
|
|
35
|
-
if (!Number.isInteger(port) || port < 1 || port > 65535) {
|
|
36
|
-
out.die(`Invalid --main-port: "${raw}". Use a port number (1-65535) or "none".`);
|
|
37
|
-
return "error";
|
|
38
|
-
}
|
|
39
|
-
return port;
|
|
40
|
-
};
|
|
41
|
-
/** Resolve deploy config for image mode (--image). */
|
|
42
|
-
const resolveImageMode = (image, mainPortRaw, out) => {
|
|
43
|
-
const mainPort = parseMainPort(mainPortRaw, out);
|
|
44
|
-
if (mainPort === "error")
|
|
45
|
-
return null;
|
|
46
|
-
const preflight = { scanned: false, warnings: [] };
|
|
47
|
-
if (mainPort !== null) {
|
|
48
|
-
const tempDir = dntShim.Deno.makeTempDirSync();
|
|
49
|
-
const configPath = join(tempDir, "fly.toml");
|
|
50
|
-
dntShim.Deno.writeTextFileSync(configPath, generateServiceToml(mainPort));
|
|
51
|
-
out.ok(`HTTP Service on Port ${mainPort} (auto start/stop)`);
|
|
52
|
-
return { image, configPath, preflight, tempDir };
|
|
53
|
-
}
|
|
54
|
-
out.info("Image Mode — No Service Config");
|
|
55
|
-
return { image, preflight };
|
|
56
|
-
};
|
|
57
|
-
// =============================================================================
|
|
58
|
-
// Config Mode
|
|
59
|
-
// =============================================================================
|
|
60
|
-
/** Resolve deploy config for config mode (default — uses fly.toml). */
|
|
61
|
-
const resolveConfigMode = async (explicitConfig, out) => {
|
|
62
|
-
// Determine config path: explicit --config, or auto-detect ./fly.toml
|
|
63
|
-
let configPath = explicitConfig;
|
|
64
|
-
if (!configPath && await fileExists("./fly.toml")) {
|
|
65
|
-
configPath = "./fly.toml";
|
|
66
|
-
}
|
|
67
|
-
if (!configPath) {
|
|
68
|
-
out.info("No fly.toml Found — Deploying Without Config Scan");
|
|
69
|
-
return { preflight: { scanned: false, warnings: [] } };
|
|
70
|
-
}
|
|
71
|
-
if (!(await fileExists(configPath))) {
|
|
72
|
-
out.die(`Config File Not Found: ${configPath}`);
|
|
73
|
-
return null;
|
|
74
|
-
}
|
|
75
|
-
// Pre-flight scan
|
|
76
|
-
const tomlContent = await dntShim.Deno.readTextFile(configPath);
|
|
77
|
-
const scan = scanFlyToml(tomlContent);
|
|
78
|
-
if (scan.errors.length > 0) {
|
|
79
|
-
for (const err of scan.errors) {
|
|
80
|
-
out.err(err);
|
|
81
|
-
}
|
|
82
|
-
out.die("Pre-flight Check Failed. Fix fly.toml Before Deploying.");
|
|
83
|
-
return null;
|
|
84
|
-
}
|
|
85
|
-
for (const warn of scan.warnings) {
|
|
86
|
-
out.warn(warn);
|
|
87
|
-
}
|
|
88
|
-
out.ok(`Scanned ${configPath}`);
|
|
89
|
-
return {
|
|
90
|
-
configPath,
|
|
91
|
-
preflight: { scanned: scan.scanned, warnings: scan.warnings },
|
|
92
|
-
};
|
|
93
|
-
};
|
|
94
|
-
// =============================================================================
|
|
95
|
-
// Template Mode
|
|
96
|
-
// =============================================================================
|
|
97
|
-
/** Resolve deploy config for template mode (--template). */
|
|
98
|
-
const resolveTemplateMode = async (templateRaw, out) => {
|
|
99
|
-
const ref = parseTemplateRef(templateRaw);
|
|
100
|
-
if (!ref) {
|
|
101
|
-
out.die(`Invalid Template Reference: "${templateRaw}". ` +
|
|
102
|
-
`Format: owner/repo[/path][@ref]`);
|
|
103
|
-
return null;
|
|
104
|
-
}
|
|
105
|
-
const label = (ref.path === "."
|
|
106
|
-
? `${ref.owner}/${ref.repo}`
|
|
107
|
-
: `${ref.owner}/${ref.repo}/${ref.path}`) +
|
|
108
|
-
(ref.ref ? `@${ref.ref}` : "");
|
|
109
|
-
out.info(`Template: ${label}`);
|
|
110
|
-
const fetchSpinner = out.spinner("Fetching Template from GitHub");
|
|
111
|
-
const result = await fetchTemplate(ref);
|
|
112
|
-
if (!result.ok) {
|
|
113
|
-
fetchSpinner.fail("Template Fetch Failed");
|
|
114
|
-
out.die(result.message);
|
|
115
|
-
return null;
|
|
116
|
-
}
|
|
117
|
-
fetchSpinner.success("Template Fetched");
|
|
118
|
-
// Find and scan the template's fly.toml
|
|
119
|
-
const configPath = join(result.templateDir, "fly.toml");
|
|
120
|
-
let tomlContent;
|
|
121
|
-
try {
|
|
122
|
-
tomlContent = await dntShim.Deno.readTextFile(configPath);
|
|
123
|
-
}
|
|
124
|
-
catch {
|
|
125
|
-
try {
|
|
126
|
-
dntShim.Deno.removeSync(result.tempDir, { recursive: true });
|
|
127
|
-
}
|
|
128
|
-
catch { /* ignore */ }
|
|
129
|
-
out.die(`Template '${ref.path === "." ? ref.repo : ref.path}' Has No fly.toml`);
|
|
130
|
-
return null;
|
|
131
|
-
}
|
|
132
|
-
const scan = scanFlyToml(tomlContent);
|
|
133
|
-
if (scan.errors.length > 0) {
|
|
134
|
-
try {
|
|
135
|
-
dntShim.Deno.removeSync(result.tempDir, { recursive: true });
|
|
136
|
-
}
|
|
137
|
-
catch { /* ignore */ }
|
|
138
|
-
for (const err of scan.errors) {
|
|
139
|
-
out.err(err);
|
|
140
|
-
}
|
|
141
|
-
out.die("Pre-flight Check Failed for Template fly.toml");
|
|
142
|
-
return null;
|
|
143
|
-
}
|
|
144
|
-
for (const warn of scan.warnings) {
|
|
145
|
-
out.warn(warn);
|
|
146
|
-
}
|
|
147
|
-
out.ok(`Scanned ${ref.path === "." ? "" : ref.path + "/"}fly.toml`);
|
|
148
|
-
return {
|
|
149
|
-
configPath,
|
|
150
|
-
preflight: { scanned: scan.scanned, warnings: scan.warnings },
|
|
151
|
-
tempDir: result.tempDir,
|
|
152
|
-
};
|
|
153
|
-
};
|
|
154
|
-
// =============================================================================
|
|
155
|
-
// Deploy Command
|
|
156
|
-
// =============================================================================
|
|
157
|
-
const deploy = async (argv) => {
|
|
158
|
-
const args = parseArgs(argv, {
|
|
159
|
-
string: [
|
|
160
|
-
"network",
|
|
161
|
-
"org",
|
|
162
|
-
"region",
|
|
163
|
-
"image",
|
|
164
|
-
"config",
|
|
165
|
-
"main-port",
|
|
166
|
-
"template",
|
|
167
|
-
],
|
|
168
|
-
boolean: ["help", "yes", "json"],
|
|
169
|
-
alias: { y: "yes" },
|
|
170
|
-
default: { "main-port": "80" },
|
|
171
|
-
});
|
|
172
|
-
if (args.help) {
|
|
173
|
-
console.log(`
|
|
174
|
-
${bold("ambit deploy")} - Deploy an App Safely on a Custom Private Network
|
|
175
|
-
|
|
176
|
-
${bold("USAGE")}
|
|
177
|
-
ambit deploy <app>.<network> [options]
|
|
178
|
-
ambit deploy <app> --network <name> [options]
|
|
179
|
-
|
|
180
|
-
The network can be specified as part of the name (app.network) or with --network.
|
|
181
|
-
|
|
182
|
-
${bold("MODES")}
|
|
183
|
-
Config mode (default):
|
|
184
|
-
ambit deploy my-app.lab Uses ./fly.toml
|
|
185
|
-
ambit deploy my-app.lab --config path Explicit fly.toml
|
|
186
|
-
|
|
187
|
-
Image mode:
|
|
188
|
-
ambit deploy my-app.lab --image <img> Docker image, no toml
|
|
189
|
-
|
|
190
|
-
Template mode:
|
|
191
|
-
ambit deploy my-app.lab --template <ref> GitHub template
|
|
192
|
-
|
|
193
|
-
${bold("OPTIONS")}
|
|
194
|
-
--network <name> Target network
|
|
195
|
-
--org <org> Fly.io organization slug
|
|
196
|
-
--region <region> Primary deployment region
|
|
197
|
-
-y, --yes Skip confirmation prompts
|
|
198
|
-
--json Output as JSON
|
|
199
|
-
|
|
200
|
-
${bold("CONFIG MODE")} (default)
|
|
201
|
-
--config <path> Explicit fly.toml path (auto-detects ./fly.toml if omitted)
|
|
202
|
-
|
|
203
|
-
${bold("IMAGE MODE")}
|
|
204
|
-
--image <img> Docker image to deploy (no fly.toml needed)
|
|
205
|
-
--main-port <port> Internal port for HTTP service (default: 80, "none" to skip)
|
|
206
|
-
|
|
207
|
-
${bold("TEMPLATE MODE")}
|
|
208
|
-
--template <ref> GitHub template as owner/repo[/path][@ref]
|
|
209
|
-
|
|
210
|
-
Reference format:
|
|
211
|
-
owner/repo Fetch repo root from the default branch
|
|
212
|
-
owner/repo/path Fetch subdirectory from the default branch
|
|
213
|
-
owner/repo/path@tag Fetch a tagged release
|
|
214
|
-
owner/repo/path@branch Fetch a specific branch
|
|
215
|
-
owner/repo/path@commit Fetch a specific commit
|
|
216
|
-
|
|
217
|
-
${bold("SAFETY")}
|
|
218
|
-
Always deploys with --no-public-ips and --flycast.
|
|
219
|
-
Post-deploy audit releases any public IPs and verifies Flycast allocation.
|
|
220
|
-
Pre-flight scan rejects fly.toml with force_https or TLS on 443.
|
|
221
|
-
|
|
222
|
-
${bold("EXAMPLES")}
|
|
223
|
-
ambit deploy my-app.lab
|
|
224
|
-
ambit deploy my-app.lab --image registry/img:latest
|
|
225
|
-
ambit deploy my-app.lab --config ./fly.toml --region sea
|
|
226
|
-
ambit deploy my-claw.lab --template ToxicPine/ambit-openclaw
|
|
227
|
-
ambit deploy my-browser.lab --template ToxicPine/ambit-templates/chromatic
|
|
228
|
-
ambit deploy my-browser --network lab --template ToxicPine/ambit-templates/chromatic@v1.0
|
|
229
|
-
`);
|
|
230
|
-
return;
|
|
231
|
-
}
|
|
232
|
-
const out = createOutput(args.json);
|
|
233
|
-
// ==========================================================================
|
|
234
|
-
// Phase 0: Parse & Validate
|
|
235
|
-
// ==========================================================================
|
|
236
|
-
const appArg = args._[0];
|
|
237
|
-
if (!appArg || typeof appArg !== "string") {
|
|
238
|
-
return out.die("Missing app name. Usage: ambit deploy <app>.<network>");
|
|
239
|
-
}
|
|
240
|
-
let app;
|
|
241
|
-
let network;
|
|
242
|
-
if (appArg.includes(".")) {
|
|
243
|
-
const parts = appArg.split(".");
|
|
244
|
-
if (parts.length !== 2 || !parts[0] || !parts[1]) {
|
|
245
|
-
return out.die(`'${appArg}' should have exactly one dot, like my-app.my-network`);
|
|
246
|
-
}
|
|
247
|
-
if (args.network) {
|
|
248
|
-
return out.die(`Network is already part of the name ('${appArg}'), --network is not needed`);
|
|
249
|
-
}
|
|
250
|
-
app = parts[0];
|
|
251
|
-
network = parts[1];
|
|
252
|
-
}
|
|
253
|
-
else {
|
|
254
|
-
app = appArg;
|
|
255
|
-
if (!args.network) {
|
|
256
|
-
return out.die(`Missing network. Use: ambit deploy ${app}.<network>`);
|
|
257
|
-
}
|
|
258
|
-
network = args.network;
|
|
259
|
-
}
|
|
260
|
-
try {
|
|
261
|
-
assertNotRouter(app);
|
|
262
|
-
}
|
|
263
|
-
catch (e) {
|
|
264
|
-
return out.die(e instanceof Error ? e.message : String(e));
|
|
265
|
-
}
|
|
266
|
-
const modeFlags = [args.image, args.config, args.template].filter(Boolean);
|
|
267
|
-
if (modeFlags.length > 1) {
|
|
268
|
-
return out.die("--image, --config, and --template Are Mutually Exclusive");
|
|
269
|
-
}
|
|
270
|
-
out.blank()
|
|
271
|
-
.header("=".repeat(50))
|
|
272
|
-
.header(` ambit Deploy: ${app}`)
|
|
273
|
-
.header("=".repeat(50))
|
|
274
|
-
.blank();
|
|
275
|
-
// ==========================================================================
|
|
276
|
-
// Phase 1: Auth & Org
|
|
277
|
-
// ==========================================================================
|
|
278
|
-
out.header("Step 1: Fly.io Configuration").blank();
|
|
279
|
-
const fly = createFlyProvider();
|
|
280
|
-
await fly.ensureInstalled();
|
|
281
|
-
const email = await fly.ensureAuth({ interactive: !args.json });
|
|
282
|
-
out.ok(`Authenticated as ${email}`);
|
|
283
|
-
const org = await resolveOrg(fly, args, out);
|
|
284
|
-
out.blank();
|
|
285
|
-
// ==========================================================================
|
|
286
|
-
// Phase 2: Network Verification
|
|
287
|
-
// ==========================================================================
|
|
288
|
-
out.header("Step 2: Network Verification").blank();
|
|
289
|
-
const routerSpinner = out.spinner("Checking for Router on Network");
|
|
290
|
-
const router = await findRouterApp(fly, org, network);
|
|
291
|
-
if (!router) {
|
|
292
|
-
routerSpinner.fail("No Router Found");
|
|
293
|
-
return out.die(`No ambit router found on network '${network}'. ` +
|
|
294
|
-
`Run 'ambit create ${network}' first.`);
|
|
295
|
-
}
|
|
296
|
-
routerSpinner.success(`Router Found: ${router.appName}`);
|
|
297
|
-
out.blank();
|
|
298
|
-
// ==========================================================================
|
|
299
|
-
// Phase 3: App Creation (if needed)
|
|
300
|
-
// ==========================================================================
|
|
301
|
-
out.header("Step 3: App Setup").blank();
|
|
302
|
-
let created = false;
|
|
303
|
-
const exists = await fly.appExists(app);
|
|
304
|
-
if (exists) {
|
|
305
|
-
out.ok(`App '${app}' Exists`);
|
|
306
|
-
}
|
|
307
|
-
else {
|
|
308
|
-
out.info(`App '${app}' Does Not Exist — Will Create on Network '${network}'`);
|
|
309
|
-
if (!args.yes && !args.json) {
|
|
310
|
-
const confirmed = await confirm(`Create app '${app}' on network '${network}'?`);
|
|
311
|
-
if (!confirmed) {
|
|
312
|
-
out.text("Cancelled.");
|
|
313
|
-
return;
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
|
-
await fly.createApp(app, org, { network });
|
|
317
|
-
out.ok(`Created App '${app}' on Network '${network}'`);
|
|
318
|
-
created = true;
|
|
319
|
-
}
|
|
320
|
-
out.blank();
|
|
321
|
-
// ==========================================================================
|
|
322
|
-
// Phase 4: Resolve Deploy Mode
|
|
323
|
-
// ==========================================================================
|
|
324
|
-
out.header("Step 4: Pre-flight Check").blank();
|
|
325
|
-
let deployConfig;
|
|
326
|
-
if (args.template) {
|
|
327
|
-
deployConfig = await resolveTemplateMode(args.template, out);
|
|
328
|
-
}
|
|
329
|
-
else if (args.image) {
|
|
330
|
-
deployConfig = resolveImageMode(args.image, String(args["main-port"]), out);
|
|
331
|
-
}
|
|
332
|
-
else {
|
|
333
|
-
deployConfig = await resolveConfigMode(args.config, out);
|
|
334
|
-
}
|
|
335
|
-
if (!deployConfig)
|
|
336
|
-
return; // mode resolver already called out.die()
|
|
337
|
-
out.blank();
|
|
338
|
-
// ==========================================================================
|
|
339
|
-
// Phase 5: Deploy with Enforced Flags
|
|
340
|
-
// ==========================================================================
|
|
341
|
-
out.header("Step 5: Deploy").blank();
|
|
342
|
-
out.dim("Deploying with --no-public-ips --flycast ...");
|
|
343
|
-
try {
|
|
344
|
-
await fly.deploySafe(app, {
|
|
345
|
-
image: deployConfig.image,
|
|
346
|
-
config: deployConfig.configPath,
|
|
347
|
-
region: args.region,
|
|
348
|
-
});
|
|
349
|
-
}
|
|
350
|
-
catch (e) {
|
|
351
|
-
if (e instanceof FlyDeployError) {
|
|
352
|
-
out.dim(` ${e.detail}`);
|
|
353
|
-
return out.die(e.message);
|
|
354
|
-
}
|
|
355
|
-
throw e;
|
|
356
|
-
}
|
|
357
|
-
finally {
|
|
358
|
-
if (deployConfig.tempDir) {
|
|
359
|
-
try {
|
|
360
|
-
dntShim.Deno.removeSync(deployConfig.tempDir, { recursive: true });
|
|
361
|
-
}
|
|
362
|
-
catch { /* ignore */ }
|
|
363
|
-
}
|
|
364
|
-
}
|
|
365
|
-
out.ok("Deploy Succeeded");
|
|
366
|
-
out.blank();
|
|
367
|
-
// ==========================================================================
|
|
368
|
-
// Phase 6: Post-flight Audit
|
|
369
|
-
// ==========================================================================
|
|
370
|
-
out.header("Step 6: Post-flight Audit").blank();
|
|
371
|
-
const auditSpinner = out.spinner("Auditing Deployment");
|
|
372
|
-
const audit = await auditDeploy(fly, app, network);
|
|
373
|
-
auditSpinner.success("Audit Complete");
|
|
374
|
-
if (audit.public_ips_released > 0) {
|
|
375
|
-
out.warn(`Released ${audit.public_ips_released} Public IP(s)`);
|
|
376
|
-
}
|
|
377
|
-
if (audit.certs_removed > 0) {
|
|
378
|
-
out.ok(`Removed ${audit.certs_removed} Public Certificate(s)`);
|
|
379
|
-
}
|
|
380
|
-
for (const alloc of audit.flycast_allocations) {
|
|
381
|
-
out.ok(`Flycast: ${alloc.address} (network: ${alloc.network})`);
|
|
382
|
-
}
|
|
383
|
-
for (const warn of audit.warnings) {
|
|
384
|
-
out.warn(warn);
|
|
385
|
-
}
|
|
386
|
-
// ==========================================================================
|
|
387
|
-
// Phase 7: Result
|
|
388
|
-
// ==========================================================================
|
|
389
|
-
const hasIssues = audit.public_ips_released > 0 || audit.warnings.length > 0;
|
|
390
|
-
const result = {
|
|
391
|
-
app,
|
|
392
|
-
network,
|
|
393
|
-
created,
|
|
394
|
-
audit: {
|
|
395
|
-
public_ips_released: audit.public_ips_released,
|
|
396
|
-
certs_removed: audit.certs_removed,
|
|
397
|
-
flycast_allocations: audit.flycast_allocations,
|
|
398
|
-
warnings: audit.warnings,
|
|
399
|
-
},
|
|
400
|
-
preflight: deployConfig.preflight,
|
|
401
|
-
};
|
|
402
|
-
if (hasIssues) {
|
|
403
|
-
out.fail("Deploy Completed with Issues", result);
|
|
404
|
-
}
|
|
405
|
-
else {
|
|
406
|
-
out.done(result);
|
|
407
|
-
}
|
|
408
|
-
out.blank()
|
|
409
|
-
.header("=".repeat(50))
|
|
410
|
-
.header(hasIssues ? " Deploy Completed (with warnings)" : " Deploy Completed!")
|
|
411
|
-
.header("=".repeat(50))
|
|
412
|
-
.blank()
|
|
413
|
-
.text(`App '${app}' Is Reachable from Your Tailnet as:`)
|
|
414
|
-
.text(` ${app}.${network}`)
|
|
415
|
-
.blank();
|
|
416
|
-
out.print();
|
|
417
|
-
};
|
|
418
|
-
// =============================================================================
|
|
419
|
-
// Register Command
|
|
420
|
-
// =============================================================================
|
|
421
|
-
registerCommand({
|
|
422
|
-
name: "deploy",
|
|
423
|
-
description: "Deploy an app safely on a custom private network",
|
|
424
|
-
usage: "ambit deploy <app> --network <name> [--image <img>] [--template <ref>] [--org <org>] [--region <region>]",
|
|
425
|
-
run: deploy,
|
|
426
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"destroy.d.ts","sourceRoot":"","sources":["../../../../src/src/cli/commands/destroy.ts"],"names":[],"mappings":""}
|