main
黄海 10 months ago
parent 7af5d3dc03
commit 7115d6f883

@ -18,7 +18,7 @@ public class PublishUtil {
* docker images --format "{{.Repository}}:{{.Tag}}" | xargs -r docker rmi -f * docker images --format "{{.Repository}}:{{.Tag}}" | xargs -r docker rmi -f
* *
* docker login --username= registry.cn-hangzhou.aliyuncs.com --password DsideaL4r5t6y7u * docker login --username= registry.cn-hangzhou.aliyuncs.com --password DsideaL4r5t6y7u
* <p>
* # * #
* docker search registry.cn-hangzhou.aliyuncs.com/yltcharge/zhu-que:20240903 * docker search registry.cn-hangzhou.aliyuncs.com/yltcharge/zhu-que:20240903
* # * #
@ -37,6 +37,7 @@ public class PublishUtil {
JSONArray ja = jo.getJSONArray("project"); JSONArray ja = jo.getJSONArray("project");
String workingPath = null, remotePath, localLibPath = null; String workingPath = null, remotePath, localLibPath = null;
boolean isStatic = false;
for (Object o : ja) { for (Object o : ja) {
JSONObject project = (JSONObject) o; JSONObject project = (JSONObject) o;
@ -44,6 +45,9 @@ public class PublishUtil {
if (p.equals(projectName)) { if (p.equals(projectName)) {
workingPath = project.getString("workingPath"); workingPath = project.getString("workingPath");
localLibPath = project.getString("localLibPath"); localLibPath = project.getString("localLibPath");
if (project.getBoolean("isStatic")) {
isStatic = true;
}
break; break;
} }
} }
@ -59,13 +63,14 @@ public class PublishUtil {
newVersion = newVersion.replace(" ", "").replace("-", "").replace(":", ""); newVersion = newVersion.replace(" ", "").replace("-", "").replace(":", "");
//准备工作 //准备工作
remotePath = "/usr/local/" + projectName+"/"; remotePath = "/usr/local/" + projectName + "/";
ssh.exec("rm -rf " + remotePath); ssh.exec("rm -rf " + remotePath);
ssh.mkdir(remotePath); ssh.mkdir(remotePath);
System.out.println("正在上传Dockerfile..."); if (!isStatic) {
ssh.upload(workingPath + "Dockerfile", remotePath + "Dockerfile"); System.out.println("正在上传Dockerfile...");
ssh.upload(workingPath + "Dockerfile", remotePath + "Dockerfile");
}
if (!StrKit.isBlank(localLibPath)) { if (!StrKit.isBlank(localLibPath)) {
System.out.println("正在创建lib目录..."); System.out.println("正在创建lib目录...");
@ -96,6 +101,36 @@ public class PublishUtil {
ssh.exec("cd " + remotePath + " && rm -rf target.zip"); ssh.exec("cd " + remotePath + " && rm -rf target.zip");
} }
//处理静态文件
if (isStatic) {
//倒数第二个/
int cnt = 0;
int pos = -1;
for (int i = workingPath.length() - 1; ; i--) {
if (workingPath.charAt(i) == '/') cnt++;
if (cnt == 2) {
pos = i;
break;
}
}
String localFile = workingPath.substring(0, pos) + "/static.zip";
if (FileUtil.exist(localFile)) {
FileUtil.del(localFile);
}
System.out.println("正在上传static.zip...");
// 将目录打包成ZIP文件不包含目录本身只包含目录下的文件和子目录
ZipUtil.zip(workingPath, localFile, false);
//上传
ssh.upload(localFile, remotePath + "static.zip");
//删除target.zip
FileUtil.del(localFile);
//解压缩
System.out.println("正在解压缩static.zip...");
ssh.exec("cd " + remotePath + " && unzip static.zip");
ssh.exec("cd " + remotePath + " && rm -rf static.zip");
}
//打包 //打包
System.out.println("开始打包镜像,稍等...."); System.out.println("开始打包镜像,稍等....");
String cmd = "cd /usr/local/" + projectName + " && docker build -t " + projectName + ":" + newVersion + " ."; String cmd = "cd /usr/local/" + projectName + " && docker build -t " + projectName + ":" + newVersion + " .";

@ -7,17 +7,20 @@
{ {
"projectName": "ds-gw", "projectName": "ds-gw",
"workingPath": "D:/dsWork/dsProject/dsGw/", "workingPath": "D:/dsWork/dsProject/dsGw/",
"localLibPath": "D:/dsWork/dsProject/dsGw/lib/" "localLibPath": "D:/dsWork/dsProject/dsGw/lib/",
"isStatic": false
}, },
{ {
"projectName": "ds-base", "projectName": "ds-base",
"workingPath": "D:/dsWork/dsProject/dsBase/", "workingPath": "D:/dsWork/dsProject/dsBase/",
"localLibPath": "D:/dsWork/dsProject/dsBase/lib/" "localLibPath": "D:/dsWork/dsProject/dsBase/lib/",
"isStatic": false
}, },
{ {
"projectName": "ds-base-web", "projectName": "ds-base-web",
"workingPath": "D:/dsWork/dsProject/dsBase/", "workingPath": "D:/dsWork/dsProject/dsBaseWeb/",
"localLibPath": "D:/dsWork/dsProject/dsBase/lib/" "localLibPath": "",
"isStatic": true
} }
] ]
} }

@ -7,12 +7,20 @@
{ {
"projectName": "ds-gw", "projectName": "ds-gw",
"workingPath": "D:/dsWork/dsProject/dsGw/", "workingPath": "D:/dsWork/dsProject/dsGw/",
"localLibPath": "D:/dsWork/dsProject/dsGw/lib/" "localLibPath": "D:/dsWork/dsProject/dsGw/lib/",
"isStatic": false
}, },
{ {
"projectName": "ds-base", "projectName": "ds-base",
"workingPath": "D:/dsWork/dsProject/dsBase/", "workingPath": "D:/dsWork/dsProject/dsBase/",
"localLibPath": "D:/dsWork/dsProject/dsBase/lib/" "localLibPath": "D:/dsWork/dsProject/dsBase/lib/",
"isStatic": false
},
{
"projectName": "ds-base-web",
"workingPath": "D:/dsWork/dsProject/dsBaseWeb/",
"localLibPath": "",
"isStatic": true
} }
] ]
} }

Loading…
Cancel
Save