|
|
|
@ -47,7 +47,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 String publish(String projectName, boolean isStatic, String workingPath, String localLibPath, Kv choiceWarehouse, String choiceConfig) throws Exception {
|
|
|
|
|
public static Kv 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";
|
|
|
|
@ -58,6 +58,8 @@ public class PublishUtil {
|
|
|
|
|
String pwd = jo.getString("pwd");
|
|
|
|
|
int port = jo.getIntValue("port");
|
|
|
|
|
|
|
|
|
|
String project_port=null;
|
|
|
|
|
|
|
|
|
|
//声明SSH对象
|
|
|
|
|
SSHUtil ssh = new SSHUtil(user, pwd, host, port);
|
|
|
|
|
ssh.connect();
|
|
|
|
@ -108,6 +110,11 @@ public class PublishUtil {
|
|
|
|
|
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("]","");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//处理静态文件
|
|
|
|
@ -152,7 +159,7 @@ public class PublishUtil {
|
|
|
|
|
System.out.println("环境变量修改成功!");
|
|
|
|
|
|
|
|
|
|
//如果容器正在运行中,那么容器对应的镜像删除失败
|
|
|
|
|
cmd="docker rm -f $(docker ps -aq)";
|
|
|
|
|
cmd = "docker rm -f $(docker ps -aq)";
|
|
|
|
|
ssh.exec(cmd);
|
|
|
|
|
|
|
|
|
|
//删除所有镜像
|
|
|
|
@ -189,7 +196,9 @@ public class PublishUtil {
|
|
|
|
|
ssh.disconnect();
|
|
|
|
|
System.out.println("恭喜,镜像打包成功!");
|
|
|
|
|
|
|
|
|
|
return projectName + ":" + newVersion;
|
|
|
|
|
Kv ret = Kv.by("projectName", projectName+":"+newVersion);
|
|
|
|
|
ret.set("project_port",project_port);
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|