Search in sources :

Example 6 with IPlugin

use of io.jpom.plugin.IPlugin in project Jpom by dromara.

the class ReleaseManage method doDockerImage.

private void doDockerImage(DockerInfoModel dockerInfoModel, File dockerfile, File baseDir, String dockerTag) {
    logRecorder.info("{} start build image {}", dockerInfoModel.getName(), dockerTag);
    Map<String, Object> map = dockerInfoModel.toParameter();
    map.put("Dockerfile", dockerfile);
    map.put("baseDirectory", baseDir);
    // 
    map.put("tags", dockerTag);
    Consumer<String> logConsumer = s -> logRecorder.append(s);
    map.put("logConsumer", logConsumer);
    IPlugin plugin = PluginFactory.getPlugin(DockerInfoService.DOCKER_PLUGIN_NAME);
    try {
        plugin.execute("buildImage", map);
    } catch (Exception e) {
        logRecorder.error("调用容器异常", e);
    }
}
Also used : DateUtil(cn.hutool.core.date.DateUtil) SecureUtil(cn.hutool.crypto.SecureUtil) DockerInfoService(io.jpom.service.docker.DockerInfoService) Map(java.util.Map) WorkspaceEnvVarService(io.jpom.service.system.WorkspaceEnvVarService) BetweenFormatter(cn.hutool.core.date.BetweenFormatter) Sftp(cn.hutool.extra.ssh.Sftp) NodeForward(io.jpom.common.forward.NodeForward) LineHandler(cn.hutool.core.io.LineHandler) SshService(io.jpom.service.node.ssh.SshService) NodeModel(io.jpom.model.data.NodeModel) AfterOpt(io.jpom.model.AfterOpt) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) Objects(java.util.Objects) StrUtil(cn.hutool.core.util.StrUtil) List(java.util.List) Builder(lombok.Builder) Session(com.jcraft.jsch.Session) ArrayUtil(cn.hutool.core.util.ArrayUtil) SshModel(io.jpom.model.data.SshModel) SystemClock(cn.hutool.core.date.SystemClock) CharPool(cn.hutool.core.text.CharPool) JSONObject(com.alibaba.fastjson.JSONObject) HttpStatus(cn.hutool.http.HttpStatus) IPlugin(io.jpom.plugin.IPlugin) CommandUtil(io.jpom.util.CommandUtil) ResourceUtil(cn.hutool.core.io.resource.ResourceUtil) LogRecorder(io.jpom.util.LogRecorder) BuildReleaseMethod(io.jpom.model.enums.BuildReleaseMethod) JschUtil(cn.hutool.extra.ssh.JschUtil) JpomRuntimeException(io.jpom.system.JpomRuntimeException) JsonMessage(cn.jiangzeyin.common.JsonMessage) JSONArray(com.alibaba.fastjson.JSONArray) BaseEnum(io.jpom.model.BaseEnum) NodeService(io.jpom.service.node.NodeService) OutGivingRun(io.jpom.outgiving.OutGivingRun) PluginFactory(io.jpom.plugin.PluginFactory) IoUtil(cn.hutool.core.io.IoUtil) DockerInfoModel(io.jpom.model.docker.DockerInfoModel) SpringUtil(cn.jiangzeyin.common.spring.SpringUtil) DockerSwarmInfoService(io.jpom.service.docker.DockerSwarmInfoService) File(java.io.File) NodeUrl(io.jpom.common.forward.NodeUrl) Consumer(java.util.function.Consumer) CollUtil(cn.hutool.core.collection.CollUtil) StringUtil(io.jpom.util.StringUtil) ConfigBean(io.jpom.system.ConfigBean) FileUtil(cn.hutool.core.io.FileUtil) UserModel(io.jpom.model.data.UserModel) BuildStatus(io.jpom.model.enums.BuildStatus) InputStream(java.io.InputStream) JSONObject(com.alibaba.fastjson.JSONObject) JpomRuntimeException(io.jpom.system.JpomRuntimeException) IPlugin(io.jpom.plugin.IPlugin)

Example 7 with IPlugin

use of io.jpom.plugin.IPlugin in project Jpom by dromara.

the class ReleaseManage method updateSwarmService.

private void updateSwarmService(String dockerTag, String swarmId, String serviceName) {
    if (StrUtil.isEmpty(swarmId)) {
        return;
    }
    List<String> splitTrim = StrUtil.splitTrim(dockerTag, StrUtil.COMMA);
    String first = CollUtil.getFirst(splitTrim);
    logRecorder.info("start update swarm service: {} use image {}", serviceName, first);
    Map<String, Object> pluginMap = buildExecuteService.dockerInfoService.getBySwarmPluginMap(swarmId);
    pluginMap.put("serviceId", serviceName);
    pluginMap.put("image", first);
    try {
        IPlugin plugin = PluginFactory.getPlugin(DockerSwarmInfoService.DOCKER_PLUGIN_NAME);
        plugin.execute("updateServiceImage", pluginMap);
    } catch (Exception e) {
        logRecorder.error("调用容器异常", e);
    }
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) JpomRuntimeException(io.jpom.system.JpomRuntimeException) IPlugin(io.jpom.plugin.IPlugin)

Example 8 with IPlugin

use of io.jpom.plugin.IPlugin in project Jpom by dromara.

the class AbstractProjectCommander method webHooks.

/**
 * 执行 webhooks 通知
 *
 * @param nodeProjectInfoModel 项目信息
 * @param javaCopyItem         副本信息
 * @param type                 类型
 * @param other                其他参数
 * @return 结果
 */
