Skip to content

Commit

Permalink
feat:蓝盾本地开发实现 TencentBlueKing#9576
Browse files Browse the repository at this point in the history
  • Loading branch information
fcfang123 committed Oct 18, 2023
1 parent f268e07 commit c4d5e07
Show file tree
Hide file tree
Showing 12 changed files with 83 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,9 @@ tasks.register("multiBootJar") {
isSpecifiedModulePath(it.path, multiModuleList)
}.forEach { subProject -> addDependencies(subProject.path) }
dependsOn("copyToRelease")
//dependsOn("bootRun")
// dependsOn("jib")
}
}

fun isSpecifiedModulePath(path: String, multiModuleList: List<String>): Boolean {
// 由于store微服务下的有些项目名称包含image,在打包image时会把store给误打包,故在打包image时,把store服务剔除
return if (path.contains("image") && path.contains("store")) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* 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

tasks.register<BootRun>("multiBootRun") {
doFirst {
systemProperty("devops.multi.from", System.getProperty("devops.multi.from"))
systemProperty("spring.main.allow-circular-references", "true")
systemProperty("spring.cloud.config.enabled", "false")
systemProperty("spring.cloud.config.fail-fast", "true")
systemProperty("spring.jmx.enabled", "true")
systemProperty("jasypt.encryptor.bootstrap", "false")
systemProperty("sun.jnu.encoding", "UTF-8")
systemProperty("file.encoding", "UTF-8")
systemProperty("spring.cloud.consul.host", "localhost")
}
dependsOn("multiBootJar")
val bootJarTask = tasks.getByName<BootJar>("bootJar")
println("multi boot run:${bootJarTask.mainClass}|${bootJarTask.classpath}")
mainClass.set(bootJarTask.mainClass)
classpath = bootJarTask.classpath
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import javax.annotation.PostConstruct


@Component
class MyStartupTask {
class MyStartupTask {
@PostConstruct
fun init() {
logger.info("MyStartupTask init")
Expand Down
8 changes: 1 addition & 7 deletions src/backend/ci/core/mutijar/boot-mutijar/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,10 @@ dependencies {
}
plugins {
`task-multi-boot-jar`
`task-multi-boot-run`
}

tasks.named<BootJar>("bootJar") {
val finalModuleName = System.getProperty("devops.multi.to")
archiveBaseName.set("boot-$finalModuleName")
}

tasks.named<BootRun>("bootRun") {
dependsOn("multiBootJar")
doFirst {
systemProperty("devops.multi.from", System.getProperty("devops.multi.from"))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class DataSourceDefinitionRegistrar : ImportBeanDefinitionRegistrar {

companion object {
private val logger = LoggerFactory.getLogger(DataSourceDefinitionRegistrar::class.java)
private val multiDataSource = System.getProperty("devops.multi.from").split(",")
private val multiDataSource = System.getProperty("devops.multi.from").split(",").filterNot { it == "process" }
private val regex = Regex("""ENC\((.*?)\)""")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ class JooqDefinitionRegistrar : ImportBeanDefinitionRegistrar {
importBeanNameGenerator: BeanNameGenerator
) {
multiDataSource.forEach { dataSource ->
//if (dataSource == "process") "shardingDataSource" else
val finalDataSource = "${dataSource}DataSource"
val finalDataSource = if (dataSource == "process") "shardingDataSource" else
"${dataSource}DataSource"
val connectionProvider = BeanDefinitionBuilder.genericBeanDefinition(
DataSourceConnectionProvider::class.java
).addConstructorArgReference(finalDataSource)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ import org.springframework.context.annotation.Primary
import org.springframework.context.annotation.Scope
import java.lang.reflect.AnnotatedElement
import java.lang.reflect.Constructor
import java.lang.reflect.Method
import java.lang.reflect.Parameter

/**
*
Expand All @@ -57,8 +59,14 @@ class MutijarDslContextConfiguration {
injectionPoint: InjectionPoint
): DSLContext {
val annotatedElement: AnnotatedElement = injectionPoint.annotatedElement
if (Constructor::class.java.isAssignableFrom(annotatedElement::class.java)) {
val declaringClass: Class<*> = (annotatedElement as Constructor<*>).declaringClass
if (Constructor::class.java.isAssignableFrom(annotatedElement::class.java) ||
Method::class.java.isAssignableFrom(annotatedElement::class.java)
) {
val declaringClass: Class<*> = when (annotatedElement) {
is Constructor<*> -> annotatedElement.declaringClass
is Method -> annotatedElement.declaringClass
else -> throw IllegalArgumentException("Invalid annotatedElement type")
}
val packageName = declaringClass.getPackage().name
logger.info("packageName:$packageName")
// lambda服务有多个数据源,需要进行处理
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ import org.springframework.amqp.rabbit.core.RabbitTemplate
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.context.annotation.Lazy

//@RestResource
@RestResource
class ServiceScmWebhookResourceImpl @Autowired constructor(
private val pipelineBuildWebhookService: PipelineBuildWebhookService,
private val rabbitTemplate: RabbitTemplate,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,7 @@ import org.springframework.core.Ordered
@Configuration
@ConditionalOnWebApplication
@AutoConfigureOrder(Ordered.LOWEST_PRECEDENCE)
class PipelinePermConfiguration constructor(
val dslContext: DSLContext
){
class PipelinePermConfiguration {

@Bean
@ConditionalOnProperty(prefix = "auth", name = ["idProvider"], havingValue = "bk_login")
Expand All @@ -75,7 +73,7 @@ class PipelinePermConfiguration constructor(
@Bean
@ConditionalOnProperty(prefix = "auth", name = ["idProvider"], havingValue = "sample")
fun mockPipelinePermissionService(

dslContext: DSLContext,
pipelineInfoDao: PipelineInfoDao,
authProjectApi: AuthProjectApi,
authResourceApi: AuthResourceApi,
Expand All @@ -93,7 +91,7 @@ class PipelinePermConfiguration constructor(
@Bean
@ConditionalOnProperty(prefix = "auth", name = ["idProvider"], havingValue = "bk_login_v3")
fun v3pipelinePermissionService(

dslContext: DSLContext,
client: Client,
redisOperation: RedisOperation,
pipelineInfoDao: PipelineInfoDao,
Expand All @@ -117,7 +115,7 @@ class PipelinePermConfiguration constructor(
fun githubStreamPipelinePermissionService(
client: Client,
pipelineInfoDao: PipelineInfoDao,

dslContext: DSLContext,
checkTokenService: ClientTokenService
): PipelinePermissionService = StreamPipelinePermissionServiceImpl(
client = client,
Expand All @@ -131,7 +129,7 @@ class PipelinePermConfiguration constructor(
fun gitlabStreamPipelinePermissionService(
client: Client,
pipelineInfoDao: PipelineInfoDao,

dslContext: DSLContext,
checkTokenService: ClientTokenService
): PipelinePermissionService = StreamPipelinePermissionServiceImpl(
client = client,
Expand All @@ -146,7 +144,7 @@ class PipelinePermConfiguration constructor(
authPermissionApi: AuthPermissionApi,
authProjectApi: AuthProjectApi,
pipelineAuthServiceCode: PipelineAuthServiceCode,

dslContext: DSLContext,
pipelineInfoDao: PipelineInfoDao,
pipelineViewGroupService: PipelineViewGroupService,
authResourceApi: AuthResourceApi
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ abstract class PipelineBuildWebhookService : ApplicationContextAware {
gitWebhookUnlockDispatcher = applicationContext.getBean(GitWebhookUnlockDispatcher::class.java)
pipelineWebHookQueueService = applicationContext.getBean(PipelineWebHookQueueService::class.java)
buildLogPrinter = applicationContext.getBean(BuildLogPrinter::class.java)
pipelinebuildWebhookService = applicationContext.getBean(PipelineBuildWebhookService::class.java)
pipelineBuildCommitService = applicationContext.getBean(PipelineBuildCommitService::class.java)
webhookBuildParameterService = applicationContext.getBean(WebhookBuildParameterService::class.java)
}
Expand All @@ -109,6 +110,7 @@ abstract class PipelineBuildWebhookService : ApplicationContextAware {
lateinit var gitWebhookUnlockDispatcher: GitWebhookUnlockDispatcher
lateinit var pipelineWebHookQueueService: PipelineWebHookQueueService
lateinit var buildLogPrinter: BuildLogPrinter
lateinit var pipelinebuildWebhookService: PipelineBuildWebhookService // 给AOP调用
lateinit var pipelineBuildCommitService: PipelineBuildCommitService
lateinit var webhookBuildParameterService: WebhookBuildParameterService
private val logger = LoggerFactory.getLogger(PipelineBuildWebhookService::class.java)
Expand Down Expand Up @@ -263,7 +265,7 @@ abstract class PipelineBuildWebhookService : ApplicationContextAware {
return@outside
}

if (webhookTriggerPipelineBuild(
if (pipelinebuildWebhookService.webhookTriggerPipelineBuild(
projectId = projectId,
pipelineId = pipelineId,
codeRepositoryType = codeRepositoryType,
Expand Down
2 changes: 1 addition & 1 deletion src/backend/ci/core/project/biz-project/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Tencent is pleased to support the open source community by making BK-CI 蓝鲸持续集成平台 available.
* Tencent is p:leased to support the open source community by making BK-CI 蓝鲸持续集成平台 available.
*
* Copyright (C)) 2019 THL A29 Limited, a Tencent company. All rights reserved.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
package com.tencent.devops.project.config

import com.tencent.devops.common.redis.RedisOperation
import com.tencent.devops.leaf.plugin.LeafSpringBootProperties
import com.tencent.devops.project.dao.ProjectDao
import com.tencent.devops.project.dao.ProjectLabelRelDao
import com.tencent.devops.project.dispatch.ProjectDispatcher
Expand All @@ -38,6 +39,8 @@ import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.context.annotation.Primary


@Configuration
class OpConfig {
Expand All @@ -57,4 +60,10 @@ class OpConfig {
projectDispatcher = projectDispatcher,
redisOperation = redisOperation
)

@Bean
@Primary
fun leafSpringBootProperties(): LeafSpringBootProperties {
return LeafSpringBootProperties()
}
}

0 comments on commit c4d5e07

Please sign in to comment.