Skip to content

Commit 5ec41ae

Browse files
author
cgw
committed
重构app目录
1 parent a0371c9 commit 5ec41ae

File tree

3 files changed

+14
-38
lines changed

3 files changed

+14
-38
lines changed

dhorse-application/src/main/java/org/dhorse/application/service/DeploymentApplicationService.java

Lines changed: 4 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -801,21 +801,16 @@ private void buildNodejsImage(DeploymentContext context) {
801801
if(!TechTypeEnum.NODEJS.getCode().equals(context.getApp().getTechType())) {
802802
return;
803803
}
804-
File branchFile = new File(context.getLocalPathOfBranch());
805-
File targetFile = new File(branchFile.getParent() + "/" + context.getApp().getAppName());
806-
rename(branchFile, targetFile);
804+
File targetFile = new File(context.getLocalPathOfBranch());
807805
doBuildImage(context, context.getApp().getBaseImage(), null, Arrays.asList(targetFile.toPath()));
808806
}
809807

810808
private void buildNuxtImage(DeploymentContext context) {
811809
if(!TechTypeEnum.NUXT.getCode().equals(context.getApp().getTechType())) {
812810
return;
813811
}
814-
815812
AppExtendNuxt appExted = context.getApp().getAppExtend();
816-
File branchFile = new File(context.getLocalPathOfBranch());
817-
File targetFile = new File(branchFile.getParent() + "/" + context.getApp().getAppName());
818-
rename(branchFile, targetFile);
813+
File targetFile = new File(context.getLocalPathOfBranch());
819814
String baseImage = Constants.NODE_IMAGE_BASE_URL + appExted.getNodeVersion().substring(1);
820815
doBuildImage(context, baseImage, null, Arrays.asList(targetFile.toPath()));
821816
}
@@ -824,9 +819,7 @@ private void buildHtmlImage(DeploymentContext context) {
824819
if(!TechTypeEnum.HTML.getCode().equals(context.getApp().getTechType())) {
825820
return;
826821
}
827-
File branchFile = new File(context.getLocalPathOfBranch());
828-
File targetFile = new File(branchFile.getParent() + "/" + context.getApp().getAppName());
829-
rename(branchFile, targetFile);
822+
File targetFile = new File(context.getLocalPathOfBranch());
830823
doBuildImage(context, context.getApp().getBaseImage(), null, Arrays.asList(targetFile.toPath()));
831824
}
832825

@@ -868,34 +861,12 @@ private void buildDjangoImage(DeploymentContext context) {
868861

869862
private void buildPythonImage(DeploymentContext context, List<String> entrypoint) {
870863
App app = context.getApp();
871-
File branchFile = new File(context.getLocalPathOfBranch());
872-
File targetFile = new File(branchFile.getParent() + "/" + app.getAppName());
873-
rename(branchFile, targetFile);
864+
File targetFile = new File(context.getLocalPathOfBranch());
874865
String version = ((AppExtendPython)app.getAppExtend()).getPythonVersion();
875866
String baseImage = Constants.PYTHON_IMAGE_BASE_URL + version.substring(1);
876867
doBuildImage(context, baseImage, entrypoint, Arrays.asList(targetFile.toPath()));
877868
}
878869

879-
private boolean rename(File source, File target) {
880-
boolean success = false;
881-
//如果30秒还没成功,则报错
882-
for(int i = 0; i < 300; i++) {
883-
if(source.renameTo(target)) {
884-
success = true;
885-
break;
886-
}
887-
try {
888-
Thread.sleep(100);
889-
} catch (InterruptedException e) {
890-
//ignore
891-
}
892-
}
893-
if(!success) {
894-
LogUtils.throwException(logger, MessageCodeEnum.RENAME_FILE_FAILURE);
895-
}
896-
return success;
897-
}
898-
899870
private void doBuildImage(DeploymentContext context, String baseImageName, List<String> entrypoint, List<Path> targetFiles) {
900871
ImageRepo imageRepo = context.getGlobalConfigAgg().getImageRepo();
901872
String imageUrl = imageRepo.getUrl();

dhorse-infrastructure/src/main/java/org/dhorse/infrastructure/strategy/repo/CodeRepoStrategy.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import java.io.IOException;
55
import java.util.List;
66

7+
import org.dhorse.api.enums.MessageCodeEnum;
78
import org.dhorse.api.response.PageData;
89
import org.dhorse.api.response.model.AppBranch;
910
import org.dhorse.api.response.model.AppTag;
@@ -13,17 +14,19 @@
1314
import org.dhorse.infrastructure.utils.DeploymentContext;
1415
import org.dhorse.infrastructure.utils.FileUtils;
1516
import org.dhorse.infrastructure.utils.K8sUtils;
17+
import org.dhorse.infrastructure.utils.LogUtils;
1618
import org.slf4j.Logger;
1719
import org.slf4j.LoggerFactory;
1820

1921
public abstract class CodeRepoStrategy {
2022

2123
public static final Logger logger = LoggerFactory.getLogger(CodeRepoStrategy.class);
2224

23-
public void clearHistoryBranch(DeploymentContext context) {
25+
void clearLocalHistoryCode(DeploymentContext context) {
26+
String localPathOfBranch = localPathOfBranch(context);
2427
File[] hisBranchs = new File(localPathOfBranch(context)).listFiles();
2528
for(File h : hisBranchs) {
26-
//为了提高Node类应用install过程的性能,不删除安装文件
29+
//为了提高Node类应用install过程的性能,不删除node_modules文件
2730
if("node_modules".equals(h.getName())) {
2831
continue;
2932
}
@@ -34,14 +37,16 @@ public void clearHistoryBranch(DeploymentContext context) {
3437
h.delete();
3538
}
3639
} catch (IOException e) {
37-
logger.error("Failed to clear local history branch", e);
40+
logger.error("Failed to clear local history code, please delete it"
41+
+ " manually, path is: " + localPathOfBranch, e);
42+
LogUtils.throwException(logger, MessageCodeEnum.DELETE_FAILURE);
3843
}
3944
}
4045
}
4146

4247
public boolean downloadBranch(DeploymentContext context) {
4348
checkLocalPathOfBranch(context);
44-
clearHistoryBranch(context);
49+
clearLocalHistoryCode(context);
4550
return doDownloadBranch(context);
4651
}
4752

dhorse-rest/src/main/resources/dhorse.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
#====================================================================================================
3636
#如果启用,则优先使用Mysql
3737
#mysql.enable: true
38-
#需要手动创建dhorse库,DHorse在启动时会自动创建表
38+
#需要手动创建dhorse库,dhorse在启动时会自动创建表
3939
#mysql.url: jdbc:mysql://localhost:3306/dhorse?useUnicode=true&characterEncoding=UTF-8&rewriteBatchedStatements=true&allowMultiQueries=true
4040
#该账号需要具有建表权限
4141
#mysql.user: username

0 commit comments

Comments
 (0)