|
|
|
@ -13,6 +13,7 @@ import java.time.LocalDateTime;
|
|
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Scanner;
|
|
|
|
|
|
|
|
|
|
public class PublishUtil {
|
|
|
|
|
/**
|
|
|
|
@ -31,7 +32,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) throws Exception {
|
|
|
|
|
public static void publish(String projectName, boolean isStatic, String workingPath, String localLibPath, int choiceWarehouse) throws Exception {
|
|
|
|
|
System.out.println("正在生成" + projectName + "的镜像...");
|
|
|
|
|
//配置文件
|
|
|
|
|
String path = PathKit.getRootClassPath() + "\\publishImage.json";
|
|
|
|
@ -138,17 +139,31 @@ public class PublishUtil {
|
|
|
|
|
System.out.println("镜像打包完成,镜像ID=" + imageId);
|
|
|
|
|
|
|
|
|
|
//登录镜像仓库
|
|
|
|
|
cmd = "docker login --username=驿来特充电 --password=ylt5033. registry.cn-hangzhou.aliyuncs.com";
|
|
|
|
|
if (choiceWarehouse == 1) {
|
|
|
|
|
cmd = "docker login --username=驿来特充电 --password=ylt5033. registry.cn-hangzhou.aliyuncs.com";
|
|
|
|
|
} else {
|
|
|
|
|
cmd = "docker login --username=东师黄海 --password=DsideaL4r5t6y7u registry.cn-hangzhou.aliyuncs.com";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
System.out.println(cmd);
|
|
|
|
|
ssh.exec(cmd);
|
|
|
|
|
System.out.println("仓库登录成功!");
|
|
|
|
|
|
|
|
|
|
System.out.println("打标签...");
|
|
|
|
|
cmd = "docker tag " + imageId + " registry.cn-hangzhou.aliyuncs.com/yltcharge/" + projectName + ":" + newVersion;
|
|
|
|
|
if (choiceWarehouse == 1) {
|
|
|
|
|
cmd = "docker tag " + imageId + " registry.cn-hangzhou.aliyuncs.com/yltcharge/" + projectName + ":" + newVersion;
|
|
|
|
|
} else {
|
|
|
|
|
cmd = "docker tag " + imageId + " registry.cn-hangzhou.aliyuncs.com/dsideal/" + projectName + ":" + newVersion;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ssh.exec(cmd);
|
|
|
|
|
|
|
|
|
|
System.out.println("开始推送到远程仓库,稍等...");
|
|
|
|
|
cmd = "docker push registry.cn-hangzhou.aliyuncs.com/yltcharge/" + projectName + ":" + newVersion;
|
|
|
|
|
if (choiceWarehouse == 1) {
|
|
|
|
|
cmd = "docker push registry.cn-hangzhou.aliyuncs.com/yltcharge/" + projectName + ":" + newVersion;
|
|
|
|
|
} else {
|
|
|
|
|
cmd = "docker push registry.cn-hangzhou.aliyuncs.com/dsideal/" + projectName + ":" + newVersion;
|
|
|
|
|
}
|
|
|
|
|
System.out.println(cmd);
|
|
|
|
|
ssh.exec(cmd);
|
|
|
|
|
|
|
|
|
@ -160,6 +175,7 @@ public class PublishUtil {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 功能:获取项目列表
|
|
|
|
|
*
|
|
|
|
|
* @return
|
|
|
|
|
* @throws IOException
|
|
|
|
|
*/
|
|
|
|
@ -189,10 +205,11 @@ public class PublishUtil {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 功能:获取项目名称
|
|
|
|
|
*
|
|
|
|
|
* @param pathName 路径名称
|
|
|
|
|
* @return 项目名称
|
|
|
|
|
*/
|
|
|
|
|
public static String getPublishProjectName(String pathName){
|
|
|
|
|
public static String getPublishProjectName(String pathName) {
|
|
|
|
|
//遍历 pathName的每个字符,如果是不是大写字母,就照抄下来,如果是大写字母,就变成小写字母,并且在小写字母前面加上下划线_
|
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
|
for (int i = 0; i < pathName.length(); i++) {
|
|
|
|
@ -206,4 +223,67 @@ public class PublishUtil {
|
|
|
|
|
return sb.toString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 功能:获取项目属性,1:JAVA后端,2:WEB前端
|
|
|
|
|
*
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public static int getProjectAttribute(int id, List<ProjectBean> listProject) throws IOException {
|
|
|
|
|
for (ProjectBean projectBean : listProject) {
|
|
|
|
|
if (projectBean.getId() == id) {
|
|
|
|
|
String basedir = new File(System.getProperty("user.dir")).getCanonicalPath();
|
|
|
|
|
String path = basedir + "\\" + projectBean.getDevProjectName();
|
|
|
|
|
//这个path目录下有没有src这样的子目录,如果有,则判定为JAVA项目,否则为WEB项目
|
|
|
|
|
if (new File(path + "\\src").exists()) {
|
|
|
|
|
return 1;
|
|
|
|
|
} else {
|
|
|
|
|
return 2;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 功能:提示用户选择项目,并返回项目编号
|
|
|
|
|
*/
|
|
|
|
|
public static int userSelectProject(List<ProjectBean> listProject) {
|
|
|
|
|
Scanner scanner = new Scanner(System.in); // 创建Scanner对象来读取控制台输入
|
|
|
|
|
|
|
|
|
|
System.out.println("请选择您本次要发布的项目编号:");
|
|
|
|
|
for (ProjectBean projectBean : listProject) {
|
|
|
|
|
System.out.print(projectBean.getId() + ":" + projectBean.getDevProjectName() + " ");
|
|
|
|
|
}
|
|
|
|
|
System.out.println();
|
|
|
|
|
int choice = scanner.nextInt(); // 读取用户输入的整数
|
|
|
|
|
//输出choice对应的项目名称
|
|
|
|
|
for (ProjectBean projectBean : listProject) {
|
|
|
|
|
if (projectBean.getId() == choice) {
|
|
|
|
|
System.out.println("您选择的项目是:" + projectBean.getDevProjectName());
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return choice;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 功能:用户选择发布的仓库
|
|
|
|
|
*
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public static int userSelectWarehouse() {
|
|
|
|
|
Scanner scanner = new Scanner(System.in); // 创建Scanner对象来读取控制台输入
|
|
|
|
|
|
|
|
|
|
System.out.println("请选择您本次要发布的仓库:");
|
|
|
|
|
System.out.println("1:驿来特仓库 2:黄海私人仓库");
|
|
|
|
|
int choice = scanner.nextInt(); // 读取用户输入的整数
|
|
|
|
|
//输出choice对应的项目名称
|
|
|
|
|
if (choice == 1) {
|
|
|
|
|
System.out.println("您选择的仓库是:驿来特仓库");
|
|
|
|
|
} else {
|
|
|
|
|
System.out.println("您选择的仓库是:黄海私人仓库");
|
|
|
|
|
}
|
|
|
|
|
scanner.close(); // 关闭Scanner对象
|
|
|
|
|
return choice;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|