|
|
|
@ -5,6 +5,7 @@ import cn.hutool.core.util.ZipUtil;
|
|
|
|
|
import com.alibaba.fastjson2.JSONObject;
|
|
|
|
|
import com.jfinal.kit.Kv;
|
|
|
|
|
import com.jfinal.kit.PathKit;
|
|
|
|
|
import com.jfinal.kit.PropKit;
|
|
|
|
|
import com.jfinal.kit.StrKit;
|
|
|
|
|
|
|
|
|
|
import java.io.*;
|
|
|
|
@ -63,12 +64,8 @@ public class PublishUtil {
|
|
|
|
|
* docker tag 19a54d2204aa registry.cn-hangzhou.aliyuncs.com/yltcharge/jdk:21
|
|
|
|
|
* docker push registry.cn-hangzhou.aliyuncs.com/yltcharge/jdk:21
|
|
|
|
|
*/
|
|
|
|
|
public static Kv publish(String projectName, boolean isStatic, String workingPath, String localLibPath, Kv choiceWarehouse, String choiceConfig) throws Exception {
|
|
|
|
|
//判断是不是有需要批处理的生成JAR的过程
|
|
|
|
|
String cmdPath = workingPath + "生成依赖jar.bat";
|
|
|
|
|
if (FileUtil.exist(cmdPath)) {
|
|
|
|
|
ExecBatchCmd(cmdPath);
|
|
|
|
|
}
|
|
|
|
|
public static Kv publish(String projectName, String devProjectName, boolean isStatic, String workingPath, String localLibPath, Kv choiceWarehouse, String choiceConfig) throws Exception {
|
|
|
|
|
|
|
|
|
|
System.out.println("正在生成" + projectName + "的镜像...");
|
|
|
|
|
//配置文件
|
|
|
|
|
String path = PathKit.getRootClassPath() + "\\publishImage.json";
|
|
|
|
@ -104,38 +101,24 @@ public class PublishUtil {
|
|
|
|
|
ssh.upload(workingPath + "Dockerfile", remotePath + "Dockerfile");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!StrKit.isBlank(localLibPath)) {
|
|
|
|
|
System.out.println("正在创建lib目录...");
|
|
|
|
|
ssh.mkdir(remotePath + "lib");
|
|
|
|
|
//遍历lib目录下的文件
|
|
|
|
|
for (File file : FileUtil.loopFiles(localLibPath)) {
|
|
|
|
|
System.out.println("正在上传jar包:" + file.getName());
|
|
|
|
|
ssh.upload(file.getAbsolutePath(), remotePath + "lib/" + file.getName());
|
|
|
|
|
System.out.println("正在上传" + projectName + "的jar包...");
|
|
|
|
|
//上传jar包
|
|
|
|
|
String fatjarName = devProjectName + "-jar-with-dependencies.jar";
|
|
|
|
|
String localFile = workingPath + "target/" + fatjarName;
|
|
|
|
|
//获取项目端口
|
|
|
|
|
String undertow_dev = workingPath.replace("\\","/") + "target/classes/undertow_dev.properties";
|
|
|
|
|
List<String> list=FileUtil.readLines(undertow_dev, "UTF-8");
|
|
|
|
|
for (String line : list) {
|
|
|
|
|
if (line.contains("undertow.port")) {
|
|
|
|
|
String[] split = line.split("=");
|
|
|
|
|
project_port = split[1];
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//打包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);
|
|
|
|
|
if (FileUtil.exist(localFile)) {
|
|
|
|
|
System.out.println("正在上传" + fatjarName + "...");
|
|
|
|
|
//上传
|
|
|
|
|
ssh.upload(localFile, remotePath + "target.zip");
|
|
|
|
|
//删除target.zip
|
|
|
|
|
FileUtil.del(localFile);
|
|
|
|
|
//解压缩
|
|
|
|
|
System.out.println("正在解压缩target.zip...");
|
|
|
|
|
ssh.exec("cd " + remotePath + " && unzip target.zip");
|
|
|
|
|
ssh.exec("cd " + remotePath + " && rm -rf target.zip");
|
|
|
|
|
|
|
|
|
|
//获取项目端口
|
|
|
|
|
String undertow_dev = remotePath + "target/classes/undertow_dev.properties";
|
|
|
|
|
String cmd = "grep '^undertow\\.port=' " + undertow_dev + " | awk -F'=' '{print $2}'";
|
|
|
|
|
project_port = ssh.exec(cmd).getStr("message").replace("[", "").replace("]", "");
|
|
|
|
|
ssh.upload(localFile, remotePath + fatjarName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//处理静态文件
|
|
|
|
@ -150,7 +133,7 @@ public class PublishUtil {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
String localFile = workingPath.substring(0, pos) + "\\static.zip";
|
|
|
|
|
localFile = workingPath.substring(0, pos) + "\\static.zip";
|
|
|
|
|
if (FileUtil.exist(localFile)) {
|
|
|
|
|
FileUtil.del(localFile);
|
|
|
|
|
}
|
|
|
|
|