Просмотр исходного кода

web 模块在配置文件中指定一个 baseDir 作为存储数据的根目录

reghao 1 год назад
Родитель
Сommit
68aea311b8

+ 0 - 17
web/src/main/java/cn/reghao/bnt/web/WebApplication.java

@@ -1,12 +1,8 @@
 package cn.reghao.bnt.web;
 package cn.reghao.bnt.web;
 
 
-import cn.reghao.bnt.web.config.AppProperties;
-import cn.reghao.bnt.web.parser.util.FileCache;
-import cn.reghao.oss.sdk.model.OssConsoleConfig;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
 import org.springframework.boot.autoconfigure.domain.EntityScan;
 import org.springframework.boot.autoconfigure.domain.EntityScan;
-import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.ComponentScan;
 import org.springframework.context.annotation.ComponentScan;
 import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
 import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
 
 
@@ -18,17 +14,4 @@ public class WebApplication {
 	public static void main(String[] args) {
 	public static void main(String[] args) {
 		SpringApplication.run(WebApplication.class, args);
 		SpringApplication.run(WebApplication.class, args);
 	}
 	}
-
-	@Bean
-	public FileCache fileCache(AppProperties appProperties) {
-		return new FileCache(appProperties.getCacheDir());
-	}
-
-	@Bean
-	public OssConsoleConfig ossConsoleConfig() {
-		String endpoint = System.getenv("CONSOLE_ENDPOINT");
-		String accessKeyId = System.getenv("CONSOLE_ACCESS_KEY_ID");
-		String accessKeySecret = System.getenv("CONSOLE_ACCESS_KEY_SECRET");
-		return new OssConsoleConfig(endpoint, accessKeyId, accessKeySecret);
-	}
 }
 }

+ 1 - 0
web/src/main/java/cn/reghao/bnt/web/config/AppProperties.java

@@ -17,4 +17,5 @@ public class AppProperties {
     private String ossEndpoint;
     private String ossEndpoint;
     private String cookiePath;
     private String cookiePath;
     private String cacheDir;
     private String cacheDir;
+    private String baseDir;
 }
 }

+ 5 - 2
web/src/main/java/cn/reghao/bnt/web/config/spring/AppLifecycle.java

@@ -3,6 +3,7 @@ package cn.reghao.bnt.web.config.spring;
 import cn.reghao.bnt.web.account.service.AccountService;
 import cn.reghao.bnt.web.account.service.AccountService;
 import cn.reghao.bnt.web.account.service.FileService;
 import cn.reghao.bnt.web.account.service.FileService;
 import cn.reghao.bnt.web.account.service.RoleService;
 import cn.reghao.bnt.web.account.service.RoleService;
+import cn.reghao.bnt.web.config.AppProperties;
 import cn.reghao.bnt.web.devops.app.db.repository.config.build.CompilerConfigRepository;
 import cn.reghao.bnt.web.devops.app.db.repository.config.build.CompilerConfigRepository;
 import cn.reghao.bnt.web.devops.app.model.po.config.build.CompilerConfig;
 import cn.reghao.bnt.web.devops.app.model.po.config.build.CompilerConfig;
 import cn.reghao.bnt.web.devops.app.service.bd.BuildStat;
 import cn.reghao.bnt.web.devops.app.service.bd.BuildStat;
