|
|
@@ -1,20 +1,21 @@
|
|
|
package cn.reghao.autodop.dmaster.app.service.build;
|
|
|
|
|
|
-import cn.reghao.autodop.common.utils.text.TextFile;
|
|
|
import cn.reghao.autodop.dmaster.app.entity.build.AppBuild;
|
|
|
-import cn.reghao.autodop.dmaster.app.entity.build.AppCompile;
|
|
|
-import cn.reghao.autodop.dmaster.app.entity.build.AppPack;
|
|
|
-import cn.reghao.autodop.dmaster.app.entity.build.AppUpdate;
|
|
|
-import cn.reghao.autodop.dmaster.app.constant.CompilerType;
|
|
|
-import cn.reghao.autodop.common.dagent.app.api.data.deploy.PackerType;
|
|
|
-import cn.reghao.autodop.dmaster.app.constant.RepoType;
|
|
|
+import cn.reghao.autodop.dmaster.app.entity.build.tools.CompilerConfig;
|
|
|
+import cn.reghao.autodop.dmaster.app.entity.build.tools.PackerConfig;
|
|
|
+import cn.reghao.autodop.dmaster.app.entity.build.tools.RepoConfig;
|
|
|
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.build.tools.compiler.CodeCompiler;
|
|
|
+import cn.reghao.autodop.dmaster.app.service.build.tools.compiler.MavenCompiler;
|
|
|
+import cn.reghao.autodop.dmaster.app.service.build.tools.compiler.NullCompiler;
|
|
|
+import cn.reghao.autodop.dmaster.app.service.build.tools.compiler.ShellCompiler;
|
|
|
+import cn.reghao.autodop.dmaster.app.service.build.tools.packer.CodePacker;
|
|
|
+import cn.reghao.autodop.dmaster.app.service.build.tools.packer.DockerPack;
|
|
|
+import cn.reghao.autodop.dmaster.app.service.build.tools.packer.ZipPack;
|
|
|
import cn.reghao.autodop.dmaster.app.service.deploy.AppDeployer;
|
|
|
-import cn.reghao.autodop.dmaster.app.service.build.tools.compiler.*;
|
|
|
-import cn.reghao.autodop.dmaster.app.service.build.tools.packer.*;
|
|
|
import cn.reghao.autodop.dmaster.app.service.build.tools.updater.CodeUpdater;
|
|
|
import cn.reghao.autodop.dmaster.app.service.build.tools.updater.CommitLog;
|
|
|
import cn.reghao.autodop.dmaster.app.service.build.tools.updater.GitImpl;
|
|
|
@@ -25,14 +26,13 @@ import lombok.AllArgsConstructor;
|
|
|
import lombok.Data;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
|
-import java.io.File;
|
|
|
import java.io.IOException;
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.util.List;
|
|
|
import java.util.Set;
|
|
|
|
|
|
/**
|
|
|
- * 应用构建部署
|
|
|
+ * 应用构建部署,每个应用持有一个对象
|
|
|
*
|
|
|
* @author reghao
|
|
|
* @date 2019-10-09 10:54:43
|
|
|
@@ -62,6 +62,10 @@ public class AppIntegrate {
|
|
|
return this.app;
|
|
|
}
|
|
|
|
|
|
+ public String appId() {
|
|
|
+ return app.getAppId();
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* TODO 若 AppOrchestration 发生变化则重新初始化
|
|
|
*
|
|
|
@@ -75,7 +79,8 @@ public class AppIntegrate {
|
|
|
|
|
|
private void init() {
|
|
|
initLocalDir();
|
|
|
- initBuildDeployConfig();
|
|
|
+ initBuildConfig();
|
|
|
+ initDeployConfig();
|
|
|
}
|
|
|
|
|
|
private void initLocalDir() {
|
|
|
@@ -84,7 +89,14 @@ public class AppIntegrate {
|
|
|
appPackDir = SysConfig.packDir + "/" + app.getAppId();
|
|
|
}
|
|
|
|
|
|
- private void initBuildDeployConfig() {
|
|
|
+ /**
|
|
|
+ * 初始化应用构建配置
|
|
|
+ *
|
|
|
+ * @param
|
|
|
+ * @return
|
|
|
+ * @date 2021-02-05 下午11:01
|
|
|
+ */
|
|
|
+ private void initBuildConfig() {
|
|
|
AppBuild appBuild;
|
|
|
ProjOrchestration proj = app.getProj();
|
|
|
if (proj != null) {
|
|
|
@@ -95,54 +107,64 @@ public class AppIntegrate {
|
|
|
}
|
|
|
|
|
|
// 初始化更新配置
|
|
|
- AppUpdate appUpdate = appBuild.getAppUpdate();
|
|
|
- if (appUpdate.getRepoType().equals(RepoType.svn.name())) {
|
|
|
- codeUpdater = new SvnImpl(appUpdate.getUsername(), appUpdate.getPassword());
|
|
|
- } else if (appUpdate.getRepoType().equals(RepoType.git.name())) {
|
|
|
- if ("rsa".equals(appUpdate.getAuthType())) {
|
|
|
- File tmp = new File(System.getProperty("java.io.tmpdir") + "/rsa_prikey");
|
|
|
- try {
|
|
|
- TextFile.write(tmp, appUpdate.getRsaPrikey());
|
|
|
- } catch (IOException e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- codeUpdater = new GitImpl(tmp.getAbsolutePath());
|
|
|
- } else if ("password".equals(appUpdate.getAuthType())) {
|
|
|
- codeUpdater = new GitImpl(appUpdate.getUsername(), appUpdate.getPassword());
|
|
|
- }
|
|
|
+ RepoConfig repoConfig = appBuild.getRepoConfig();
|
|
|
+ switch (repoConfig.getType()) {
|
|
|
+ case git:
|
|
|
+ codeUpdater = new GitImpl(repoConfig);
|
|
|
+ break;
|
|
|
+ case svn:
|
|
|
+ codeUpdater = new SvnImpl(repoConfig);
|
|
|
+ break;
|
|
|
+ default:
|
|
|
}
|
|
|
|
|
|
// 初始化编译配置
|
|
|
- AppCompile appCompile = appBuild.getAppCompile();
|
|
|
- if (appCompile.getCompilerType().equals(CompilerType.shell.name())) {
|
|
|
- codeCompiler = new ShellCompiler(appCompile);
|
|
|
- } else if (appCompile.getCompilerType().equals(CompilerType.maven.name())) {
|
|
|
- codeCompiler = new MavenCompiler("");
|
|
|
- } else if (appCompile.getCompilerType().equals(CompilerType.none.name())) {
|
|
|
- // 静态应用,不需要编译器
|
|
|
- codeCompiler = new NullCompiler();
|
|
|
+ CompilerConfig compilerConfig = appBuild.getCompilerConfig();
|
|
|
+ switch (compilerConfig.getType()) {
|
|
|
+ case shell:
|
|
|
+ codeCompiler = new ShellCompiler(compilerConfig);
|
|
|
+ break;
|
|
|
+ case dotnet:
|
|
|
+ break;
|
|
|
+ case maven:
|
|
|
+ codeCompiler = new MavenCompiler(compilerConfig);
|
|
|
+ break;
|
|
|
+ case npm:
|
|
|
+ break;
|
|
|
+ case none:
|
|
|
+ codeCompiler = new NullCompiler();
|
|
|
+ break;
|
|
|
+ default:
|
|
|
}
|
|
|
|
|
|
// 初始化打包配置
|
|
|
- AppPack appPack = appBuild.getAppPack();
|
|
|
- if (appPack.getPackerType().equals(PackerType.docker.name())) {
|
|
|
- codePacker = new DockerPack(appPack.getLocation());
|
|
|
- } else if (appPack.getPackerType().equals(PackerType.zip.name())) {
|
|
|
- codePacker = new ZipPack(appPackDir);
|
|
|
+ PackerConfig packerConfig = appBuild.getPackerConfig();
|
|
|
+ switch (packerConfig.getType()) {
|
|
|
+ case docker:
|
|
|
+ codePacker = new DockerPack(packerConfig);
|
|
|
+ break;
|
|
|
+ case zip:
|
|
|
+ codePacker = new ZipPack(packerConfig);
|
|
|
+ break;
|
|
|
+ default:
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private void initDeployConfig() {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
/* 构建:更新 -> 编译 -> 打包 */
|
|
|
// TODO 处理集群部署时,不同节点使用不同配置文件的问题
|
|
|
public BuildLog build() {
|
|
|
BuildLog buildLog = new BuildLog();
|
|
|
- buildLog.setAppId(app.getAppId());
|
|
|
+ /*buildLog.setAppId(app.getAppId());
|
|
|
buildLog.setAppType(app.getAppType());
|
|
|
buildLog.setEnv(app.getEnv());
|
|
|
buildLog.setAppCompile(app.getAppBuild().getAppCompile());
|
|
|
- buildLog.setAppPack(app.getAppBuild().getAppPack());
|
|
|
+ buildLog.setAppPack(app.getAppBuild().getAppPack());*/
|
|
|
|
|
|
- boolean isUpdate;
|
|
|
+ /*boolean isUpdate;
|
|
|
try {
|
|
|
long start = System.currentTimeMillis();
|
|
|
isUpdate = update(buildLog);
|
|
|
@@ -185,18 +207,11 @@ public class AppIntegrate {
|
|
|
|
|
|
buildLog.setMsg("构建成功");
|
|
|
buildLog.setStatusCode(0);
|
|
|
- buildLog.setBuildTime(LocalDateTime.now());
|
|
|
+ buildLog.setBuildTime(LocalDateTime.now());*/
|
|
|
return buildLog;
|
|
|
}
|
|
|
|
|
|
- private void buildException(BuildLog buildLog, Exception e) {
|
|
|
- buildLog.setStatusCode(1);
|
|
|
- buildLog.setMsg("构建失败");
|
|
|
- buildLog.setErrDetail(ExceptionUtil.errorMsg(e));
|
|
|
- buildLog.setBuildTime(LocalDateTime.now());
|
|
|
- }
|
|
|
-
|
|
|
- private boolean update(BuildLog buildLog) throws Exception {
|
|
|
+ public CommitLog update() throws Exception {
|
|
|
String remote;
|
|
|
String branch;
|
|
|
String local = SysConfig.localRepo + "/" + app.getAppId();
|
|
|
@@ -217,18 +232,17 @@ public class AppIntegrate {
|
|
|
// TODO 代码版本未更改的情况下,是否应该构建
|
|
|
if (updateStatus.isUpdated || app.isAlwaysBuild()) {
|
|
|
lastCommitLog = updateStatus.getLastCommitLog();
|
|
|
- buildLog.setCommitLog(lastCommitLog);
|
|
|
+ //buildLog.setCommitLog(lastCommitLog);
|
|
|
BuilderUtil.copyToCompileDir(local, app);
|
|
|
- return true;
|
|
|
- } else {
|
|
|
- return false;
|
|
|
}
|
|
|
+
|
|
|
+ return null;
|
|
|
}
|
|
|
|
|
|
private UpdateStatus update0(String remote, String branch, String local) throws Exception {
|
|
|
CommitLog current = codeUpdater.update(remote, branch, local);
|
|
|
current.setAppId(app.getAppId());
|
|
|
- current.setEnv(app.getEnv());
|
|
|
+ //current.setEnv(app.getEnv());
|
|
|
if (lastCommitLog != null) {
|
|
|
if (lastCommitLog.getCommitId().equals(current.getCommitId())) {
|
|
|
return new UpdateStatus(current, false);
|
|
|
@@ -241,15 +255,16 @@ public class AppIntegrate {
|
|
|
return new UpdateStatus(current, true);
|
|
|
}
|
|
|
|
|
|
- private void compile() throws Exception {
|
|
|
+ public void compile() throws Exception {
|
|
|
// TODO 通过脚本调用编译器时会卡住
|
|
|
- codeCompiler.compile(app.getDirname(), appCompileDir + app.getCompileDir(), app.getEnv());
|
|
|
+ codeCompiler.compile(app.getDirname(), appCompileDir + app.getCompileDir());
|
|
|
}
|
|
|
|
|
|
- private void pack(BuildLog buildLog) throws Exception {
|
|
|
+ public String pack() throws Exception {
|
|
|
String appEntryDir = appCompileDir + app.getCompileDir();
|
|
|
String appPath = codePacker.pack(app.getAppId(), lastCommitLog.getCommitId(), appEntryDir);
|
|
|
- buildLog.setAppPath(appPath);
|
|
|
+ return appPath;
|
|
|
+ //buildLog.setAppPath(appPath);
|
|
|
}
|
|
|
|
|
|
/* 部署 */
|