| @@ -131,8 +131,9 @@ public class ImageController extends BaseController { | |||
| @ApiOperation("从本地上传构建镜像") | |||
| public GenericsAjaxResult<Map<String, String>> createImageFromLocal(@RequestParam("name") String imageName, | |||
| @RequestParam("tag") String imageTag, | |||
| @RequestParam("path") String path) throws Exception { | |||
| return genericsSuccess(this.imageService.createImageFromLocal(imageName, imageTag, path)); | |||
| @RequestParam("path") String path, | |||
| @RequestParam("fileName") String fileName) throws Exception { | |||
| return genericsSuccess(this.imageService.createImageFromLocal(imageName, imageTag, path, fileName)); | |||
| } | |||
| @@ -86,8 +86,10 @@ public interface ImageService { | |||
| * @param path | |||
| * @return | |||
| */ | |||
| Map<String, String> createImageFromLocal(String imageName, String imageTag, String path) throws Exception; | |||
| Map<String, String> createImageFromLocal(String imageName, String imageTag, String path,String fileName) throws Exception; | |||
| Map<String, String> createImageFromNet(String imageName, String imageTag, String NetPath) throws Exception; | |||
| Map<String, String> uploadImageFiles(MultipartFile file) throws Exception; | |||
| void saveImage(ImageVo imageVo); | |||
| @@ -4,7 +4,6 @@ import com.alibaba.fastjson2.JSON; | |||
| import com.alibaba.fastjson2.util.DateUtils; | |||
| import com.ruoyi.common.core.web.domain.GenericsAjaxResult; | |||
| import com.ruoyi.common.security.utils.SecurityUtils; | |||
| import com.ruoyi.system.api.constant.Constant; | |||
| import com.ruoyi.platform.domain.*; | |||
| import com.ruoyi.platform.mapper.*; | |||
| 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.K8sClientUtil; | |||
| import com.ruoyi.platform.vo.ImageVo; | |||
| import com.ruoyi.system.api.constant.Constant; | |||
| import com.ruoyi.system.api.model.LoginUser; | |||
| import io.kubernetes.client.openapi.models.V1Pod; | |||
| import org.apache.commons.lang3.StringUtils; | |||
| @@ -86,8 +86,6 @@ public class ImageServiceImpl implements ImageService { | |||
| private String mountPath; | |||
| @Value("${dockerpush.proxyUrl}") | |||
| private String proxyUrl; | |||
| @Value("${minio.pvcName}") | |||
| private String pvcName; | |||
| @Value("${jupyter.namespace}") | |||
| private String namespace; | |||
| @@ -270,7 +268,7 @@ public class ImageServiceImpl implements ImageService { | |||
| if (imageVo.getUploadType() == 0) { | |||
| resultMap = createImageFromNet(imageVo.getName(), imageVo.getTagName(), imageVo.getPath()); | |||
| } else { | |||
| resultMap = createImageFromLocal(imageVo.getName(), imageVo.getTagName(), imageVo.getPath()); | |||
| resultMap = createImageFromLocal(imageVo.getName(), imageVo.getTagName(), imageVo.getPath(), imageVo.getFileName()); | |||
| } | |||
| } catch (Exception e) { | |||
| imageVersion.setStatus("failed"); | |||
| @@ -304,7 +302,7 @@ public class ImageServiceImpl implements ImageService { | |||
| V1Pod pod = k8sClientUtil.getNSPodList(serviceNS, deploymentName); | |||
| if (pod == null) { | |||
| 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; | |||
| // 执行命令 docker login -u admin -p Harbor12345 172.20.32.187 | |||
| @@ -341,13 +339,13 @@ public class ImageServiceImpl implements ImageService { | |||
| } | |||
| @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<>(); | |||
| // 得到容器 | |||
| V1Pod pod = k8sClientUtil.getNSPodList(serviceNS, deploymentName); | |||
| if (pod == null) { | |||
| 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; | |||
| // 执行命令 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 | |||
| 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); | |||
| // 在容器里执行 docker tag name:tag nexus3.kube-system.svc:8083/imageName:imageTag | |||
| @@ -386,7 +384,7 @@ public class ImageServiceImpl implements ImageService { | |||
| @Override | |||
| public Map<String, String> uploadImageFiles(MultipartFile file) throws Exception { | |||
| 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); | |||
| } | |||
| @@ -41,6 +41,9 @@ public class K8sClientUtil { | |||
| @Value("${dockerpush.proxyUrl}") | |||
| private String proxyUrl; | |||
| @Value("${git.localPath}") | |||
| String localPathlocal; | |||
| private String http; | |||
| private String token; | |||
| /** | |||
| @@ -638,7 +641,7 @@ public class K8sClientUtil { | |||
| } | |||
| public V1Pod createPodWithEnv(String podName, String namespace, String proxyUrl, String mountPath, String pvcName, String image) { | |||
| public V1Pod createPodWithEnv(String podName, String namespace, String proxyUrl, String mountPath, String image) { | |||
| CoreV1Api api = new CoreV1Api(apiClient); | |||
| V1SecurityContext v1SecurityContext = new V1SecurityContext(); | |||
| @@ -649,7 +652,7 @@ public class K8sClientUtil { | |||
| volumeMounts.add(new V1VolumeMount().name("workspace").mountPath(mountPath)); | |||
| List<V1Volume> volumes = new ArrayList<>(); | |||
| volumes.add(new V1Volume().name("workspace").hostPath(new V1HostPathVolumeSource().path(hostPath + "/" + podName + "/" + mountPath).type("DirectoryOrCreate"))); | |||
| volumes.add(new V1Volume().name("workspace").hostPath(new V1HostPathVolumeSource().path(hostPath + "/images").type("DirectoryOrCreate"))); | |||
| V1Pod pod = new V1PodBuilder() | |||
| .withNewMetadata() | |||
| @@ -3,10 +3,12 @@ package com.ruoyi.platform.vo; | |||
| import com.fasterxml.jackson.databind.PropertyNamingStrategy; | |||
| import com.fasterxml.jackson.databind.annotation.JsonNaming; | |||
| import io.swagger.annotations.ApiModelProperty; | |||
| import lombok.Data; | |||
| import java.io.Serializable; | |||
| @JsonNaming(PropertyNamingStrategy.SnakeCaseStrategy.class) | |||
| @Data | |||
| public class ImageVo implements Serializable { | |||
| @@ -51,6 +53,10 @@ public class ImageVo implements Serializable { | |||
| */ | |||
| @ApiModelProperty(name = "file_size") | |||
| private String fileSize; | |||
| @ApiModelProperty(name = "file_name") | |||
| private String fileName; | |||
| /** | |||
| * 镜像构建状态 | |||
| */ | |||
| @@ -66,101 +72,4 @@ public class ImageVo implements Serializable { | |||
| @ApiModelProperty(name = "dev_environment_id", value = "环境id") | |||
| private Integer devEnvironmentId; | |||
| // public Integer getId() { | |||
| // return id; | |||
| // } | |||
| // | |||
| // public void setId(Integer id) { | |||
| // this.id = id; | |||
| // } | |||
| public String getName() { | |||
| return name; | |||
| } | |||
| public void setName(String name) { | |||
| this.name = name; | |||
| } | |||
| public String getDescription() { | |||
| return description; | |||
| } | |||
| public void setDescription(String description) { | |||
| this.description = description; | |||
| } | |||
| public Integer getImageType() { | |||
| return imageType; | |||
| } | |||
| public void setImageType(Integer imageType) { | |||
| this.imageType = imageType; | |||
| } | |||
| public String getVersion() { | |||
| return version; | |||
| } | |||
| public void setVersion(String version) { | |||
| this.version = version; | |||
| } | |||
| // public String getUrl() { | |||
| // return url; | |||
| // } | |||
| // | |||
| // public void setUrl(String url) { | |||
| // this.url = url; | |||
| // } | |||
| public String getTagName() { | |||
| return tagName; | |||
| } | |||
| public void setTagName(String tagName) { | |||
| this.tagName = tagName; | |||
| } | |||
| public String getFileSize() { | |||
| return fileSize; | |||
| } | |||
| public void setFileSize(String fileSize) { | |||
| this.fileSize = fileSize; | |||
| } | |||
| public String getStatus() { | |||
| return status; | |||
| } | |||
| public void setStatus(String status) { | |||
| this.status = status; | |||
| } | |||
| public Integer getUploadType() { | |||
| return uploadType; | |||
| } | |||
| public void setUploadType(Integer uploadType) { | |||
| this.uploadType = uploadType; | |||
| } | |||
| public String getPath() { | |||
| return path; | |||
| } | |||
| public void setPath(String path) { | |||
| this.path = path; | |||
| } | |||
| public Integer getDevEnvironmentId() { | |||
| return devEnvironmentId; | |||
| } | |||
| public void setDevEnvironmentId(Integer devEnvironmentId) { | |||
| this.devEnvironmentId = devEnvironmentId; | |||
| } | |||
| } | |||