@oussema_mili/test-pkg-123 1.1.47 → 1.1.49
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/containerManager.js +49 -10
- package/daemon/agentRunner.js +0 -2
- package/package.json +1 -1
package/containerManager.js
CHANGED
|
@@ -184,16 +184,55 @@ class ContainerManager {
|
|
|
184
184
|
// Stop existing container if running
|
|
185
185
|
await this.stopContainer();
|
|
186
186
|
|
|
187
|
-
//
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
187
|
+
// Check if image exists locally and handle pull accordingly
|
|
188
|
+
const imageExists = await this.imageExistsLocally();
|
|
189
|
+
|
|
190
|
+
if (!imageExists) {
|
|
191
|
+
// Image doesn't exist, pull it
|
|
192
|
+
try {
|
|
193
|
+
await this.pullImage();
|
|
194
|
+
} catch (pullError) {
|
|
195
|
+
throw new Error('Failed to pull image. Please check your network connection.');
|
|
196
|
+
}
|
|
197
|
+
} else {
|
|
198
|
+
// Image exists, check for updates silently
|
|
199
|
+
console.log(chalk.blue('📦 Checking for image updates...'));
|
|
200
|
+
try {
|
|
201
|
+
const pullProcess = spawn('docker', ['pull', DOCKER_IMAGE], {
|
|
202
|
+
stdio: 'pipe',
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
let hasUpdates = false;
|
|
206
|
+
let errorOutput = '';
|
|
207
|
+
|
|
208
|
+
pullProcess.stdout.on('data', (data) => {
|
|
209
|
+
const output = data.toString();
|
|
210
|
+
if (output.includes('Downloaded') || output.includes('Downloading')) {
|
|
211
|
+
hasUpdates = true;
|
|
212
|
+
}
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
pullProcess.stderr.on('data', (data) => {
|
|
216
|
+
errorOutput += data.toString();
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
await new Promise((resolve, reject) => {
|
|
220
|
+
pullProcess.on('close', (code) => {
|
|
221
|
+
if (code === 0) {
|
|
222
|
+
if (hasUpdates) {
|
|
223
|
+
console.log(chalk.green('✅ Image updated successfully'));
|
|
224
|
+
} else {
|
|
225
|
+
console.log(chalk.green('✅ Image is up to date'));
|
|
226
|
+
}
|
|
227
|
+
resolve();
|
|
228
|
+
} else {
|
|
229
|
+
reject(new Error(`Update check failed with code ${code}`));
|
|
230
|
+
}
|
|
231
|
+
});
|
|
232
|
+
});
|
|
233
|
+
} catch (updateError) {
|
|
234
|
+
console.log(chalk.yellow('⚠️ Update check failed, using cached local image'));
|
|
195
235
|
}
|
|
196
|
-
console.log(chalk.green('✅ Using cached local image'));
|
|
197
236
|
}
|
|
198
237
|
|
|
199
238
|
// Now resolve container port (after image is ready)
|
|
@@ -211,7 +250,7 @@ class ContainerManager {
|
|
|
211
250
|
if (APP_PORT === WS_PORT || !(await isPortAvailable(APP_PORT))) {
|
|
212
251
|
try {
|
|
213
252
|
const newPort = await findAvailableContainerPort(DEFAULT_CONTAINER_PORT, 100, [WS_PORT]);
|
|
214
|
-
console.log(chalk.
|
|
253
|
+
console.log(chalk.yellow(`Port ${APP_PORT} is in use, using port ${newPort} for DevApp`));
|
|
215
254
|
APP_PORT = newPort;
|
|
216
255
|
} catch (err) {
|
|
217
256
|
throw new Error(`Failed to resolve DevApp port conflict: ${err.message}`);
|
package/daemon/agentRunner.js
CHANGED
|
@@ -428,14 +428,12 @@ export async function runAgent(options = {}) {
|
|
|
428
428
|
};
|
|
429
429
|
|
|
430
430
|
// Now that WebSocket is bound, start container (so it cannot take the WS port)
|
|
431
|
-
log('Starting container (after WebSocket bind)...');
|
|
432
431
|
let actualContainerPort = preferredContainerPort;
|
|
433
432
|
try {
|
|
434
433
|
actualContainerPort = await containerManager.startContainer({
|
|
435
434
|
wsPort: actualPort,
|
|
436
435
|
containerPort: preferredContainerPort,
|
|
437
436
|
});
|
|
438
|
-
log(`Container started successfully on port ${actualContainerPort}`);
|
|
439
437
|
} catch (containerError) {
|
|
440
438
|
log(`Failed to start container: ${containerError.message}`, 'warn');
|
|
441
439
|
log('Continuing without container...');
|