extract start module (#59)

This commit is contained in:
TheoneFx
2023-03-20 13:38:34 +08:00
committed by GitHub
parent 11ad90c33c
commit 033ab83006
12 changed files with 78 additions and 86 deletions

53
initializer-start/pom.xml Normal file
View File

@@ -0,0 +1,53 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<parent>
<groupId>com.alibaba</groupId>
<artifactId>cloud-native-app-initializer</artifactId>
<version>${revision}</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>initializer-start</artifactId>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>initializer-generator</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>initializer-page</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.3.7.RELEASE</version>
<configuration>
<mainClass>com.alibaba.initializer.start.Application</mainClass>
<attach>true</attach>
<classifier>fatjar</classifier>
</configuration>
<executions>
<execution>
<id>repackage</id>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@@ -0,0 +1,54 @@
/*
* Copyright 2022-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.initializer.start;
import com.alibaba.initializer.configure.BootstrapProjectGenerationConfigure;
import com.alibaba.initializer.configure.InitializerMetadataConfigure;
import com.alibaba.initializer.start.web.WebConfig;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.context.annotation.Import;
import org.springframework.scheduling.annotation.EnableAsync;
/**
* @author <a href="mailto:chenxilzx1@gmail.com">theonefx</a>
*/
@SpringBootConfiguration
@EnableAutoConfiguration
@EnableCaching
@EnableAsync
@EnableAspectJAutoProxy(proxyTargetClass = true)
@Configuration
@ComponentScan("com.alibaba.initializer.protocol")
@Import({
InitializerMetadataConfigure.class,
BootstrapProjectGenerationConfigure.class,
WebConfig.class,
})
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}

View File

@@ -0,0 +1,37 @@
/*
* Copyright 2022-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.initializer.start.web;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.ResourceLoader;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
public class CommonPages {
@Autowired
private ResourceLoader resourceLoader;
@GetMapping({"/checkpreload.htm", "nginx_status"})
@ResponseBody
public String checkPreload() {
return "success";
}
}

View File

@@ -0,0 +1,67 @@
/*
* Copyright 2022-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.initializer.start.web;
import java.util.HashSet;
import java.util.Set;
import org.springframework.boot.web.server.ErrorPage;
import org.springframework.boot.web.server.ErrorPageRegistrar;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpStatus;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
/**
* @author <a href="mailto:chenxilzx1@gmail.com">theonefx</a>
*/
@ComponentScan
@Configuration
public class WebConfig implements WebMvcConfigurer {
static private final Set<String> ALLOWED_ORIGIN_HTTP = new HashSet<>();
static {
ALLOWED_ORIGIN_HTTP.add("https://start.aliyun.com");
ALLOWED_ORIGIN_HTTP.add("https://pre-start.aliyun.com");
}
@Bean
public ErrorPageRegistrar errorPageRegistrar() {
return (registry) -> {
registry.addErrorPages(new ErrorPage(HttpStatus.NOT_FOUND, "/404.html"));
registry.addErrorPages(new ErrorPage("/error/index.html"));
};
}
@Override
public void addCorsMappings(CorsRegistry registry) {
//添加映射路径
registry.addMapping("/**")
//放行哪些原始域
.allowedOrigins(ALLOWED_ORIGIN_HTTP.toArray(new String[0]))
//是否发送Cookie信息
.allowCredentials(true)
//放行哪些原始域(请求方式)
.allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS")
//放行哪些原始域(头部信息)
.allowedHeaders("*");
}
}

View File

@@ -0,0 +1,11 @@
application:
cache:
repo:
expTime:
local: 30
oss: 120
holder: 600
interval:
checkoss: 20
metadata-path: ${METADATA_PATH}
democode-path: ${DEMOCODE_PATH}

View File

@@ -0,0 +1,55 @@
server:
port: 7001
compression:
enabled: true
mime-types: application/json,text/css,text/html
min-response-size: 2048
error:
whitelabel:
enabled: false
forward-headers-strategy: native
management:
server:
port: 7002
endpoints:
web:
exposure:
include: "*"
spring:
application:
name: "initializr"
jackson:
serialization:
write-dates-as-timestamps: false
mustache:
check-template-location: false
resources:
static_locations:
- "classpath:/static/"
cache:
jcache:
config: classpath:ehcache.xml
security:
csrf:
enabled: true
url:
excluded: "/**/git-upload-pack,/**/info/refs"
logging:
level:
org.springframework.core.env: warn
org.springframework.jndi: warn
application:
metadata-path: classpath:metadata.yaml
democode-path: classpath:/templates/codes
cache:
repo:
expTime:
local: 30
oss: 120
holder: 300
interval:
checkoss: 30

View File

@@ -0,0 +1,11 @@
<config
xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
xmlns='http://www.ehcache.org/v3'
xsi:schemaLocation="http://www.ehcache.org/v3 http://www.ehcache.org/schema/ehcache-core-3.0.xsd">
<!--默认配置-->
<cache-template name="defaultCache">
<heap>100</heap>
</cache-template>
</config>

View File

@@ -0,0 +1,57 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<!-- https://github.com/spring-projects/spring-boot/blob/v1.5.13.RELEASE/spring-boot/src/main/resources/org/springframework/boot/logging/logback/defaults.xml -->
<include resource="org/springframework/boot/logging/logback/defaults.xml"/>
<property name="APP_NAME" value="initializer"/>
<property name="LOG_PATH" value="${user.home}/${APP_NAME}/logs"/>
<property name="APP_LOG_FILE" value="${LOG_PATH}/application.log"/>
<property name="COLLECT_LOG_FILE" value="${LOG_PATH}/collect.log"/>
<!-- appenders -->
<appender name="APPLICATION"
class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${APP_LOG_FILE}</file>
<encoder>
<pattern>${FILE_LOG_PATTERN}</pattern>
</encoder>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<fileNamePattern>${APP_LOG_FILE}.%d{yyyy-MM-dd}.%i.log</fileNamePattern>
<maxHistory>7</maxHistory>
<maxFileSize>50MB</maxFileSize>
<totalSizeCap>1GB</totalSizeCap>
</rollingPolicy>
</appender>
<appender name="ConfigCollecterAppender"
class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${COLLECT_LOG_FILE}</file>
<encoder>
<pattern>%msg%n</pattern>
</encoder>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<fileNamePattern>${COLLECT_LOG_FILE}.%d{yyyy-MM-dd}.%i.log</fileNamePattern>
<maxHistory>30</maxHistory>
<maxFileSize>50MB</maxFileSize>
<totalSizeCap>1GB</totalSizeCap>
</rollingPolicy>
</appender>
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%clr(%d{HH:mm:ss}) %clr(${LOG_LEVEL_PATTERN:-%5p}) %clr(--){faint} %clr([%25.25t]){faint} %clr(%-50.50logger{39}){cyan} %clr(:){faint} %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}</pattern>
<charset>utf8</charset>
</encoder>
</appender>
<!-- loggers -->
<logger name="ConfigCollecter" additivity="false">
<level value="INFO"/>
<appender-ref ref="ConfigCollecterAppender"/>
</logger>
<root level="INFO">
<appender-ref ref="CONSOLE"/>
<appender-ref ref="APPLICATION"/>
</root>
</configuration>