|
|
|
@@ -181,7 +181,6 @@ public class ImageServiceImpl implements ImageService { |
|
|
|
ImageVersion imageVersion = new ImageVersion(); |
|
|
|
imageVersion.setImageId(imageInsert.getId()); |
|
|
|
imageVersion.setVersion(imageVo.getVersion()); |
|
|
|
imageVersion.setUrl(imageVo.getUrl()); |
|
|
|
imageVersion.setTagName(imageVo.getTagName()); |
|
|
|
imageVersion.setFileSize(imageVo.getFileSize()); |
|
|
|
imageVersion.setStatus("building"); |
|
|
|
@@ -241,18 +240,18 @@ 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.indexOf(harborUrl), logs2.length()); |
|
|
|
String substring = logs2.substring(logs2.lastIndexOf(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 cmd3 = "docker inspect --format='{{.Size}}' " + imageUrl; |
|
|
|
|
|
|
|
String s = k8sClientUtil.executeCommand(pod, cmd1); |
|
|
|
if (StringUtils.isNotEmpty(k8sClientUtil.executeCommand(pod, cmd2))){ |
|
|
|
String tagCmd = "docker tag " + cleanedString + " " + harborUrl + "/" + repository + "/" + username + "/" + imageName + ":" + imageTag; |
|
|
|
String imageUrl = harborUrl + "/" + repository + "/" + username + "/" + imageName + ":" + imageTag; |
|
|
|
String pushCmd = "docker push " + imageUrl; |
|
|
|
String sizeCmd = "docker inspect --format='{{.Size}}' " + imageUrl; |
|
|
|
String s = k8sClientUtil.executeCommand(pod, tagCmd); |
|
|
|
if (StringUtils.isNotEmpty(k8sClientUtil.executeCommand(pod, pushCmd))){ |
|
|
|
resultMap.put("url", imageUrl); |
|
|
|
//得到镜像文件大小 |
|
|
|
long sizeInBytes = Long.parseLong(k8sClientUtil.executeCommand(pod, cmd3)); |
|
|
|
String imageSizeStr = k8sClientUtil.executeCommand(pod, sizeCmd); |
|
|
|
long sizeInBytes = Long.parseLong(imageSizeStr.trim()); |
|
|
|
String formattedImageSize = FileUtil.formatFileSize(sizeInBytes); // 格式化镜像文件大小 |
|
|
|
resultMap.put("fileSize", formattedImageSize); |
|
|
|
return resultMap; |
|
|
|
@@ -283,17 +282,18 @@ public class ImageServiceImpl implements ImageService { |
|
|
|
String logs2 = k8sClientUtil.executeCommand(pod,"docker load -i "+filePath); |
|
|
|
// 在容器里执行 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 substring = logs2.substring(logs2.lastIndexOf(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 cmd3 = "docker inspect --format='{{.Size}}' " + imageUrl; |
|
|
|
String s = k8sClientUtil.executeCommand(pod, cmd1); |
|
|
|
if (StringUtils.isNotEmpty(k8sClientUtil.executeCommand(pod, cmd2))){ |
|
|
|
String tagCmd = "docker tag " + cleanedString + " " + harborUrl + "/" + repository + "/" + username + "/" + imageName + ":" + imageTag; |
|
|
|
String imageUrl = harborUrl + "/" + repository + "/" + username + "/" + imageName + ":" + imageTag; |
|
|
|
String pushCmd = "docker push " + imageUrl; |
|
|
|
String sizeCmd = "docker inspect --format='{{.Size}}' " + imageUrl; |
|
|
|
String s = k8sClientUtil.executeCommand(pod, tagCmd); |
|
|
|
if (StringUtils.isNotEmpty(k8sClientUtil.executeCommand(pod, pushCmd))){ |
|
|
|
resultMap.put("url", imageUrl); |
|
|
|
//得到镜像文件大小 |
|
|
|
long sizeInBytes = Long.parseLong(k8sClientUtil.executeCommand(pod, cmd3)); |
|
|
|
String imageSizeStr = k8sClientUtil.executeCommand(pod, sizeCmd); |
|
|
|
long sizeInBytes = Long.parseLong(imageSizeStr.trim()); |
|
|
|
String formattedImageSize = FileUtil.formatFileSize(sizeInBytes); // 格式化镜像文件大小 |
|
|
|
resultMap.put("fileSize", formattedImageSize); |
|
|
|
return resultMap; |
|
|
|
|