@aifabrix/builder 2.0.5 → 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
 
@@ -107,18 +107,22 @@ function buildRequiresConfig(config) {
107
107
  * @returns {Object} Service configuration
108
108
  */
109
109
  function buildServiceConfig(appName, config, port) {
110
- // Host port is the local port (from options.port or build.localPort)
111
- const hostPort = port;
112
- // Container port: use build.containerPort if specified, otherwise use port config
113
- const containerPortValue = config.build?.containerPort || config.port || hostPort;
110
+ // Container port: build.containerPort > config.port
111
+ const containerPortValue = config.build?.containerPort || config.port || port;
112
+
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);
114
117
 
115
118
  return {
116
119
  app: buildAppConfig(appName, config),
117
120
  image: buildImageConfig(config, appName),
118
121
  port: containerPortValue, // Container port (for health check and template)
119
- 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)
120
124
  build: {
121
- localPort: hostPort // Host port
125
+ localPort: config.build?.localPort || null // Only used for .env file PORT variable, not for Docker Compose
122
126
  },
123
127
  healthCheck: buildHealthCheckConfig(config),
124
128
  ...buildRequiresConfig(config)
@@ -162,7 +166,9 @@ async function generateDockerCompose(appName, config, options) {
162
166
  const language = config.build?.language || config.language || 'typescript';
163
167
  const template = loadDockerComposeTemplate(language);
164
168
 
165
- const port = options.port || config.build?.localPort || 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;
166
172
 
167
173
  const serviceConfig = buildServiceConfig(appName, config, port);
168
174
  const volumesConfig = buildVolumesConfig(appName);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aifabrix/builder",
3
- "version": "2.0.5",
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}}