Skip to content

Commit

Permalink
feat: 指定模块统一打包插件 TencentBlueKing#8672
Browse files Browse the repository at this point in the history
  • Loading branch information
fcfang123 committed Oct 18, 2023
1 parent 85762ce commit 73d0f8e
Show file tree
Hide file tree
Showing 10 changed files with 356 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ tasks.register("multiBootJar") {
isSpecifiedModulePath(it.path, multiModuleList)
}.forEach { subProject -> addDependencies(subProject.path) }
dependsOn("copyToRelease")
dependsOn("jib")
// dependsOn("jib")
}
}
fun isSpecifiedModulePath(path: String, multiModuleList: List<String>): Boolean {
// 由于store微服务下的有些项目名称包含image,在打包image时会把store给误打包,故在打包image时,把store服务剔除
return if (path.contains("image") && path.contains("store")) {
false
} else {
path.contains("ext") && path.contains("biz")
path.contains("biz")
&& multiModuleList.any { module -> path.contains(module) }
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/backend/ci/core/auth/boot-auth/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,7 @@ dependencies {
api(project(":core:auth:biz-auth-blueking"))
api(project(":core:auth:biz-auth-rbac"))
}
tasks.named<org.springframework.boot.gradle.tasks.run.BootRun>("bootRun") {
//classpath = files("${project.rootDir}\\release\\boot-finalModule.jar")
println("greysonfang-test classpath = ${classpath.asPath}")
}
48 changes: 48 additions & 0 deletions src/backend/ci/core/mutijar/boot-mutijar/build.gradle.kts
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")
}
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\((.*?)\)""")
}
}
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" }
}
}
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)
}
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()
}
}
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
30 changes: 30 additions & 0 deletions src/backend/ci/core/mutijar/build.gradle.kts
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"
}
7 changes: 7 additions & 0 deletions src/backend/ci/settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -267,3 +267,10 @@ include(":core:metrics:biz-metrics")
include(":core:metrics:biz-metrics-sample")
include(":core:metrics:boot-metrics")
include(":core:metrics:model-metrics")

include("core:mutijar")
include("core:mutijar:boot-mutijar")
include("core:mutijar:boot-mutijar")
findProject(":core:mutijar:boot-mutijar")?.name = "boot-mutijar"
include("core:mutijar:boot-mutijar")
findProject(":core:mutijar:boot-mutijar")?.name = "boot-mutijar"

0 comments on commit 73d0f8e

Please sign in to comment.