@aifabrix/builder 2.0.6 → 2.0.7

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/lib/secrets.js CHANGED
@@ -173,6 +173,8 @@ function loadEnvTemplate(templatePath) {
173
173
 
174
174
  /**
175
175
  * Processes environment variables and copies to output path if needed
176
+ * Updates PORT variable to use localPort if available (only when copying to envOutputPath)
177
+ * When .env stays in builder folder, uses port (container port)
176
178
  * @function processEnvVariables
177
179
  * @param {string} envPath - Path to generated .env file
178
180
  * @param {string} variablesPath - Path to variables.yaml
@@ -204,7 +206,18 @@ function processEnvVariables(envPath, variablesPath) {
204
206
  fs.mkdirSync(outputDir, { recursive: true });
205
207
  }
206
208
 
207
- fs.copyFileSync(envPath, outputPath);
209
+ // Read the .env file content
210
+ let envContent = fs.readFileSync(envPath, 'utf8');
211
+
212
+ // Update PORT variable: use localPort ONLY when copying to envOutputPath (outside builder folder)
213
+ // When .env stays in builder folder, it uses port (container port)
214
+ const portToUse = variables.build?.localPort || variables.port || 3000;
215
+
216
+ // Replace PORT line (handles PORT=value format, with or without spaces)
217
+ envContent = envContent.replace(/^PORT\s*=\s*.*$/m, `PORT=${portToUse}`);
218
+
219
+ // Write updated content to output path
220
+ fs.writeFileSync(outputPath, envContent, { mode: 0o600 });
208
221
  logger.log(chalk.green(`✓ Copied .env to: ${variables.build.envOutputPath}`));
209
222
  }
210
223
 
@@ -110,20 +110,19 @@ function buildServiceConfig(appName, config, port) {
110
110
  // Container port: build.containerPort > config.port
111
111
  const containerPortValue = config.build?.containerPort || config.port || port;
112
112
 
113
- // Host port logic:
114
- // - If containerPort is specified: use options.port or build.localPort
115
- // - If containerPort is NOT specified: use options.port if provided, otherwise config.port (same as container port)
116
- const hostPort = config.build?.containerPort
117
- ? (port || config.build?.localPort || config.port || 3000) // If containerPort exists, use options.port or localPort
118
- : (port !== config.port ? port : config.port || port); // If no containerPort, use options.port if different, else config.port
113
+ // Host port: use options.port if provided (CLI --port), otherwise use config.port
114
+ // Container port: use containerPort if exists, otherwise port
115
+ // Note: build.localPort is ONLY used for .env file PORT variable (for local PC dev), NOT for Docker Compose
116
+ const hostPort = port !== config.port ? port : (config.port || port);
119
117
 
120
118
  return {
121
119
  app: buildAppConfig(appName, config),
122
120
  image: buildImageConfig(config, appName),
123
121
  port: containerPortValue, // Container port (for health check and template)
124
- containerPort: config.build?.containerPort || null, // Explicit containerPort if specified, null otherwise
122
+ containerPort: containerPortValue, // Container port (always set, equals containerPort if exists, else port)
123
+ hostPort: hostPort, // Host port (options.port if provided, else config.port)
125
124
  build: {
126
- localPort: hostPort // Host port
125
+ localPort: config.build?.localPort || null // Only used for .env file PORT variable, not for Docker Compose
127
126
  },
128
127
  healthCheck: buildHealthCheckConfig(config),
129
128
  ...buildRequiresConfig(config)
@@ -167,8 +166,9 @@ async function generateDockerCompose(appName, config, options) {
167
166
  const language = config.build?.language || config.language || 'typescript';
168
167
  const template = loadDockerComposeTemplate(language);
169
168
 
170
- // Determine port: use options.port if provided, otherwise use config.port (ignore build.localPort when no containerPort)
171
- const port = options.port || (config.build?.containerPort ? config.build?.localPort : null) || config.port || 3000;
169
+ // Use options.port if provided, otherwise use config.port
170
+ // (localPort will be handled in buildServiceConfig)
171
+ const port = options.port || config.port || 3000;
172
172
 
173
173
  const serviceConfig = buildServiceConfig(appName, config, port);
174
174
  const volumesConfig = buildVolumesConfig(appName);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aifabrix/builder",
3
- "version": "2.0.6",
3
+ "version": "2.0.7",
4
4
  "description": "AI Fabrix Local Fabric & Deployment SDK",
5
5
  "main": "lib/index.js",
6
6
  "bin": {
@@ -9,11 +9,7 @@ services:
9
9
  env_file:
10
10
  - {{envFile}}
11
11
  ports:
12
- {{#if containerPort}}
13
- - "{{build.localPort}}:{{containerPort}}"
14
- {{else}}
15
- - "{{build.localPort}}:{{port}}"
16
- {{/if}}
12
+ - "{{hostPort}}:{{containerPort}}"
17
13
  networks:
18
14
  - infra_aifabrix-network
19
15
  {{#if requiresStorage}}
@@ -9,11 +9,7 @@ services:
9
9
  env_file:
10
10
  - {{envFile}}
11
11
  ports:
12
- {{#if containerPort}}
13
- - "{{build.localPort}}:{{containerPort}}"
14
- {{else}}
15
- - "{{build.localPort}}:{{port}}"
16
- {{/if}}
12
+ - "{{hostPort}}:{{containerPort}}"
17
13
  networks:
18
14
  - infra_aifabrix-network
19
15
  {{#if requiresStorage}}