@aifabrix/builder 2.37.0 → 2.37.5
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/.cursor/rules/project-rules.mdc +19 -0
- package/integration/hubspot/test.js +1 -1
- package/lib/api/wizard.api.js +24 -1
- package/lib/app/deploy.js +43 -7
- package/lib/app/list.js +3 -1
- package/lib/build/index.js +3 -4
- package/lib/cli/setup-app.js +1 -0
- package/lib/cli/setup-external-system.js +1 -0
- package/lib/cli/setup-utility.js +1 -1
- package/lib/commands/up-common.js +31 -1
- package/lib/commands/up-miso.js +5 -1
- package/lib/commands/wizard-core.js +32 -7
- package/lib/deployment/deployer-status.js +101 -0
- package/lib/deployment/deployer.js +62 -110
- package/lib/deployment/environment.js +133 -34
- package/lib/external-system/deploy.js +5 -1
- package/lib/external-system/test-auth.js +14 -7
- package/lib/generator/wizard.js +27 -16
- package/lib/schema/environment-deploy-request.schema.json +64 -0
- package/lib/utils/paths.js +22 -4
- package/lib/utils/secrets-generator.js +23 -8
- package/lib/utils/secrets-helpers.js +46 -21
- package/package.json +1 -1
- package/scripts/install-local.js +11 -2
- package/templates/external-system/deploy.js.hbs +11 -0
- package/templates/infra/environment-dev.json +10 -0
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "http://json-schema.org/draft-07/schema#",
|
|
3
|
+
"$id": "https://raw.githubusercontent.com/esystemsdev/aifabrix-builder/refs/heads/main/lib/schema/environment-deploy-request.schema.json",
|
|
4
|
+
"title": "Environment Deploy Request",
|
|
5
|
+
"description": "Request body for POST /api/v1/environments/{envKey}/deploy",
|
|
6
|
+
"type": "object",
|
|
7
|
+
"required": ["environmentConfig"],
|
|
8
|
+
"properties": {
|
|
9
|
+
"environmentConfig": {
|
|
10
|
+
"type": "object",
|
|
11
|
+
"description": "Environment infrastructure configuration",
|
|
12
|
+
"required": ["key", "environment", "preset", "serviceName", "location"],
|
|
13
|
+
"properties": {
|
|
14
|
+
"key": {
|
|
15
|
+
"type": "string",
|
|
16
|
+
"description": "Environment key",
|
|
17
|
+
"pattern": "^[a-z0-9-]+$",
|
|
18
|
+
"minLength": 2,
|
|
19
|
+
"maxLength": 40
|
|
20
|
+
},
|
|
21
|
+
"environment": {
|
|
22
|
+
"type": "string",
|
|
23
|
+
"description": "Environment type",
|
|
24
|
+
"enum": ["miso", "dev", "tst", "pro"]
|
|
25
|
+
},
|
|
26
|
+
"preset": {
|
|
27
|
+
"type": "string",
|
|
28
|
+
"description": "Deployment preset size",
|
|
29
|
+
"enum": ["evaluation", "eval", "s", "m", "l", "xl"]
|
|
30
|
+
},
|
|
31
|
+
"serviceName": {
|
|
32
|
+
"type": "string",
|
|
33
|
+
"description": "Service name for resource naming",
|
|
34
|
+
"pattern": "^[a-z0-9-]{2,40}$"
|
|
35
|
+
},
|
|
36
|
+
"location": {
|
|
37
|
+
"type": "string",
|
|
38
|
+
"description": "Azure region (e.g. swedencentral)"
|
|
39
|
+
},
|
|
40
|
+
"resourceGroupName": { "type": "string" },
|
|
41
|
+
"subscriptionId": { "type": "string" },
|
|
42
|
+
"tenantId": { "type": "string" },
|
|
43
|
+
"customDomain": { "type": "object" },
|
|
44
|
+
"frontDoor": { "type": "object" },
|
|
45
|
+
"networking": { "type": "object" },
|
|
46
|
+
"allowedIPs": {
|
|
47
|
+
"type": "array",
|
|
48
|
+
"items": { "type": "string" }
|
|
49
|
+
},
|
|
50
|
+
"infrastructureAccess": {
|
|
51
|
+
"type": "array",
|
|
52
|
+
"items": { "type": "object" }
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
"additionalProperties": true
|
|
56
|
+
},
|
|
57
|
+
"dryRun": {
|
|
58
|
+
"type": "boolean",
|
|
59
|
+
"description": "If true, validate only without deploying",
|
|
60
|
+
"default": false
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
"additionalProperties": false
|
|
64
|
+
}
|
package/lib/utils/paths.js
CHANGED
|
@@ -281,7 +281,23 @@ function getAppPath(appName, appType) {
|
|
|
281
281
|
}
|
|
282
282
|
|
|
283
283
|
/**
|
|
284
|
-
*
|
|
284
|
+
* Base directory for integration/builder: project root when cwd is inside project, else cwd.
|
|
285
|
+
* So deploy works when run from integration/<app> (e.g. node deploy.js), and tests using temp dirs still work.
|
|
286
|
+
* @returns {string} Directory to resolve integration/ and builder/ from
|
|
287
|
+
*/
|
|
288
|
+
function getIntegrationBuilderBaseDir() {
|
|
289
|
+
const root = getProjectRoot();
|
|
290
|
+
const cwd = path.resolve(process.cwd());
|
|
291
|
+
const rootNorm = path.resolve(root);
|
|
292
|
+
if (cwd === rootNorm || cwd.startsWith(rootNorm + path.sep)) {
|
|
293
|
+
return rootNorm;
|
|
294
|
+
}
|
|
295
|
+
return cwd;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
/**
|
|
299
|
+
* Gets the integration folder path for external systems.
|
|
300
|
+
* Uses project root when cwd is inside project so deploy works when run from integration/<app> (e.g. node deploy.js).
|
|
285
301
|
* @param {string} appName - Application name
|
|
286
302
|
* @returns {string} Absolute path to integration directory
|
|
287
303
|
*/
|
|
@@ -289,13 +305,14 @@ function getIntegrationPath(appName) {
|
|
|
289
305
|
if (!appName || typeof appName !== 'string') {
|
|
290
306
|
throw new Error('App name is required and must be a string');
|
|
291
307
|
}
|
|
292
|
-
|
|
308
|
+
const base = getIntegrationBuilderBaseDir();
|
|
309
|
+
return path.join(base, 'integration', appName);
|
|
293
310
|
}
|
|
294
311
|
|
|
295
312
|
/**
|
|
296
313
|
* Gets the builder folder path for regular applications.
|
|
297
314
|
* When AIFABRIX_BUILDER_DIR is set (e.g. by up-miso/up-dataplane from config aifabrix-env-config),
|
|
298
|
-
* uses that as builder root
|
|
315
|
+
* uses that as builder root; otherwise uses project root so deploy works when run from integration/<app>.
|
|
299
316
|
* @param {string} appName - Application name
|
|
300
317
|
* @returns {string} Absolute path to builder directory
|
|
301
318
|
*/
|
|
@@ -309,7 +326,8 @@ function getBuilderPath(appName) {
|
|
|
309
326
|
if (builderRoot) {
|
|
310
327
|
return path.join(builderRoot, appName);
|
|
311
328
|
}
|
|
312
|
-
|
|
329
|
+
const base = getIntegrationBuilderBaseDir();
|
|
330
|
+
return path.join(base, 'builder', appName);
|
|
313
331
|
}
|
|
314
332
|
|
|
315
333
|
/**
|
|
@@ -18,7 +18,17 @@ const logger = require('./logger');
|
|
|
18
18
|
const pathsUtil = require('./paths');
|
|
19
19
|
|
|
20
20
|
/**
|
|
21
|
-
*
|
|
21
|
+
* Skips commented or empty lines when scanning env.template
|
|
22
|
+
* @param {string} line - Single line
|
|
23
|
+
* @returns {boolean}
|
|
24
|
+
*/
|
|
25
|
+
function isCommentOrEmptyLine(line) {
|
|
26
|
+
const t = line.trim();
|
|
27
|
+
return t === '' || t.startsWith('#');
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Finds missing secret keys from template (skips commented and empty lines)
|
|
22
32
|
* @function findMissingSecretKeys
|
|
23
33
|
* @param {string} envTemplate - Environment template content
|
|
24
34
|
* @param {Object} existingSecrets - Existing secrets object
|
|
@@ -28,13 +38,18 @@ function findMissingSecretKeys(envTemplate, existingSecrets) {
|
|
|
28
38
|
const kvPattern = /kv:\/\/([a-zA-Z0-9-_]+)/g;
|
|
29
39
|
const missingKeys = [];
|
|
30
40
|
const seenKeys = new Set();
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
41
|
+
const lines = envTemplate.split('\n');
|
|
42
|
+
|
|
43
|
+
for (const line of lines) {
|
|
44
|
+
if (isCommentOrEmptyLine(line)) continue;
|
|
45
|
+
let match;
|
|
46
|
+
kvPattern.lastIndex = 0;
|
|
47
|
+
while ((match = kvPattern.exec(line)) !== null) {
|
|
48
|
+
const secretKey = match[1];
|
|
49
|
+
if (!seenKeys.has(secretKey) && !(secretKey in existingSecrets)) {
|
|
50
|
+
missingKeys.push(secretKey);
|
|
51
|
+
seenKeys.add(secretKey);
|
|
52
|
+
}
|
|
38
53
|
}
|
|
39
54
|
}
|
|
40
55
|
|
|
@@ -33,7 +33,17 @@ function interpolateEnvVars(content, envVars) {
|
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
/**
|
|
36
|
-
*
|
|
36
|
+
* Returns true if the line is a comment or empty (should be skipped for kv:// resolution)
|
|
37
|
+
* @param {string} line - Single line
|
|
38
|
+
* @returns {boolean}
|
|
39
|
+
*/
|
|
40
|
+
function isCommentOrEmptyLine(line) {
|
|
41
|
+
const t = line.trim();
|
|
42
|
+
return t === '' || t.startsWith('#');
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Collect missing kv:// secrets referenced in content (skips commented and empty lines)
|
|
37
47
|
* @function collectMissingSecrets
|
|
38
48
|
* @param {string} content - Text content
|
|
39
49
|
* @param {Object} secrets - Available secrets
|
|
@@ -42,11 +52,16 @@ function interpolateEnvVars(content, envVars) {
|
|
|
42
52
|
function collectMissingSecrets(content, secrets) {
|
|
43
53
|
const kvPattern = /kv:\/\/([a-zA-Z0-9-_]+)/g;
|
|
44
54
|
const missing = [];
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
55
|
+
const lines = content.split('\n');
|
|
56
|
+
for (const line of lines) {
|
|
57
|
+
if (isCommentOrEmptyLine(line)) continue;
|
|
58
|
+
let match;
|
|
59
|
+
kvPattern.lastIndex = 0;
|
|
60
|
+
while ((match = kvPattern.exec(line)) !== null) {
|
|
61
|
+
const secretKey = match[1];
|
|
62
|
+
if (!(secretKey in secrets)) {
|
|
63
|
+
missing.push(`kv://${secretKey}`);
|
|
64
|
+
}
|
|
50
65
|
}
|
|
51
66
|
}
|
|
52
67
|
return missing;
|
|
@@ -76,7 +91,7 @@ function formatMissingSecretsFileInfo(secretsFilePaths) {
|
|
|
76
91
|
}
|
|
77
92
|
|
|
78
93
|
/**
|
|
79
|
-
* Replace kv:// references with actual values
|
|
94
|
+
* Replace kv:// references with actual values (skips commented and empty lines)
|
|
80
95
|
* @function replaceKvInContent
|
|
81
96
|
* @param {string} content - Text content containing kv:// references
|
|
82
97
|
* @param {Object} secrets - Secrets map
|
|
@@ -85,15 +100,20 @@ function formatMissingSecretsFileInfo(secretsFilePaths) {
|
|
|
85
100
|
*/
|
|
86
101
|
function replaceKvInContent(content, secrets, envVars) {
|
|
87
102
|
const kvPattern = /kv:\/\/([a-zA-Z0-9-_]+)/g;
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
if (
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
103
|
+
const lines = content.split('\n');
|
|
104
|
+
const result = lines.map(line => {
|
|
105
|
+
if (isCommentOrEmptyLine(line)) return line;
|
|
106
|
+
return line.replace(kvPattern, (match, secretKey) => {
|
|
107
|
+
let value = secrets[secretKey];
|
|
108
|
+
if (typeof value === 'string') {
|
|
109
|
+
value = value.replace(/\$\{([A-Z_]+)\}/g, (m, envVar) => {
|
|
110
|
+
return envVars[envVar] || m;
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
return value;
|
|
114
|
+
});
|
|
96
115
|
});
|
|
116
|
+
return result.join('\n');
|
|
97
117
|
}
|
|
98
118
|
|
|
99
119
|
/**
|
|
@@ -420,7 +440,7 @@ function ensureNonEmptySecrets(secrets) {
|
|
|
420
440
|
}
|
|
421
441
|
|
|
422
442
|
/**
|
|
423
|
-
* Validate secrets against the env template
|
|
443
|
+
* Validate secrets against the env template (skips commented and empty lines)
|
|
424
444
|
* @function validateSecrets
|
|
425
445
|
* @param {string} envTemplate - Environment template content
|
|
426
446
|
* @param {Object} secrets - Available secrets
|
|
@@ -429,11 +449,16 @@ function ensureNonEmptySecrets(secrets) {
|
|
|
429
449
|
function validateSecrets(envTemplate, secrets) {
|
|
430
450
|
const kvPattern = /kv:\/\/([a-zA-Z0-9-_]+)/g;
|
|
431
451
|
const missing = [];
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
452
|
+
const lines = envTemplate.split('\n');
|
|
453
|
+
for (const line of lines) {
|
|
454
|
+
if (isCommentOrEmptyLine(line)) continue;
|
|
455
|
+
let match;
|
|
456
|
+
kvPattern.lastIndex = 0;
|
|
457
|
+
while ((match = kvPattern.exec(line)) !== null) {
|
|
458
|
+
const secretKey = match[1];
|
|
459
|
+
if (!(secretKey in secrets)) {
|
|
460
|
+
missing.push(`kv://${secretKey}`);
|
|
461
|
+
}
|
|
437
462
|
}
|
|
438
463
|
}
|
|
439
464
|
return {
|
package/package.json
CHANGED
package/scripts/install-local.js
CHANGED
|
@@ -114,10 +114,19 @@ function installLocal() {
|
|
|
114
114
|
console.log('Linking @aifabrix/builder globally...\n');
|
|
115
115
|
|
|
116
116
|
try {
|
|
117
|
+
const projectRoot = path.join(__dirname, '..');
|
|
117
118
|
if (pm === 'pnpm') {
|
|
118
|
-
|
|
119
|
+
// Update pnpm global.
|
|
120
|
+
execSync('pnpm link --global', { stdio: 'inherit', cwd: projectRoot });
|
|
121
|
+
// Also run npm link so npm's global bin points here; often PATH has
|
|
122
|
+
// npm's global bin before pnpm's, so "aifabrix" would otherwise stay old.
|
|
123
|
+
try {
|
|
124
|
+
execSync('npm link', { stdio: 'inherit', cwd: projectRoot });
|
|
125
|
+
} catch {
|
|
126
|
+
// npm may not be available or may fail; pnpm link already ran
|
|
127
|
+
}
|
|
119
128
|
} else {
|
|
120
|
-
execSync('npm link', { stdio: 'inherit' });
|
|
129
|
+
execSync('npm link', { stdio: 'inherit', cwd: projectRoot });
|
|
121
130
|
}
|
|
122
131
|
|
|
123
132
|
// Get new version after linking
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
/* eslint-disable no-console */
|
|
2
3
|
/**
|
|
3
4
|
* Deploy {{systemKey}} external system and datasources using aifabrix CLI.
|
|
4
5
|
* Run: node deploy.js
|
|
@@ -13,6 +14,12 @@ const appKey = '{{systemKey}}';
|
|
|
13
14
|
const env = process.env.ENVIRONMENT || 'dev';
|
|
14
15
|
// Controller URL: from config (aifabrix auth config) or set CONTROLLER env before running
|
|
15
16
|
|
|
17
|
+
/**
|
|
18
|
+
* Run a shell command with optional options.
|
|
19
|
+
* @param {string} cmd - Command to run
|
|
20
|
+
* @param {Object} [options={}] - Options (cwd, stdio, ignoreExit)
|
|
21
|
+
* @returns {boolean} True if command succeeded
|
|
22
|
+
*/
|
|
16
23
|
function run(cmd, options = {}) {
|
|
17
24
|
const opts = { cwd: scriptDir, stdio: 'inherit', ...options };
|
|
18
25
|
try {
|
|
@@ -24,6 +31,10 @@ function run(cmd, options = {}) {
|
|
|
24
31
|
}
|
|
25
32
|
}
|
|
26
33
|
|
|
34
|
+
/**
|
|
35
|
+
* Check if aifabrix auth is logged in.
|
|
36
|
+
* @returns {boolean} True if logged in
|
|
37
|
+
*/
|
|
27
38
|
function isLoggedIn() {
|
|
28
39
|
try {
|
|
29
40
|
execSync('aifabrix auth status', { cwd: scriptDir, stdio: 'pipe' });
|