import RandomString from '../randomString.js';
import Image from './image.js';
export default class Volume {
    _BASE_IMAGE_NAME = "busybox:latest";
    docker;
    name;
    constructor(docker) {
        this.docker = docker;
        this.name = "cloudscripts-vol-" + RandomString.get();
    }
    async create() {
        await this.docker.createVolume({ "Name": this.name });
    }
    async destroy() {
        const volume = this.docker.getVolume(this.name);
        await volume.remove();
    }
    getName() {
        return this.name;
    }
    async put(srcRoot, srcPaths, destPath) {
        const image = new Image(this.docker, this._BASE_IMAGE_NAME);
        await image.pull();
        await image.withContainer({ mounts: { [destPath]: this } }, async (container) => {
            await container.run();
            await container.putFiles(srcRoot, srcPaths, destPath);
        });
    }
}
