async execute()

in app/lib/server/processors/DockerJobExecutor.ts [16:57]


  async execute(jobId: string, jobData: any, credentials: any) {
    console.log(`🐳 Executing job ${jobId} via Docker`);
    console.log(`📦 Job data:`, jobData);

    try {
      // Initialize Docker if not already done
      if (!this.docker) {
        try {
          // Dynamic import to avoid issues in client-side code
          const Docker = await import("dockerode");
          this.docker = new Docker.default();

          // Test Docker connection
          await this.docker.ping();
          console.log("🐳 Docker daemon connected successfully");
        } catch (error) {
          throw new Error(`Docker daemon not available: ${error.message}`);
        }
      }

      // Execute job in Docker container using the same setup as API
      const { output, environment, secrets } = await this.runJobInContainer(
        jobId,
        jobData,
        credentials
      );

      // Extract diff from output
      const diff = this.extractDiffFromOutput(output, jobId);

      return {
        success: true,
        output: output,
        diff: diff,
        environment: environment,
        secrets: secrets,
      };
    } catch (error) {
      console.error(`❌ Docker job execution failed for ${jobId}:`, error);
      throw error;
    }
  }