diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/image/ImageController.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/image/ImageController.java index 64b569d8..a0b117d8 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/image/ImageController.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/image/ImageController.java @@ -116,7 +116,7 @@ public class ImageController extends BaseController { * @return 删除是否成功 */ @DeleteMapping("{id}") - public GenericsAjaxResult deleteById(@PathVariable("id") Integer id) { + public GenericsAjaxResult deleteById(@PathVariable("id") Integer id) throws Exception { return genericsSuccess(this.imageService.removeById(id)); } diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/ImageServiceImpl.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/ImageServiceImpl.java index 2d8da4cf..7748c954 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/ImageServiceImpl.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/ImageServiceImpl.java @@ -263,7 +263,7 @@ public class ImageServiceImpl implements ImageService { V1Pod pod = k8sClientUtil.getNSPodList(serviceNS, deploymentName); if (pod == null) { String podName = deploymentName+"-"+ DateUtils.formatYMD10(new Date()); - pod = createPod(serviceNS, podName); + pod = k8sClientUtil.createPodWithEnv(podName,serviceNS,proxyUrl,mountPath,pvcName,image); } String loginCmd = "docker login -u " + harborUser +" -p "+harborpassword+" "+harborUrl; // 执行命令 docker login -u admin -p Harbor12345 172.20.32.187 @@ -274,9 +274,9 @@ public class ImageServiceImpl implements ImageService { 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.lastIndexOf(harborUrl)); - String cleanedString = substring.replaceAll("(\\r|\\n)", ""); - String tagCmd = "docker tag " + cleanedString + " " + harborUrl + "/" + repository + "/" + username + "/" + imageName + ":" + imageTag; + String[] lines = logs2.split("\n"); + String lastLine = lines[lines.length - 1].trim(); + String tagCmd = "docker tag " + lastLine + " " + harborUrl + "/" + repository + "/" + username + "/" + imageName + ":" + imageTag; String imageUrl = harborUrl + "/" + repository + "/" + username + "/" + imageName + ":" + imageTag; String pushCmd = "docker push " + imageUrl; String sizeCmd = "docker inspect --format='{{.Size}}' " + imageUrl; @@ -305,7 +305,7 @@ public class ImageServiceImpl implements ImageService { V1Pod pod = k8sClientUtil.getNSPodList(serviceNS, deploymentName); if (pod == null) { String podName = deploymentName+"-"+ DateUtils.formatYMD10(new Date()); - pod = createPod(serviceNS, podName); + pod = k8sClientUtil.createPodWithEnv(podName,serviceNS,proxyUrl,mountPath,pvcName,image); } String loginCmd = "docker login -u " + harborUser +" -p "+harborpassword+" "+harborUrl; // 执行命令 docker login -u admin -p Harbor12345 172.20.32.187 @@ -346,8 +346,4 @@ public class ImageServiceImpl implements ImageService { String path = loginUser.getUsername()+"/"+file.getOriginalFilename(); return minioService.uploadFile(bucketName, path, file); } - - private V1Pod createPod(String namespace, String podName){ - return k8sClientUtil.createPodWithEnv(podName,namespace,proxyUrl,mountPath,pvcName,image); - } }