diff --git a/dsBaseWeb/docker run.txt b/dsBaseWeb/docker_run.txt similarity index 100% rename from dsBaseWeb/docker run.txt rename to dsBaseWeb/docker_run.txt diff --git a/dsBuild/src/main/java/Util/PublishUtil.java b/dsBuild/src/main/java/Util/PublishUtil.java index ef5c263b..aed89a7f 100644 --- a/dsBuild/src/main/java/Util/PublishUtil.java +++ b/dsBuild/src/main/java/Util/PublishUtil.java @@ -18,7 +18,7 @@ public class PublishUtil { * docker images --format "{{.Repository}}:{{.Tag}}" | xargs -r docker rmi -f * 登录远程仓库 * docker login --username=东师黄海 registry.cn-hangzhou.aliyuncs.com --password DsideaL4r5t6y7u - + *
* # 搜索 * docker search registry.cn-hangzhou.aliyuncs.com/yltcharge/zhu-que:20240903 * #拉取 @@ -37,6 +37,7 @@ public class PublishUtil { JSONArray ja = jo.getJSONArray("project"); String workingPath = null, remotePath, localLibPath = null; + boolean isStatic = false; for (Object o : ja) { JSONObject project = (JSONObject) o; @@ -44,6 +45,9 @@ public class PublishUtil { if (p.equals(projectName)) { workingPath = project.getString("workingPath"); localLibPath = project.getString("localLibPath"); + if (project.getBoolean("isStatic")) { + isStatic = true; + } break; } } @@ -59,13 +63,14 @@ public class PublishUtil { newVersion = newVersion.replace(" ", "").replace("-", "").replace(":", ""); //准备工作 - remotePath = "/usr/local/" + projectName+"/"; + remotePath = "/usr/local/" + projectName + "/"; ssh.exec("rm -rf " + remotePath); ssh.mkdir(remotePath); - System.out.println("正在上传Dockerfile..."); - ssh.upload(workingPath + "Dockerfile", remotePath + "Dockerfile"); - + if (!isStatic) { + System.out.println("正在上传Dockerfile..."); + ssh.upload(workingPath + "Dockerfile", remotePath + "Dockerfile"); + } if (!StrKit.isBlank(localLibPath)) { System.out.println("正在创建lib目录..."); @@ -96,6 +101,36 @@ public class PublishUtil { 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("开始打包镜像,稍等...."); String cmd = "cd /usr/local/" + projectName + " && docker build -t " + projectName + ":" + newVersion + " ."; diff --git a/dsBuild/src/main/resources/publishImage.json b/dsBuild/src/main/resources/publishImage.json index b9c9d759..bf823b09 100644 --- a/dsBuild/src/main/resources/publishImage.json +++ b/dsBuild/src/main/resources/publishImage.json @@ -7,17 +7,20 @@ { "projectName": "ds-gw", "workingPath": "D:/dsWork/dsProject/dsGw/", - "localLibPath": "D:/dsWork/dsProject/dsGw/lib/" + "localLibPath": "D:/dsWork/dsProject/dsGw/lib/", + "isStatic": false }, { "projectName": "ds-base", "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/dsBase/", - "localLibPath": "D:/dsWork/dsProject/dsBase/lib/" + "workingPath": "D:/dsWork/dsProject/dsBaseWeb/", + "localLibPath": "", + "isStatic": true } ] } diff --git a/dsBuild/target/classes/publishImage.json b/dsBuild/target/classes/publishImage.json index 21078513..bf823b09 100644 --- a/dsBuild/target/classes/publishImage.json +++ b/dsBuild/target/classes/publishImage.json @@ -7,12 +7,20 @@ { "projectName": "ds-gw", "workingPath": "D:/dsWork/dsProject/dsGw/", - "localLibPath": "D:/dsWork/dsProject/dsGw/lib/" + "localLibPath": "D:/dsWork/dsProject/dsGw/lib/", + "isStatic": false }, { "projectName": "ds-base", "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 } ] } diff --git a/dsBuild/target/classes/publishImage.jsonstatic.zip b/dsBuild/target/classes/publishImage.jsonstatic.zip new file mode 100644 index 00000000..3038dad6 Binary files /dev/null and b/dsBuild/target/classes/publishImage.jsonstatic.zip differ