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);
}
}
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);
}
}
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);
}
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);
}
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, "创建成功");
}
Aggregations