|
|
@@ -3,6 +3,7 @@ package cn.reghao.bnt.common.agent.app.iface.impl;
|
|
|
import cn.reghao.bnt.common.docker.Docker;
|
|
|
import cn.reghao.bnt.common.docker.DockerImpl;
|
|
|
import cn.reghao.bnt.common.docker.po.Config;
|
|
|
+import cn.reghao.bnt.common.docker.po.DockerAuth;
|
|
|
import cn.reghao.bnt.common.docker.po.HostConfig;
|
|
|
import cn.reghao.bnt.common.machine.Machine;
|
|
|
import cn.reghao.bnt.common.msg.constant.NodeStatus;
|
|
|
@@ -13,12 +14,19 @@ import cn.reghao.jutil.jdk.converter.DateTimeConverter;
|
|
|
import cn.reghao.jutil.jdk.serializer.JsonConverter;
|
|
|
import com.github.dockerjava.api.command.InspectContainerResponse;
|
|
|
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
/**
|
|
|
* @author reghao
|
|
|
* @date 2023-03-06 15:26:22
|
|
|
*/
|
|
|
public class DockerApp {
|
|
|
- private final Docker docker = new DockerImpl();
|
|
|
+ private Map<String, Docker> map = new HashMap<>();
|
|
|
+
|
|
|
+ public DockerApp() {
|
|
|
+ this.map.put("noAuth", new DockerImpl());
|
|
|
+ }
|
|
|
|
|
|
public EvtAppStatResult deploy(EvtAppDeploy deployParam) throws Exception {
|
|
|
String appId = deployParam.getAppId();
|
|
|
@@ -33,27 +41,44 @@ public class DockerApp {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ Docker docker;
|
|
|
+ DockerAuth dockerAuth = deployParam.getDockerAuth();
|
|
|
+ if (dockerAuth != null) {
|
|
|
+ String registryUrl = dockerAuth.getRegistryUrl();
|
|
|
+ docker = map.get(registryUrl);
|
|
|
+ if (docker == null) {
|
|
|
+ // TODO DockerAuth 修改后 map 中的 Docker 实例无效
|
|
|
+ docker = new DockerImpl(dockerAuth);
|
|
|
+ map.put(registryUrl, docker);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ docker = map.get("noAuth");
|
|
|
+ }
|
|
|
docker.pull(packagePath);
|
|
|
InspectContainerResponse containerInfo = docker.createAndRun(appId, containerConfig);
|
|
|
return getStat(appId, containerInfo);
|
|
|
}
|
|
|
|
|
|
public EvtAppStatResult start(String appId) throws Exception {
|
|
|
+ Docker docker = map.get("noAuth");
|
|
|
InspectContainerResponse containerInfo = docker.start(appId);
|
|
|
return getStat(appId, containerInfo);
|
|
|
}
|
|
|
|
|
|
public EvtAppStatResult stop(String appId) throws Exception {
|
|
|
+ Docker docker = map.get("noAuth");
|
|
|
InspectContainerResponse containerInfo = docker.stop(appId);
|
|
|
return getStat(appId, containerInfo);
|
|
|
}
|
|
|
|
|
|
public EvtAppStatResult restart(String appId) throws Exception {
|
|
|
+ Docker docker = map.get("noAuth");
|
|
|
InspectContainerResponse containerInfo = docker.restart(appId);
|
|
|
return getStat(appId, containerInfo);
|
|
|
}
|
|
|
|
|
|
public EvtAppStatResult stat(String appId) throws Exception {
|
|
|
+ Docker docker = map.get("noAuth");
|
|
|
InspectContainerResponse containerInfo = docker.inspectContainer(appId);
|
|
|
return getStat(appId, containerInfo);
|
|
|
}
|