@aifabrix/builder 2.48.0 → 2.49.1
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/skills/README.md +14 -0
- package/jest.isolated-projects.js +3 -0
- package/jest.projects.js +12 -0
- package/lib/api/applications.api.js +23 -0
- package/lib/api/dev.api.js +1 -1
- package/lib/api/index.js +5 -2
- package/lib/api/types/dev.types.js +3 -2
- package/lib/app/deploy-config.js +6 -4
- package/lib/app/register.js +1 -1
- package/lib/app/run-container-start.js +0 -9
- package/lib/app/run-helpers.js +8 -4
- package/lib/app/run-reload-sync.js +16 -18
- package/lib/app/run-stop-containers.js +48 -5
- package/lib/app/run.js +6 -3
- package/lib/app/show.js +2 -2
- package/lib/cli/infra-guided-auth.js +50 -12
- package/lib/cli/infra-guided-footers.js +164 -0
- package/lib/cli/infra-guided-spinners.js +57 -0
- package/lib/cli/infra-guided.js +52 -181
- package/lib/cli/setup-app.js +1 -1
- package/lib/cli/setup-dev.js +3 -2
- package/lib/cli/setup-infra.js +3 -2
- package/lib/cli/setup-platform.js +3 -0
- package/lib/commands/login-device.js +6 -2
- package/lib/commands/login.js +4 -1
- package/lib/commands/setup-modes.js +19 -3
- package/lib/commands/setup-platform-auth.js +25 -0
- package/lib/commands/setup-prompts-admin.js +9 -0
- package/lib/commands/setup.js +60 -8
- package/lib/commands/teardown.js +3 -5
- package/lib/commands/up-common.js +8 -11
- package/lib/commands/up-dataplane-bootstrap.js +149 -0
- package/lib/commands/up-dataplane-credentials.js +19 -4
- package/lib/commands/up-dataplane.js +155 -24
- package/lib/commands/up-miso.js +6 -2
- package/lib/core/secrets-env-declarative-expand.js +35 -23
- package/lib/core/setup-platform-mode.js +43 -0
- package/lib/deployment/deployer-status.js +26 -3
- package/lib/deployment/deployer.js +7 -14
- package/lib/external-system/download-helpers.js +10 -1
- package/lib/infrastructure/compose.js +40 -12
- package/lib/infrastructure/services.js +15 -3
- package/lib/infrastructure/traefik-tls-dynamic.js +88 -0
- package/lib/utils/app-bootstrap-api.js +53 -0
- package/lib/utils/app-run-containers.js +14 -3
- package/lib/utils/applications-config-defaults.js +19 -3
- package/lib/utils/compose-generate-docker-compose.js +16 -5
- package/lib/utils/compose-generator.js +34 -15
- package/lib/utils/compose-traefik-ingress-base.js +13 -14
- package/lib/utils/config-paths.js +6 -1
- package/lib/utils/dev-user-groups.js +1 -0
- package/lib/utils/docker-daemon-tls-ca.js +94 -57
- package/lib/utils/docker-reload-mount.js +12 -1
- package/lib/utils/external-env-template.js +53 -18
- package/lib/utils/health-check-poll-ui.js +119 -0
- package/lib/utils/health-check-url.js +54 -34
- package/lib/utils/health-check.js +91 -35
- package/lib/utils/infra-optional-service-flags.js +31 -2
- package/lib/utils/mutagen.js +7 -4
- package/lib/utils/paths.js +26 -36
- package/lib/utils/platform-controller-url.js +23 -1
- package/lib/utils/refresh-remote-settings.js +67 -0
- package/lib/utils/remote-host-for-front-door.js +43 -0
- package/lib/utils/run-cli-flags.js +37 -1
- package/lib/utils/url-declarative-public-base.js +11 -4
- package/lib/utils/url-declarative-resolve-build-urls.js +11 -2
- package/lib/utils/url-declarative-resolve-expand-token.js +12 -1
- package/lib/utils/url-declarative-resolve-load-doc.js +30 -11
- package/lib/utils/url-declarative-resolve.js +2 -0
- package/lib/utils/urls-local-registry-scan.js +95 -10
- package/lib/utils/urls-local-registry.js +24 -1
- package/lib/utils/worker-sidecars.js +2 -2
- package/lib/validation/external-system-auth-rules.js +45 -7
- package/package.json +2 -1
- package/scripts/test-dataplane-bootstrap.js +331 -0
- package/templates/applications/dataplane/application.yaml +1 -1
- package/templates/applications/dataplane/env.template +24 -6
- package/templates/applications/dataplane/rbac.yaml +11 -0
- package/templates/applications/miso-controller/application.yaml +1 -1
- package/templates/applications/miso-controller/env.template +5 -0
- package/templates/infra/compose.yaml.hbs +13 -9
- package/templates/python/docker-compose.hbs +3 -0
- package/templates/typescript/docker-compose.hbs +3 -0
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Traefik v3 dynamic TLS configuration (file provider).
|
|
3
|
+
* Static CLI flags for certificate stores were removed in Traefik v3.
|
|
4
|
+
*
|
|
5
|
+
* @fileoverview Write traefik-tls.yaml for infra compose
|
|
6
|
+
* @author AI Fabrix Team
|
|
7
|
+
* @version 1.0.0
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
'use strict';
|
|
11
|
+
|
|
12
|
+
const fs = require('fs');
|
|
13
|
+
const path = require('path');
|
|
14
|
+
|
|
15
|
+
const TRAEFIK_TLS_DYNAMIC_BASENAME = 'traefik-tls.yaml';
|
|
16
|
+
const TRAEFIK_TLS_CONTAINER_PATH = '/etc/traefik/dynamic/tls.yaml';
|
|
17
|
+
const TRAEFIK_CERT_CONTAINER_PATH = '/etc/traefik/certs/tls.crt';
|
|
18
|
+
const TRAEFIK_KEY_CONTAINER_PATH = '/etc/traefik/certs/tls.key';
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* @param {string} storeName
|
|
22
|
+
* @returns {string}
|
|
23
|
+
*/
|
|
24
|
+
function buildTraefikTlsDynamicYaml(storeName) {
|
|
25
|
+
const store = String(storeName || 'default').trim() || 'default';
|
|
26
|
+
const certLine = ` certFile: ${TRAEFIK_CERT_CONTAINER_PATH}`;
|
|
27
|
+
const keyLine = ` keyFile: ${TRAEFIK_KEY_CONTAINER_PATH}`;
|
|
28
|
+
const blocks = [
|
|
29
|
+
'tls:',
|
|
30
|
+
' stores:',
|
|
31
|
+
' default:',
|
|
32
|
+
' defaultCertificate:',
|
|
33
|
+
certLine,
|
|
34
|
+
keyLine
|
|
35
|
+
];
|
|
36
|
+
if (store !== 'default') {
|
|
37
|
+
blocks.push(` ${store}:`);
|
|
38
|
+
blocks.push(' defaultCertificate:');
|
|
39
|
+
blocks.push(certLine);
|
|
40
|
+
blocks.push(keyLine);
|
|
41
|
+
}
|
|
42
|
+
return `${blocks.join('\n')}\n`;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* @param {Object} traefikConfig
|
|
47
|
+
* @returns {boolean}
|
|
48
|
+
*/
|
|
49
|
+
function traefikConfigHasTlsFiles(traefikConfig) {
|
|
50
|
+
return Boolean(
|
|
51
|
+
traefikConfig &&
|
|
52
|
+
traefikConfig.certStore &&
|
|
53
|
+
traefikConfig.certFile &&
|
|
54
|
+
traefikConfig.keyFile
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Write dynamic TLS config for Traefik file provider when cert store + files are set.
|
|
60
|
+
*
|
|
61
|
+
* @param {string} infraDir
|
|
62
|
+
* @param {Object} traefikConfig
|
|
63
|
+
* @returns {{ hostPath: string, containerPath: string, certContainerPath: string, keyContainerPath: string }|null}
|
|
64
|
+
*/
|
|
65
|
+
function writeTraefikTlsDynamicConfig(infraDir, traefikConfig) {
|
|
66
|
+
if (!traefikConfigHasTlsFiles(traefikConfig)) {
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
const hostPath = path.join(infraDir, TRAEFIK_TLS_DYNAMIC_BASENAME);
|
|
70
|
+
const content = buildTraefikTlsDynamicYaml(traefikConfig.certStore);
|
|
71
|
+
fs.writeFileSync(hostPath, content, { mode: 0o600 });
|
|
72
|
+
return {
|
|
73
|
+
hostPath,
|
|
74
|
+
containerPath: TRAEFIK_TLS_CONTAINER_PATH,
|
|
75
|
+
certContainerPath: TRAEFIK_CERT_CONTAINER_PATH,
|
|
76
|
+
keyContainerPath: TRAEFIK_KEY_CONTAINER_PATH
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
module.exports = {
|
|
81
|
+
TRAEFIK_TLS_DYNAMIC_BASENAME,
|
|
82
|
+
TRAEFIK_TLS_CONTAINER_PATH,
|
|
83
|
+
TRAEFIK_CERT_CONTAINER_PATH,
|
|
84
|
+
TRAEFIK_KEY_CONTAINER_PATH,
|
|
85
|
+
buildTraefikTlsDynamicYaml,
|
|
86
|
+
traefikConfigHasTlsFiles,
|
|
87
|
+
writeTraefikTlsDynamicConfig
|
|
88
|
+
};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
const { formatBlockingError } = require('./cli-test-layout-chalk');
|
|
2
|
+
/**
|
|
3
|
+
* Bootstrap API utilities for install-time application provisioning.
|
|
4
|
+
*
|
|
5
|
+
* @fileoverview Bootstrap API call helpers
|
|
6
|
+
* @author AI Fabrix Team
|
|
7
|
+
* @version 1.0.0
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
const chalk = require('chalk');
|
|
11
|
+
const logger = require('./logger');
|
|
12
|
+
const { bootstrapApplication } = require('../api/applications.api');
|
|
13
|
+
const { formatApiError } = require('./api-error-handler');
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Call bootstrap provisioning API.
|
|
17
|
+
* @async
|
|
18
|
+
* @param {string} apiUrl - Controller URL
|
|
19
|
+
* @param {string} encryptionKey - Shared ENCRYPTION_KEY (never log)
|
|
20
|
+
* @param {string} environment - Environment key
|
|
21
|
+
* @param {Object} registrationData - Registration payload
|
|
22
|
+
* @returns {Promise<Object>} Application data (credentials only when newly created)
|
|
23
|
+
*/
|
|
24
|
+
async function callBootstrapApi(apiUrl, encryptionKey, environment, registrationData) {
|
|
25
|
+
try {
|
|
26
|
+
const response = await bootstrapApplication(apiUrl, environment, encryptionKey, registrationData);
|
|
27
|
+
|
|
28
|
+
if (!response.success) {
|
|
29
|
+
const formattedError = response.formattedError || formatApiError(response, apiUrl);
|
|
30
|
+
logger.error(formattedError);
|
|
31
|
+
logger.error(chalk.gray(`\nController URL: ${apiUrl}`));
|
|
32
|
+
throw new Error(formattedError);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const apiResponse = response.data;
|
|
36
|
+
if (apiResponse && apiResponse.data) {
|
|
37
|
+
return apiResponse.data;
|
|
38
|
+
}
|
|
39
|
+
if (apiResponse && (apiResponse.application || apiResponse.status)) {
|
|
40
|
+
return apiResponse;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
logger.error(formatBlockingError('Invalid bootstrap response: missing application data'));
|
|
44
|
+
throw new Error('Invalid bootstrap response');
|
|
45
|
+
} catch (error) {
|
|
46
|
+
logger.error(formatBlockingError('Bootstrap API call failed'));
|
|
47
|
+
logger.error(chalk.gray(`Controller URL: ${apiUrl}`));
|
|
48
|
+
logger.error(chalk.gray(`Error: ${error.message}`));
|
|
49
|
+
throw error;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
module.exports = { callBootstrapApi };
|
|
@@ -136,10 +136,19 @@ async function checkContainerRunning(appName, developerId, debug = false, scopeO
|
|
|
136
136
|
* @param {number|string} developerId - Developer ID (0 = default infra, > 0 = developer-specific; string allowed)
|
|
137
137
|
* @param {boolean} [debug=false] - Enable debug logging
|
|
138
138
|
*/
|
|
139
|
-
async function stopAndRemoveContainer(
|
|
139
|
+
async function stopAndRemoveContainer(
|
|
140
|
+
appName,
|
|
141
|
+
developerId,
|
|
142
|
+
debug = false,
|
|
143
|
+
scopeOpts = null,
|
|
144
|
+
opts = {}
|
|
145
|
+
) {
|
|
146
|
+
const suppressLog = opts && opts.suppressLog === true;
|
|
140
147
|
try {
|
|
141
148
|
const containerName = getContainerName(appName, developerId, scopeOpts);
|
|
142
|
-
|
|
149
|
+
if (!suppressLog) {
|
|
150
|
+
logger.log(formatProgress(`Stopping container ${containerName}…`));
|
|
151
|
+
}
|
|
143
152
|
const stopCmd = `docker stop ${containerName}`;
|
|
144
153
|
if (debug) {
|
|
145
154
|
logger.log(chalk.gray(`[DEBUG] Executing: ${stopCmd}`));
|
|
@@ -150,7 +159,9 @@ async function stopAndRemoveContainer(appName, developerId, debug = false, scope
|
|
|
150
159
|
logger.log(chalk.gray(`[DEBUG] Executing: ${rmCmd}`));
|
|
151
160
|
}
|
|
152
161
|
await execWithDockerEnv(rmCmd);
|
|
153
|
-
|
|
162
|
+
if (!suppressLog) {
|
|
163
|
+
logger.log(formatSuccessLine(`Container ${containerName} stopped and removed`));
|
|
164
|
+
}
|
|
154
165
|
} catch (error) {
|
|
155
166
|
if (debug) {
|
|
156
167
|
logger.log(chalk.gray(`[DEBUG] Stop/remove container error: ${error.message}`));
|
|
@@ -120,8 +120,8 @@ function coerceTriStateBool(v) {
|
|
|
120
120
|
}
|
|
121
121
|
|
|
122
122
|
/**
|
|
123
|
-
*
|
|
124
|
-
*
|
|
123
|
+
* Stored per-app `proxy` preference from config (may be stale when `traefik: false`).
|
|
124
|
+
* Use {@link getEffectiveApplicationsRunProxyHint} for runtime / display.
|
|
125
125
|
*
|
|
126
126
|
* @param {Object|null|undefined} userConfig - Parsed config.yaml root
|
|
127
127
|
* @param {string} appKey - Application key
|
|
@@ -183,6 +183,21 @@ async function persistApplicationRunProxyFlag(appKey, proxyEnabled) {
|
|
|
183
183
|
await config.saveConfig(cfg);
|
|
184
184
|
}
|
|
185
185
|
|
|
186
|
+
/**
|
|
187
|
+
* Effective proxy hint for URL expansion and CLI display.
|
|
188
|
+
* Always **false** when infra Traefik is off — stored `applications.<app>.proxy` is ignored.
|
|
189
|
+
*
|
|
190
|
+
* @param {Object|null|undefined} userConfig
|
|
191
|
+
* @param {string} appKey
|
|
192
|
+
* @returns {boolean}
|
|
193
|
+
*/
|
|
194
|
+
function getEffectiveApplicationsRunProxyHint(userConfig, appKey) {
|
|
195
|
+
if (!userConfig || userConfig.traefik !== true) {
|
|
196
|
+
return false;
|
|
197
|
+
}
|
|
198
|
+
return getApplicationsRunProxyHint(userConfig, appKey);
|
|
199
|
+
}
|
|
200
|
+
|
|
186
201
|
/**
|
|
187
202
|
* Whether declarative `url://*` expansion should treat Traefik as on (infra Traefik + per-app `proxy: true`).
|
|
188
203
|
*
|
|
@@ -191,11 +206,12 @@ async function persistApplicationRunProxyFlag(appKey, proxyEnabled) {
|
|
|
191
206
|
* @returns {boolean}
|
|
192
207
|
*/
|
|
193
208
|
function isDeclarativeTraefikUrlsEnabled(userConfig, appKey) {
|
|
194
|
-
return
|
|
209
|
+
return getEffectiveApplicationsRunProxyHint(userConfig, appKey);
|
|
195
210
|
}
|
|
196
211
|
|
|
197
212
|
module.exports = {
|
|
198
213
|
getApplicationsRunProxyHint,
|
|
214
|
+
getEffectiveApplicationsRunProxyHint,
|
|
199
215
|
isApplicationsReloadDefaultOn,
|
|
200
216
|
isDeclarativeTraefikUrlsEnabled,
|
|
201
217
|
isPreferLocalEnvOutputPath,
|
|
@@ -144,6 +144,8 @@ function buildComposeTemplateContext(ctx) {
|
|
|
144
144
|
dbInitEnvFile: ctx.dbInitEnvFileAbsolutePath,
|
|
145
145
|
databasePasswords: ctx.databasePasswords,
|
|
146
146
|
devId: ctx.idNum,
|
|
147
|
+
idNum: ctx.idNum,
|
|
148
|
+
traefikScoped: ctx.idNum > 0,
|
|
147
149
|
networkName: ctx.networkName,
|
|
148
150
|
containerName: ctx.containerName,
|
|
149
151
|
misoEnvironment: resolveMisoEnvironment(ctx.options),
|
|
@@ -201,7 +203,12 @@ async function readDatabasePasswordsIfNeeded(readDatabasePasswords, requiresData
|
|
|
201
203
|
* @returns {Promise<object>}
|
|
202
204
|
*/
|
|
203
205
|
async function loadComposeHead(deps, appName, appConfig, options) {
|
|
204
|
-
const {
|
|
206
|
+
const {
|
|
207
|
+
loadDockerComposeTemplate,
|
|
208
|
+
resolveComposeImageOverrideString,
|
|
209
|
+
getDeveloperIdAndNumeric,
|
|
210
|
+
getFrontDoorHostContextForCompose
|
|
211
|
+
} = deps;
|
|
205
212
|
const language = appConfig.build?.language || appConfig.language || 'typescript';
|
|
206
213
|
const template = loadDockerComposeTemplate(language);
|
|
207
214
|
const port = options.port || appConfig.port || 3000;
|
|
@@ -209,10 +216,13 @@ async function loadComposeHead(deps, appName, appConfig, options) {
|
|
|
209
216
|
const { devId, idNum } = await getDeveloperIdAndNumeric();
|
|
210
217
|
const { scoped } = resolveScopedComposeOpts(options);
|
|
211
218
|
let remoteServer = null;
|
|
212
|
-
|
|
213
|
-
|
|
219
|
+
let developerRootDomain = null;
|
|
220
|
+
if (typeof getFrontDoorHostContextForCompose === 'function') {
|
|
221
|
+
const frontDoorCtx = await getFrontDoorHostContextForCompose();
|
|
222
|
+
remoteServer = frontDoorCtx.remoteServer;
|
|
223
|
+
developerRootDomain = frontDoorCtx.developerRootDomain;
|
|
214
224
|
}
|
|
215
|
-
return { template, port, imageOverride, devId, idNum, scoped, remoteServer };
|
|
225
|
+
return { template, port, imageOverride, devId, idNum, scoped, remoteServer, developerRootDomain };
|
|
216
226
|
}
|
|
217
227
|
|
|
218
228
|
/**
|
|
@@ -224,12 +234,13 @@ async function loadComposeHead(deps, appName, appConfig, options) {
|
|
|
224
234
|
*/
|
|
225
235
|
function buildComposeLayouts(deps, appName, appConfig, head, options) {
|
|
226
236
|
const { buildNetworkAndContainerNames, buildServiceConfig, buildVolumesConfig, buildNetworksConfig } = deps;
|
|
227
|
-
const { port, imageOverride, devId, idNum, scoped, remoteServer } = head;
|
|
237
|
+
const { port, imageOverride, devId, idNum, scoped, remoteServer, developerRootDomain } = head;
|
|
228
238
|
const { networkName, containerName } = buildNetworkAndContainerNames(appName, devId, idNum, scoped);
|
|
229
239
|
const serviceConfig = buildServiceConfig(appName, appConfig, port, devId, {
|
|
230
240
|
imageOverride,
|
|
231
241
|
scopeOpts: scoped,
|
|
232
242
|
remoteServer,
|
|
243
|
+
developerRootDomain,
|
|
233
244
|
omitAppTraefikLabels: options && options.omitAppTraefikLabels === true
|
|
234
245
|
});
|
|
235
246
|
const volumesConfig = buildVolumesConfig(appName);
|
|
@@ -116,7 +116,7 @@ function buildImageConfig(config, appName, imageOverride) {
|
|
|
116
116
|
* @param {string|null|undefined} [readinessSuffix] - Path after vdir (default /health/ready or healthCheck.readinessPathSuffix)
|
|
117
117
|
* @returns {string} Absolute path starting with /
|
|
118
118
|
*/
|
|
119
|
-
function computeAlignedHealthCheckPath(config, devId, scopeOpts, remoteServer, readinessSuffix) {
|
|
119
|
+
function computeAlignedHealthCheckPath(config, devId, scopeOpts, remoteServer, readinessSuffix, developerRootDomain) {
|
|
120
120
|
const hc = config.healthCheck || {};
|
|
121
121
|
let suffix = '/health/ready';
|
|
122
122
|
if (
|
|
@@ -128,7 +128,7 @@ function computeAlignedHealthCheckPath(config, devId, scopeOpts, remoteServer, r
|
|
|
128
128
|
} else if (typeof hc.readinessPathSuffix === 'string' && hc.readinessPathSuffix.startsWith('/')) {
|
|
129
129
|
suffix = hc.readinessPathSuffix;
|
|
130
130
|
}
|
|
131
|
-
const traefik = buildTraefikIngressBase(config, devId, scopeOpts, remoteServer);
|
|
131
|
+
const traefik = buildTraefikIngressBase(config, devId, scopeOpts, remoteServer, developerRootDomain);
|
|
132
132
|
if (traefik.enabled === true) {
|
|
133
133
|
const p = traefik.path;
|
|
134
134
|
if (!p || p === '/') {
|
|
@@ -158,7 +158,7 @@ function computeAlignedHealthCheckPath(config, devId, scopeOpts, remoteServer, r
|
|
|
158
158
|
* @param {{ skipVdirMergeWhenPathIsBareHealth?: boolean }} [opts] - When `skipVdirMergeWhenPathIsBareHealth`, path `/health` is left as-is (in-container probe; ingress strips vdir for miso/dataplane). Deployment JSON health paths do **not** use this helper — see `buildHealthCheck` in `builders.js` (YAML paths only).
|
|
159
159
|
* @returns {string} Absolute path starting with /
|
|
160
160
|
*/
|
|
161
|
-
function resolveHealthCheckPathWithFrontDoorVdir(config, devId, scopeOpts, remoteServer, opts) {
|
|
161
|
+
function resolveHealthCheckPathWithFrontDoorVdir(config, devId, scopeOpts, remoteServer, opts, developerRootDomain) {
|
|
162
162
|
const hc = config.healthCheck || {};
|
|
163
163
|
const raw = typeof hc.path === 'string' && hc.path.startsWith('/') ? hc.path : '/health';
|
|
164
164
|
const fd = config.frontDoorRouting;
|
|
@@ -168,7 +168,7 @@ function resolveHealthCheckPathWithFrontDoorVdir(config, devId, scopeOpts, remot
|
|
|
168
168
|
if (opts && opts.skipVdirMergeWhenPathIsBareHealth === true && raw === '/health') {
|
|
169
169
|
return raw;
|
|
170
170
|
}
|
|
171
|
-
const traefik = buildTraefikIngressBase(config, devId, scopeOpts, remoteServer);
|
|
171
|
+
const traefik = buildTraefikIngressBase(config, devId, scopeOpts, remoteServer, developerRootDomain);
|
|
172
172
|
if (traefik.enabled !== true) {
|
|
173
173
|
return raw;
|
|
174
174
|
}
|
|
@@ -178,7 +178,7 @@ function resolveHealthCheckPathWithFrontDoorVdir(config, devId, scopeOpts, remot
|
|
|
178
178
|
? ''
|
|
179
179
|
: String(vdirRaw).replace(/\/+$/, '');
|
|
180
180
|
if (!vdir) {
|
|
181
|
-
return computeAlignedHealthCheckPath(config, devId, scopeOpts, remoteServer, raw);
|
|
181
|
+
return computeAlignedHealthCheckPath(config, devId, scopeOpts, remoteServer, raw, developerRootDomain);
|
|
182
182
|
}
|
|
183
183
|
if (raw === vdir || raw.startsWith(`${vdir}/`)) {
|
|
184
184
|
return raw;
|
|
@@ -192,13 +192,14 @@ function resolveHealthCheckPathWithFrontDoorVdir(config, devId, scopeOpts, remot
|
|
|
192
192
|
* @param {string|number} devId - Developer id
|
|
193
193
|
* @param {Object|null} scopeOpts - Env-scoped compose options
|
|
194
194
|
* @param {string|null|undefined} remoteServer - Remote server URL
|
|
195
|
+
* @param {string|null|undefined} [developerRootDomain] - App hostname root
|
|
195
196
|
* @returns {Object} Health check configuration
|
|
196
197
|
*/
|
|
197
|
-
function buildHealthCheckConfig(config, devId, scopeOpts, remoteServer) {
|
|
198
|
+
function buildHealthCheckConfig(config, devId, scopeOpts, remoteServer, developerRootDomain) {
|
|
198
199
|
const hc = config.healthCheck || {};
|
|
199
200
|
const path = resolveHealthCheckPathWithFrontDoorVdir(config, devId, scopeOpts, remoteServer, {
|
|
200
201
|
skipVdirMergeWhenPathIsBareHealth: true
|
|
201
|
-
});
|
|
202
|
+
}, developerRootDomain);
|
|
202
203
|
return {
|
|
203
204
|
path,
|
|
204
205
|
interval: hc.interval || 30,
|
|
@@ -230,10 +231,11 @@ function buildDevUsername(devId) {
|
|
|
230
231
|
* @param {Object|null} scopeOpts - Env-scoped Traefik path
|
|
231
232
|
* @param {string|null|undefined} remoteServer - From config (for ${REMOTE_HOST})
|
|
232
233
|
* @param {string|undefined} [resolvedHealthPathForStrip] - Compose health path; when omitted, derived via resolveHealthCheckPathWithFrontDoorVdir (same as probe)
|
|
234
|
+
* @param {string|null|undefined} [developerRootDomain] - App hostname root from settings
|
|
233
235
|
* @returns {Object} Traefik configuration object
|
|
234
236
|
*/
|
|
235
|
-
function buildTraefikConfig(config, devId, scopeOpts = null, remoteServer = null, resolvedHealthPathForStrip) {
|
|
236
|
-
const base = buildTraefikIngressBase(config, devId, scopeOpts, remoteServer);
|
|
237
|
+
function buildTraefikConfig(config, devId, scopeOpts = null, remoteServer = null, resolvedHealthPathForStrip, developerRootDomain) {
|
|
238
|
+
const base = buildTraefikIngressBase(config, devId, scopeOpts, remoteServer, developerRootDomain);
|
|
237
239
|
if (!base.enabled) {
|
|
238
240
|
return { enabled: false };
|
|
239
241
|
}
|
|
@@ -242,7 +244,7 @@ function buildTraefikConfig(config, devId, scopeOpts = null, remoteServer = null
|
|
|
242
244
|
? String(resolvedHealthPathForStrip)
|
|
243
245
|
: resolveHealthCheckPathWithFrontDoorVdir(config, devId, scopeOpts, remoteServer, {
|
|
244
246
|
skipVdirMergeWhenPathIsBareHealth: true
|
|
245
|
-
});
|
|
247
|
+
}, developerRootDomain);
|
|
246
248
|
const devNum = parseDeveloperIdNum(devId);
|
|
247
249
|
// Shared builder host: nginx terminates TLS on :443 and proxies HTTP to per-dev Traefik :80 (e.g. 280).
|
|
248
250
|
// Traefik must only attach routers to `web` for developer-id > 0; `websecure`+tls labels without
|
|
@@ -282,6 +284,7 @@ function buildRequiresConfig(config) {
|
|
|
282
284
|
* @param {string} [runExtras.imageOverride] - Full image reference for run (e.g. from --image)
|
|
283
285
|
* @param {Object|null} [runExtras.scopeOpts] - Traefik / scoped compose options
|
|
284
286
|
* @param {string|null|undefined} [runExtras.remoteServer] - For ${REMOTE_HOST} in frontDoorRouting.host
|
|
287
|
+
* @param {string|null|undefined} [runExtras.developerRootDomain] - App hostname root (overrides remote-server host)
|
|
285
288
|
* @param {boolean} [runExtras.omitAppTraefikLabels] - When true (user config `traefik: false`), omit Traefik labels and BASE_PATH env from compose even if application.yaml enables frontDoorRouting
|
|
286
289
|
* @returns {Object} Service configuration
|
|
287
290
|
*/
|
|
@@ -290,6 +293,7 @@ function buildServiceConfig(appName, config, port, devId, runExtras = {}) {
|
|
|
290
293
|
imageOverride = null,
|
|
291
294
|
scopeOpts = null,
|
|
292
295
|
remoteServer = null,
|
|
296
|
+
developerRootDomain = null,
|
|
293
297
|
omitAppTraefikLabels = false
|
|
294
298
|
} = runExtras;
|
|
295
299
|
const containerPortValue = getContainerPort(config, 3000);
|
|
@@ -303,7 +307,7 @@ function buildServiceConfig(appName, config, port, devId, runExtras = {}) {
|
|
|
303
307
|
? composeTraefikServiceKey(appName, scopeOpts.runEnvKey)
|
|
304
308
|
: null;
|
|
305
309
|
const scopeForHealthAndTraefik = useTraefikScope ? scopeOpts : null;
|
|
306
|
-
const healthCheck = buildHealthCheckConfig(config, devId, scopeForHealthAndTraefik, remoteServer);
|
|
310
|
+
const healthCheck = buildHealthCheckConfig(config, devId, scopeForHealthAndTraefik, remoteServer, developerRootDomain);
|
|
307
311
|
return {
|
|
308
312
|
app: buildAppConfig(appName, config, composeAppKey),
|
|
309
313
|
image: buildImageConfig(config, appName, imageOverride),
|
|
@@ -319,7 +323,8 @@ function buildServiceConfig(appName, config, port, devId, runExtras = {}) {
|
|
|
319
323
|
devId,
|
|
320
324
|
scopeForHealthAndTraefik,
|
|
321
325
|
remoteServer,
|
|
322
|
-
healthCheck.path
|
|
326
|
+
healthCheck.path,
|
|
327
|
+
developerRootDomain
|
|
323
328
|
),
|
|
324
329
|
...buildRequiresConfig(config)
|
|
325
330
|
};
|
|
@@ -379,20 +384,34 @@ function buildNetworkAndContainerNames(appName, devId, idNum, scopeOpts = null)
|
|
|
379
384
|
}
|
|
380
385
|
|
|
381
386
|
const { createGenerateDockerCompose } = require('./compose-generate-docker-compose');
|
|
382
|
-
async function
|
|
387
|
+
async function getFrontDoorHostContextForCompose() {
|
|
383
388
|
try {
|
|
384
389
|
const rs = await config.getRemoteServer();
|
|
385
|
-
|
|
390
|
+
const remoteServer = rs && String(rs).trim() ? String(rs).trim() : null;
|
|
391
|
+
let developerRootDomain = null;
|
|
392
|
+
try {
|
|
393
|
+
const root = await config.getDeveloperRootDomain();
|
|
394
|
+
developerRootDomain = root && String(root).trim() ? String(root).trim() : null;
|
|
395
|
+
} catch {
|
|
396
|
+
developerRootDomain = null;
|
|
397
|
+
}
|
|
398
|
+
return { remoteServer, developerRootDomain };
|
|
386
399
|
} catch {
|
|
387
|
-
return null;
|
|
400
|
+
return { remoteServer: null, developerRootDomain: null };
|
|
388
401
|
}
|
|
389
402
|
}
|
|
390
403
|
|
|
404
|
+
async function getRemoteServerForCompose() {
|
|
405
|
+
const ctx = await getFrontDoorHostContextForCompose();
|
|
406
|
+
return ctx.remoteServer;
|
|
407
|
+
}
|
|
408
|
+
|
|
391
409
|
const generateDockerCompose = createGenerateDockerCompose({
|
|
392
410
|
loadDockerComposeTemplate,
|
|
393
411
|
resolveComposeImageOverrideString,
|
|
394
412
|
getDeveloperIdAndNumeric,
|
|
395
413
|
getRemoteServerForCompose,
|
|
414
|
+
getFrontDoorHostContextForCompose,
|
|
396
415
|
buildNetworkAndContainerNames,
|
|
397
416
|
buildServiceConfig,
|
|
398
417
|
buildVolumesConfig,
|
|
@@ -10,6 +10,10 @@ const {
|
|
|
10
10
|
buildEnvScopedTraefikPath
|
|
11
11
|
} = require('./environment-scoped-resources');
|
|
12
12
|
const { parseDeveloperIdNum } = require('./declarative-url-ports');
|
|
13
|
+
const {
|
|
14
|
+
resolveRemoteHostForFrontDoor,
|
|
15
|
+
hasFrontDoorRemoteHostContext
|
|
16
|
+
} = require('./remote-host-for-front-door');
|
|
13
17
|
|
|
14
18
|
/**
|
|
15
19
|
* Derives base path from routing pattern by removing trailing wildcards
|
|
@@ -66,21 +70,15 @@ function buildDevUsernameForFrontDoorHost(devId) {
|
|
|
66
70
|
* @param {string} template
|
|
67
71
|
* @param {string|number|null|undefined} developerIdRaw
|
|
68
72
|
* @param {string|null|undefined} remoteServer
|
|
73
|
+
* @param {string|null|undefined} [developerRootDomain] - App hostname root (overrides remote-server hostname for ${REMOTE_HOST})
|
|
69
74
|
* @returns {string}
|
|
70
75
|
*/
|
|
71
|
-
function expandFrontDoorHostPlaceholders(template, developerIdRaw, remoteServer) {
|
|
76
|
+
function expandFrontDoorHostPlaceholders(template, developerIdRaw, remoteServer, developerRootDomain) {
|
|
72
77
|
let t = String(template || '');
|
|
73
78
|
t = t.replace(/\$\{DEV_USERNAME\}\$\{REMOTE_HOST\}/g, '${DEV_USERNAME}.${REMOTE_HOST}');
|
|
74
79
|
const devU = buildDevUsernameForFrontDoorHost(developerIdRaw);
|
|
75
80
|
t = t.replace(/\$\{DEV_USERNAME\}/g, devU);
|
|
76
|
-
|
|
77
|
-
try {
|
|
78
|
-
if (remoteServer && String(remoteServer).trim()) {
|
|
79
|
-
remoteHost = new URL(String(remoteServer).trim()).hostname;
|
|
80
|
-
}
|
|
81
|
-
} catch {
|
|
82
|
-
remoteHost = '';
|
|
83
|
-
}
|
|
81
|
+
const remoteHost = resolveRemoteHostForFrontDoor({ remoteServer, developerRootDomain });
|
|
84
82
|
t = t.replace(/\$\{REMOTE_HOST\}/g, remoteHost);
|
|
85
83
|
t = t.replace(/^\.+/g, '').replace(/\.{2,}/g, '.').replace(/\.+$/g, '').trim();
|
|
86
84
|
return t;
|
|
@@ -90,13 +88,13 @@ function templateUsesRemoteHostPlaceholder(hostTemplate) {
|
|
|
90
88
|
return /\$\{REMOTE_HOST\}/.test(String(hostTemplate || ''));
|
|
91
89
|
}
|
|
92
90
|
|
|
93
|
-
function resolveTraefikRouterHost(hostTemplate, developerIdRaw, remoteServer) {
|
|
91
|
+
function resolveTraefikRouterHost(hostTemplate, developerIdRaw, remoteServer, developerRootDomain) {
|
|
94
92
|
const usesRemote = templateUsesRemoteHostPlaceholder(hostTemplate);
|
|
95
|
-
const hasRemote =
|
|
93
|
+
const hasRemote = hasFrontDoorRemoteHostContext({ remoteServer, developerRootDomain });
|
|
96
94
|
if (usesRemote && !hasRemote) {
|
|
97
95
|
return 'localhost';
|
|
98
96
|
}
|
|
99
|
-
return expandFrontDoorHostPlaceholders(hostTemplate, developerIdRaw, remoteServer);
|
|
97
|
+
return expandFrontDoorHostPlaceholders(hostTemplate, developerIdRaw, remoteServer, developerRootDomain);
|
|
100
98
|
}
|
|
101
99
|
|
|
102
100
|
/**
|
|
@@ -108,9 +106,10 @@ function resolveTraefikRouterHost(hostTemplate, developerIdRaw, remoteServer) {
|
|
|
108
106
|
* @param {string|number} devId - Developer id for host expansion
|
|
109
107
|
* @param {Object|null} scopeOpts - Env-scoped Traefik path (effectiveEnvironmentScopedResources, runEnvKey)
|
|
110
108
|
* @param {string|null|undefined} remoteServer - For ${REMOTE_HOST}
|
|
109
|
+
* @param {string|null|undefined} [developerRootDomain] - App hostname root from settings
|
|
111
110
|
* @returns {{ enabled: false } | { enabled: true, host: string, path: string, tls: boolean, certStore: string|null }}
|
|
112
111
|
*/
|
|
113
|
-
function buildTraefikIngressBase(config, devId, scopeOpts, remoteServer) {
|
|
112
|
+
function buildTraefikIngressBase(config, devId, scopeOpts, remoteServer, developerRootDomain) {
|
|
114
113
|
const frontDoor = config.frontDoorRouting;
|
|
115
114
|
if (!frontDoor || frontDoor.enabled !== true) {
|
|
116
115
|
return { enabled: false };
|
|
@@ -118,7 +117,7 @@ function buildTraefikIngressBase(config, devId, scopeOpts, remoteServer) {
|
|
|
118
117
|
if (!frontDoor.host || typeof frontDoor.host !== 'string') {
|
|
119
118
|
throw new Error('frontDoorRouting.host is required when frontDoorRouting.enabled is true');
|
|
120
119
|
}
|
|
121
|
-
const host = resolveTraefikRouterHost(frontDoor.host, devId, remoteServer);
|
|
120
|
+
const host = resolveTraefikRouterHost(frontDoor.host, devId, remoteServer, developerRootDomain);
|
|
122
121
|
const basePath = derivePathFromPattern(frontDoor.pattern);
|
|
123
122
|
let pathOut = basePath;
|
|
124
123
|
if (
|
|
@@ -22,6 +22,7 @@ const SETTINGS_RESPONSE_KEYS = [
|
|
|
22
22
|
'aifabrix-env-config',
|
|
23
23
|
'remote-server',
|
|
24
24
|
'docker-endpoint',
|
|
25
|
+
'developer-root-domain',
|
|
25
26
|
'docker-tls-skip-verify',
|
|
26
27
|
'sync-ssh-user',
|
|
27
28
|
'sync-ssh-host'
|
|
@@ -290,6 +291,9 @@ function createRemoteConfigGetters(getConfigFn) {
|
|
|
290
291
|
},
|
|
291
292
|
async getSyncSshHost() {
|
|
292
293
|
return getPathConfig(getConfigFn, 'sync-ssh-host');
|
|
294
|
+
},
|
|
295
|
+
async getDeveloperRootDomain() {
|
|
296
|
+
return getPathConfig(getConfigFn, 'developer-root-domain');
|
|
293
297
|
}
|
|
294
298
|
};
|
|
295
299
|
}
|
|
@@ -424,6 +428,7 @@ module.exports = {
|
|
|
424
428
|
resolveEnvConfigPathToAbsolute,
|
|
425
429
|
SETTINGS_RESPONSE_KEYS,
|
|
426
430
|
applySecretsUrlFromRemote,
|
|
427
|
-
applySyncAndDockerFromHost
|
|
431
|
+
applySyncAndDockerFromHost,
|
|
432
|
+
hostnameFromUrl
|
|
428
433
|
};
|
|
429
434
|
|