forked from TencentBlueKing/bk-ci
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: 指定模块统一打包插件 TencentBlueKing#8672
- Loading branch information
Showing
10 changed files
with
356 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* Tencent is pleased to support the open source community by making BK-CI 蓝鲸持续集成平台 available. | ||
* | ||
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. | ||
* | ||
* BK-CI 蓝鲸持续集成平台 is licensed under the MIT license. | ||
* | ||
* A copy of the MIT License is included in this file. | ||
* | ||
* | ||
* Terms of the MIT License: | ||
* --------------------------------------------------- | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated | ||
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation the | ||
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to | ||
* permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of | ||
* the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT | ||
* LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN | ||
* NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | ||
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE | ||
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
*/ | ||
import org.springframework.boot.gradle.tasks.bundling.BootJar | ||
import org.springframework.boot.gradle.tasks.run.BootRun | ||
|
||
dependencies { | ||
api(project(":core:common:common-web")) | ||
api(project(":core:common:common-db-base")) | ||
api("mysql:mysql-connector-java") | ||
implementation(kotlin("stdlib")) | ||
} | ||
plugins { | ||
`task-multi-boot-jar` | ||
} | ||
|
||
tasks.named<BootJar>("bootJar") { | ||
val finalModuleName = System.getProperty("devops.multi.to") | ||
archiveBaseName.set("boot-$finalModuleName") | ||
} | ||
|
||
tasks.named<BootRun>("bootRun") { | ||
println("bootRun classpath is :" + classpath.asPath.toString()) | ||
//classpath = files("C:\\Users\\bk-ci-2\\src\\backend\\ci\\core\\mutijar\\boot-mutijar\\build\\classes\\kotlin\\main") | ||
} |
64 changes: 64 additions & 0 deletions
64
.../boot-mutijar/src/main/kotlin/com/tencent/devops/mutijar/DataSourceDefinitionRegistrar.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package com.tencent.devops.mutijar | ||
|
||
import com.mysql.jdbc.Driver | ||
import com.tencent.devops.common.web.jasypt.DefaultEncryptor | ||
import com.zaxxer.hikari.HikariDataSource | ||
import org.slf4j.LoggerFactory | ||
import org.springframework.beans.factory.config.YamlPropertiesFactoryBean | ||
import org.springframework.beans.factory.support.BeanDefinitionBuilder | ||
import org.springframework.beans.factory.support.BeanDefinitionRegistry | ||
import org.springframework.beans.factory.support.BeanNameGenerator | ||
import org.springframework.boot.autoconfigure.AutoConfigureOrder | ||
import org.springframework.context.annotation.Configuration | ||
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar | ||
import org.springframework.core.Ordered | ||
import org.springframework.core.env.Environment | ||
import org.springframework.core.io.ClassPathResource | ||
import org.springframework.core.type.AnnotationMetadata | ||
import org.springframework.transaction.annotation.EnableTransactionManagement | ||
import java.util.Properties | ||
|
||
|
||
@Configuration | ||
@AutoConfigureOrder(Ordered.HIGHEST_PRECEDENCE) | ||
@EnableTransactionManagement | ||
class DataSourceDefinitionRegistrar : ImportBeanDefinitionRegistrar { | ||
override fun registerBeanDefinitions( | ||
importingClassMetadata: AnnotationMetadata, | ||
registry: BeanDefinitionRegistry, | ||
importBeanNameGenerator: BeanNameGenerator | ||
) { | ||
multiDataSource.forEach { dataSource -> | ||
logger.info("DataSourceDefinitionRegistrar:$dataSource") | ||
val resource = ClassPathResource("application-$dataSource.yml") | ||
val yamlFactory = YamlPropertiesFactoryBean() | ||
yamlFactory.setResources(resource) | ||
val properties = yamlFactory.getObject()!! | ||
val dataSourceUrl = properties.getProperty("spring.datasource.url") | ||
val datasourceUsername = properties.getProperty("spring.datasource.username") | ||
val datasourcePassword = properties.getProperty("spring.datasource.password") | ||
val datasourceInitSql = properties.getProperty("spring.datasource.initSql") | ||
val leakDetectionThreshold = properties.getProperty("spring.datasource.leakDetectionThreshold") ?: 0 | ||
val beanDefinitionBuilder = BeanDefinitionBuilder.rootBeanDefinition(HikariDataSource::class.java) | ||
.addPropertyValue("poolName", "DBPool-$dataSource") | ||
.addPropertyValue("jdbcUrl", dataSourceUrl) | ||
.addPropertyValue("username", datasourceUsername!!) | ||
.addPropertyValue("password", datasourcePassword!!) | ||
.addPropertyValue("driverClassName", Driver::class.java.name) | ||
.addPropertyValue("minimumIdle", 10) | ||
.addPropertyValue("maximumPoolSize", 50) | ||
.addPropertyValue("idleTimeout", 60000) | ||
.addPropertyValue("connectionInitSql", datasourceInitSql) | ||
.addPropertyValue("leakDetectionThreshold", leakDetectionThreshold) | ||
.setPrimary(false) | ||
registry.registerBeanDefinition("${dataSource}DataSource", beanDefinitionBuilder.beanDefinition) | ||
} | ||
} | ||
|
||
|
||
companion object { | ||
private val logger = LoggerFactory.getLogger(DataSourceDefinitionRegistrar::class.java) | ||
private val multiDataSource = listOf("auth","image").filterNot { it == "process" } | ||
private val regex = Regex("""ENC\((.*?)\)""") | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
...utijar/boot-mutijar/src/main/kotlin/com/tencent/devops/mutijar/JooqDefinitionRegistrar.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package com.tencent.devops.mutijar | ||
|
||
import com.tencent.devops.common.db.listener.BkJooqExecuteListener | ||
import org.jooq.SQLDialect | ||
import org.jooq.impl.DataSourceConnectionProvider | ||
import org.jooq.impl.DefaultConfiguration | ||
import org.jooq.impl.DefaultExecuteListenerProvider | ||
import org.slf4j.LoggerFactory | ||
import org.springframework.beans.factory.support.BeanDefinitionBuilder | ||
import org.springframework.beans.factory.support.BeanDefinitionRegistry | ||
import org.springframework.beans.factory.support.BeanNameGenerator | ||
import org.springframework.context.annotation.Configuration | ||
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar | ||
import org.springframework.core.type.AnnotationMetadata | ||
|
||
@Configuration | ||
class JooqDefinitionRegistrar : ImportBeanDefinitionRegistrar { | ||
override fun registerBeanDefinitions( | ||
importingClassMetadata: AnnotationMetadata, | ||
registry: BeanDefinitionRegistry, | ||
importBeanNameGenerator: BeanNameGenerator | ||
) { | ||
multiDataSource.forEach { dataSource -> | ||
val finalDataSource = if (dataSource == "process") "shardingDataSource" else "${dataSource}DataSource" | ||
val connectionProvider = BeanDefinitionBuilder.genericBeanDefinition( | ||
DataSourceConnectionProvider::class.java | ||
).addConstructorArgReference(finalDataSource) | ||
registry.registerBeanDefinition("${dataSource}ConnectionProvider", connectionProvider.beanDefinition) | ||
val beanDefinitionBuilder = BeanDefinitionBuilder.genericBeanDefinition(DefaultConfiguration::class.java) { | ||
val configuration = DefaultConfiguration() | ||
configuration.set(SQLDialect.MYSQL) | ||
configuration.settings().isRenderSchema = false | ||
configuration.set(DefaultExecuteListenerProvider(BkJooqExecuteListener())) | ||
configuration | ||
} | ||
beanDefinitionBuilder.addPropertyReference("connectionProvider", "${dataSource}ConnectionProvider") | ||
registry.registerBeanDefinition("${dataSource}JooqConfiguration", beanDefinitionBuilder.beanDefinition) | ||
} | ||
} | ||
|
||
companion object { | ||
private val logger = LoggerFactory.getLogger(DataSourceDefinitionRegistrar::class.java) | ||
private val multiDataSource = listOf("auth","image").filterNot { it == "process" } | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
...ore/mutijar/boot-mutijar/src/main/kotlin/com/tencent/devops/mutijar/MutijarApplication.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* Tencent is pleased to support the open source community by making BK-CI 蓝鲸持续集成平台 available. | ||
* | ||
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. | ||
* | ||
* BK-CI 蓝鲸持续集成平台 is licensed under the MIT license. | ||
* | ||
* A copy of the MIT License is included in this file. | ||
* | ||
* | ||
* Terms of the MIT License: | ||
* --------------------------------------------------- | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated | ||
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation the | ||
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to | ||
* permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of | ||
* the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT | ||
* LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN | ||
* NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | ||
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE | ||
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
*/ | ||
|
||
package com.tencent.devops.mutijar | ||
|
||
import com.tencent.devops.common.service.MicroService | ||
import com.tencent.devops.common.service.MicroServiceApplication | ||
import org.springframework.context.annotation.ComponentScan | ||
import org.springframework.context.annotation.FilterType | ||
|
||
@MicroService | ||
@ComponentScan( | ||
"com.tencent.devops", | ||
excludeFilters = [ | ||
ComponentScan.Filter( | ||
type = FilterType.REGEX, | ||
pattern = ["com\\.tencent\\.devops\\.common\\..*"] | ||
) | ||
] | ||
) | ||
class MutijarApplication | ||
|
||
fun main(args: Array<String>) { | ||
MicroServiceApplication.run(MutijarApplication::class, args) | ||
} |
86 changes: 86 additions & 0 deletions
86
...boot-mutijar/src/main/kotlin/com/tencent/devops/mutijar/MutijarDslContextConfiguration.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/* | ||
* Tencent is pleased to support the open source community by making BK-CI 蓝鲸持续集成平台 available. | ||
* | ||
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. | ||
* | ||
* BK-CI 蓝鲸持续集成平台 is licensed under the MIT license. | ||
* | ||
* A copy of the MIT License is included in this file. | ||
* | ||
* | ||
* Terms of the MIT License: | ||
* --------------------------------------------------- | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated | ||
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation the | ||
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to | ||
* permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of | ||
* the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT | ||
* LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN | ||
* NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | ||
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE | ||
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
*/ | ||
package com.tencent.devops.mutijar | ||
|
||
import com.tencent.devops.common.db.config.DBBaseConfiguration | ||
import org.jooq.DSLContext | ||
import org.jooq.impl.DSL | ||
import org.jooq.impl.DefaultConfiguration | ||
import org.slf4j.LoggerFactory | ||
import org.springframework.beans.factory.InjectionPoint | ||
import org.springframework.beans.factory.NoSuchBeanDefinitionException | ||
import org.springframework.beans.factory.config.ConfigurableBeanFactory | ||
import org.springframework.context.annotation.Bean | ||
import org.springframework.context.annotation.Configuration | ||
import org.springframework.context.annotation.Import | ||
import org.springframework.context.annotation.Primary | ||
import org.springframework.context.annotation.Scope | ||
import java.lang.reflect.AnnotatedElement | ||
import java.lang.reflect.Constructor | ||
|
||
/** | ||
* | ||
* Powered By Tencent | ||
*/ | ||
@Configuration | ||
@Import(DBBaseConfiguration::class, DataSourceDefinitionRegistrar::class, JooqDefinitionRegistrar::class) | ||
class MutijarDslContextConfiguration { | ||
@Bean | ||
@Primary | ||
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) | ||
fun dslContext( | ||
configurationMap: Map<String?, DefaultConfiguration?>, | ||
injectionPoint: InjectionPoint | ||
): DSLContext { | ||
val annotatedElement: AnnotatedElement = injectionPoint.annotatedElement | ||
if (Constructor::class.java.isAssignableFrom(annotatedElement::class.java)) { | ||
val declaringClass: Class<*> = (annotatedElement as Constructor<*>).declaringClass | ||
val packageName = declaringClass.getPackage().name | ||
logger.info("packageName:$packageName") | ||
// lambda服务有多个数据源,需要进行处理 | ||
val configurationName = if (packageName.contains(".lambda")) { | ||
val matchResult = lambdaServiceRegex.find(packageName) | ||
"${matchResult?.groupValues?.get(1) ?: "lambda"}JooqConfiguration" | ||
} else { | ||
val serviceName = multiModelService.find { packageName.contains(it) } | ||
?: throw NoSuchBeanDefinitionException("no jooq configuration") | ||
serviceName.removePrefix(".").plus("JooqConfiguration") | ||
} | ||
logger.info("AccessoriesJooqConfiguration:$configurationName") | ||
val configuration: org.jooq.Configuration = configurationMap[configurationName] | ||
?: throw NoSuchBeanDefinitionException("no $configurationName") | ||
return DSL.using(configuration) | ||
} | ||
throw NoSuchBeanDefinitionException("no jooq configuration") | ||
} | ||
|
||
companion object { | ||
private val logger = LoggerFactory.getLogger(MutijarDslContextConfiguration::class.java) | ||
private val multiModelService = listOf("auth","image").filterNot { it == "process" } | ||
private val lambdaServiceRegex = "\\.(tsource|ttarget|process|project|store)".toRegex() | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/backend/ci/core/mutijar/boot-mutijar/src/main/resources/application.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
spring: | ||
profiles: | ||
active: | ||
- common | ||
- auth | ||
- image | ||
main: | ||
allow-bean-definition-overriding: true | ||
application: | ||
name: mutijar | ||
desc: DevOps MUTIJAR Service | ||
version: 4.0.0 | ||
packageName: com.tencent.devops.mutijar | ||
cloud: | ||
config: | ||
fail-fast: true | ||
server: | ||
port: 21930 | ||
logging: | ||
level: | ||
root=DEBUG: DEBUG |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* Tencent is pleased to support the open source community by making BK-CI 蓝鲸持续集成平台 available. | ||
* | ||
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. | ||
* | ||
* BK-CI 蓝鲸持续集成平台 is licensed under the MIT license. | ||
* | ||
* A copy of the MIT License is included in this file. | ||
* | ||
* | ||
* Terms of the MIT License: | ||
* --------------------------------------------------- | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated | ||
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation the | ||
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to | ||
* permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of | ||
* the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT | ||
* LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN | ||
* NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | ||
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE | ||
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
*/ | ||
|
||
subprojects { | ||
group = "com.tencent.bk.devops.ci.mutijar" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters