@omnibase/cli 0.8.1 → 0.9.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/dist/commands/cloud.d.ts +10 -2
- package/dist/commands/cloud.d.ts.map +1 -1
- package/dist/commands/cloud.js +376 -70
- package/dist/commands/cloud.js.map +1 -1
- package/dist/commands/db/migrate.d.ts.map +1 -1
- package/dist/commands/db/migrate.js +6 -2
- package/dist/commands/db/migrate.js.map +1 -1
- package/dist/commands/environment.d.ts.map +1 -1
- package/dist/commands/environment.js +17 -8
- package/dist/commands/environment.js.map +1 -1
- package/dist/commands/stripe.d.ts.map +1 -1
- package/dist/commands/stripe.js +3 -8
- package/dist/commands/stripe.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +80 -6
- package/dist/index.js.map +1 -1
- package/dist/services/db/migrate.d.ts.map +1 -1
- package/dist/services/db/migrate.js +4 -0
- package/dist/services/db/migrate.js.map +1 -1
- package/dist/utils/api-client.d.ts +5 -0
- package/dist/utils/api-client.d.ts.map +1 -1
- package/dist/utils/api-client.js +24 -0
- package/dist/utils/api-client.js.map +1 -1
- package/dist/utils/config.d.ts +48 -0
- package/dist/utils/config.d.ts.map +1 -0
- package/dist/utils/config.js +226 -0
- package/dist/utils/config.js.map +1 -0
- package/dist/utils/docker.d.ts +17 -0
- package/dist/utils/docker.d.ts.map +1 -1
- package/dist/utils/docker.js +45 -2
- package/dist/utils/docker.js.map +1 -1
- package/dist/utils/environment.d.ts +3 -34
- package/dist/utils/environment.d.ts.map +1 -1
- package/dist/utils/environment.js +127 -123
- package/dist/utils/environment.js.map +1 -1
- package/docker/docker-compose.base.yml +3 -19
- package/package.json +4 -2
- package/templates/omnibase.toml +30 -0
- package/templates/.omnibase-config +0 -4
- package/templates/environments/.env.dev +0 -12
- package/templates/environments/.env.local +0 -34
- package/templates/environments/.env.prod +0 -12
- package/templates/environments/.env.staging +0 -12
package/dist/commands/cloud.d.ts
CHANGED
|
@@ -1,8 +1,16 @@
|
|
|
1
1
|
import { Command } from "commander";
|
|
2
2
|
/**
|
|
3
|
-
* Push
|
|
3
|
+
* Push config from omnibase.toml to managed hosting.
|
|
4
|
+
*
|
|
5
|
+
* Everything except [local] is sent; managed hosting maps what it understands
|
|
6
|
+
* and reports the rest. [local] stays on this machine — that is where Stripe
|
|
7
|
+
* lives, since managed hosting owns Stripe env via the Connect account it
|
|
8
|
+
* provisions per branch.
|
|
9
|
+
*
|
|
10
|
+
* {VAR} secrets resolve from process.env, then an optional --from-env file.
|
|
11
|
+
* .env.local is NEVER read here — it is strictly for local dev (omnibase start).
|
|
4
12
|
*/
|
|
5
|
-
export declare function pushEnvConfig(envFlag?: string): Promise<void>;
|
|
13
|
+
export declare function pushEnvConfig(envFlag?: string, fromEnvPath?: string): Promise<void>;
|
|
6
14
|
/**
|
|
7
15
|
* Add cloud commands to the CLI program
|
|
8
16
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cloud.d.ts","sourceRoot":"","sources":["../../src/commands/cloud.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"cloud.d.ts","sourceRoot":"","sources":["../../src/commands/cloud.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAmgBpC;;;;;;;;;;GAUG;AACH,wBAAsB,aAAa,CACjC,OAAO,CAAC,EAAE,MAAM,EAChB,WAAW,CAAC,EAAE,MAAM,GACnB,OAAO,CAAC,IAAI,CAAC,CA0Ff;AAiLD;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CA6JvD"}
|
package/dist/commands/cloud.js
CHANGED
|
@@ -40,17 +40,20 @@ exports.pushEnvConfig = pushEnvConfig;
|
|
|
40
40
|
exports.addCloudCommands = addCloudCommands;
|
|
41
41
|
const child_process_1 = require("child_process");
|
|
42
42
|
const promises_1 = require("fs/promises");
|
|
43
|
+
const fs = __importStar(require("fs"));
|
|
43
44
|
const form_data_1 = __importDefault(require("form-data"));
|
|
44
45
|
const jszip_1 = __importDefault(require("jszip"));
|
|
45
46
|
const TOML = __importStar(require("smol-toml"));
|
|
46
47
|
const axios_1 = __importDefault(require("axios"));
|
|
47
48
|
const prompts_1 = require("@inquirer/prompts");
|
|
48
49
|
const path = __importStar(require("path"));
|
|
50
|
+
const dotenv_1 = require("dotenv");
|
|
49
51
|
const environment_1 = require("../utils/environment");
|
|
50
52
|
const credentials_1 = require("../utils/credentials");
|
|
51
53
|
const logger_1 = require("../utils/logger");
|
|
52
54
|
const errors_1 = require("../utils/errors");
|
|
53
55
|
const api_client_1 = require("../utils/api-client");
|
|
56
|
+
const config_1 = require("../utils/config");
|
|
54
57
|
/**
|
|
55
58
|
* Login to OmniBase Cloud
|
|
56
59
|
*/
|
|
@@ -63,7 +66,7 @@ async function login(apiKey, options) {
|
|
|
63
66
|
Authorization: `Bearer ${apiKey}`,
|
|
64
67
|
},
|
|
65
68
|
});
|
|
66
|
-
const data = response.data
|
|
69
|
+
const data = response.data;
|
|
67
70
|
if (!data?.tenant_id) {
|
|
68
71
|
throw new Error("Invalid API key");
|
|
69
72
|
}
|
|
@@ -165,7 +168,7 @@ async function switchProfile(profileName) {
|
|
|
165
168
|
if (!credentials.profiles[profileName]) {
|
|
166
169
|
logger_1.logger.fail(`Profile '${profileName}' not found.`);
|
|
167
170
|
logger_1.logger.log("Available profiles:");
|
|
168
|
-
profiles.forEach((p) => logger_1.logger.log(` - ${p}`));
|
|
171
|
+
profiles.forEach((p) => { logger_1.logger.log(` - ${p}`); });
|
|
169
172
|
return;
|
|
170
173
|
}
|
|
171
174
|
credentials.active_profile = profileName;
|
|
@@ -209,46 +212,94 @@ async function listProfiles() {
|
|
|
209
212
|
logger_1.logger.log(` Key: ${profile.key_name} (${profile.key_prefix}...)`);
|
|
210
213
|
});
|
|
211
214
|
}
|
|
215
|
+
/**
|
|
216
|
+
* Get deployments from config or fall back to legacy single-worker dir
|
|
217
|
+
*/
|
|
218
|
+
function getDeployments(root) {
|
|
219
|
+
const config = (0, config_1.loadConfig)(root);
|
|
220
|
+
if (config.deployments.length > 0)
|
|
221
|
+
return config.deployments;
|
|
222
|
+
const legacyWorkersDir = path.join(root, "omnibase", "workers");
|
|
223
|
+
if (fs.existsSync(legacyWorkersDir)) {
|
|
224
|
+
return [{ name: "default", path: "workers" }];
|
|
225
|
+
}
|
|
226
|
+
throw new Error("No deployments found. Add [[deployments]] to omnibase/omnibase.toml\n" +
|
|
227
|
+
" or create omnibase/workers/ for the default deployment.");
|
|
228
|
+
}
|
|
212
229
|
/**
|
|
213
230
|
* Deploy workers to Cloudflare via managed hosting
|
|
214
231
|
*/
|
|
215
|
-
async function deployWorkers(envFlag) {
|
|
232
|
+
async function deployWorkers(envFlag, nameFlag, allFlag) {
|
|
216
233
|
const root = (0, environment_1.findOmnibaseRoot)();
|
|
217
|
-
const workersDir = path.join(root, "omnibase/workers");
|
|
218
234
|
const env = await (0, environment_1.selectEnvironment)(envFlag);
|
|
219
235
|
if (env.name === "local") {
|
|
220
236
|
logger_1.logger.warn("Workers deployment is not available for local environment.");
|
|
221
|
-
logger_1.logger.log("
|
|
222
|
-
logger_1.logger.log("Or deploy to a cloud environment with --env flag:");
|
|
237
|
+
logger_1.logger.log("Use --env flag to specify a cloud environment:");
|
|
223
238
|
logger_1.logger.log(" omnibase cloud workers deploy --env dev");
|
|
224
239
|
logger_1.logger.log(" omnibase cloud workers deploy --env staging");
|
|
225
240
|
logger_1.logger.log(" omnibase cloud workers deploy --env production");
|
|
226
241
|
return;
|
|
227
242
|
}
|
|
228
243
|
if (!env.branchId) {
|
|
229
|
-
throw new Error(`
|
|
230
|
-
`
|
|
244
|
+
throw new Error(`No branch ID resolved for environment '${env.name}'.\n` +
|
|
245
|
+
`Ensure your branch has finished provisioning.`);
|
|
231
246
|
}
|
|
232
247
|
if (!env.managedHostingApiUrl) {
|
|
233
|
-
throw new Error(`
|
|
234
|
-
`
|
|
248
|
+
throw new Error(`No managed hosting URL resolved for environment '${env.name}'.\n` +
|
|
249
|
+
`Ensure your profile is configured: 'omnibase cloud login'`);
|
|
235
250
|
}
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
251
|
+
const deployments = getDeployments(root);
|
|
252
|
+
let targets;
|
|
253
|
+
if (nameFlag) {
|
|
254
|
+
const match = deployments.find((d) => d.name === nameFlag);
|
|
255
|
+
if (!match) {
|
|
256
|
+
throw new Error(`Deployment '${nameFlag}' not found.\n` +
|
|
257
|
+
`Available deployments: ${deployments.map((d) => d.name).join(", ")}`);
|
|
258
|
+
}
|
|
259
|
+
targets = [match];
|
|
260
|
+
}
|
|
261
|
+
else if (allFlag) {
|
|
262
|
+
targets = deployments;
|
|
263
|
+
}
|
|
264
|
+
else if (deployments.length === 1) {
|
|
265
|
+
targets = deployments;
|
|
266
|
+
}
|
|
267
|
+
else {
|
|
268
|
+
const selected = await (0, prompts_1.select)({
|
|
269
|
+
message: "Select deployment to deploy:",
|
|
270
|
+
choices: deployments.map((d) => ({ name: d.name, value: d })),
|
|
241
271
|
});
|
|
272
|
+
targets = [selected];
|
|
273
|
+
}
|
|
274
|
+
for (const dep of targets) {
|
|
275
|
+
const workersDir = path.join(root, "omnibase", dep.path ?? dep.name);
|
|
276
|
+
if (!fs.existsSync(workersDir)) {
|
|
277
|
+
logger_1.logger.fail(`Deployment '${dep.name}' directory not found: ${workersDir}`);
|
|
278
|
+
continue;
|
|
279
|
+
}
|
|
280
|
+
logger_1.logger.start(`Building '${dep.name}' for ${env.name}...`);
|
|
281
|
+
try {
|
|
282
|
+
(0, child_process_1.execSync)("bunx wrangler deploy --dry-run --outdir .bundle", {
|
|
283
|
+
cwd: workersDir,
|
|
284
|
+
stdio: "inherit",
|
|
285
|
+
});
|
|
286
|
+
}
|
|
287
|
+
catch (error) {
|
|
288
|
+
logger_1.logger.fail(`Build failed for '${dep.name}'. Check the output above.`);
|
|
289
|
+
continue;
|
|
290
|
+
}
|
|
291
|
+
const bundle = await packageWorkerBundle(workersDir);
|
|
292
|
+
logger_1.logger.succeed(`${dep.name}: packaged (${(bundle.length / 1024).toFixed(1)} KB)`);
|
|
293
|
+
logger_1.logger.start(`Deploying '${dep.name}'...`);
|
|
294
|
+
try {
|
|
295
|
+
const result = await uploadToManagedHosting(env, bundle, dep.name);
|
|
296
|
+
logger_1.logger.succeed(`${dep.name} deployed`);
|
|
297
|
+
logger_1.logger.log(` URL: ${result.url}`);
|
|
298
|
+
}
|
|
299
|
+
catch (error) {
|
|
300
|
+
logger_1.logger.fail(`${dep.name} deploy failed: ${(0, errors_1.formatHttpError)(error)}`);
|
|
301
|
+
}
|
|
242
302
|
}
|
|
243
|
-
catch (error) {
|
|
244
|
-
throw new Error("Build failed. Check the output above for details.");
|
|
245
|
-
}
|
|
246
|
-
const bundle = await packageWorkerBundle(workersDir);
|
|
247
|
-
logger_1.logger.succeed(`Packaged worker bundle: ${(bundle.length / 1024).toFixed(1)} KB`);
|
|
248
|
-
logger_1.logger.start("Deploying to Cloudflare Workers...");
|
|
249
|
-
const result = await uploadToManagedHosting(env, bundle);
|
|
250
|
-
logger_1.logger.succeed("Workers deployed successfully");
|
|
251
|
-
logger_1.logger.log(` URL: ${result.url}`);
|
|
252
303
|
}
|
|
253
304
|
/**
|
|
254
305
|
* Turn a `wrangler deploy --dry-run --outdir .bundle` output into a
|
|
@@ -315,7 +366,7 @@ async function addDirToZip(folder, dir, skip) {
|
|
|
315
366
|
}
|
|
316
367
|
}
|
|
317
368
|
}
|
|
318
|
-
async function uploadToManagedHosting(env, bundle) {
|
|
369
|
+
async function uploadToManagedHosting(env, bundle, deploymentName = "default") {
|
|
319
370
|
const api = (0, api_client_1.createManagedHostingClient)(env);
|
|
320
371
|
const form = new form_data_1.default();
|
|
321
372
|
form.append("bundle", bundle, {
|
|
@@ -323,81 +374,277 @@ async function uploadToManagedHosting(env, bundle) {
|
|
|
323
374
|
contentType: "application/zip",
|
|
324
375
|
});
|
|
325
376
|
try {
|
|
326
|
-
const response = await api.post(`/api/v1/
|
|
377
|
+
const response = await api.post(`/api/v1/project_branches/${env.branchId}/workers/${encodeURIComponent(deploymentName)}/deploy`, form, {
|
|
327
378
|
headers: {
|
|
328
379
|
...form.getHeaders(),
|
|
329
380
|
},
|
|
330
381
|
maxBodyLength: Infinity,
|
|
331
382
|
maxContentLength: Infinity,
|
|
332
383
|
});
|
|
333
|
-
return response.data
|
|
384
|
+
return response.data;
|
|
334
385
|
}
|
|
335
386
|
catch (error) {
|
|
336
387
|
throw new Error((0, errors_1.formatHttpError)(error));
|
|
337
388
|
}
|
|
338
389
|
}
|
|
339
390
|
/**
|
|
340
|
-
*
|
|
391
|
+
* Resolve a branch for the project from managed hosting. A `--env` value
|
|
392
|
+
* matches by name, slug, or id; otherwise a single branch is auto-selected or
|
|
393
|
+
* the user is prompted.
|
|
394
|
+
*/
|
|
395
|
+
async function resolveBranch(managedHostingUrl, projectId, branchFlag) {
|
|
396
|
+
const api = (0, api_client_1.createManagedHostingClient)({
|
|
397
|
+
name: branchFlag || "cloud",
|
|
398
|
+
managedHostingApiUrl: managedHostingUrl,
|
|
399
|
+
});
|
|
400
|
+
const { data } = await api.get(`/api/v1/projects/${projectId}/branches`);
|
|
401
|
+
const branches = data ?? [];
|
|
402
|
+
if (branches.length === 0) {
|
|
403
|
+
throw new Error(`No branches found for project ${projectId}`);
|
|
404
|
+
}
|
|
405
|
+
if (branchFlag) {
|
|
406
|
+
const found = branches.find((b) => b.name === branchFlag || b.slug === branchFlag || b.id === branchFlag);
|
|
407
|
+
if (!found) {
|
|
408
|
+
throw new Error(`Branch '${branchFlag}' not found. Available: ${branches
|
|
409
|
+
.map((b) => b.name)
|
|
410
|
+
.join(", ")}`);
|
|
411
|
+
}
|
|
412
|
+
return found;
|
|
413
|
+
}
|
|
414
|
+
if (branches.length === 1)
|
|
415
|
+
return branches[0];
|
|
416
|
+
const id = await (0, prompts_1.select)({
|
|
417
|
+
message: "Select branch:",
|
|
418
|
+
choices: branches.map((b) => ({
|
|
419
|
+
name: `${b.name} (${b.status})`,
|
|
420
|
+
value: b.id,
|
|
421
|
+
})),
|
|
422
|
+
});
|
|
423
|
+
return branches.find((b) => b.id === id);
|
|
424
|
+
}
|
|
425
|
+
/**
|
|
426
|
+
* Push config from omnibase.toml to managed hosting.
|
|
427
|
+
*
|
|
428
|
+
* Everything except [local] is sent; managed hosting maps what it understands
|
|
429
|
+
* and reports the rest. [local] stays on this machine — that is where Stripe
|
|
430
|
+
* lives, since managed hosting owns Stripe env via the Connect account it
|
|
431
|
+
* provisions per branch.
|
|
432
|
+
*
|
|
433
|
+
* {VAR} secrets resolve from process.env, then an optional --from-env file.
|
|
434
|
+
* .env.local is NEVER read here — it is strictly for local dev (omnibase start).
|
|
341
435
|
*/
|
|
342
|
-
async function pushEnvConfig(envFlag) {
|
|
436
|
+
async function pushEnvConfig(envFlag, fromEnvPath) {
|
|
343
437
|
const root = (0, environment_1.findOmnibaseRoot)();
|
|
344
438
|
const env = await (0, environment_1.selectEnvironment)(envFlag);
|
|
345
439
|
if (env.name === "local") {
|
|
346
|
-
logger_1.logger.warn("Environment push is not available for local environment.");
|
|
347
|
-
logger_1.logger.log("
|
|
348
|
-
logger_1.logger.log(" omnibase cloud env push --env dev");
|
|
349
|
-
logger_1.logger.log(" omnibase cloud env push --env staging");
|
|
350
|
-
logger_1.logger.log(" omnibase cloud env push --env production");
|
|
440
|
+
logger_1.logger.warn("Environment push is not available for the local environment.");
|
|
441
|
+
logger_1.logger.log(" omnibase cloud env push --env <branch>");
|
|
351
442
|
return;
|
|
352
443
|
}
|
|
353
444
|
if (!env.branchId) {
|
|
354
|
-
throw new Error(`
|
|
355
|
-
`
|
|
445
|
+
throw new Error(`No branch ID resolved for environment '${env.name}'.\n` +
|
|
446
|
+
`Ensure your branch has finished provisioning.`);
|
|
356
447
|
}
|
|
357
448
|
if (!env.managedHostingApiUrl) {
|
|
358
|
-
throw new Error(`
|
|
359
|
-
`
|
|
449
|
+
throw new Error(`No managed hosting URL resolved for environment '${env.name}'.\n` +
|
|
450
|
+
`Ensure your profile is configured: 'omnibase cloud login'`);
|
|
451
|
+
}
|
|
452
|
+
const config = (0, config_1.loadConfig)(root);
|
|
453
|
+
if (!config.project_id) {
|
|
454
|
+
throw new Error("project_id is required in omnibase/omnibase.toml for cloud env push.");
|
|
455
|
+
}
|
|
456
|
+
// Cloud resolution is process.env then --from-env; .env.local is local-only.
|
|
457
|
+
const secrets = {};
|
|
458
|
+
for (const [k, v] of Object.entries(process.env)) {
|
|
459
|
+
if (v !== undefined)
|
|
460
|
+
secrets[k] = v;
|
|
461
|
+
}
|
|
462
|
+
if (fromEnvPath) {
|
|
463
|
+
const resolvedPath = path.resolve(fromEnvPath);
|
|
464
|
+
const parsed = (0, dotenv_1.config)({ path: resolvedPath }).parsed;
|
|
465
|
+
if (!parsed) {
|
|
466
|
+
throw new Error(`--from-env file not found or empty: ${resolvedPath}`);
|
|
467
|
+
}
|
|
468
|
+
for (const [k, v] of Object.entries(parsed)) {
|
|
469
|
+
if (!(k in secrets))
|
|
470
|
+
secrets[k] = v;
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
const resolved = (0, config_1.interpolateValue)(config, secrets);
|
|
474
|
+
const payload = (0, config_1.cloudConfigOf)(resolved);
|
|
475
|
+
const sections = Object.keys(payload);
|
|
476
|
+
if (sections.length === 0) {
|
|
477
|
+
logger_1.logger.info("Nothing to push: omnibase.toml has no cloud config sections.");
|
|
478
|
+
return;
|
|
360
479
|
}
|
|
361
|
-
const
|
|
362
|
-
|
|
363
|
-
|
|
480
|
+
const unresolved = [
|
|
481
|
+
...new Set(JSON.stringify(payload).match(/\{([A-Za-z_][A-Za-z0-9_]*)\}/g) ?? []),
|
|
482
|
+
];
|
|
483
|
+
if (unresolved.length > 0) {
|
|
484
|
+
logger_1.logger.warn(`Unresolved ${unresolved.join(", ")} left literal. ` +
|
|
485
|
+
`Set them in process.env or pass --from-env <file>.`);
|
|
486
|
+
}
|
|
487
|
+
logger_1.logger.start(`Applying config (${sections.join(", ")}) to branch ${env.name}...`);
|
|
364
488
|
const api = (0, api_client_1.createManagedHostingClient)(env);
|
|
365
489
|
try {
|
|
366
|
-
const response = await api.post(`/api/v1/
|
|
367
|
-
headers: {
|
|
368
|
-
"Content-Type": "text/plain",
|
|
369
|
-
},
|
|
370
|
-
});
|
|
490
|
+
const response = await api.post(`/api/v1/project_branches/${env.branchId}/env/config`, payload);
|
|
371
491
|
const result = response.data;
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
if (appliedServices.length > 0) {
|
|
375
|
-
logger_1.logger.succeed("Environment variables applied:");
|
|
376
|
-
for (const service of appliedServices) {
|
|
377
|
-
const keys = result.applied[service];
|
|
378
|
-
logger_1.logger.log(` ${service}: ${keys.join(", ")}`);
|
|
379
|
-
}
|
|
492
|
+
if (result.applied && result.applied.length > 0) {
|
|
493
|
+
logger_1.logger.succeed(`Config applied: ${result.applied.join(", ")}`);
|
|
380
494
|
}
|
|
381
495
|
else {
|
|
382
|
-
logger_1.logger.info("No
|
|
496
|
+
logger_1.logger.info("No config changes applied.");
|
|
383
497
|
}
|
|
384
|
-
// Show ignored keys
|
|
385
498
|
if (result.ignored && result.ignored.length > 0) {
|
|
386
|
-
logger_1.logger.
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
499
|
+
logger_1.logger.warn(`Ignored: ${result.ignored.join(", ")}`);
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
catch (error) {
|
|
503
|
+
throw new Error((0, errors_1.formatHttpError)(error));
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
/**
|
|
507
|
+
* Create a new branch
|
|
508
|
+
*/
|
|
509
|
+
async function branchNew(options) {
|
|
510
|
+
const root = (0, environment_1.findOmnibaseRoot)();
|
|
511
|
+
const config = (0, config_1.loadConfig)(root);
|
|
512
|
+
const api = (0, api_client_1.createProfileClient)();
|
|
513
|
+
const projectId = options.projectId ?? config.project_id ?? (await (0, prompts_1.input)({ message: "Project ID:" }));
|
|
514
|
+
const branchName = options.name ?? (await (0, prompts_1.input)({ message: "Branch name:", default: "dev" }));
|
|
515
|
+
const email = options.email ?? (await (0, prompts_1.input)({ message: "Billing email:" }));
|
|
516
|
+
let region = options.region;
|
|
517
|
+
let tier = options.tier;
|
|
518
|
+
if (!region || !tier) {
|
|
519
|
+
try {
|
|
520
|
+
const optsRes = await api.get("/api/v1/options");
|
|
521
|
+
const opts = optsRes.data;
|
|
522
|
+
if (!region && opts.regions?.length) {
|
|
523
|
+
region = await (0, prompts_1.select)({
|
|
524
|
+
message: "Region:",
|
|
525
|
+
choices: opts.regions.map((r) => ({ name: `${r.name} (${r.id})`, value: r.id })),
|
|
526
|
+
});
|
|
390
527
|
}
|
|
528
|
+
if (!tier && opts.tiers?.length) {
|
|
529
|
+
tier = await (0, prompts_1.select)({
|
|
530
|
+
message: "Deployment tier:",
|
|
531
|
+
choices: opts.tiers.map((t) => ({ name: `${t.name}`, value: t.id })),
|
|
532
|
+
});
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
catch {
|
|
536
|
+
if (!region)
|
|
537
|
+
region = await (0, prompts_1.input)({ message: "Region:", default: "syd" });
|
|
538
|
+
if (!tier)
|
|
539
|
+
tier = await (0, prompts_1.input)({ message: "Deployment tier:", default: "shared" });
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
logger_1.logger.start(`Creating branch '${branchName}'...`);
|
|
543
|
+
try {
|
|
544
|
+
const response = await api.post("/api/v1/project_branches", {
|
|
545
|
+
project_id: projectId,
|
|
546
|
+
branch_name: branchName,
|
|
547
|
+
region,
|
|
548
|
+
deployment_tier: tier,
|
|
549
|
+
billing_email: email,
|
|
550
|
+
});
|
|
551
|
+
const data = response.data;
|
|
552
|
+
logger_1.logger.succeed(`Branch '${branchName}' provisioning started`);
|
|
553
|
+
logger_1.logger.log(` Branch ID: ${data.branch_id}`);
|
|
554
|
+
logger_1.logger.log(` Status: ${data.status}`);
|
|
555
|
+
logger_1.logger.log("");
|
|
556
|
+
logger_1.logger.log("Next steps:");
|
|
557
|
+
logger_1.logger.log(` Use --env ${branchName} with any command once provisioning completes:`);
|
|
558
|
+
logger_1.logger.log(` omnibase cloud workers deploy --env ${branchName}`);
|
|
559
|
+
logger_1.logger.log(` omnibase db migrate push --env ${branchName}`);
|
|
560
|
+
}
|
|
561
|
+
catch (error) {
|
|
562
|
+
throw new Error((0, errors_1.formatHttpError)(error));
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
/**
|
|
566
|
+
* List branches for a project
|
|
567
|
+
*/
|
|
568
|
+
async function branchList(projectIdFlag) {
|
|
569
|
+
const root = (0, environment_1.findOmnibaseRoot)();
|
|
570
|
+
const api = (0, api_client_1.createProfileClient)();
|
|
571
|
+
const config = (0, config_1.loadConfig)(root);
|
|
572
|
+
const projectId = projectIdFlag ?? config.project_id;
|
|
573
|
+
if (!projectId) {
|
|
574
|
+
throw new Error("project_id is required. Provide --project-id or set it in omnibase.toml");
|
|
575
|
+
}
|
|
576
|
+
logger_1.logger.start("Fetching branches...");
|
|
577
|
+
try {
|
|
578
|
+
const response = await api.get(`/api/v1/projects/${projectId}/branches`);
|
|
579
|
+
const branches = response.data;
|
|
580
|
+
logger_1.logger.succeed(`Found ${branches?.length || 0} branches`);
|
|
581
|
+
if (!branches || branches.length === 0)
|
|
582
|
+
return;
|
|
583
|
+
for (const b of branches) {
|
|
584
|
+
const statusIcon = b.status === "active" ? "✓" : b.status === "provisioning" ? "…" : "✗";
|
|
585
|
+
logger_1.logger.log(` ${statusIcon} ${b.name} (${b.slug}) — ${b.status}`);
|
|
586
|
+
if (b.api_url)
|
|
587
|
+
logger_1.logger.log(` URL: ${b.api_url}`);
|
|
391
588
|
}
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
589
|
+
}
|
|
590
|
+
catch (error) {
|
|
591
|
+
logger_1.logger.fail("Failed to fetch branches");
|
|
592
|
+
throw new Error((0, errors_1.formatHttpError)(error));
|
|
593
|
+
}
|
|
594
|
+
}
|
|
595
|
+
/**
|
|
596
|
+
* Delete a branch by name or ID
|
|
597
|
+
*/
|
|
598
|
+
async function branchDelete(branchRef, projectIdFlag) {
|
|
599
|
+
const root = (0, environment_1.findOmnibaseRoot)();
|
|
600
|
+
const api = (0, api_client_1.createProfileClient)();
|
|
601
|
+
const config = (0, config_1.loadConfig)(root);
|
|
602
|
+
const projectId = projectIdFlag ?? config.project_id;
|
|
603
|
+
if (!projectId) {
|
|
604
|
+
throw new Error("project_id is required. Provide --project-id or set it in omnibase.toml");
|
|
605
|
+
}
|
|
606
|
+
logger_1.logger.start(`Resolving branch '${branchRef}'...`);
|
|
607
|
+
const response = await api.get(`/api/v1/projects/${projectId}/branches`);
|
|
608
|
+
const branches = response.data;
|
|
609
|
+
const match = branches.find((b) => b.id === branchRef || b.name === branchRef || b.slug === branchRef);
|
|
610
|
+
if (!match) {
|
|
611
|
+
logger_1.logger.fail(`Branch '${branchRef}' not found`);
|
|
612
|
+
throw new Error(`Branch '${branchRef}' not found in project ${projectId}`);
|
|
613
|
+
}
|
|
614
|
+
logger_1.logger.succeed(`Resolved to ${match.name} (${match.id})`);
|
|
615
|
+
logger_1.logger.start(`Deprovisioning branch '${branchRef}'...`);
|
|
616
|
+
try {
|
|
617
|
+
await api.delete(`/api/v1/project_branches/${match.id}`);
|
|
618
|
+
logger_1.logger.succeed(`Branch '${branchRef}' deprovisioning started`);
|
|
619
|
+
}
|
|
620
|
+
catch (error) {
|
|
621
|
+
logger_1.logger.fail("Failed to deprovision branch");
|
|
622
|
+
throw new Error((0, errors_1.formatHttpError)(error));
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
/**
|
|
626
|
+
* List workers for a branch
|
|
627
|
+
*/
|
|
628
|
+
async function listWorkers(envFlag) {
|
|
629
|
+
const env = await (0, environment_1.selectEnvironment)(envFlag);
|
|
630
|
+
const api = (0, api_client_1.createManagedHostingClient)(env);
|
|
631
|
+
const branchId = env.branchId;
|
|
632
|
+
if (!branchId) {
|
|
633
|
+
throw new Error("No branch selected");
|
|
634
|
+
}
|
|
635
|
+
logger_1.logger.start("Fetching workers...");
|
|
636
|
+
try {
|
|
637
|
+
const response = await api.get(`/api/v1/project_branches/${branchId}/workers`);
|
|
638
|
+
const workers = response.data;
|
|
639
|
+
logger_1.logger.succeed(`Found ${workers?.length || 0} worker(s)`);
|
|
640
|
+
if (!workers || workers.length === 0)
|
|
641
|
+
return;
|
|
642
|
+
for (const w of workers) {
|
|
643
|
+
logger_1.logger.log(` ${w.name}${w.worker_url ? ` — ${w.worker_url}` : ""}`);
|
|
398
644
|
}
|
|
399
645
|
}
|
|
400
646
|
catch (error) {
|
|
647
|
+
logger_1.logger.fail("Failed to fetch workers");
|
|
401
648
|
throw new Error((0, errors_1.formatHttpError)(error));
|
|
402
649
|
}
|
|
403
650
|
}
|
|
@@ -463,10 +710,68 @@ function addCloudCommands(program) {
|
|
|
463
710
|
workers
|
|
464
711
|
.command("deploy")
|
|
465
712
|
.description("Deploy workers to Cloudflare")
|
|
713
|
+
.option("--name <name>", "Deploy a specific deployment by name")
|
|
714
|
+
.option("--all", "Deploy all deployments")
|
|
715
|
+
.action(async (cmdOptions) => {
|
|
716
|
+
try {
|
|
717
|
+
const globalOptions = program.opts();
|
|
718
|
+
await deployWorkers(globalOptions.env, cmdOptions.name, cmdOptions.all);
|
|
719
|
+
}
|
|
720
|
+
catch (error) {
|
|
721
|
+
await (0, errors_1.handleCommandError)(error);
|
|
722
|
+
}
|
|
723
|
+
});
|
|
724
|
+
workers
|
|
725
|
+
.command("list")
|
|
726
|
+
.description("List deployed workers for a branch")
|
|
466
727
|
.action(async () => {
|
|
467
728
|
try {
|
|
468
729
|
const globalOptions = program.opts();
|
|
469
|
-
await
|
|
730
|
+
await listWorkers(globalOptions.env);
|
|
731
|
+
}
|
|
732
|
+
catch (error) {
|
|
733
|
+
await (0, errors_1.handleCommandError)(error);
|
|
734
|
+
}
|
|
735
|
+
});
|
|
736
|
+
// Branch subcommand
|
|
737
|
+
const branch = cloud
|
|
738
|
+
.command("branch")
|
|
739
|
+
.description("Manage project branches");
|
|
740
|
+
branch
|
|
741
|
+
.command("new")
|
|
742
|
+
.description("Create a new project branch")
|
|
743
|
+
.option("--project-id <id>", "Project ID")
|
|
744
|
+
.option("--name <name>", "Branch name")
|
|
745
|
+
.option("--region <region>", "Region (e.g. syd)")
|
|
746
|
+
.option("--tier <tier>", "Deployment tier (e.g. shared)")
|
|
747
|
+
.option("--email <email>", "Billing email")
|
|
748
|
+
.action(async (cmdOptions) => {
|
|
749
|
+
try {
|
|
750
|
+
await branchNew(cmdOptions);
|
|
751
|
+
}
|
|
752
|
+
catch (error) {
|
|
753
|
+
await (0, errors_1.handleCommandError)(error);
|
|
754
|
+
}
|
|
755
|
+
});
|
|
756
|
+
branch
|
|
757
|
+
.command("list")
|
|
758
|
+
.description("List branches")
|
|
759
|
+
.option("--project-id <id>", "Project ID")
|
|
760
|
+
.action(async (cmdOptions) => {
|
|
761
|
+
try {
|
|
762
|
+
await branchList(cmdOptions.projectId);
|
|
763
|
+
}
|
|
764
|
+
catch (error) {
|
|
765
|
+
await (0, errors_1.handleCommandError)(error);
|
|
766
|
+
}
|
|
767
|
+
});
|
|
768
|
+
branch
|
|
769
|
+
.command("rm <branch>")
|
|
770
|
+
.description("Delete a branch by name, slug, or ID")
|
|
771
|
+
.option("--project-id <id>", "Project ID")
|
|
772
|
+
.action(async (branchRef, cmdOptions) => {
|
|
773
|
+
try {
|
|
774
|
+
await branchDelete(branchRef, cmdOptions.projectId);
|
|
470
775
|
}
|
|
471
776
|
catch (error) {
|
|
472
777
|
await (0, errors_1.handleCommandError)(error);
|
|
@@ -478,11 +783,12 @@ function addCloudCommands(program) {
|
|
|
478
783
|
.description("Manage environment configuration");
|
|
479
784
|
envCmd
|
|
480
785
|
.command("push")
|
|
481
|
-
.description("Push
|
|
482
|
-
.
|
|
786
|
+
.description("Push omnibase.toml config to managed hosting")
|
|
787
|
+
.option("--from-env <path>", "Env file to resolve {VAR} secrets from (in addition to process.env). Never reads .env.local.")
|
|
788
|
+
.action(async (cmdOptions) => {
|
|
483
789
|
try {
|
|
484
790
|
const globalOptions = program.opts();
|
|
485
|
-
await pushEnvConfig(globalOptions.env);
|
|
791
|
+
await pushEnvConfig(globalOptions.env, cmdOptions.fromEnv);
|
|
486
792
|
}
|
|
487
793
|
catch (error) {
|
|
488
794
|
await (0, errors_1.handleCommandError)(error);
|