import Docker from 'dockerode';
import BuildHost from '../buildHost.js';
import OutputManager from '../outputManager.js';
import DockerWrapper from './dockerWrapper.js';
export default class RemoteDockerWrapper extends DockerWrapper {
    async dispose() {
        const buildHost = await BuildHost.get();
        buildHost.getTunnel()?.close();
    }
    async getDocker() {
        // When using remote docker, don't allow DOCKER_HOST to override it.
        // (You might think explicitly passing the host/port into the constructor
        // would win out, but it does not.)
        delete process.env.DOCKER_HOST;
        const buildHost = await BuildHost.get();
        return new Docker({ host: buildHost.getDockerLocalHost(), port: buildHost.getDockerLocalPort() });
    }
    async isAvailable() {
        const buildHost = await BuildHost.get();
        return buildHost.isProvisioned();
    }
    async prepare() {
        const buildHost = await BuildHost.get();
        await buildHost.createTunnel();
    }
    async start() {
        const buildHost = await BuildHost.get();
        OutputManager.detail(`Starting Build Host (Kyndryl Cloud Uplift environment ${buildHost.getEnvironmentId()})`);
        await buildHost.start();
    }
}
