main
黄海 10 months ago
parent 280568ea67
commit b329ae9360

@ -63,7 +63,9 @@ public class Publish {
if (ret.getStr("project_port") != null) {
String port = ret.getStr("project_port");
System.out.println("docker run --name " + ret.getStr("projectName").split(":")[0] + " -p " + port + ":" + port + " -d " + ret.getStr("projectName"));
System.out.println("docker exec -it 替换我为容器ID /bin/bash");
//System.out.println("docker exec -it 替换我为容器ID /bin/bash");
}else{
System.out.println("docker run --name " + ret.getStr("projectName").split(":")[0] + " -p 80:80 -d " + ret.getStr("projectName"));
}
}
}

@ -58,7 +58,7 @@ public class PublishUtil {
String pwd = jo.getString("pwd");
int port = jo.getIntValue("port");
String project_port=null;
String project_port = null;
//声明SSH对象
SSHUtil ssh = new SSHUtil(user, pwd, host, port);
@ -114,7 +114,7 @@ public class PublishUtil {
//获取项目端口
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("]","");
project_port = ssh.exec(cmd).getStr("message").replace("[", "").replace("]", "");
}
//处理静态文件
@ -148,12 +148,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的引用镜像成功!");
if (choiceWarehouse.get("id") != null) {
doLogin(ssh, choiceWarehouse.getStr("username"), choiceWarehouse.getStr("password"));
System.out.println("仓库登录成功!");
}
//修改镜像要用的配置文件
cmd = "sed -i 's|ENV WORKING_ENV=\"pro\"|ENV WORKING_ENV=\"" + choiceConfig + "\"|g' " + remoteDockerFile;
String cmd = "sed -i 's|ENV WORKING_ENV=\"pro\"|ENV WORKING_ENV=\"" + choiceConfig + "\"|g' " + remoteDockerFile;
ssh.exec(cmd);
System.out.println(cmd);
System.out.println("环境变量修改成功!");
@ -183,21 +185,23 @@ public class PublishUtil {
System.exit(0);
}
System.out.println("打标签...");
cmd = "docker tag " + imageId + " registry.cn-hangzhou.aliyuncs.com/" + choiceWarehouse.getStr("name") + "/" + projectName + ":" + newVersion;
ssh.exec(cmd);
if (choiceWarehouse.get("id") != null) {
System.out.println("打标签...");
cmd = "docker tag " + imageId + " registry.cn-hangzhou.aliyuncs.com/" + choiceWarehouse.getStr("name") + "/" + projectName + ":" + newVersion;
ssh.exec(cmd);
System.out.println("开始推送到远程仓库,稍等...");
cmd = "docker push registry.cn-hangzhou.aliyuncs.com/" + choiceWarehouse.getStr("name") + "/" + projectName + ":" + newVersion;
System.out.println(cmd);
ssh.exec(cmd);
System.out.println("推送到远程仓库完成!");
System.out.println("开始推送到远程仓库,稍等...");
cmd = "docker push registry.cn-hangzhou.aliyuncs.com/" + choiceWarehouse.getStr("name") + "/" + projectName + ":" + newVersion;
System.out.println(cmd);
ssh.exec(cmd);
System.out.println("推送到远程仓库完成!");
}
ssh.disconnect();
System.out.println("恭喜,镜像打包成功!");
Kv ret = Kv.by("projectName", projectName+":"+newVersion);
ret.set("project_port",project_port);
Kv ret = Kv.by("projectName", projectName + ":" + newVersion);
ret.set("project_port", project_port);
return ret;
}
@ -313,26 +317,34 @@ public class PublishUtil {
Kv kv = Kv.create();
while (true) {
redPrint("2、请选择您本次要发布的仓库");
System.out.println("1:驿来特仓库 2:黄海私人仓库");
System.out.println("1:不上传到仓库 2:黄海私人仓库 3驿来特仓库");
int choice = scanner.nextInt(); // 读取用户输入的整数
if (choice == 1) {
kv.set("id", 1);
kv.set("name", "yltcharge");
kv.set("username", "驿来特充电");
kv.set("password", "ylt5033.");
System.out.println("您选择的仓库是:驿来特仓库");
} else {
kv.set("id", null);
kv.set("name", null);
kv.set("username", null);
kv.set("password", null);
System.out.println("您选择的仓库是:不上传到仓库");
}
if (choice == 2) {
kv.set("id", 2);
kv.set("name", "dsideal");
kv.set("username", "东师黄海");
kv.set("password", "DsideaL4r5t6y7u");
System.out.println("您选择的仓库是:黄海私人仓库");
}
if (choice == 1 || choice == 2) {
if (choice == 3) {
kv.set("id", 3);
kv.set("name", "yltcharge");
kv.set("username", "驿来特充电");
kv.set("password", "ylt5033.");
System.out.println("您选择的仓库是:驿来特仓库");
}
if (choice == 1 || choice == 2 || choice == 3) {
break; // 如果输入正确,退出循环
} else {
System.out.println("输入不正确请输入1 或者 2 !"); // 提示用户输入不正确
System.out.println("输入不正确请输入1, 2 或者 3 !"); // 提示用户输入不正确
}
}
return kv;

Loading…
Cancel
Save