@noosphere/agent-core 0.1.0-alpha.8 → 0.1.0-alpha.9

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/dist/index.cjs CHANGED
@@ -495,14 +495,19 @@ var ContainerManager = class {
495
495
  console.log(`
496
496
  \u{1F680} Preparing ${containers.size} containers...`);
497
497
  const pullAndStartPromises = Array.from(containers.entries()).map(async ([id, container]) => {
498
+ const imageTag = `${container.image}:${container.tag || "latest"}`;
498
499
  try {
499
- const imageTag = `${container.image}:${container.tag || "latest"}`;
500
500
  console.log(` Pulling ${imageTag}...`);
501
501
  await this.pullImage(container.image, container.tag || "latest");
502
502
  console.log(` \u2713 ${imageTag} ready`);
503
+ } catch (error) {
504
+ console.error(` \u274C Failed to pull ${imageTag}:`, error.message);
505
+ return;
506
+ }
507
+ try {
503
508
  await this.startPersistentContainer(id, container);
504
509
  } catch (error) {
505
- console.error(` \u274C Failed to prepare ${container.image}:`, error.message);
510
+ console.error(` \u274C Failed to start ${container.name || container.image}:`, error.message);
506
511
  }
507
512
  });
508
513
  await Promise.all(pullAndStartPromises);
@@ -514,21 +519,23 @@ var ContainerManager = class {
514
519
  async startPersistentContainer(containerId, metadata) {
515
520
  const containerName = `noosphere-${metadata.name}`;
516
521
  const imageTag = `${metadata.image}:${metadata.tag || "latest"}`;
522
+ const existingContainer = this.docker.getContainer(containerName);
517
523
  try {
518
- const existingContainer = this.docker.getContainer(containerName);
519
- try {
520
- const inspect = await existingContainer.inspect();
521
- if (inspect.State.Running) {
522
- console.log(` \u2713 Container ${containerName} already running`);
523
- this.persistentContainers.set(containerId, existingContainer);
524
- return;
525
- } else {
524
+ const inspect = await existingContainer.inspect();
525
+ if (inspect.State.Running) {
526
+ console.log(` \u2713 Container ${containerName} already running`);
527
+ this.persistentContainers.set(containerId, existingContainer);
528
+ return;
529
+ } else {
530
+ try {
526
531
  await existingContainer.start();
527
532
  console.log(` \u2713 Started existing container ${containerName}`);
528
533
  this.persistentContainers.set(containerId, existingContainer);
529
534
  return;
535
+ } catch (startErr) {
536
+ console.log(` Removing stopped container ${containerName} to recreate...`);
537
+ await existingContainer.remove({ force: true });
530
538
  }
531
- } catch (err) {
532
539
  }
533
540
  } catch (err) {
534
541
  }