private String webHooks(NodeProjectInfoModel nodeProjectInfoModel, NodeProjectInfoModel.JavaCopyItem javaCopyItem, String type, Object... other) throws Exception {
    String token = nodeProjectInfoModel.getToken();
    IPlugin plugin = PluginFactory.getPlugin("webhook");
    Map<String, Object> map = new HashMap<>(10);
    map.put("projectId", nodeProjectInfoModel.getId());
    map.put("projectName", nodeProjectInfoModel.getName());
    map.put("type", type);
    if (javaCopyItem != null) {
        map.put("copyId", javaCopyItem.getId());
    }
    for (int i = 0; i < other.length; i += 2) {
        map.put(other[i].toString(), other[i + 1]);
    }
    Object execute = plugin.execute(token, map);
    return Convert.toStr(execute, StrUtil.EMPTY);
}
Also used : HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) IPlugin(io.jpom.plugin.IPlugin)

Example 9 with IPlugin

use of io.jpom.plugin.IPlugin in project Jpom by dromara.

the class DockerImagesController method pullImage.

/**
 * @return json
 */
@GetMapping(value = "pull-image", produces = MediaType.APPLICATION_JSON_VALUE)
@Feature(method = MethodFeature.EXECUTE)
public String pullImage(@ValidatorItem String id, String repository) throws Exception {
    DockerInfoModel dockerInfoModel = dockerInfoService.getByKey(id, getRequest());
    IPlugin plugin = PluginFactory.getPlugin(DockerInfoService.DOCKER_PLUGIN_NAME);
    Map<String, Object> parameter = dockerInfoModel.toParameter();
    parameter.put("repository", repository);
    // 
    String uuid = IdUtil.fastSimpleUUID();
    File file = FileUtil.file(ServerConfigBean.getInstance().getUserTempPath(), "docker-log", uuid + ".log");
    LogRecorder logRecorder = LogRecorder.builder().file(file).build();
    logRecorder.info("start pull {}", repository);
    Consumer<String> logConsumer = logRecorder::info;
    parameter.put("logConsumer", logConsumer);
    ThreadUtil.execute(() -> {
        try {
            plugin.execute("pullImage", parameter);
        } catch (Exception e) {
            logRecorder.error("拉取异常", e);
        }
        logRecorder.info("pull end");
    });
    return JsonMessage.getString(200, "开始拉取", uuid);
}
Also used : DockerInfoModel(io.jpom.model.docker.DockerInfoModel) JSONObject(com.alibaba.fastjson.JSONObject) File(java.io.File) LogRecorder(io.jpom.util.LogRecorder) IPlugin(io.jpom.plugin.IPlugin) Feature(io.jpom.permission.Feature) MethodFeature(io.jpom.permission.MethodFeature) ClassFeature(io.jpom.permission.ClassFeature)

Example 10 with IPlugin

use of io.jpom.plugin.IPlugin in project Jpom by dromara.

the class DockerImagesController method createContainer.

/**
 * @return json
 */
@PostMapping(value = "create-container", produces = MediaType.APPLICATION_JSON_VALUE)
@Feature(method = MethodFeature.EXECUTE)
public String createContainer(@RequestBody JSONObject jsonObject) throws Exception {
    Assert.hasText(jsonObject.getString("id"), "id 不能为空");
    Assert.hasText(jsonObject.getString("imageId"), "镜像不能为空");
    Assert.hasText(jsonObject.getString("name"), "容器名称不能为空");
    DockerInfoModel dockerInfoModel = dockerInfoService.getByKey(jsonObject.getString("id"), getRequest());
    IPlugin plugin = PluginFactory.getPlugin(DockerInfoService.DOCKER_PLUGIN_NAME);
    Map<String, Object> parameter = dockerInfoModel.toParameter();
    parameter.putAll(jsonObject);
    plugin.execute("createContainer", parameter);
    return JsonMessage.getString(200, "创建成功");
}
Also used : DockerInfoModel(io.jpom.model.docker.DockerInfoModel) JSONObject(com.alibaba.fastjson.JSONObject) IPlugin(io.jpom.plugin.IPlugin) Feature(io.jpom.permission.Feature) MethodFeature(io.jpom.permission.MethodFeature) ClassFeature(io.jpom.permission.ClassFeature)

Aggregations

IPlugin (io.jpom.plugin.IPlugin)16 JSONObject (com.alibaba.fastjson.JSONObject)10 DockerInfoModel (io.jpom.model.docker.DockerInfoModel)8 ClassFeature (io.jpom.permission.ClassFeature)5 Feature (io.jpom.permission.Feature)5 MethodFeature (io.jpom.permission.MethodFeature)5 HashMap (java.util.HashMap)5 File (java.io.File)4 JpomRuntimeException (io.jpom.system.JpomRuntimeException)2 CollUtil (cn.hutool.core.collection.CollUtil)1 BetweenFormatter (cn.hutool.core.date.BetweenFormatter)1 DateUtil (cn.hutool.core.date.DateUtil)1 SystemClock (cn.hutool.core.date.SystemClock)1 FileUtil (cn.hutool.core.io.FileUtil)1 IoUtil (cn.hutool.core.io.IoUtil)1 LineHandler (cn.hutool.core.io.LineHandler)1 ResourceUtil (cn.hutool.core.io.resource.ResourceUtil)1 CharPool (cn.hutool.core.text.CharPool)1 ArrayUtil (cn.hutool.core.util.ArrayUtil)1 StrUtil (cn.hutool.core.util.StrUtil)1