@geekmidas/cli 0.14.0 → 0.16.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/{bundler-DWctKN1z.mjs → bundler-B6z6HEeh.mjs} +39 -5
- package/dist/bundler-B6z6HEeh.mjs.map +1 -0
- package/dist/{bundler-BjholBlA.cjs → bundler-C74EKlNa.cjs} +38 -4
- package/dist/bundler-C74EKlNa.cjs.map +1 -0
- package/dist/index.cjs +73 -15
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +74 -16
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
- package/src/build/__tests__/bundler.spec.ts +5 -3
- package/src/build/bundler.ts +54 -5
- package/src/deploy/__tests__/docker.spec.ts +44 -6
- package/src/deploy/__tests__/index.spec.ts +62 -0
- package/src/deploy/docker.ts +77 -2
- package/src/deploy/index.ts +63 -20
- package/src/deploy/types.ts +5 -1
- package/dist/bundler-BjholBlA.cjs.map +0 -1
- package/dist/bundler-DWctKN1z.mjs.map +0 -1
package/dist/index.mjs
CHANGED
|
@@ -5,7 +5,7 @@ import { DokployApi } from "./dokploy-api-CaETb2L6.mjs";
|
|
|
5
5
|
import { generateReactQueryCommand } from "./openapi-react-query-CM2_qlW9.mjs";
|
|
6
6
|
import { maskPassword, readStageSecrets, secretsExist, setCustomSecret, writeStageSecrets } from "./storage-BaOP55oq.mjs";
|
|
7
7
|
import { createRequire } from "node:module";
|
|
8
|
-
import { copyFileSync, existsSync, mkdirSync, unlinkSync } from "node:fs";
|
|
8
|
+
import { copyFileSync, existsSync, mkdirSync, readFileSync, unlinkSync } from "node:fs";
|
|
9
9
|
import { basename, dirname, join, parse, relative, resolve } from "node:path";
|
|
10
10
|
import { Command } from "commander";
|
|
11
11
|
import { stdin, stdout } from "node:process";
|
|
@@ -29,7 +29,7 @@ var __require = /* @__PURE__ */ createRequire(import.meta.url);
|
|
|
29
29
|
//#endregion
|
|
30
30
|
//#region package.json
|
|
31
31
|
var name = "@geekmidas/cli";
|
|
32
|
-
var version = "0.
|
|
32
|
+
var version = "0.16.0";
|
|
33
33
|
var description = "CLI tools for building Lambda handlers, server applications, and generating OpenAPI specs";
|
|
34
34
|
var private$1 = false;
|
|
35
35
|
var type = "module";
|
|
@@ -1297,7 +1297,7 @@ async function buildForProvider(provider, context, rootOutputDir, endpointGenera
|
|
|
1297
1297
|
let masterKey;
|
|
1298
1298
|
if (context.production?.bundle && !skipBundle) {
|
|
1299
1299
|
logger$6.log(`\n📦 Bundling production server...`);
|
|
1300
|
-
const { bundleServer } = await import("./bundler-
|
|
1300
|
+
const { bundleServer } = await import("./bundler-B6z6HEeh.mjs");
|
|
1301
1301
|
const allConstructs = [
|
|
1302
1302
|
...endpoints.map((e) => e.construct),
|
|
1303
1303
|
...functions.map((f) => f.construct),
|
|
@@ -2084,6 +2084,36 @@ async function pushDockerImage(imageName, options) {
|
|
|
2084
2084
|
|
|
2085
2085
|
//#endregion
|
|
2086
2086
|
//#region src/deploy/docker.ts
|
|
2087
|
+
/**
|
|
2088
|
+
* Get app name from package.json in the current working directory
|
|
2089
|
+
* Used for Dokploy app/project naming
|
|
2090
|
+
*/
|
|
2091
|
+
function getAppNameFromCwd() {
|
|
2092
|
+
const packageJsonPath = join(process.cwd(), "package.json");
|
|
2093
|
+
if (!existsSync(packageJsonPath)) return void 0;
|
|
2094
|
+
try {
|
|
2095
|
+
const pkg = JSON.parse(readFileSync(packageJsonPath, "utf-8"));
|
|
2096
|
+
if (pkg.name) return pkg.name.replace(/^@[^/]+\//, "");
|
|
2097
|
+
} catch {}
|
|
2098
|
+
return void 0;
|
|
2099
|
+
}
|
|
2100
|
+
/**
|
|
2101
|
+
* Get app name from package.json adjacent to the lockfile (project root)
|
|
2102
|
+
* Used for Docker image naming
|
|
2103
|
+
*/
|
|
2104
|
+
function getAppNameFromPackageJson() {
|
|
2105
|
+
const cwd = process.cwd();
|
|
2106
|
+
const lockfilePath = findLockfilePath(cwd);
|
|
2107
|
+
if (!lockfilePath) return void 0;
|
|
2108
|
+
const projectRoot = dirname(lockfilePath);
|
|
2109
|
+
const packageJsonPath = join(projectRoot, "package.json");
|
|
2110
|
+
if (!existsSync(packageJsonPath)) return void 0;
|
|
2111
|
+
try {
|
|
2112
|
+
const pkg = JSON.parse(readFileSync(packageJsonPath, "utf-8"));
|
|
2113
|
+
if (pkg.name) return pkg.name.replace(/^@[^/]+\//, "");
|
|
2114
|
+
} catch {}
|
|
2115
|
+
return void 0;
|
|
2116
|
+
}
|
|
2087
2117
|
const logger$4 = console;
|
|
2088
2118
|
/**
|
|
2089
2119
|
* Get the full image reference
|
|
@@ -2148,7 +2178,7 @@ async function pushImage(imageRef) {
|
|
|
2148
2178
|
*/
|
|
2149
2179
|
async function deployDocker(options) {
|
|
2150
2180
|
const { stage, tag, skipPush, masterKey, config: config$1 } = options;
|
|
2151
|
-
const imageName = config$1.imageName
|
|
2181
|
+
const imageName = config$1.imageName;
|
|
2152
2182
|
const imageRef = getImageRef(config$1.registry, imageName, tag);
|
|
2153
2183
|
await buildImage(imageRef);
|
|
2154
2184
|
if (!skipPush) if (!config$1.registry) logger$4.warn("\n⚠️ No registry configured. Use --skip-push or configure docker.registry in gkm.config.ts");
|
|
@@ -2170,11 +2200,19 @@ async function deployDocker(options) {
|
|
|
2170
2200
|
}
|
|
2171
2201
|
/**
|
|
2172
2202
|
* Resolve Docker deploy config from gkm config
|
|
2203
|
+
* - imageName: from config, or cwd package.json, or 'app' (for Docker image)
|
|
2204
|
+
* - projectName: from root package.json, or 'app' (for Dokploy project)
|
|
2205
|
+
* - appName: from cwd package.json, or projectName (for Dokploy app within project)
|
|
2173
2206
|
*/
|
|
2174
2207
|
function resolveDockerConfig(config$1) {
|
|
2208
|
+
const projectName = getAppNameFromPackageJson() ?? "app";
|
|
2209
|
+
const appName = getAppNameFromCwd() ?? projectName;
|
|
2210
|
+
const imageName = config$1.docker?.imageName ?? appName;
|
|
2175
2211
|
return {
|
|
2176
2212
|
registry: config$1.docker?.registry,
|
|
2177
|
-
imageName
|
|
2213
|
+
imageName,
|
|
2214
|
+
projectName,
|
|
2215
|
+
appName
|
|
2178
2216
|
};
|
|
2179
2217
|
}
|
|
2180
2218
|
|
|
@@ -2502,8 +2540,13 @@ async function provisionServices(api, projectId, environmentId, appName, service
|
|
|
2502
2540
|
logger$1.log(` ✓ Created PostgreSQL: ${postgres.postgresId}`);
|
|
2503
2541
|
await api.deployPostgres(postgres.postgresId);
|
|
2504
2542
|
logger$1.log(" ✓ PostgreSQL deployed");
|
|
2543
|
+
serviceUrls.DATABASE_HOST = postgres.appName;
|
|
2544
|
+
serviceUrls.DATABASE_PORT = "5432";
|
|
2545
|
+
serviceUrls.DATABASE_NAME = postgres.databaseName;
|
|
2546
|
+
serviceUrls.DATABASE_USER = postgres.databaseUser;
|
|
2547
|
+
serviceUrls.DATABASE_PASSWORD = postgres.databasePassword;
|
|
2505
2548
|
serviceUrls.DATABASE_URL = `postgresql://${postgres.databaseUser}:${postgres.databasePassword}@${postgres.appName}:5432/${postgres.databaseName}`;
|
|
2506
|
-
logger$1.log(` ✓
|
|
2549
|
+
logger$1.log(` ✓ Database credentials configured`);
|
|
2507
2550
|
} catch (error) {
|
|
2508
2551
|
const message = error instanceof Error ? error.message : "Unknown error";
|
|
2509
2552
|
if (message.includes("already exists") || message.includes("duplicate")) logger$1.log(` ℹ PostgreSQL already exists`);
|
|
@@ -2521,9 +2564,12 @@ async function provisionServices(api, projectId, environmentId, appName, service
|
|
|
2521
2564
|
logger$1.log(` ✓ Created Redis: ${redis.redisId}`);
|
|
2522
2565
|
await api.deployRedis(redis.redisId);
|
|
2523
2566
|
logger$1.log(" ✓ Redis deployed");
|
|
2567
|
+
serviceUrls.REDIS_HOST = redis.appName;
|
|
2568
|
+
serviceUrls.REDIS_PORT = "6379";
|
|
2569
|
+
if (redis.databasePassword) serviceUrls.REDIS_PASSWORD = redis.databasePassword;
|
|
2524
2570
|
const password = redis.databasePassword ? `:${redis.databasePassword}@` : "";
|
|
2525
2571
|
serviceUrls.REDIS_URL = `redis://${password}${redis.appName}:6379`;
|
|
2526
|
-
logger$1.log(` ✓
|
|
2572
|
+
logger$1.log(` ✓ Redis credentials configured`);
|
|
2527
2573
|
} catch (error) {
|
|
2528
2574
|
const message = error instanceof Error ? error.message : "Unknown error";
|
|
2529
2575
|
if (message.includes("already exists") || message.includes("duplicate")) logger$1.log(` ℹ Redis already exists`);
|
|
@@ -2585,7 +2631,7 @@ async function ensureDokploySetup(config$1, dockerConfig, stage, services) {
|
|
|
2585
2631
|
}
|
|
2586
2632
|
const environmentId$1 = environment.environmentId;
|
|
2587
2633
|
logger$1.log(` Services config: ${JSON.stringify(services)}, envId: ${environmentId$1}`);
|
|
2588
|
-
const serviceUrls$1 = await provisionServices(api, existingConfig.projectId, environmentId$1, dockerConfig.
|
|
2634
|
+
const serviceUrls$1 = await provisionServices(api, existingConfig.projectId, environmentId$1, dockerConfig.appName, services, existingUrls);
|
|
2589
2635
|
return {
|
|
2590
2636
|
config: {
|
|
2591
2637
|
endpoint: existingConfig.endpoint,
|
|
@@ -2601,7 +2647,7 @@ async function ensureDokploySetup(config$1, dockerConfig, stage, services) {
|
|
|
2601
2647
|
}
|
|
2602
2648
|
}
|
|
2603
2649
|
logger$1.log("\n📁 Looking for project...");
|
|
2604
|
-
const projectName = dockerConfig.
|
|
2650
|
+
const projectName = dockerConfig.projectName;
|
|
2605
2651
|
const projects = await api.listProjects();
|
|
2606
2652
|
let project = projects.find((p) => p.name.toLowerCase() === projectName.toLowerCase());
|
|
2607
2653
|
let environmentId;
|
|
@@ -2632,7 +2678,7 @@ async function ensureDokploySetup(config$1, dockerConfig, stage, services) {
|
|
|
2632
2678
|
logger$1.log(` ✓ Using environment: ${stage}`);
|
|
2633
2679
|
}
|
|
2634
2680
|
logger$1.log("\n📦 Looking for application...");
|
|
2635
|
-
const appName = dockerConfig.
|
|
2681
|
+
const appName = dockerConfig.appName;
|
|
2636
2682
|
let applicationId;
|
|
2637
2683
|
if (existingConfig && typeof existingConfig !== "boolean" && existingConfig.applicationId) {
|
|
2638
2684
|
applicationId = existingConfig.applicationId;
|
|
@@ -2701,7 +2747,7 @@ async function ensureDokploySetup(config$1, dockerConfig, stage, services) {
|
|
|
2701
2747
|
logger$1.log(` Project: ${project.projectId}`);
|
|
2702
2748
|
logger$1.log(` Application: ${applicationId}`);
|
|
2703
2749
|
if (registryId) logger$1.log(` Registry: ${registryId}`);
|
|
2704
|
-
const serviceUrls = await provisionServices(api, project.projectId, environmentId, dockerConfig.
|
|
2750
|
+
const serviceUrls = await provisionServices(api, project.projectId, environmentId, dockerConfig.appName, services, existingUrls);
|
|
2705
2751
|
return {
|
|
2706
2752
|
config: dokployConfig,
|
|
2707
2753
|
serviceUrls
|
|
@@ -2725,7 +2771,7 @@ async function deployCommand(options) {
|
|
|
2725
2771
|
const imageTag = tag ?? generateTag(stage);
|
|
2726
2772
|
logger$1.log(` Tag: ${imageTag}`);
|
|
2727
2773
|
const dockerConfig = resolveDockerConfig(config$1);
|
|
2728
|
-
const imageName = dockerConfig.imageName
|
|
2774
|
+
const imageName = dockerConfig.imageName;
|
|
2729
2775
|
const registry = dockerConfig.registry;
|
|
2730
2776
|
const imageRef = registry ? `${registry}/${imageName}:${imageTag}` : `${imageName}:${imageTag}`;
|
|
2731
2777
|
let dokployConfig;
|
|
@@ -2753,11 +2799,23 @@ async function deployCommand(options) {
|
|
|
2753
2799
|
secrets = initStageSecrets(stage);
|
|
2754
2800
|
}
|
|
2755
2801
|
let updated = false;
|
|
2802
|
+
const urlFields = [
|
|
2803
|
+
"DATABASE_URL",
|
|
2804
|
+
"REDIS_URL",
|
|
2805
|
+
"RABBITMQ_URL"
|
|
2806
|
+
];
|
|
2756
2807
|
for (const [key, value] of Object.entries(setupResult.serviceUrls)) {
|
|
2757
|
-
|
|
2758
|
-
if (
|
|
2759
|
-
|
|
2760
|
-
|
|
2808
|
+
if (!value) continue;
|
|
2809
|
+
if (urlFields.includes(key)) {
|
|
2810
|
+
const urlKey = key;
|
|
2811
|
+
if (!secrets.urls[urlKey]) {
|
|
2812
|
+
secrets.urls[urlKey] = value;
|
|
2813
|
+
logger$1.log(` Saved ${key} to secrets.urls`);
|
|
2814
|
+
updated = true;
|
|
2815
|
+
}
|
|
2816
|
+
} else if (!secrets.custom[key]) {
|
|
2817
|
+
secrets.custom[key] = value;
|
|
2818
|
+
logger$1.log(` Saved ${key} to secrets.custom`);
|
|
2761
2819
|
updated = true;
|
|
2762
2820
|
}
|
|
2763
2821
|
}
|