|
|
@@ -4,7 +4,6 @@ import com.alibaba.fastjson2.JSON; |
|
|
import com.alibaba.fastjson2.util.DateUtils; |
|
|
import com.alibaba.fastjson2.util.DateUtils; |
|
|
import com.ruoyi.common.core.web.domain.GenericsAjaxResult; |
|
|
import com.ruoyi.common.core.web.domain.GenericsAjaxResult; |
|
|
import com.ruoyi.common.security.utils.SecurityUtils; |
|
|
import com.ruoyi.common.security.utils.SecurityUtils; |
|
|
import com.ruoyi.system.api.constant.Constant; |
|
|
|
|
|
import com.ruoyi.platform.domain.*; |
|
|
import com.ruoyi.platform.domain.*; |
|
|
import com.ruoyi.platform.mapper.*; |
|
|
import com.ruoyi.platform.mapper.*; |
|
|
import com.ruoyi.platform.service.ImageService; |
|
|
import com.ruoyi.platform.service.ImageService; |
|
|
@@ -14,6 +13,7 @@ import com.ruoyi.platform.utils.DockerClientUtil; |
|
|
import com.ruoyi.platform.utils.FileUtil; |
|
|
import com.ruoyi.platform.utils.FileUtil; |
|
|
import com.ruoyi.platform.utils.K8sClientUtil; |
|
|
import com.ruoyi.platform.utils.K8sClientUtil; |
|
|
import com.ruoyi.platform.vo.ImageVo; |
|
|
import com.ruoyi.platform.vo.ImageVo; |
|
|
|
|
|
import com.ruoyi.system.api.constant.Constant; |
|
|
import com.ruoyi.system.api.model.LoginUser; |
|
|
import com.ruoyi.system.api.model.LoginUser; |
|
|
import io.kubernetes.client.openapi.models.V1Pod; |
|
|
import io.kubernetes.client.openapi.models.V1Pod; |
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
@@ -86,8 +86,6 @@ public class ImageServiceImpl implements ImageService { |
|
|
private String mountPath; |
|
|
private String mountPath; |
|
|
@Value("${dockerpush.proxyUrl}") |
|
|
@Value("${dockerpush.proxyUrl}") |
|
|
private String proxyUrl; |
|
|
private String proxyUrl; |
|
|
@Value("${minio.pvcName}") |
|
|
|
|
|
private String pvcName; |
|
|
|
|
|
@Value("${jupyter.namespace}") |
|
|
@Value("${jupyter.namespace}") |
|
|
private String namespace; |
|
|
private String namespace; |
|
|
|
|
|
|
|
|
@@ -270,7 +268,7 @@ public class ImageServiceImpl implements ImageService { |
|
|
if (imageVo.getUploadType() == 0) { |
|
|
if (imageVo.getUploadType() == 0) { |
|
|
resultMap = createImageFromNet(imageVo.getName(), imageVo.getTagName(), imageVo.getPath()); |
|
|
resultMap = createImageFromNet(imageVo.getName(), imageVo.getTagName(), imageVo.getPath()); |
|
|
} else { |
|
|
} else { |
|
|
resultMap = createImageFromLocal(imageVo.getName(), imageVo.getTagName(), imageVo.getPath()); |
|
|
|
|
|
|
|
|
resultMap = createImageFromLocal(imageVo.getName(), imageVo.getTagName(), imageVo.getPath(), imageVo.getFileName()); |
|
|
} |
|
|
} |
|
|
} catch (Exception e) { |
|
|
} catch (Exception e) { |
|
|
imageVersion.setStatus("failed"); |
|
|
imageVersion.setStatus("failed"); |
|
|
@@ -304,7 +302,7 @@ public class ImageServiceImpl implements ImageService { |
|
|
V1Pod pod = k8sClientUtil.getNSPodList(serviceNS, deploymentName); |
|
|
V1Pod pod = k8sClientUtil.getNSPodList(serviceNS, deploymentName); |
|
|
if (pod == null) { |
|
|
if (pod == null) { |
|
|
String podName = deploymentName + "-" + DateUtils.formatYMD10(new Date()); |
|
|
String podName = deploymentName + "-" + DateUtils.formatYMD10(new Date()); |
|
|
pod = k8sClientUtil.createPodWithEnv(podName, serviceNS, proxyUrl, mountPath, pvcName, image); |
|
|
|
|
|
|
|
|
pod = k8sClientUtil.createPodWithEnv(podName, serviceNS, proxyUrl, mountPath, image); |
|
|
} |
|
|
} |
|
|
String loginCmd = "docker login -u " + harborUser + " -p " + harborpassword + " " + harborUrl; |
|
|
String loginCmd = "docker login -u " + harborUser + " -p " + harborpassword + " " + harborUrl; |
|
|
// 执行命令 docker login -u admin -p Harbor12345 172.20.32.187 |
|
|
// 执行命令 docker login -u admin -p Harbor12345 172.20.32.187 |
|
|
@@ -341,13 +339,13 @@ public class ImageServiceImpl implements ImageService { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public Map<String, String> createImageFromLocal(String imageName, String imageTag, String path) throws Exception { |
|
|
|
|
|
|
|
|
public Map<String, String> createImageFromLocal(String imageName, String imageTag, String path, String fileName) throws Exception { |
|
|
Map<String, String> resultMap = new HashMap<>(); |
|
|
Map<String, String> resultMap = new HashMap<>(); |
|
|
// 得到容器 |
|
|
// 得到容器 |
|
|
V1Pod pod = k8sClientUtil.getNSPodList(serviceNS, deploymentName); |
|
|
V1Pod pod = k8sClientUtil.getNSPodList(serviceNS, deploymentName); |
|
|
if (pod == null) { |
|
|
if (pod == null) { |
|
|
String podName = deploymentName + "-" + DateUtils.formatYMD10(new Date()); |
|
|
String podName = deploymentName + "-" + DateUtils.formatYMD10(new Date()); |
|
|
pod = k8sClientUtil.createPodWithEnv(podName, serviceNS, proxyUrl, mountPath, pvcName, image); |
|
|
|
|
|
|
|
|
pod = k8sClientUtil.createPodWithEnv(podName, serviceNS, proxyUrl, mountPath, image); |
|
|
} |
|
|
} |
|
|
String loginCmd = "docker login -u " + harborUser + " -p " + harborpassword + " " + harborUrl; |
|
|
String loginCmd = "docker login -u " + harborUser + " -p " + harborpassword + " " + harborUrl; |
|
|
// 执行命令 docker login -u admin -p Harbor12345 172.20.32.187 |
|
|
// 执行命令 docker login -u admin -p Harbor12345 172.20.32.187 |
|
|
@@ -355,7 +353,7 @@ public class ImageServiceImpl implements ImageService { |
|
|
// 在这个容器的/data/admin 目录下执行命令 docker load -i fileName 得到返回的镜像名字name:tag |
|
|
// 在这个容器的/data/admin 目录下执行命令 docker load -i fileName 得到返回的镜像名字name:tag |
|
|
String username = SecurityUtils.getLoginUser().getUsername(); |
|
|
String username = SecurityUtils.getLoginUser().getUsername(); |
|
|
// |
|
|
// |
|
|
String filePath = "/data/argo-workflow/" + bucketName + "/" + path; |
|
|
|
|
|
|
|
|
String filePath = "/data/" + path + "/" + fileName; |
|
|
String logs2 = k8sClientUtil.executeCommand(pod, "docker load -i " + filePath); |
|
|
String logs2 = k8sClientUtil.executeCommand(pod, "docker load -i " + filePath); |
|
|
// 在容器里执行 docker tag name:tag nexus3.kube-system.svc:8083/imageName:imageTag |
|
|
// 在容器里执行 docker tag name:tag nexus3.kube-system.svc:8083/imageName:imageTag |
|
|
|
|
|
|
|
|
@@ -386,7 +384,7 @@ public class ImageServiceImpl implements ImageService { |
|
|
@Override |
|
|
@Override |
|
|
public Map<String, String> uploadImageFiles(MultipartFile file) throws Exception { |
|
|
public Map<String, String> uploadImageFiles(MultipartFile file) throws Exception { |
|
|
LoginUser loginUser = SecurityUtils.getLoginUser(); |
|
|
LoginUser loginUser = SecurityUtils.getLoginUser(); |
|
|
String path = "images/" + loginUser.getUsername() + "/" + file.getOriginalFilename(); |
|
|
|
|
|
|
|
|
String path = "/mini-model-platform-data/images/" + loginUser.getUsername() + "/" + file.getOriginalFilename(); |
|
|
return minioService.uploadFile(bucketName, path, file); |
|
|
return minioService.uploadFile(bucketName, path, file); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|