|
|
|
@@ -191,6 +191,38 @@ public class ImageServiceImpl implements ImageService { |
|
|
|
return "新增镜像成功"; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public String createImageFromNet(String imageName, String imageTag, String netPath) throws Exception { |
|
|
|
// 得到容器 |
|
|
|
V1Pod pod = K8sClientUtil.getNSPodList(serviceNS, deploymentName); |
|
|
|
if (pod == null) { |
|
|
|
throw new Exception("镜像推送服务不存在"); |
|
|
|
} |
|
|
|
String loginCmd = "docker login -u " + harborUser +" -p "+harborpassword+" "+harborUrl; |
|
|
|
// 执行命令 docker login -u admin -p Harbor12345 172.20.32.187 |
|
|
|
String loginlog = K8sClientUtil.executeCommand(pod,loginCmd); |
|
|
|
// 在这个容器的/data/admin 目录下执行命令 docker load -i fileName 得到返回的镜像名字name:tag |
|
|
|
String username = SecurityUtils.getLoginUser().getUsername(); |
|
|
|
// |
|
|
|
String logs2 = K8sClientUtil.executeCommand(pod,"docker pull "+netPath); |
|
|
|
// 在容器里执行 docker tag name:tag nexus3.kube-system.svc:8083/imageName:imageTag |
|
|
|
if (StringUtils.isNoneBlank(logs2)){ |
|
|
|
String substring = logs2.substring(logs2.indexOf(harborUrl), logs2.length()); |
|
|
|
String cleanedString = substring.replaceAll("(\\r|\\n)", ""); |
|
|
|
String cmd1 = "docker tag " + cleanedString+ " " + harborUrl+"/"+repository+"/"+username+"/" + imageName + imageTag; |
|
|
|
String imageUrl = harborUrl+"/"+repository+"/"+username+"/" + imageName + imageTag; |
|
|
|
String cmd2 = "docker push " + imageUrl; |
|
|
|
String s = K8sClientUtil.executeCommand(pod, cmd1); |
|
|
|
if (StringUtils.isNotEmpty(K8sClientUtil.executeCommand(pod, cmd2))){ |
|
|
|
return imageUrl; |
|
|
|
}else { |
|
|
|
throw new Exception("拉取公网镜像失败,请检查网络或者镜像地址"); |
|
|
|
} |
|
|
|
}else { |
|
|
|
throw new Exception("拉取公网镜像失败,请检查网络或者镜像地址"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public String createImageFromLocal(String imageName, String imageTag, String path) throws Exception { |
|
|
|
// 得到容器 |
|
|
|
|