diff --git a/src/backend/ci/buildSrc/src/main/kotlin/plugins/task-multi-boot-jar.gradle.kts b/src/backend/ci/buildSrc/src/main/kotlin/plugins/task-multi-boot-jar.gradle.kts index ede02c326ab..86770d54a0a 100644 --- a/src/backend/ci/buildSrc/src/main/kotlin/plugins/task-multi-boot-jar.gradle.kts +++ b/src/backend/ci/buildSrc/src/main/kotlin/plugins/task-multi-boot-jar.gradle.kts @@ -31,7 +31,7 @@ tasks.register("multiBootJar") { isSpecifiedModulePath(it.path, multiModuleList) }.forEach { subProject -> addDependencies(subProject.path) } dependsOn("copyToRelease") - dependsOn("jib") + // dependsOn("jib") } } fun isSpecifiedModulePath(path: String, multiModuleList: List): Boolean { @@ -39,7 +39,7 @@ fun isSpecifiedModulePath(path: String, multiModuleList: List): Boolean 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) } } } diff --git a/src/backend/ci/core/auth/boot-auth/build.gradle.kts b/src/backend/ci/core/auth/boot-auth/build.gradle.kts index b7dd3810af9..eafedf3eab8 100644 --- a/src/backend/ci/core/auth/boot-auth/build.gradle.kts +++ b/src/backend/ci/core/auth/boot-auth/build.gradle.kts @@ -30,3 +30,7 @@ dependencies { api(project(":core:auth:biz-auth-blueking")) api(project(":core:auth:biz-auth-rbac")) } +tasks.named("bootRun") { + //classpath = files("${project.rootDir}\\release\\boot-finalModule.jar") + println("greysonfang-test classpath = ${classpath.asPath}") +} diff --git a/src/backend/ci/core/mutijar/boot-mutijar/build.gradle.kts b/src/backend/ci/core/mutijar/boot-mutijar/build.gradle.kts new file mode 100644 index 00000000000..d1eca936005 --- /dev/null +++ b/src/backend/ci/core/mutijar/boot-mutijar/build.gradle.kts @@ -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") { + val finalModuleName = System.getProperty("devops.multi.to") + archiveBaseName.set("boot-$finalModuleName") +} + +tasks.named("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") +} diff --git a/src/backend/ci/core/mutijar/boot-mutijar/src/main/kotlin/com/tencent/devops/mutijar/DataSourceDefinitionRegistrar.kt b/src/backend/ci/core/mutijar/boot-mutijar/src/main/kotlin/com/tencent/devops/mutijar/DataSourceDefinitionRegistrar.kt new file mode 100644 index 00000000000..b5b7124961d --- /dev/null +++ b/src/backend/ci/core/mutijar/boot-mutijar/src/main/kotlin/com/tencent/devops/mutijar/DataSourceDefinitionRegistrar.kt @@ -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\((.*?)\)""") + } +} diff --git a/src/backend/ci/core/mutijar/boot-mutijar/src/main/kotlin/com/tencent/devops/mutijar/JooqDefinitionRegistrar.kt b/src/backend/ci/core/mutijar/boot-mutijar/src/main/kotlin/com/tencent/devops/mutijar/JooqDefinitionRegistrar.kt new file mode 100644 index 00000000000..5f85c4de0b5 --- /dev/null +++ b/src/backend/ci/core/mutijar/boot-mutijar/src/main/kotlin/com/tencent/devops/mutijar/JooqDefinitionRegistrar.kt @@ -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" } + } +} diff --git a/src/backend/ci/core/mutijar/boot-mutijar/src/main/kotlin/com/tencent/devops/mutijar/MutijarApplication.kt b/src/backend/ci/core/mutijar/boot-mutijar/src/main/kotlin/com/tencent/devops/mutijar/MutijarApplication.kt new file mode 100644 index 00000000000..fd3dbeced32 --- /dev/null +++ b/src/backend/ci/core/mutijar/boot-mutijar/src/main/kotlin/com/tencent/devops/mutijar/MutijarApplication.kt @@ -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) { + MicroServiceApplication.run(MutijarApplication::class, args) +} diff --git a/src/backend/ci/core/mutijar/boot-mutijar/src/main/kotlin/com/tencent/devops/mutijar/MutijarDslContextConfiguration.kt b/src/backend/ci/core/mutijar/boot-mutijar/src/main/kotlin/com/tencent/devops/mutijar/MutijarDslContextConfiguration.kt new file mode 100644 index 00000000000..0bea288654b --- /dev/null +++ b/src/backend/ci/core/mutijar/boot-mutijar/src/main/kotlin/com/tencent/devops/mutijar/MutijarDslContextConfiguration.kt @@ -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, + 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() + } +} diff --git a/src/backend/ci/core/mutijar/boot-mutijar/src/main/resources/application.yml b/src/backend/ci/core/mutijar/boot-mutijar/src/main/resources/application.yml new file mode 100644 index 00000000000..ac834873dd3 --- /dev/null +++ b/src/backend/ci/core/mutijar/boot-mutijar/src/main/resources/application.yml @@ -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 diff --git a/src/backend/ci/core/mutijar/build.gradle.kts b/src/backend/ci/core/mutijar/build.gradle.kts new file mode 100644 index 00000000000..1216a155ec6 --- /dev/null +++ b/src/backend/ci/core/mutijar/build.gradle.kts @@ -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" +} diff --git a/src/backend/ci/settings.gradle.kts b/src/backend/ci/settings.gradle.kts index bbcf02fd0e9..6573d628329 100644 --- a/src/backend/ci/settings.gradle.kts +++ b/src/backend/ci/settings.gradle.kts @@ -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"