Browse Source

PackType 添加一个 staticFiles 值, 表示前端静态文件打包, 并添加相应的 StaticPack 实现

reghao 9 tháng trước cách đây
mục cha
commit
860e6ffd26

+ 1 - 1
common/src/main/java/cn/reghao/devops/common/msg/constant/PackType.java

@@ -8,7 +8,7 @@ package cn.reghao.devops.common.msg.constant;
  */
 public enum PackType {
     //docker, zip;
-    docker, zip;
+    docker, zip, staticFiles;
 
     public String getName() {
         return this.name();

+ 4 - 0
mgr/src/main/java/cn/reghao/devops/mgr/mgr/build/chain/BuildTools.java

@@ -13,6 +13,7 @@ import cn.reghao.devops.mgr.mgr.build.tool.compiler.*;
 import cn.reghao.devops.common.msg.constant.PackType;
 import cn.reghao.devops.mgr.mgr.build.tool.packer.CodePacker;
 import cn.reghao.devops.mgr.mgr.build.tool.packer.DockerPack;
+import cn.reghao.devops.mgr.mgr.build.tool.packer.StaticPack;
 import cn.reghao.devops.mgr.mgr.build.tool.packer.ZipPack;
 import cn.reghao.devops.mgr.mgr.build.tool.repo.CodeUpdater;
 import cn.reghao.devops.mgr.mgr.build.tool.repo.GitImpl;
@@ -130,6 +131,9 @@ public class BuildTools {
                         codePacker = new DockerPack(packerDto.getTargetPath());
                     }
 
+                    break;
+                case staticFiles:
+                    codePacker = new StaticPack(packerDto.getBinDirname());
                     break;
                 default:
                     codePacker = new ZipPack(packerDto.getBinDirname());

+ 58 - 0
mgr/src/main/java/cn/reghao/devops/mgr/mgr/build/tool/packer/StaticPack.java

@@ -0,0 +1,58 @@
+package cn.reghao.devops.mgr.mgr.build.tool.packer;
+
+import cn.reghao.devops.mgr.mgr.build.model.LocalBuildDir;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.io.FileUtils;
+
+import java.io.File;
+import java.io.IOException;
+
+/**
+ * 静态文件打包
+ *
+ * @author reghao
+ * @date 2025-06-05 14:53:20
+ */
+@Slf4j
+public class StaticPack implements CodePacker {
+    // TODO 必须指定构建存在的目录
+    private final String binDirname;
+
+    public StaticPack(String binDirname) {
+        this.binDirname = binDirname;
+    }
+
+    private void createTargetDir(String targetPath) throws IOException {
+        File dir = new File(targetPath);
+        if (!dir.exists()) {
+            FileUtils.forceMkdir(new File(targetPath));
+        }
+    }
+
+    @Override
+    public String pack(String appId, String commitId, String appRootPath, String dockerfile) throws Exception {
+        if (binDirname == null) {
+            throw new Exception("存放编译产物的目录 binDirname 不能是 null");
+        }
+
+        String sourceDirPath = appRootPath + File.separator + binDirname;
+        File srcDir = new File(sourceDirPath);
+        String targetDirPath = LocalBuildDir.packDir + File.separator + appId;
+        createTargetDir(targetDirPath);
+
+        String dirname = String.format("%s_%s", appId, commitId);
+        String destDirPath = targetDirPath + File.separator + dirname;
+        File destDir = new File(destDirPath);
+        if (!destDir.exists()) {
+            FileUtils.copyDirectory(srcDir, destDir);
+        } else {
+            log.info("{} exist", destDirPath);
+        }
+        return "";
+    }
+
+    @Override
+    public String push(String localPath) {
+        return localPath;
+    }
+}