main
黄海 10 months ago
parent 8dbb0a2391
commit f4377104af

@ -36,7 +36,7 @@ public class Publish {
System.out.println(); System.out.println();
//让用户选择使用哪个配置文件进行打镜像? //让用户选择使用哪个配置文件进行打镜像?
//这个项目下有以application_?.yaml形式的配置文件分配ID为123...,让用户选择使用哪个进行镜像打包 //这个项目下有以application_?.yaml形式的配置文件分配ID为123...,让用户选择使用哪个进行镜像打包
String choiceConfig = PublishUtil.userSelectConfig(listProject,choiceProject); String choiceConfig = PublishUtil.userSelectConfig(listProject, choiceProject);
//这个项目是什么类型? //这个项目是什么类型?
String projectAttribute = PublishUtil.getProjectAttribute(choiceProject, listProject); String projectAttribute = PublishUtil.getProjectAttribute(choiceProject, listProject);
@ -47,8 +47,8 @@ public class Publish {
String basedir = new File(System.getProperty("user.dir")).getCanonicalPath(); String basedir = new File(System.getProperty("user.dir")).getCanonicalPath();
workingPath = basedir + "\\" + projectBean.getDevProjectName() + "\\"; workingPath = basedir + "\\" + projectBean.getDevProjectName() + "\\";
projectName = projectBean.getPublishProjectName(); projectName = projectBean.getPublishProjectName();
if (FileUtil.exist(workingPath + "\\lib")) { if (FileUtil.exist(workingPath + "lib")) {
localLibPath = workingPath + "\\lib\\"; localLibPath = workingPath + "lib\\";
} }
break; break;
} }
@ -57,6 +57,8 @@ public class Publish {
isStatic = true; isStatic = true;
} }
//开始打包 //开始打包
PublishUtil.publish(projectName, isStatic, workingPath, localLibPath, choiceWarehouse,choiceConfig); String result = PublishUtil.publish(projectName, isStatic, workingPath, localLibPath, choiceWarehouse, choiceConfig);
System.out.println("测试运行一个容器吧,比如docker run --name " + result.split(":")[0] + " -p 8001:8001 -d " + result);
} }
} }

@ -47,7 +47,7 @@ public class PublishUtil {
* docker tag 19a54d2204aa registry.cn-hangzhou.aliyuncs.com/yltcharge/jdk:21 * docker tag 19a54d2204aa registry.cn-hangzhou.aliyuncs.com/yltcharge/jdk:21
* docker push registry.cn-hangzhou.aliyuncs.com/yltcharge/jdk:21 * docker push registry.cn-hangzhou.aliyuncs.com/yltcharge/jdk:21
*/ */
public static void publish(String projectName, boolean isStatic, String workingPath, String localLibPath, Kv choiceWarehouse, String choiceConfig) throws Exception { public static String publish(String projectName, boolean isStatic, String workingPath, String localLibPath, Kv choiceWarehouse, String choiceConfig) throws Exception {
System.out.println("正在生成" + projectName + "的镜像..."); System.out.println("正在生成" + projectName + "的镜像...");
//配置文件 //配置文件
String path = PathKit.getRootClassPath() + "\\publishImage.json"; String path = PathKit.getRootClassPath() + "\\publishImage.json";
@ -66,8 +66,11 @@ public class PublishUtil {
LocalDateTime now = LocalDateTime.now(); LocalDateTime now = LocalDateTime.now();
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
String newVersion = now.format(formatter); String newVersion = now.format(formatter);
newVersion = choiceConfig + "_" + newVersion.replace(" ", "").replace("-", "").replace(":", ""); if (!StrKit.isBlank(choiceConfig)) {
newVersion = choiceConfig + "_" + newVersion.replace(" ", "").replace("-", "").replace(":", "");
} else {
newVersion = newVersion.replace(" ", "").replace("-", "").replace(":", "");
}
//准备工作 //准备工作
String remotePath = "/usr/local/" + projectName + "/"; String remotePath = "/usr/local/" + projectName + "/";
ssh.exec("rm -rf " + remotePath); ssh.exec("rm -rf " + remotePath);
@ -148,6 +151,10 @@ public class PublishUtil {
System.out.println(cmd); System.out.println(cmd);
System.out.println("环境变量修改成功!"); System.out.println("环境变量修改成功!");
//如果容器正在运行中,那么容器对应的镜像删除失败
cmd="docker rm -f $(docker ps -aq)";
ssh.exec(cmd);
//删除所有镜像 //删除所有镜像
cmd = "docker rmi -f $(docker images -q)"; cmd = "docker rmi -f $(docker images -q)";
ssh.exec(cmd); ssh.exec(cmd);
@ -181,6 +188,8 @@ public class PublishUtil {
ssh.disconnect(); ssh.disconnect();
System.out.println("恭喜,镜像打包成功!"); System.out.println("恭喜,镜像打包成功!");
return projectName + ":" + newVersion;
} }
/** /**
@ -204,7 +213,7 @@ public class PublishUtil {
// 获取目录名称 // 获取目录名称
String dirName = file.getName(); String dirName = file.getName();
// 检查目录名称是否以"ds"开头且不是"dsBuild" // 检查目录名称是否以"ds"开头且不是"dsBuild"
if (dirName.startsWith("ds") && !dirName.equals("dsBuild")) { if (dirName.startsWith("ds") && !dirName.equals("dsBuild") && !dirName.contains("-")) {
dirList.add(file.getAbsolutePath()); dirList.add(file.getAbsolutePath());
} }
} }

Loading…
Cancel
Save