|
|
|
@ -11,9 +11,8 @@ import java.io.File;
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.time.LocalDateTime;
|
|
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Scanner;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
import java.io.FilenameFilter;
|
|
|
|
|
|
|
|
|
|
public class PublishUtil {
|
|
|
|
|
|
|
|
|
@ -38,7 +37,7 @@ 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 void publish(String projectName, boolean isStatic, String workingPath, String localLibPath, Kv choiceWarehouse) throws Exception {
|
|
|
|
|
public static void publish(String projectName, boolean isStatic, String workingPath, String localLibPath, Kv choiceWarehouse,String choiceConfig) throws Exception {
|
|
|
|
|
System.out.println("正在生成" + projectName + "的镜像...");
|
|
|
|
|
//配置文件
|
|
|
|
|
String path = PathKit.getRootClassPath() + "\\publishImage.json";
|
|
|
|
@ -129,12 +128,14 @@ public class PublishUtil {
|
|
|
|
|
//登录镜像仓库
|
|
|
|
|
//处理一下Dockerfile中的JDK21此用问题,因为不同的打包操作,需要登录不同的仓库,这里临时用shell修改一下
|
|
|
|
|
String remoteDockerFile = remotePath + "Dockerfile";
|
|
|
|
|
|
|
|
|
|
doLogin(ssh, choiceWarehouse.getStr("username"), choiceWarehouse.getStr("password"));
|
|
|
|
|
String cmd = "sed -i '1s/^FROM .*/FROM registry.cn-hangzhou.aliyuncs.com\\/" + choiceWarehouse.getStr("name") + "\\/jdk:21/' " + remoteDockerFile;
|
|
|
|
|
ssh.exec(cmd);
|
|
|
|
|
System.out.println("仓库登录成功!修改JDK21的引用镜像成功!");
|
|
|
|
|
|
|
|
|
|
//修改镜像要用的配置文件
|
|
|
|
|
cmd="sed -i 's|ENV WORKING_ENV=\"pro\"|ENV WORKING_ENV=\""+choiceConfig+"\"|g'";
|
|
|
|
|
ssh.exec(cmd);
|
|
|
|
|
System.out.println("环境变量修改成功!");
|
|
|
|
|
|
|
|
|
|
//删除所有镜像
|
|
|
|
|
cmd = "docker rmi -f $(docker images -q)";
|
|
|
|
@ -298,13 +299,70 @@ public class PublishUtil {
|
|
|
|
|
kv.set("password", "DsideaL4r5t6y7u");
|
|
|
|
|
System.out.println("您选择的仓库是:黄海私人仓库");
|
|
|
|
|
}
|
|
|
|
|
if (choice == 1 || choice == 2 ) {
|
|
|
|
|
if (choice == 1 || choice == 2) {
|
|
|
|
|
break; // 如果输入正确,退出循环
|
|
|
|
|
} else {
|
|
|
|
|
System.out.println("输入不正确,请输入1 或者 2 !"); // 提示用户输入不正确
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
scanner.close(); // 关闭Scanner对象
|
|
|
|
|
return kv;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 功能:让用户选择使用哪个配置文件
|
|
|
|
|
*
|
|
|
|
|
* @param listProject
|
|
|
|
|
* @param choiceProject
|
|
|
|
|
* @return
|
|
|
|
|
* @throws IOException
|
|
|
|
|
*/
|
|
|
|
|
public static String userSelectConfig(List<ProjectBean> listProject, int choiceProject) throws IOException {
|
|
|
|
|
//输出choice对应的项目名称
|
|
|
|
|
List<String> setConfigFiles = new ArrayList<>();
|
|
|
|
|
for (ProjectBean projectBean : listProject) {
|
|
|
|
|
if (projectBean.getId() == choiceProject) {
|
|
|
|
|
System.out.println("您选择的项目是:" + projectBean.getDevProjectName());
|
|
|
|
|
String basedir = new File(System.getProperty("user.dir")).getCanonicalPath() + "\\";
|
|
|
|
|
String directoryPath = basedir + projectBean.getDevProjectName() + "\\src\\main\\resource\\";
|
|
|
|
|
// 创建一个 File 对象,代表目录
|
|
|
|
|
File directory = new File(directoryPath);
|
|
|
|
|
// 获取目录下的所有文件和子目录
|
|
|
|
|
File[] files = directory.listFiles();
|
|
|
|
|
// 定义一个 FilenameFilter 来过滤文件
|
|
|
|
|
FilenameFilter filter = (dir, name) -> {
|
|
|
|
|
// 检查是否是文件以及文件名是否匹配 application_?.yaml 模式
|
|
|
|
|
return new File(dir, name).isFile() && name.matches("application_.*\\.yaml");
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (files != null) {
|
|
|
|
|
// 过滤出符合条件的文件
|
|
|
|
|
for (File file : files) {
|
|
|
|
|
if (filter.accept(directory, file.getName())) {
|
|
|
|
|
setConfigFiles.add(file.getName());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
System.out.println("项目" + projectBean.getDevProjectName() + "没有配置文件");
|
|
|
|
|
System.exit(0);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
Scanner scanner = new Scanner(System.in); // 创建Scanner对象来读取控制台输入
|
|
|
|
|
//输出choice对应的项目名称
|
|
|
|
|
while (true) {
|
|
|
|
|
System.out.println("请选择您本次要发布的配置文件:");
|
|
|
|
|
for (int i = 0; i < setConfigFiles.size(); i++) {
|
|
|
|
|
System.out.print((i + 1) + ":" + setConfigFiles.get(i) + " ");
|
|
|
|
|
}
|
|
|
|
|
System.out.println();
|
|
|
|
|
|
|
|
|
|
int choice = scanner.nextInt(); // 读取用户输入的整数
|
|
|
|
|
if (choice >= 1 && choice <= setConfigFiles.size()) {
|
|
|
|
|
return setConfigFiles.get(choice - 1);
|
|
|
|
|
} else {
|
|
|
|
|
System.out.println("输入不正确,请输入1与 " + setConfigFiles.size() + "之间的数值!"); // 提示用户输入不正确
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|