Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
103f3ffe7a
@ -110,5 +110,5 @@ public interface IImageService {
|
|||||||
|
|
||||||
PageResult<DockerImageDo> getLocalImagePage(DockerImagePageReqVO pageVO);
|
PageResult<DockerImageDo> getLocalImagePage(DockerImagePageReqVO pageVO);
|
||||||
|
|
||||||
Object localImagePush(String imageId, String machineId);
|
Boolean localImagePush(String imageId, String machineId);
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package cd.casic.module.execute.docker.service.impl;
|
package cd.casic.module.execute.docker.service.impl;
|
||||||
|
|
||||||
import cd.casic.ci.commons.properties.TargetFileUploadProperties;
|
import cd.casic.ci.commons.properties.TargetFileUploadProperties;
|
||||||
|
import cd.casic.framework.commons.exception.ServerException;
|
||||||
import cd.casic.framework.commons.pojo.PageResult;
|
import cd.casic.framework.commons.pojo.PageResult;
|
||||||
import cd.casic.framework.mybatis.core.query.LambdaQueryWrapperX;
|
import cd.casic.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||||
import cd.casic.module.execute.docker.DockerClientFactory;
|
import cd.casic.module.execute.docker.DockerClientFactory;
|
||||||
@ -9,6 +10,7 @@ import cd.casic.module.execute.docker.dataobject.dto.DockerImageDo;
|
|||||||
import cd.casic.module.execute.docker.dataobject.model.DockerImage;
|
import cd.casic.module.execute.docker.dataobject.model.DockerImage;
|
||||||
import cd.casic.module.execute.docker.dataobject.vo.DockerImagePageReqVO;
|
import cd.casic.module.execute.docker.dataobject.vo.DockerImagePageReqVO;
|
||||||
import cd.casic.module.execute.docker.service.IImageService;
|
import cd.casic.module.execute.docker.service.IImageService;
|
||||||
|
import cd.casic.module.machine.contants.MachineErrorCodeConstants;
|
||||||
import cd.casic.module.machine.dal.dataobject.MachineInfoDO;
|
import cd.casic.module.machine.dal.dataobject.MachineInfoDO;
|
||||||
import cd.casic.module.machine.dal.dataobject.SecretKeyDO;
|
import cd.casic.module.machine.dal.dataobject.SecretKeyDO;
|
||||||
import cd.casic.module.machine.dal.mysql.MachineInfoMapper;
|
import cd.casic.module.machine.dal.mysql.MachineInfoMapper;
|
||||||
@ -183,9 +185,9 @@ public class ImageService implements IImageService {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Object localImagePush(String imageId, String machineId) {
|
public Boolean localImagePush(String imageId, String machineId) {
|
||||||
if (Objects.isNull(imageId) || Objects.isNull(machineId)) {
|
if (Objects.isNull(imageId) || Objects.isNull(machineId)) {
|
||||||
return null;
|
throw new ServerException(MachineErrorCodeConstants.MACHINE_INFO_TAG_NULL);
|
||||||
}
|
}
|
||||||
DockerImageDo imageDo = dockerImageDao.selectById(imageId);
|
DockerImageDo imageDo = dockerImageDao.selectById(imageId);
|
||||||
//1 远程下载
|
//1 远程下载
|
||||||
@ -203,8 +205,8 @@ public class ImageService implements IImageService {
|
|||||||
targetFtp.setSystemKey(CryptogramUtil.doDecrypt(secretKeyDO.getPrivateKey()));
|
targetFtp.setSystemKey(CryptogramUtil.doDecrypt(secretKeyDO.getPrivateKey()));
|
||||||
targetFtp.setPassword(CryptogramUtil.doDecrypt(secretKeyDO.getPassword()));
|
targetFtp.setPassword(CryptogramUtil.doDecrypt(secretKeyDO.getPassword()));
|
||||||
}
|
}
|
||||||
Sftp uploadSftp = getSftp(targetFtp);
|
|
||||||
// 2.1 上传
|
// 2.1 上传
|
||||||
|
Sftp uploadSftp = getSftp(targetFtp);
|
||||||
String suffix = FileUtil.getSuffix(srcPath);
|
String suffix = FileUtil.getSuffix(srcPath);
|
||||||
String fileName = imageDo.getName() + "." + suffix;
|
String fileName = imageDo.getName() + "." + suffix;
|
||||||
ByteArrayInputStream arrayInputStream = new ByteArrayInputStream(byteOut.toByteArray()); //转换
|
ByteArrayInputStream arrayInputStream = new ByteArrayInputStream(byteOut.toByteArray()); //转换
|
||||||
@ -212,7 +214,7 @@ public class ImageService implements IImageService {
|
|||||||
uploadSftp.mkDirs(romPath);//递归创建
|
uploadSftp.mkDirs(romPath);//递归创建
|
||||||
uploadSftp.upload(romPath, fileName, arrayInputStream);
|
uploadSftp.upload(romPath, fileName, arrayInputStream);
|
||||||
uploadSftp.close();
|
uploadSftp.close();
|
||||||
return null;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -221,13 +223,17 @@ public class ImageService implements IImageService {
|
|||||||
* @param config 连接配置
|
* @param config 连接配置
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
private Sftp getSftp(FtpConfig config){
|
private Sftp getSftp(FtpConfig config) {
|
||||||
Session session;
|
Session session;
|
||||||
if (Objects.nonNull(config.getSystemKey())) {
|
if (Objects.nonNull(config.getSystemKey())) {
|
||||||
session = JschUtil.getSession(config.getHost(), config.getPort(), config.getUser(), config.getSystemKey().getBytes(StandardCharsets.UTF_8), config.getPassword().getBytes());
|
session = JschUtil.getSession(config.getHost(), config.getPort(), config.getUser(), config.getSystemKey().getBytes(StandardCharsets.UTF_8), config.getPassword().getBytes());
|
||||||
} else {
|
} else {
|
||||||
session = JschUtil.getSession(config.getHost(), config.getPort(), config.getUser(), config.getPassword());
|
session = JschUtil.getSession(config.getHost(), config.getPort(), config.getUser(), config.getPassword());
|
||||||
}
|
}
|
||||||
|
if (!session.isConnected()) {
|
||||||
|
log.error("与主机IP:{} 建立SSH连接失败", config.getHost());
|
||||||
|
throw new ServerException(500, "部署失败,请检测主机是否可用");
|
||||||
|
}
|
||||||
return new Sftp(session);
|
return new Sftp(session);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user