|
|
|
@ -51,10 +51,10 @@ public class PublishUtil {
|
|
|
|
|
workingPath = project.getString("workingPath");
|
|
|
|
|
localLibPath = project.getString("localLibPath");
|
|
|
|
|
if (project.getString("localStatic") != null) {
|
|
|
|
|
localStatic = workingPath + project.getString("localStatic");
|
|
|
|
|
localStatic = project.getString("localStatic");
|
|
|
|
|
}
|
|
|
|
|
if (project.getString("localNginxConf") != null) {
|
|
|
|
|
localNginxConf = workingPath + project.getString("localNginxConf");
|
|
|
|
|
localNginxConf = project.getString("localNginxConf");
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
@ -71,7 +71,7 @@ public class PublishUtil {
|
|
|
|
|
newVersion = newVersion.replace(" ", "").replace("-", "").replace(":", "");
|
|
|
|
|
|
|
|
|
|
//准备工作
|
|
|
|
|
remotePath = "/usr/local/" + projectName;
|
|
|
|
|
remotePath = "/usr/local/" + projectName+"/";
|
|
|
|
|
ssh.exec("rm -rf " + remotePath);
|
|
|
|
|
ssh.mkdir(remotePath);
|
|
|
|
|
|
|
|
|
@ -89,13 +89,21 @@ public class PublishUtil {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!StrKit.isBlank(localStatic)) {
|
|
|
|
|
System.out.println("正在创建static目录...");
|
|
|
|
|
ssh.mkdir(remotePath + "/static");
|
|
|
|
|
//遍历static目录下的文件
|
|
|
|
|
for (File file : FileUtil.loopFiles(localStatic)) {
|
|
|
|
|
System.out.println("正在上传文件:" + file.getName());
|
|
|
|
|
ssh.upload(file.getAbsolutePath(), remotePath + "/static/" + file.getName());
|
|
|
|
|
}
|
|
|
|
|
System.out.println("正在创建" + localStatic + "目录...");
|
|
|
|
|
ssh.mkdir(remotePath + "/" + localStatic);
|
|
|
|
|
//1、需要把目录压缩成ZIP文件
|
|
|
|
|
// 将目录打包成ZIP文件,不包含目录本身,只包含目录下的文件和子目录
|
|
|
|
|
String localFile = workingPath + localStatic + ".zip";
|
|
|
|
|
System.out.println("正在进行静态文件的打包ZIP操作,请稍等...");
|
|
|
|
|
ZipUtil.zip(workingPath + localStatic, localFile, true);
|
|
|
|
|
System.out.println("静态文件打包ZIP已完成,正在上传...");
|
|
|
|
|
//2、需要把ZIP文件上传
|
|
|
|
|
ssh.upload(localFile, remotePath + "/" + localStatic + ".zip");
|
|
|
|
|
//3、把ZIP文件在远端解压缩
|
|
|
|
|
ssh.exec("cd " + remotePath + " && unzip " + localStatic + ".zip");
|
|
|
|
|
ssh.exec("cd " + remotePath + " && rm -rf " + localStatic + ".zip");
|
|
|
|
|
//4、删除target.zip
|
|
|
|
|
FileUtil.del(localFile);
|
|
|
|
|
}
|
|
|
|
|
if (!StrKit.isBlank(localNginxConf)) {
|
|
|
|
|
System.out.println("正在上传nginx.conf...");
|
|
|
|
@ -104,16 +112,16 @@ public class PublishUtil {
|
|
|
|
|
System.out.println("成功完成上传文件nginx.conf");
|
|
|
|
|
}
|
|
|
|
|
//打包target为zip
|
|
|
|
|
if (FileUtil.isDirectory(workingPath + "/target")) {
|
|
|
|
|
String localFile = workingPath + "/target.zip";
|
|
|
|
|
if (FileUtil.isDirectory(workingPath + "target")) {
|
|
|
|
|
String localFile = workingPath + "target.zip";
|
|
|
|
|
if (FileUtil.exist(localFile)) {
|
|
|
|
|
FileUtil.del(localFile);
|
|
|
|
|
}
|
|
|
|
|
System.out.println("正在上传target.zip...");
|
|
|
|
|
// 将目录打包成ZIP文件,不包含目录本身,只包含目录下的文件和子目录
|
|
|
|
|
ZipUtil.zip(workingPath + "/target", localFile, true);
|
|
|
|
|
ZipUtil.zip(workingPath + "target", localFile, true);
|
|
|
|
|
//上传
|
|
|
|
|
ssh.upload(localFile, remotePath + "/target.zip");
|
|
|
|
|
ssh.upload(localFile, remotePath + "target.zip");
|
|
|
|
|
//删除target.zip
|
|
|
|
|
FileUtil.del(localFile);
|
|
|
|
|
//解压缩
|
|
|
|
@ -127,6 +135,7 @@ public class PublishUtil {
|
|
|
|
|
String cmd = "cd /usr/local/" + projectName + " && docker build -t " + projectName + ":" + newVersion + " .";
|
|
|
|
|
System.out.println(cmd);
|
|
|
|
|
ssh.exec(cmd);
|
|
|
|
|
|
|
|
|
|
//获取最新打包后的镜像ID
|
|
|
|
|
cmd = "docker images --format \"{{.Repository}} {{.Tag}} {{.ID}} {{.CreatedAt}}\" | grep " + projectName + " | sort -k4,5 -r | head -n1 | awk '{print $3}'";
|
|
|
|
|
Kv kv = ssh.exec(cmd);
|
|
|
|
|