@@ -40,11 +41,12 @@ public class AppLifecycle implements ApplicationRunner, DisposableBean {
     private final AccountService accountService;
     private final AccountService accountService;
     private final SysMessageRepository sysMessageRepository;
     private final SysMessageRepository sysMessageRepository;
     private BuildStat buildStat;
     private BuildStat buildStat;
+    private AppProperties appProperties;
 
 
     public AppLifecycle(BuildDirService buildDirService, MachineService machineService, LogHandler logHandler,
     public AppLifecycle(BuildDirService buildDirService, MachineService machineService, LogHandler logHandler,
                         CompilerConfigRepository compilerConfigRepository, FileService fileService,
                         CompilerConfigRepository compilerConfigRepository, FileService fileService,
                         RoleService roleService, AccountService accountService, SysMessageRepository sysMessageRepository,
                         RoleService roleService, AccountService accountService, SysMessageRepository sysMessageRepository,
-                        BuildStat buildStat) {
+                        BuildStat buildStat, AppProperties appProperties) {
         this.buildDirService = buildDirService;
         this.buildDirService = buildDirService;
         this.machineService = machineService;
         this.machineService = machineService;
         this.logHandler = logHandler;
         this.logHandler = logHandler;
@@ -54,6 +56,7 @@ public class AppLifecycle implements ApplicationRunner, DisposableBean {
         this.accountService = accountService;
         this.accountService = accountService;
         this.sysMessageRepository = sysMessageRepository;
         this.sysMessageRepository = sysMessageRepository;
         this.buildStat = buildStat;
         this.buildStat = buildStat;
+        this.appProperties = appProperties;
     }
     }
 
 
     @Override
     @Override
@@ -100,7 +103,7 @@ public class AppLifecycle implements ApplicationRunner, DisposableBean {
     @Deprecated
     @Deprecated
     private void initBuildDir() {
     private void initBuildDir() {
         String userDir = System.getProperty("user.dir");
         String userDir = System.getProperty("user.dir");
-        String baseDir = String.format("%s/bnt_data", userDir);
+        String baseDir = appProperties.getBaseDir();
         File dir = new File(baseDir);
         File dir = new File(baseDir);
         if (!dir.exists() && !dir.mkdirs()) {
         if (!dir.exists() && !dir.mkdirs()) {
             log.error("创建本地构建目录 {} 失败,bnt-web 结束运行", baseDir);
             log.error("创建本地构建目录 {} 失败,bnt-web 结束运行", baseDir);

+ 16 - 0
web/src/main/java/cn/reghao/bnt/web/config/spring/BeansConfig.java

@@ -1,9 +1,12 @@
 package cn.reghao.bnt.web.config.spring;
 package cn.reghao.bnt.web.config.spring;
 
 
+import cn.reghao.bnt.web.config.AppProperties;
+import cn.reghao.bnt.web.parser.util.FileCache;
 import cn.reghao.jutil.jdk.converter.ByteConverter;
 import cn.reghao.jutil.jdk.converter.ByteConverter;
 import cn.reghao.jutil.jdk.http.WebClient;
 import cn.reghao.jutil.jdk.http.WebClient;
 import cn.reghao.jutil.jdk.http.WebRequest;
 import cn.reghao.jutil.jdk.http.WebRequest;
 import cn.reghao.jutil.tool.http.DefaultWebRequest;
 import cn.reghao.jutil.tool.http.DefaultWebRequest;
+import cn.reghao.oss.sdk.model.OssConsoleConfig;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
 import org.springframework.context.annotation.Configuration;
 import oshi.SystemInfo;
 import oshi.SystemInfo;
@@ -29,4 +32,17 @@ public class BeansConfig {
     public ByteConverter byteConverter() {
     public ByteConverter byteConverter() {
         return new ByteConverter();
         return new ByteConverter();
     }
     }
+
+    @Bean
+    public FileCache fileCache(AppProperties appProperties) {
+        return new FileCache(appProperties.getCacheDir());
+    }
+
+    @Bean
+    public OssConsoleConfig ossConsoleConfig() {
+        String endpoint = System.getenv("CONSOLE_ENDPOINT");
+        String accessKeyId = System.getenv("CONSOLE_ACCESS_KEY_ID");
+        String accessKeySecret = System.getenv("CONSOLE_ACCESS_KEY_SECRET");
+        return new OssConsoleConfig(endpoint, accessKeyId, accessKeySecret);
+    }
 }
 }

+ 2 - 1
web/src/main/resources/application.yml

@@ -57,4 +57,5 @@ spring:
 app:
 app:
   ossEndpoint: https://oss.reghao.cn
   ossEndpoint: https://oss.reghao.cn
   cookiePath: /home/reghao/Downloads/cookie.txt
   cookiePath: /home/reghao/Downloads/cookie.txt
-  cacheDir: /home/reghao/mnt
+  cacheDir: /home/reghao/mnt
+  baseDir: /opt/data/bntdata