|
|
@@ -4,13 +4,14 @@ import cn.reghao.autodop.dmaster.app.entity.build.AppBuild;
|
|
|
import cn.reghao.autodop.dmaster.app.entity.build.compile.AppCompile;
|
|
|
import cn.reghao.autodop.dmaster.app.entity.build.pack.AppPack;
|
|
|
import cn.reghao.autodop.dmaster.app.entity.build.update.AppUpdate;
|
|
|
-import cn.reghao.autodop.dmaster.app.entity.constant.AppStage;
|
|
|
+import cn.reghao.autodop.dmaster.app.entity.constant.BuildDeployStage;
|
|
|
import cn.reghao.autodop.dmaster.app.entity.constant.CompilerType;
|
|
|
import cn.reghao.autodop.common.deploy.PackerType;
|
|
|
import cn.reghao.autodop.dmaster.app.entity.constant.RepoType;
|
|
|
import cn.reghao.autodop.dmaster.app.entity.deploy.AppDeploy;
|
|
|
import cn.reghao.autodop.dmaster.app.entity.log.BuildDeployLog;
|
|
|
import cn.reghao.autodop.dmaster.app.entity.log.BuildLog;
|
|
|
+import cn.reghao.autodop.dmaster.app.entity.log.DeployLog;
|
|
|
import cn.reghao.autodop.dmaster.app.entity.orchestration.AppOrchestration;
|
|
|
import cn.reghao.autodop.dmaster.app.entity.orchestration.ProjOrchestration;
|
|
|
import cn.reghao.autodop.dmaster.app.service.deploy.AppDeployer;
|
|
|
@@ -23,6 +24,9 @@ import cn.reghao.autodop.dmaster.app.service.tools.updater.SvnImpl;
|
|
|
import cn.reghao.autodop.dmaster.common.config.SysConfig;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
/**
|
|
|
* 应用构建部署,根据 AppOrchestration 的值完成应用构建和部署的配置
|
|
|
*
|
|
|
@@ -39,6 +43,8 @@ public class AppIntegrate {
|
|
|
private ProjOrchestration proj;
|
|
|
// 远程仓库最近一次提交的信息
|
|
|
private CommitLog lastCommitLog;
|
|
|
+ private BuildLog buildLog;
|
|
|
+ private List<DeployLog> deployLogs;
|
|
|
private BuildDeployLog buildDeployLog;
|
|
|
|
|
|
private CodeUpdater codeUpdater;
|
|
|
@@ -68,7 +74,7 @@ public class AppIntegrate {
|
|
|
|
|
|
private void init() {
|
|
|
initLocalDir();
|
|
|
- initBuildDeployLog();
|
|
|
+ initBuildLog();
|
|
|
initBuildDeployConfig();
|
|
|
}
|
|
|
|
|
|
@@ -78,9 +84,9 @@ public class AppIntegrate {
|
|
|
appPackDir = SysConfig.packDir + "/" + app.getAppId();
|
|
|
}
|
|
|
|
|
|
- private void initBuildDeployLog() {
|
|
|
- buildDeployLog = new BuildDeployLog();
|
|
|
- buildDeployLog.setApp(app);
|
|
|
+ private void initBuildLog() {
|
|
|
+ buildLog = new BuildLog();
|
|
|
+ buildLog.setApp(app);
|
|
|
}
|
|
|
|
|
|
private void initBuildDeployConfig() {
|
|
|
@@ -118,11 +124,11 @@ public class AppIntegrate {
|
|
|
}
|
|
|
|
|
|
// TODO 特定于 dnkt-mgr 项目的处理
|
|
|
- if ("dnkt-mgr".equals(app.getAppId())) {
|
|
|
+ if (app.getAppId().startsWith("dnkt-mgr")) {
|
|
|
codePacker = new DntkMgrDockerPack(appPack.getPackerPath(), app.getEnv());
|
|
|
}
|
|
|
|
|
|
- // 初始化部署配置
|
|
|
+ // TODO 初始化部署配置
|
|
|
AppDeploy appDeploy = app.getAppDeploy();
|
|
|
}
|
|
|
|
|
|
@@ -139,17 +145,6 @@ public class AppIntegrate {
|
|
|
preCompile.preCompile(app, appEntryDir);
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 构建部署日志
|
|
|
- *
|
|
|
- * @param
|
|
|
- * @return
|
|
|
- * @date 2020-05-15 上午11:31
|
|
|
- */
|
|
|
- public BuildDeployLog log() {
|
|
|
- return this.buildDeployLog;
|
|
|
- }
|
|
|
-
|
|
|
public boolean update() {
|
|
|
try {
|
|
|
if (lastCommitLog == null) {
|
|
|
@@ -163,28 +158,33 @@ public class AppIntegrate {
|
|
|
updateStatus = updateApp();
|
|
|
}
|
|
|
lastCommitLog = updateStatus.getLastCommitLog();
|
|
|
- BuildLog buildLog = new BuildLog();
|
|
|
buildLog.setCommitLog(lastCommitLog);
|
|
|
- buildDeployLog.setBuildLog(buildLog);
|
|
|
|
|
|
if (updateStatus.isUpdated()) {
|
|
|
BuilderUtil.copyToCompileDir(appLocalRepo, app);
|
|
|
return true;
|
|
|
} else {
|
|
|
- buildDeployLog.getBuildLog().setStage(AppStage.update.name());
|
|
|
- buildDeployLog.getBuildLog().setCode(0);
|
|
|
- buildDeployLog.getBuildLog().setMsg("应用代码未更新");
|
|
|
+ buildLog.setStage(BuildDeployStage.update.name());
|
|
|
+ buildLog.setCode(0);
|
|
|
+ buildLog.setMsg("应用代码未更新");
|
|
|
return false;
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
- buildDeployLog.getBuildLog().setStage(AppStage.update.name());
|
|
|
- buildDeployLog.getBuildLog().setCode(1);
|
|
|
- buildDeployLog.getBuildLog().setMsg(e.getMessage());
|
|
|
+ buildLog.setStage(BuildDeployStage.update.name());
|
|
|
+ buildLog.setCode(1);
|
|
|
+ buildLog.setMsg(e.getMessage());
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * TODO 拉取应用所在项目的所有代码,后期应该优化
|
|
|
+ *
|
|
|
+ * @param
|
|
|
+ * @return
|
|
|
+ * @date 2020-05-28 下午3:28
|
|
|
+ */
|
|
|
private AppUpdateStatus updateProj() throws Exception {
|
|
|
String remoteRepo = proj.getProjRepo();
|
|
|
codeUpdater.update(remoteRepo, appLocalRepo);
|
|
|
@@ -229,9 +229,9 @@ public class AppIntegrate {
|
|
|
return true;
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
- buildDeployLog.getBuildLog().setStage(AppStage.compile.name());
|
|
|
- buildDeployLog.getBuildLog().setCode(1);
|
|
|
- buildDeployLog.getBuildLog().setMsg(e.getMessage());
|
|
|
+ buildLog.setStage(BuildDeployStage.compile.name());
|
|
|
+ buildLog.setCode(1);
|
|
|
+ buildLog.setMsg(e.getMessage());
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
@@ -240,27 +240,32 @@ public class AppIntegrate {
|
|
|
try {
|
|
|
String appPath = codePacker.pack(app.getAppId(), lastCommitLog.getCommitId(),
|
|
|
appCompileDir + app.getEntryDir());
|
|
|
- buildDeployLog.getBuildLog().setAppPath(appPath);
|
|
|
+ buildLog.setAppPath(appPath);
|
|
|
+ buildLog.setBuildTime(new Date());
|
|
|
return true;
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
- buildDeployLog.getBuildLog().setStage(AppStage.pack.name());
|
|
|
- buildDeployLog.getBuildLog().setCode(1);
|
|
|
- buildDeployLog.getBuildLog().setMsg(e.getMessage());
|
|
|
+ buildLog.setStage(BuildDeployStage.pack.name());
|
|
|
+ buildLog.setCode(1);
|
|
|
+ // TODO 提取错误信息
|
|
|
+ buildLog.setMsg(e.getMessage());
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public boolean deploy() {
|
|
|
- try {
|
|
|
- AppDeployer.deploy(app, buildDeployLog);
|
|
|
- return true;
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- buildDeployLog.getBuildLog().setStage(AppStage.deploy.name());
|
|
|
- buildDeployLog.getBuildLog().setCode(1);
|
|
|
- buildDeployLog.getBuildLog().setMsg(e.getMessage());
|
|
|
- return false;
|
|
|
- }
|
|
|
+ public void deploy() {
|
|
|
+ deployLogs = AppDeployer.deploy(app, buildLog);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 构建部署日志
|
|
|
+ *
|
|
|
+ * @param
|
|
|
+ * @return
|
|
|
+ * @date 2020-05-15 上午11:31
|
|
|
+ */
|
|
|
+ public BuildDeployLog log() {
|
|
|
+ buildDeployLog = new BuildDeployLog(buildLog, deployLogs);
|
|
|
+ return buildDeployLog;
|
|
|
}
|
|
|
}
|