"use server";

import Dockerode from "dockerode";

export async function pullImage(imageName: string) {
  console.log("Pulling image:", imageName);
  const docker = new Dockerode({ socketPath: "/var/run/docker.sock" });
  return new Promise((resolve, reject) => {
    docker.pull(imageName, (err: Error, stream: NodeJS.ReadableStream) => {
      if (err) {
        reject(err);
        return;
      }
      docker.modem.followProgress(stream, (err, output) => {
        if (err) {
          reject(err);
        }
        resolve(output);
      });
    });
  });
}
