소스 검색

在 AppConfig 中添加了一个 appDirPath 字段, 用于指定应用代码目录在项目代码目录中的相对位置, 主要是应用在一个项目中拥有多个应用模块的场景, 目前是应用在 maven 项目的多模块场景

reghao 4 년 전
부모
커밋
063c12cc96

+ 2 - 1
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/model/po/config/AppConfig.java

@@ -42,8 +42,9 @@ public class AppConfig extends BaseEntity<Integer> implements Cloneable {
 
     // TODO 操作系统类型和版本,CPU 架构
     /* 构建配置 */
-    @NotBlank(message = "代码目录不能为空白字符串")
+    @NotBlank(message = "代码目录不能为空白字符串")
     private String codeDirname;
+    private String appDirPath;
     private String execBinName;
     private Integer httpPort;
     private String healthCheck;

+ 2 - 1
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/AppBuilder.java

@@ -105,7 +105,8 @@ public class AppBuilder {
                 codeCompiler = new ShellCompiler(compilerConfig);
                 break;
             case maven:
-                codeCompiler = new MavenCompiler(compilerConfig.getHomePath(), app.getEnv(), app.getCodeDirname());
+                String appDirPath = app.getCodeDirname() + app.getAppDirPath();
+                codeCompiler = new MavenCompiler(compilerConfig.getHomePath(), app.getEnv(), appDirPath);
                 break;
             case docker:
                 codeCompiler = new NullCompiler();

+ 1 - 1
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/util/buildtool/compiler/CodeCompiler.java

@@ -9,7 +9,7 @@ package cn.reghao.autodop.dmaster.app.util.buildtool.compiler;
 public interface CodeCompiler {
     /**
      * @param appId 应用标识
-     * @param appCompileHome 应用代码编译目录
+     * @param appCompileHome 编译应用代码所处的目录
      * @date 2020-01-21 下午4:20
      */
     void compile(String appId, String appCompileHome) throws Exception;

+ 8 - 7
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/util/buildtool/compiler/MavenCompiler.java

@@ -18,26 +18,27 @@ import java.util.List;
  */
 @Slf4j
 public class MavenCompiler implements CodeCompiler {
-    private final String dirname;
+    private final String appDirPath;
     // TODO 和 EnvType 关联
     private final String env;
     private final InvocationRequest request;
     private final Invoker invoker;
     private final List<String> compileLog;
 
-    public MavenCompiler(String homePath, String env, String dirname) {
+    public MavenCompiler(String homePath, String env, String appDirPath) {
         System.setProperty("maven.home", homePath);
         this.env = env;
         this.request = new DefaultInvocationRequest();
         this.invoker = new DefaultInvoker();
         this.compileLog = new ArrayList<>();
-        this.dirname = dirname;
+        this.appDirPath = appDirPath;
     }
 
     @Override
     public void compile(String appId, String appCompileHome) throws Exception {
         String pomPath = appCompileHome + "/pom.xml";
-        setInvocationRequest(appId, pomPath);
+        String appDirname = appDirPath.substring(appDirPath.lastIndexOf(File.separator)+1);
+        setInvocationRequest(appDirname, pomPath);
         InvocationResult result = invoker.execute(request);
         if (result.getExitCode() != 0) {
             CommandLineException exception = result.getExecutionException();
@@ -49,7 +50,7 @@ public class MavenCompiler implements CodeCompiler {
             compileLog.forEach(line -> sb.append(line).append(System.lineSeparator()));
             throw new Exception(sb.toString());
         } else {
-            log.info("构建成功");
+            log.info("maven 构建成功");
         }
     }
 
@@ -60,7 +61,7 @@ public class MavenCompiler implements CodeCompiler {
      * @return
      * @date 2020-05-12 上午10:36
      */
-    private void setInvocationRequest(String appId, String pomPath) {
+    private void setInvocationRequest(String appDirname, String pomPath) {
         request.setPomFile(new File(pomPath));
         // mvn clean package -Dmaven.test.skip=true
         request.setGoals(Arrays.asList("clean", "package", "-Dmaven.test.skip=true"));
@@ -69,7 +70,7 @@ public class MavenCompiler implements CodeCompiler {
         // -Penv
         request.setProfiles(Collections.singletonList(env));
         // -pl app
-        request.setProjects(Collections.singletonList(appId));
+        request.setProjects(Collections.singletonList(appDirname));
         // 清空前一次构建的日志
         // TODO 多线程环境时编译日志会出现问题
         compileLog.clear();

+ 27 - 17
dmaster/src/main/resources/templates/app/config/app/add.html

@@ -93,48 +93,58 @@
                 </td>
             </tr>
             <tr>
-                <th>HTTP 端口</th>
+                <th>
+                    <label class="layui-form-label required">代码目录</label>
+                </th>
                 <td>
                     <div class="layui-form-item">
                         <div class="layui-input-inline">
-                            <input class="layui-input" type="text" name="httpPort" placeholder="请输入应用的 HTTP 端口" th:value="${app?.httpPort}">
+                            <input class="layui-input" type="text" name="codeDirname"  placeholder="请输入代码目录" required th:value="${app?.codeDirname}">
                         </div>
                     </div>
                 </td>
-                <th>健康检查地址</th>
-                <td >
+                <th>
+                    <label class="layui-form-label required">应用目录路径</label>
+                </th>
+                <td>
                     <div class="layui-form-item">
                         <div class="layui-input-inline">
-                            <input class="layui-input" type="text" name="healthCheck" placeholder="请输入健康检查 URI" required th:value="${app?.healthCheck}">
+                            <input class="layui-input" type="text" name="appDirPath"  placeholder="请输入应用目录相对路径" required th:value="${app?.appDirPath}">
+                        </div>
+                    </div>
+                </td>
+                <th>可执行文件名</th>
+                <td>
+                    <div class="layui-form-item">
+                        <div class="layui-input-inline">
+                            <input class="layui-input" type="text" name="execBinName"  placeholder="请输入构建生成的可执行文件名" required th:value="${app?.execBinName}">
                         </div>
                     </div>
                 </td>
             </tr>
-            </tbody>
-        </table>
-        <div class="timo-detail-title">构建配置</div>
-        <table class="layui-table timo-detail-table">
-            <tbody>
             <tr>
-                <th>
-                    <label class="layui-form-label required">代码目录</label>
-                </th>
+                <th>HTTP 端口</th>
                 <td>
                     <div class="layui-form-item">
                         <div class="layui-input-inline">
-                            <input class="layui-input" type="text" name="codeDirname"  placeholder="请输入应用代码目录" required th:value="${app?.codeDirname}">
+                            <input class="layui-input" type="text" name="httpPort" placeholder="请输入应用的 HTTP 端口" th:value="${app?.httpPort}">
                         </div>
                     </div>
                 </td>
-                <th>可执行文件名</th>
-                <td>
+                <th>健康检查地址</th>
+                <td >
                     <div class="layui-form-item">
                         <div class="layui-input-inline">
-                            <input class="layui-input" type="text" name="execBinName"  placeholder="请输入构建生成的可执行文件名" required th:value="${app?.execBinName}">
+                            <input class="layui-input" type="text" name="healthCheck" placeholder="请输入健康检查 URI" required th:value="${app?.healthCheck}">
                         </div>
                     </div>
                 </td>
             </tr>
+            </tbody>
+        </table>
+        <div class="timo-detail-title">构建配置</div>
+        <table class="layui-table timo-detail-table">
+            <tbody>
             <tr>
                 <th>
                     <label class="layui-form-label required">仓库认证</label>

+ 12 - 10
dmaster/src/main/resources/templates/app/config/app/detail.html

@@ -26,6 +26,18 @@
                 <th>仓库分支</th>
                 <td th:text="${app.repoBranch}"></td>
             </tr>
+            <tr>
+                <th>代码目录</th>
+                <td th:text="${app.codeDirname}"></td>
+                <th>应用目录路径</th>
+                <td th:text="${app.appDirPath}"></td>
+                <th>可执行文件名</th>
+                <td th:text="${app.execBinName}"></td>
+                <th>Dockerfile</th>
+                <td>
+                    <textarea class="layui-textarea" readonly="readonly" th:text="${app.dockerfile}"></textarea>
+                </td>
+            </tr>
             <tr>
                 <th>HTTP 端口</th>
                 <td th:text="${app.httpPort}"></td>
@@ -37,16 +49,6 @@
         <div class="timo-detail-title">构建配置</div>
         <table class="layui-table timo-detail-table">
             <tbody>
-            <tr>
-                <th>代码目录</th>
-                <td th:text="${app.codeDirname}"></td>
-                <th>可执行文件名</th>
-                <td th:text="${app.execBinName}"></td>
-                <th>Dockerfile</th>
-                <td>
-                    <textarea class="layui-textarea" readonly="readonly" th:text="${app.dockerfile}"></textarea>
-                </td>
-            </tr>
             <tr>
                 <th>仓库类型</th>
                 <td th:text="${app.repoAuthConfig.type}"></td>