Jelajahi Sumber

PackerConfig 字段变更
添加一个 binfilesDirname 字段, 表示构建生成的可执行文件及配置文件, 脚本文件等所在的目录名, 目录位于 appRootPath

reghao 4 tahun lalu
induk
melakukan
ebfd76a88a

+ 4 - 0
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/model/po/config/build/PackerConfig.java

@@ -8,6 +8,7 @@ import lombok.*;
 import javax.persistence.Column;
 import javax.persistence.Entity;
 import javax.validation.constraints.NotBlank;
+import javax.validation.constraints.NotNull;
 
 /**
  * 打包方式配置
@@ -29,6 +30,9 @@ public class PackerConfig extends BaseEntity<Integer> {
     @Column(nullable = false, unique = true)
     @NotBlank(message = "打包工具名字不能为空白字符串")
     private String name;
+    // 构建生成的可执行文件及配置文件, 脚本文件等所在的目录名, 目录位于 appRootPath
+    @NotNull
+    private String binfilesDirname;
     // 打包后的应用存放的位置,可以是一个本地目录,也可以是一个网络位置
     // 根据打包类型来确定
     @Column(nullable = false)

+ 2 - 2
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/util/buildtool/packer/CodePacker.java

@@ -15,11 +15,11 @@ public interface CodePacker {
      *
      * @param appId 应用 ID
      * @param commitId 应用版本
-     * @param appCompileHome 应用编译目录
+     * @param appRootPath 应用根目录
      * @return 返回可执行应用的路径
      *
      * @date 2020-01-21 下午4:19
      */
-    String pack(String appId, String commitId, String appCompileHome) throws Exception;
+    String pack(String appId, String commitId, String appRootPath) throws Exception;
     String push(String localPath) throws DockerException;
 }

+ 2 - 2
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/util/buildtool/packer/DockerPack.java

@@ -27,10 +27,10 @@ public class DockerPack implements CodePacker {
     }
 
     @Override
-    public String pack(String appId, String commitId, String appCompileHome) throws Exception {
+    public String pack(String appId, String commitId, String appRootPath) throws Exception {
         String repo = targetPath + File.separator + appId;
         String image = repo + ":" + commitId;
-        docker.build(image, appCompileHome, dockerfile);
+        docker.build(image, appRootPath, dockerfile);
         return image;
     }
 

+ 5 - 2
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/util/buildtool/packer/ZipPack.java

@@ -15,20 +15,23 @@ import java.io.File;
 @Slf4j
 public class ZipPack implements CodePacker {
     private final String targetPath;
+    private String binfilesDirname;
 
     public ZipPack(PackerConfig packerConfig) {
         this.targetPath = packerConfig.getType().equals(PackType.zip.getName()) ?
                 LocalBuildDir.packDir : packerConfig.getTargetPath();
+        this.binfilesDirname = packerConfig.getBinfilesDirname();
     }
 
     @Override
-    public String pack(String appId, String commitId, String appCompileHome) throws Exception {
+    public String pack(String appId, String commitId, String appRootPath) throws Exception {
+        String binfilesDirPath = appRootPath + File.separator + binfilesDirname;
         String filename = String.format("%s_%s.zip", appId, commitId);
         String dst = targetPath + File.separator + filename;
         if (new File(dst).exists()) {
             throw new Exception(dst + " 已存在");
         }
-        ZipFiles.zip(new File(appCompileHome), dst);
+        ZipFiles.zip(new File(binfilesDirPath), dst);
 
         return String.format("http://localhost:4020/api/sys/package/%s", filename);
     }