From 250f401b177748b79995d79c5098ed0f905b3afe Mon Sep 17 00:00:00 2001
From: liu2592603532 <2592603532@qq.com>
Date: Mon, 22 Apr 2024 09:59:40 +0800
Subject: [PATCH 1/3] merge
---
react-ui/src/components/RightContent/index.tsx | 2 +-
react-ui/src/pages/Dataset/index.less | 11 +++++------
react-ui/src/pages/Model/index.less | 8 ++++----
3 files changed, 10 insertions(+), 11 deletions(-)
diff --git a/react-ui/src/components/RightContent/index.tsx b/react-ui/src/components/RightContent/index.tsx
index 52a49bbd..c2a4a7bf 100644
--- a/react-ui/src/components/RightContent/index.tsx
+++ b/react-ui/src/components/RightContent/index.tsx
@@ -50,7 +50,7 @@ const GlobalHeaderRight: React.FC = () => {
-
+ {/* */}
);
};
diff --git a/react-ui/src/pages/Dataset/index.less b/react-ui/src/pages/Dataset/index.less
index d22c8dbe..2ff0b580 100644
--- a/react-ui/src/pages/Dataset/index.less
+++ b/react-ui/src/pages/Dataset/index.less
@@ -210,7 +210,6 @@
display: flex;
flex: 1;
flex-direction: column;
- font-family: 'Alibaba';
height: 100%;
padding: 22px 30px 26px 30px;
background: #ffffff;
@@ -229,11 +228,11 @@
flex: 1;
flex-wrap: wrap;
align-content: flex-start;
- font-family: 'Alibaba';
- width: 103%;
+
+ width: 102%;
.dataItem {
position: relative;
- width: 23%;
+ width: 23.5%;
height:164px;
background:#ffffff;
border:1px solid;
@@ -250,7 +249,7 @@
line-height: 0px;
color:#1d1d20;
font-size:16px;
-
+ font-family: 'Alibaba';
}
.itemDescripition{
position: absolute;
@@ -286,7 +285,7 @@
}
.dataItem:hover{
border-color: #1664FF;
- box-shadow: 0px 0px 6px 1px rgba(0, 0, 0, 0.2)
+ box-shadow: 0px 0px 6px 1px rgba(0, 0, 0, 0.1)
}
.dataItem:hover .itemText{
diff --git a/react-ui/src/pages/Model/index.less b/react-ui/src/pages/Model/index.less
index 5bf1cc1b..7bee2701 100644
--- a/react-ui/src/pages/Model/index.less
+++ b/react-ui/src/pages/Model/index.less
@@ -219,10 +219,10 @@
flex: 1;
flex-wrap: wrap;
align-content: flex-start;
- width: 100%;
+ width: 102%;
.dataItem {
position: relative;
- width: 23%;
+ width: 23.5%;
height:164px;
background:#ffffff;
border:1px solid;
@@ -239,7 +239,7 @@
line-height: 0px;
color:#1d1d20;
font-size:16px;
-
+ font-family: 'Alibaba';
}
.itemDescripition{
position: absolute;
@@ -275,7 +275,7 @@
}
.dataItem:hover{
border-color: #1664FF;
- box-shadow: 0px 0px 6px 1px rgba(0, 0, 0, 0.2)
+ box-shadow: 0px 0px 6px 1px rgba(0, 0, 0, 0.1)
}
.dataItem:hover .itemText{
From eef2f3e4f56c1e842600c30c134592824d252721 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E8=A5=BF=E5=A4=A7=E9=94=90?= <1070211640@qq.com>
Date: Mon, 22 Apr 2024 14:16:19 +0800
Subject: [PATCH 2/3] =?UTF-8?q?=E9=95=9C=E5=83=8F=E6=9E=84=E5=BB=BA?=
=?UTF-8?q?=E6=8E=A5=E5=8F=A3=E4=BF=AE=E6=94=B9docker=E5=91=BD=E4=BB=A4?=
=?UTF-8?q?=E6=88=AA=E5=8F=96=E9=80=BB=E8=BE=91=EF=BC=8C=E4=BF=AE=E5=A4=8D?=
=?UTF-8?q?bug?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../service/impl/ImageServiceImpl.java | 36 +++++++++----------
.../ruoyi/platform/utils/K8sClientUtil.java | 7 ++++
.../java/com/ruoyi/platform/vo/ImageVo.java | 20 ++++++-----
3 files changed, 36 insertions(+), 27 deletions(-)
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 831c242f..b9a3d990 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
@@ -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;
diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/utils/K8sClientUtil.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/utils/K8sClientUtil.java
index 58bdabfe..9815d25c 100644
--- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/utils/K8sClientUtil.java
+++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/utils/K8sClientUtil.java
@@ -406,6 +406,13 @@ public class K8sClientUtil {
builder.append(line);
builder.append(System.getProperty("line.separator"));
}
+ // 等待进程结束,并获取退出值
+ int exitValue = proc.waitFor();
+ if (exitValue != 0) {
+ // 如果进程的退出值不为0,表示命令执行失败
+ throw new RuntimeException("命令执行失败,退出值:" + exitValue);
+ }
+
return builder.toString();
} catch (Exception e) {
log.error("执行命令异常", e);
diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/vo/ImageVo.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/vo/ImageVo.java
index 1f6319cf..c4b313c2 100644
--- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/vo/ImageVo.java
+++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/vo/ImageVo.java
@@ -33,11 +33,13 @@ public class ImageVo implements Serializable {
*/
@ApiModelProperty(name = "version")
private String version;
+
/**
* 镜像推送地址
*/
- @ApiModelProperty(name = "url")
- private String url;
+// @ApiModelProperty(name = "url")
+// private String url;
+
/**
* 镜像tag名称
*/
@@ -102,13 +104,13 @@ public class ImageVo implements Serializable {
this.version = version;
}
- public String getUrl() {
- return url;
- }
-
- public void setUrl(String url) {
- this.url = url;
- }
+// public String getUrl() {
+// return url;
+// }
+//
+// public void setUrl(String url) {
+// this.url = url;
+// }
public String getTagName() {
return tagName;
From 00e5d32ea321851d51507ab811cf038f11e51e26 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E8=A5=BF=E5=A4=A7=E9=94=90?= <1070211640@qq.com>
Date: Tue, 23 Apr 2024 10:30:22 +0800
Subject: [PATCH 3/3] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=95=9C=E5=83=8F?=
=?UTF-8?q?=E5=88=A0=E9=99=A4mapper=E6=96=87=E4=BB=B6?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../com/ruoyi/platform/mapper/ImageDao.java | 2 +
.../ruoyi/platform/service/ImageService.java | 22 +++++++-
.../service/impl/ImageServiceImpl.java | 56 +++++++++++++------
.../ruoyi/platform/utils/K8sClientUtil.java | 7 +--
.../managementPlatform/ImageDaoMapper.xml | 17 +++++-
5 files changed, 79 insertions(+), 25 deletions(-)
diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/mapper/ImageDao.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/mapper/ImageDao.java
index d0aa74c4..915a2425 100644
--- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/mapper/ImageDao.java
+++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/mapper/ImageDao.java
@@ -80,5 +80,7 @@ public interface ImageDao {
int deleteById(Integer id);
List queryByName(String name);
+
+ Image getByName(String name);
}
diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/ImageService.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/ImageService.java
index 4e6290dd..59614ac9 100644
--- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/ImageService.java
+++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/ImageService.java
@@ -26,6 +26,20 @@ public interface ImageService {
*/
Image queryById(Integer id);
+
+ Page queryByName(String name);
+
+ /**
+ * 通过名字精确查询单条数据
+ *
+ * @param name 名字
+ * @return 实例对象
+ */
+
+ Image getByName(String name);
+
+
+
/**
* 分页查询
*
@@ -59,9 +73,11 @@ public interface ImageService {
*/
boolean deleteById(Integer id);
- String removeById(Integer id);
+ String removeById(Integer id) throws Exception;
+
+
+
- Page queryByName(String name);
String insertImageAndVersion(ImageVo imageVo) throws Exception;
@@ -77,4 +93,6 @@ public interface ImageService {
Map createImageFromNet(String imageName, String imageTag, String NetPath) throws Exception;
Map uploadImageFiles(MultipartFile file) throws Exception;
+
+
}
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 b9a3d990..d7e835f8 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
@@ -88,6 +88,8 @@ public class ImageServiceImpl implements ImageService {
return new PageImpl<>(this.imageDao.queryAllByLimit(image, pageRequest), pageRequest, total);
}
+
+
/**
* 新增数据
*
@@ -138,10 +140,10 @@ public class ImageServiceImpl implements ImageService {
}
@Override
- public String removeById(Integer id) {
+ public String removeById(Integer id) throws Exception {
Image image = this.imageDao.queryById(id);
if (image == null){
- return "镜像不存在";
+ throw new Exception("镜像不存在");
}
//判断权限,只有admin和创建者本身可以删除该数据集
@@ -150,11 +152,11 @@ public class ImageServiceImpl implements ImageService {
String createdBy = image.getCreateBy();
- if (!(StringUtils.equals(username,"admin") || StringUtils.equals(username,createdBy))){
- return "无权限删除该镜像";
+ if (!(StringUtils.equals(username,"admin") || !StringUtils.equals(username,createdBy))){
+ throw new Exception("无权限删除该镜像");
}
if (!imageVersionService.queryByImageId(id).isEmpty()){
- return "请先删除该镜像下的版本文件";
+ throw new Exception("请先删除该镜像下的版本文件");
}
image.setState(0);
return this.imageDao.update(image)>0?"删除成功":"删除失败";
@@ -167,26 +169,46 @@ public class ImageServiceImpl implements ImageService {
return new PageImpl<>(this.imageDao.queryByName(name));
}
+
+ /**
+ * 通过名字精确查询镜像
+ *
+ * @param name 名字
+ * @return 镜像
+ */
+ @Override
+ public Image getByName(String name) {
+ return this.imageDao.getByName(name);
+ }
+
@Override
@Transactional
public String insertImageAndVersion(ImageVo imageVo) throws Exception {
- Image image = new Image();
- image.setName(imageVo.getName());
- image.setDescription(imageVo.getDescription());
- image.setImageType(imageVo.getImageType());
- Image imageInsert = this.insert(image);
- if (imageInsert == null){
- throw new Exception("新增镜像失败");
+ Image existingImage = getByName(imageVo.getName());
+ Image imageToUse;
+ if(existingImage == null) {
+ // 如果不存在相同名称的镜像,则创建新的镜像记录
+ Image newImage = new Image();
+ newImage.setName(imageVo.getName());
+ newImage.setDescription(imageVo.getDescription());
+ newImage.setImageType(imageVo.getImageType());
+ imageToUse = this.insert(newImage);
+ if (imageToUse == null) {
+ throw new Exception("新增镜像失败");
+ }
+ }else{
+ // 如果已存在相同名称的镜像,使用已存在的镜像
+ imageToUse = existingImage;
}
ImageVersion imageVersion = new ImageVersion();
- imageVersion.setImageId(imageInsert.getId());
+ imageVersion.setImageId(imageToUse.getId());
imageVersion.setVersion(imageVo.getVersion());
imageVersion.setTagName(imageVo.getTagName());
imageVersion.setFileSize(imageVo.getFileSize());
imageVersion.setStatus("building");
ImageVersion imageVersionInsert = this.imageVersionService.insert(imageVersion);
if (imageVersionInsert == null) {
- throw new Exception("新增镜像失败");
+ throw new Exception("新增镜像版本失败");
}
// 使用CompletableFuture异步执行不同的镜像构建逻辑
CompletableFuture.supplyAsync(() -> {
@@ -206,7 +228,7 @@ public class ImageServiceImpl implements ImageService {
}).thenAccept(resultMap ->{
try {
String imageUrl = resultMap.get("url");
- String fileSize = resultMap.get("filesize");
+ String fileSize = resultMap.get("fileSize");
imageVersion.setUrl(imageUrl);
imageVersion.setFileSize(fileSize);
imageVersion.setStatus("available");
@@ -240,7 +262,7 @@ 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), logs2.length());
+ String substring = logs2.substring(logs2.lastIndexOf(harborUrl));
String cleanedString = substring.replaceAll("(\\r|\\n)", "");
String tagCmd = "docker tag " + cleanedString + " " + harborUrl + "/" + repository + "/" + username + "/" + imageName + ":" + imageTag;
String imageUrl = harborUrl + "/" + repository + "/" + username + "/" + imageName + ":" + imageTag;
@@ -282,7 +304,7 @@ 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.lastIndexOf(harborUrl), logs2.length());
+ String substring = logs2.substring(logs2.lastIndexOf(harborUrl));
String cleanedString = substring.replaceAll("(\\r|\\n)", "");
String tagCmd = "docker tag " + cleanedString + " " + harborUrl + "/" + repository + "/" + username + "/" + imageName + ":" + imageTag;
String imageUrl = harborUrl + "/" + repository + "/" + username + "/" + imageName + ":" + imageTag;
diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/utils/K8sClientUtil.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/utils/K8sClientUtil.java
index 9815d25c..b23b0143 100644
--- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/utils/K8sClientUtil.java
+++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/utils/K8sClientUtil.java
@@ -410,13 +410,12 @@ public class K8sClientUtil {
int exitValue = proc.waitFor();
if (exitValue != 0) {
// 如果进程的退出值不为0,表示命令执行失败
- throw new RuntimeException("命令执行失败,退出值:" + exitValue);
+ throw new RuntimeException("容器中命令执行失败,退出值:" + exitValue);
}
-
return builder.toString();
} catch (Exception e) {
- log.error("执行命令异常", e);
- throw new RuntimeException("执行命令异常");
+ log.error("容器执行命令异常", e);
+ throw new RuntimeException("容器执行命令异常");
}
}
diff --git a/ruoyi-modules/management-platform/src/main/resources/mapper/managementPlatform/ImageDaoMapper.xml b/ruoyi-modules/management-platform/src/main/resources/mapper/managementPlatform/ImageDaoMapper.xml
index c9e80b5f..9b46775f 100644
--- a/ruoyi-modules/management-platform/src/main/resources/mapper/managementPlatform/ImageDaoMapper.xml
+++ b/ruoyi-modules/management-platform/src/main/resources/mapper/managementPlatform/ImageDaoMapper.xml
@@ -26,7 +26,7 @@
+
+
+
insert into image(name,description,image_type,create_by,create_time,update_by,update_time,state)
@@ -161,7 +174,7 @@ name = values(name)description = values(description)image_type = values(image_ty
update_time = #{image.updateTime},
-
+
state = #{image.state},