|
|
@@ -1,12 +1,14 @@
|
|
|
package cn.reghao.autodop.dmaster.app.service.build;
|
|
|
|
|
|
-import cn.reghao.autodop.dmaster.app.pojo.BuildResult;
|
|
|
+import cn.reghao.autodop.common.config.BuildDeployResult;
|
|
|
+import cn.reghao.autodop.common.utils.JsonUtil;
|
|
|
import cn.reghao.autodop.dmaster.orchestrate.pojo.SysConfig;
|
|
|
import cn.reghao.autodop.dmaster.orchestrate.pojo.orchestration.AppOrchestration;
|
|
|
import cn.reghao.autodop.dmaster.app.service.build.tools.vc.VersionControl;
|
|
|
import cn.reghao.autodop.dmaster.utils.ProxyUtils;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
|
+import java.util.List;
|
|
|
import java.util.concurrent.Callable;
|
|
|
|
|
|
/**
|
|
|
@@ -16,16 +18,16 @@ import java.util.concurrent.Callable;
|
|
|
* @date 2019-11-16 21:39:53
|
|
|
*/
|
|
|
@Slf4j
|
|
|
-public class AppBuildPipeline implements Callable<BuildResult> {
|
|
|
+public class AppBuildPipeline implements Callable<String> {
|
|
|
private AppOrchestration app;
|
|
|
- private long version;
|
|
|
+ private String version;
|
|
|
private boolean isDeploy;
|
|
|
private AppIntegrate appIntegrate;
|
|
|
|
|
|
private final String appLocalRepo;
|
|
|
private final String appCompileDir;
|
|
|
|
|
|
- public AppBuildPipeline(AppOrchestration app, long version, boolean isDeploy) {
|
|
|
+ public AppBuildPipeline(AppOrchestration app, String version, boolean isDeploy) {
|
|
|
this.app = app;
|
|
|
this.version = version;
|
|
|
this.isDeploy = isDeploy;
|
|
|
@@ -41,25 +43,26 @@ public class AppBuildPipeline implements Callable<BuildResult> {
|
|
|
* 更新 -> 编译 -> 打包 -> 部署流水线
|
|
|
*
|
|
|
* @param
|
|
|
- * @return
|
|
|
+ * @return 返回 JSON
|
|
|
* @date 2019-11-07 下午10:14
|
|
|
*/
|
|
|
@Override
|
|
|
- public BuildResult call() {
|
|
|
- BuildResult buildResult = new BuildResult();
|
|
|
- buildResult.setAppId(app.getIdentifier());
|
|
|
+ public String call() {
|
|
|
+ BuildDeployResult result = new BuildDeployResult();
|
|
|
+ result.setAppId(app.getIdentifier());
|
|
|
/* 更新阶段 */
|
|
|
- if (version == -1 ) {
|
|
|
+ if (version == null ) {
|
|
|
try {
|
|
|
version = updateApp();
|
|
|
BuilderUtil.copyToCompileDir(appLocalRepo, app);
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
- buildResult.setMsg(e.getMessage());
|
|
|
- return buildResult;
|
|
|
+ result.setStage("更新");
|
|
|
+ result.setMsg(e.getMessage());
|
|
|
+ return JsonUtil.objectToJson(result);
|
|
|
}
|
|
|
}
|
|
|
- buildResult.setVersioin(version);
|
|
|
+ result.setVersion(version);
|
|
|
|
|
|
String appEntryDir;
|
|
|
if (app.getProjBuild() != null) {
|
|
|
@@ -70,14 +73,15 @@ public class AppBuildPipeline implements Callable<BuildResult> {
|
|
|
|
|
|
try {
|
|
|
/* 编译阶段 */
|
|
|
- if ("dotnet".equals(app.getBuild().getCodeCompiler().getCompilerType())) {
|
|
|
- appIntegrate.preCompile(app.getConfigFiles(), appEntryDir);
|
|
|
+ if (appIntegrate.needPreCompile()) {
|
|
|
+ appIntegrate.preCompile(appEntryDir);
|
|
|
}
|
|
|
appIntegrate.compile(appEntryDir);
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
- buildResult.setMsg(e.getMessage());
|
|
|
- return buildResult;
|
|
|
+ result.setStage("编译");
|
|
|
+ result.setMsg(e.getMessage());
|
|
|
+ return JsonUtil.objectToJson(result);
|
|
|
}
|
|
|
|
|
|
/* 打包阶段 */
|
|
|
@@ -86,35 +90,39 @@ public class AppBuildPipeline implements Callable<BuildResult> {
|
|
|
appPath = appIntegrate.pack(app.getIdentifier(), String.valueOf(version), appEntryDir);
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
- buildResult.setMsg(e.getMessage());
|
|
|
- return buildResult;
|
|
|
+ result.setStage("打包");
|
|
|
+ result.setMsg(e.getMessage());
|
|
|
+ return JsonUtil.objectToJson(result);
|
|
|
}
|
|
|
- buildResult.setAppPath(appPath);
|
|
|
+ result.setAppPath(appPath);
|
|
|
|
|
|
/* 部署阶段 */
|
|
|
if (isDeploy) {
|
|
|
- try {
|
|
|
- AppDeploy.deploy(app, appPath);
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- buildResult.setMsg(e.getMessage());
|
|
|
- return buildResult;
|
|
|
- }
|
|
|
+ List<BuildDeployResult> results = AppDeploy.deploy(app, appPath);
|
|
|
+ results.forEach(res -> {
|
|
|
+ if ("成功".equalsIgnoreCase(res.getMsg())) {
|
|
|
+ // TODO 发出通知
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ return JsonUtil.objectToJson(results);
|
|
|
}
|
|
|
|
|
|
- return buildResult;
|
|
|
+ return JsonUtil.objectToJson(result);
|
|
|
}
|
|
|
|
|
|
- private long updateApp() throws Exception {
|
|
|
+ private String updateApp() throws Exception {
|
|
|
String remoteRepo = app.getBuild().getCodeRepos().getReposUrl();
|
|
|
VersionControl vc = BuilderUtil.versionControl(app.getBuild().getCodeRepos().getReposAuth());
|
|
|
- long version = vc.update(remoteRepo, appLocalRepo + BuilderUtil.dirname(remoteRepo));
|
|
|
+ String version = vc.update(remoteRepo, appLocalRepo + BuilderUtil.dirname(remoteRepo));
|
|
|
|
|
|
- String[] dependencyRepos = app.getBuild().getCodeRepos().getDependencyUrls().split(",");
|
|
|
- for (String repo : dependencyRepos) {
|
|
|
- vc.update(repo, appLocalRepo + BuilderUtil.dirname(repo));
|
|
|
+ String dep = app.getBuild().getCodeRepos().getDependencyUrls();
|
|
|
+ if (dep != null) {
|
|
|
+ String[] dependencyRepos = dep.split(",");
|
|
|
+ for (String repo : dependencyRepos) {
|
|
|
+ vc.update(repo, appLocalRepo + BuilderUtil.dirname(repo));
|
|
|
+ }
|
|
|
}
|
|
|
-
|
|
|
return version;
|
|
|
}
|
|
|
}
|