genbox 1.0.92 → 1.0.93
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/create.js +36 -3
- package/dist/commands/init.js +43 -0
- package/dist/scanner/index.js +3 -0
- package/dist/utils/env-parser.js +56 -0
- package/package.json +1 -1
package/dist/commands/create.js
CHANGED
|
@@ -796,11 +796,15 @@ function buildPayload(resolved, config, publicKey, privateKey, configLoader) {
|
|
|
796
796
|
const appPath = config.apps[app.name]?.path || app.name;
|
|
797
797
|
const repoPath = resolved.repos.find(r => r.name === app.name)?.path ||
|
|
798
798
|
(resolved.repos[0]?.path ? `${resolved.repos[0].path}/${appPath}` : `/home/dev/${config.project.name}/${appPath}`);
|
|
799
|
+
// Get runner type to determine infrastructure URL prefix (docker vs host)
|
|
800
|
+
const runner = config.apps[app.name]?.runner || 'pm2';
|
|
801
|
+
const infraUrlMap = (0, utils_1.buildInfraUrlMap)(envVarsFromFile, runner);
|
|
802
|
+
const combinedUrlMap = { ...serviceUrlMap, ...infraUrlMap };
|
|
799
803
|
const servicesSections = Array.from(sections.keys()).filter(s => s.startsWith(`${app.name}/`));
|
|
800
804
|
if (servicesSections.length > 0) {
|
|
801
805
|
for (const serviceSectionName of servicesSections) {
|
|
802
806
|
const serviceName = serviceSectionName.split('/')[1];
|
|
803
|
-
const serviceEnvContent = (0, utils_1.buildAppEnvContent)(sections, serviceSectionName,
|
|
807
|
+
const serviceEnvContent = (0, utils_1.buildAppEnvContent)(sections, serviceSectionName, combinedUrlMap);
|
|
804
808
|
const stagingName = `${app.name}-${serviceName}.env`;
|
|
805
809
|
const targetPath = `${repoPath}/apps/${serviceName}/.env`;
|
|
806
810
|
files.push({
|
|
@@ -812,7 +816,7 @@ function buildPayload(resolved, config, publicKey, privateKey, configLoader) {
|
|
|
812
816
|
}
|
|
813
817
|
}
|
|
814
818
|
else {
|
|
815
|
-
const appEnvContent = (0, utils_1.buildAppEnvContent)(sections, app.name,
|
|
819
|
+
const appEnvContent = (0, utils_1.buildAppEnvContent)(sections, app.name, combinedUrlMap);
|
|
816
820
|
files.push({
|
|
817
821
|
path: `/home/dev/.env-staging/${app.name}.env`,
|
|
818
822
|
content: appEnvContent,
|
|
@@ -934,10 +938,39 @@ function generateSetupScript(resolved, config, envFilesToMove = []) {
|
|
|
934
938
|
lines.push(' \' "$file" | grep -v "^$" | head -n -1');
|
|
935
939
|
lines.push(' }');
|
|
936
940
|
lines.push('');
|
|
941
|
+
lines.push(' # Function to expand infrastructure URL placeholders based on runner type');
|
|
942
|
+
lines.push(' # Docker apps use DOCKER_* values, PM2/host apps use HOST_* values');
|
|
943
|
+
lines.push(' expand_infra_urls() {');
|
|
944
|
+
lines.push(' local envfile="$1"');
|
|
945
|
+
lines.push(' local runner="$2"');
|
|
946
|
+
lines.push(' if [ "$runner" = "docker" ]; then');
|
|
947
|
+
lines.push(' # For docker apps, replace ${VAR} with DOCKER_VAR value');
|
|
948
|
+
lines.push(' for var in MONGODB_URI MONGO_URI REDIS_URL REDIS_URI RABBITMQ_URL AMQP_URL DATABASE_URL DATABASE_URI; do');
|
|
949
|
+
lines.push(' docker_val=$(grep "^DOCKER_${var}=" /home/dev/.env.genbox 2>/dev/null | cut -d= -f2-)');
|
|
950
|
+
lines.push(' if [ -n "$docker_val" ]; then');
|
|
951
|
+
lines.push(' sed -i "s|\\${${var}}|${docker_val}|g" "$envfile"');
|
|
952
|
+
lines.push(' fi');
|
|
953
|
+
lines.push(' done');
|
|
954
|
+
lines.push(' else');
|
|
955
|
+
lines.push(' # For PM2/host apps, replace ${VAR} with HOST_VAR value');
|
|
956
|
+
lines.push(' for var in MONGODB_URI MONGO_URI REDIS_URL REDIS_URI RABBITMQ_URL AMQP_URL DATABASE_URL DATABASE_URI; do');
|
|
957
|
+
lines.push(' host_val=$(grep "^HOST_${var}=" /home/dev/.env.genbox 2>/dev/null | cut -d= -f2-)');
|
|
958
|
+
lines.push(' if [ -n "$host_val" ]; then');
|
|
959
|
+
lines.push(' sed -i "s|\\${${var}}|${host_val}|g" "$envfile"');
|
|
960
|
+
lines.push(' fi');
|
|
961
|
+
lines.push(' done');
|
|
962
|
+
lines.push(' fi');
|
|
963
|
+
lines.push(' }');
|
|
964
|
+
lines.push('');
|
|
937
965
|
for (const { stagingName, targetPath } of envFilesToMove) {
|
|
938
|
-
|
|
966
|
+
// Determine runner type for this app
|
|
967
|
+
// stagingName could be "appName" or "appName/serviceName" for service sections
|
|
968
|
+
const appName = stagingName.includes('/') ? stagingName.split('/')[0] : stagingName;
|
|
969
|
+
const runner = config.apps[appName]?.runner || 'pm2';
|
|
970
|
+
lines.push(` # Create .env for ${stagingName} (runner: ${runner})`);
|
|
939
971
|
lines.push(` mkdir -p "$(dirname "${targetPath}")"`);
|
|
940
972
|
lines.push(` extract_section "${stagingName}" /home/dev/.env.genbox > "${targetPath}"`);
|
|
973
|
+
lines.push(` expand_infra_urls "${targetPath}" "${runner}"`);
|
|
941
974
|
lines.push(` echo " Created ${targetPath}"`);
|
|
942
975
|
}
|
|
943
976
|
lines.push('');
|
package/dist/commands/init.js
CHANGED
|
@@ -162,12 +162,19 @@ function convertScanToDetected(scan, root) {
|
|
|
162
162
|
}
|
|
163
163
|
}
|
|
164
164
|
}
|
|
165
|
+
// Map to store git info for directories with docker apps (to preserve repo info)
|
|
166
|
+
const dockerDirGitInfo = new Map();
|
|
165
167
|
// Convert apps from package.json (skip if docker app builds from same directory)
|
|
166
168
|
const isMultiRepo = scan.structure.type === 'hybrid';
|
|
167
169
|
for (const app of scan.apps) {
|
|
168
170
|
// Skip if there's a docker app building from this directory
|
|
169
171
|
const normalizedPath = app.path.replace(/^\.?\/?/, '').replace(/\/$/, '');
|
|
170
172
|
if (dockerBuildContexts.has(normalizedPath)) {
|
|
173
|
+
// Save git info for this directory so docker apps can use it
|
|
174
|
+
const gitInfo = detectGitForDirectory(path_1.default.join(root, app.path));
|
|
175
|
+
if (gitInfo) {
|
|
176
|
+
dockerDirGitInfo.set(normalizedPath, gitInfo);
|
|
177
|
+
}
|
|
171
178
|
continue; // Docker app takes precedence
|
|
172
179
|
}
|
|
173
180
|
const mappedType = mapAppType(app.type);
|
|
@@ -195,6 +202,8 @@ function convertScanToDetected(scan, root) {
|
|
|
195
202
|
git: appGit,
|
|
196
203
|
};
|
|
197
204
|
}
|
|
205
|
+
// Store dockerDirGitInfo for use when adding docker apps
|
|
206
|
+
const _dockerDirGitInfo = dockerDirGitInfo;
|
|
198
207
|
// Convert infrastructure (keep all, no deduplication - user selects by source file)
|
|
199
208
|
if (scan.compose) {
|
|
200
209
|
detected.infrastructure = [];
|
|
@@ -263,6 +272,9 @@ function convertScanToDetected(scan, root) {
|
|
|
263
272
|
continue; // Same source, skip duplicate
|
|
264
273
|
}
|
|
265
274
|
}
|
|
275
|
+
// Look up git info for this docker app's build context
|
|
276
|
+
const buildContext = dockerApp.build?.context?.replace(/^\.?\/?/, '').replace(/\/$/, '') || '';
|
|
277
|
+
const dockerAppGit = _dockerDirGitInfo.get(buildContext);
|
|
266
278
|
detected.apps[detectedAppKey] = {
|
|
267
279
|
path: dockerApp.build?.context || '.',
|
|
268
280
|
type: mappedType,
|
|
@@ -278,6 +290,7 @@ function convertScanToDetected(scan, root) {
|
|
|
278
290
|
port: dockerApp.ports?.[0]?.host,
|
|
279
291
|
port_source: `${dockerApp.sourceFile || 'docker-compose.yml'} ports`,
|
|
280
292
|
source: dockerApp.sourceFile || 'docker-compose',
|
|
293
|
+
git: dockerAppGit,
|
|
281
294
|
};
|
|
282
295
|
}
|
|
283
296
|
}
|
|
@@ -1408,6 +1421,36 @@ function generateEnvFile(projectName, detected, envVars, serviceUrlMappings) {
|
|
|
1408
1421
|
}
|
|
1409
1422
|
}
|
|
1410
1423
|
}
|
|
1424
|
+
// Add infrastructure URL mappings (HOST_ vs DOCKER_ prefixes)
|
|
1425
|
+
// These are used to differentiate between PM2 apps (use HOST_*) and Docker apps (use DOCKER_*)
|
|
1426
|
+
if (detected.infrastructure && detected.infrastructure.length > 0) {
|
|
1427
|
+
content += `\n# Infrastructure URL Configuration\n`;
|
|
1428
|
+
content += `# HOST_* = for PM2/host-based apps (uses localhost)\n`;
|
|
1429
|
+
content += `# DOCKER_* = for Docker apps (uses docker network hostnames)\n\n`;
|
|
1430
|
+
for (const infra of detected.infrastructure) {
|
|
1431
|
+
const name = infra.name.toLowerCase();
|
|
1432
|
+
const port = infra.port;
|
|
1433
|
+
if (infra.type === 'database' && infra.image?.includes('mongo')) {
|
|
1434
|
+
// MongoDB - use project name as database name
|
|
1435
|
+
const dbName = projectName.replace(/[^a-zA-Z0-9]/g, '').toLowerCase();
|
|
1436
|
+
content += `HOST_MONGODB_URI=mongodb://localhost:${port}/${dbName}\n`;
|
|
1437
|
+
content += `DOCKER_MONGODB_URI=mongodb://${name}:27017/${dbName}\n`;
|
|
1438
|
+
content += `MONGODB_URI=\${MONGODB_URI}\n\n`;
|
|
1439
|
+
}
|
|
1440
|
+
else if (infra.type === 'cache' && infra.image?.includes('redis')) {
|
|
1441
|
+
// Redis
|
|
1442
|
+
content += `HOST_REDIS_URL=redis://localhost:${port}\n`;
|
|
1443
|
+
content += `DOCKER_REDIS_URL=redis://${name}:6379\n`;
|
|
1444
|
+
content += `REDIS_URL=\${REDIS_URL}\n\n`;
|
|
1445
|
+
}
|
|
1446
|
+
else if (infra.type === 'queue' && infra.image?.includes('rabbitmq')) {
|
|
1447
|
+
// RabbitMQ
|
|
1448
|
+
content += `HOST_RABBITMQ_URL=amqp://localhost:${port}\n`;
|
|
1449
|
+
content += `DOCKER_RABBITMQ_URL=amqp://${name}:5672\n`;
|
|
1450
|
+
content += `RABBITMQ_URL=\${RABBITMQ_URL}\n\n`;
|
|
1451
|
+
}
|
|
1452
|
+
}
|
|
1453
|
+
}
|
|
1411
1454
|
// Add GIT_TOKEN placeholder if not present
|
|
1412
1455
|
if (!envVars['GIT_TOKEN']) {
|
|
1413
1456
|
content += `\n# Git authentication\n# GIT_TOKEN=ghp_xxxxxxxxxxxx\n`;
|
package/dist/scanner/index.js
CHANGED
|
@@ -133,6 +133,9 @@ class ProjectScanner {
|
|
|
133
133
|
type: 'backend', // Will be refined by framework detection
|
|
134
134
|
scripts,
|
|
135
135
|
});
|
|
136
|
+
// Also scan first-level subdirectories for additional apps
|
|
137
|
+
const subApps = await this.discoverMultiRepoApps(root, exclude);
|
|
138
|
+
apps.push(...subApps);
|
|
136
139
|
}
|
|
137
140
|
return apps;
|
|
138
141
|
}
|
package/dist/utils/env-parser.js
CHANGED
|
@@ -7,6 +7,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
7
7
|
exports.parseEnvGenboxSections = parseEnvGenboxSections;
|
|
8
8
|
exports.buildServiceUrlMap = buildServiceUrlMap;
|
|
9
9
|
exports.buildAppEnvContent = buildAppEnvContent;
|
|
10
|
+
exports.buildInfraUrlMap = buildInfraUrlMap;
|
|
10
11
|
exports.parseEnvVarsFromSection = parseEnvVarsFromSection;
|
|
11
12
|
/**
|
|
12
13
|
* Parse .env.genbox file into segregated sections
|
|
@@ -106,6 +107,61 @@ function buildAppEnvContent(sections, appName, serviceUrlMap) {
|
|
|
106
107
|
.trim();
|
|
107
108
|
return envContent;
|
|
108
109
|
}
|
|
110
|
+
/**
|
|
111
|
+
* Infrastructure variable patterns that need HOST_ vs DOCKER_ prefixes
|
|
112
|
+
* These are database/cache/queue connection strings that differ between
|
|
113
|
+
* host-based apps (PM2) and containerized apps (Docker)
|
|
114
|
+
*/
|
|
115
|
+
const INFRA_VAR_PATTERNS = [
|
|
116
|
+
/^(MONGODB|MONGO)_URI$/i,
|
|
117
|
+
/^(MONGODB|MONGO)_URL$/i,
|
|
118
|
+
/^(REDIS)_URL$/i,
|
|
119
|
+
/^(REDIS)_URI$/i,
|
|
120
|
+
/^(RABBITMQ|RABBIT|AMQP)_URL$/i,
|
|
121
|
+
/^(RABBITMQ|RABBIT|AMQP)_URI$/i,
|
|
122
|
+
/^(POSTGRES|POSTGRESQL|PG)_URL$/i,
|
|
123
|
+
/^(POSTGRES|POSTGRESQL|PG)_URI$/i,
|
|
124
|
+
/^DATABASE_URL$/i,
|
|
125
|
+
/^DATABASE_URI$/i,
|
|
126
|
+
];
|
|
127
|
+
/**
|
|
128
|
+
* Build a map of infrastructure URL variables based on runner type
|
|
129
|
+
* For docker apps: use DOCKER_* prefixed values (e.g., mongodb://mongodb:27017)
|
|
130
|
+
* For host/PM2 apps: use HOST_* prefixed values (e.g., mongodb://localhost:27018)
|
|
131
|
+
*
|
|
132
|
+
* Example .env.genbox:
|
|
133
|
+
* HOST_MONGODB_URI=mongodb://localhost:27018/myapp
|
|
134
|
+
* DOCKER_MONGODB_URI=mongodb://mongodb:27017/myapp
|
|
135
|
+
* MONGODB_URI=${MONGODB_URI} # Placeholder that gets expanded
|
|
136
|
+
*/
|
|
137
|
+
function buildInfraUrlMap(envVarsFromFile, runner) {
|
|
138
|
+
const urlMap = {};
|
|
139
|
+
const useDocker = runner === 'docker';
|
|
140
|
+
const prefix = useDocker ? 'DOCKER_' : 'HOST_';
|
|
141
|
+
// Find all infrastructure variables that have HOST_ or DOCKER_ prefixes
|
|
142
|
+
const infraVarNames = new Set();
|
|
143
|
+
for (const key of Object.keys(envVarsFromFile)) {
|
|
144
|
+
const match = key.match(/^(HOST|DOCKER)_(.+)$/);
|
|
145
|
+
if (match) {
|
|
146
|
+
const varName = match[2];
|
|
147
|
+
// Check if it's an infrastructure variable
|
|
148
|
+
if (INFRA_VAR_PATTERNS.some(pattern => pattern.test(varName))) {
|
|
149
|
+
infraVarNames.add(varName);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
// Build mapping: VARNAME → value from appropriate prefix
|
|
154
|
+
for (const varName of infraVarNames) {
|
|
155
|
+
const prefixedKey = `${prefix}${varName}`;
|
|
156
|
+
const fallbackKey = useDocker ? `HOST_${varName}` : `DOCKER_${varName}`;
|
|
157
|
+
// Use prefixed value if available, otherwise fall back
|
|
158
|
+
const value = envVarsFromFile[prefixedKey] || envVarsFromFile[fallbackKey];
|
|
159
|
+
if (value) {
|
|
160
|
+
urlMap[varName] = value;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
return urlMap;
|
|
164
|
+
}
|
|
109
165
|
/**
|
|
110
166
|
* Parse env vars from a section content string
|
|
111
167
|
*/
|