package cn.reghao.bnt.web.devops.builder.tool.compiler;

import cn.reghao.bnt.common.docker.Docker;
import cn.reghao.bnt.common.docker.DockerImpl;
import cn.reghao.bnt.common.docker.model.Config;

/**
 * @author reghao
 * @date 2024-08-09 09:49:11
 */
public class DockerCompiler implements CodeCompiler {
    private final Docker docker;
    private final Config config;

    public DockerCompiler(Config config) {
        this.docker = new DockerImpl();
        this.config = config;
    }

    @Override
    public void compile(String appId, String appCompileHome) throws Exception {
        Config config1;
        synchronized(this) {
            config.getVolumes().getMap().put("/app", appCompileHome);
            config1 = (Config) config.clone();
        }

        docker.runAndRm(config1);
    }
}
