Skip to content

Commit

Permalink
feat:蓝盾本地开发实现 TencentBlueKing#9576
Browse files Browse the repository at this point in the history
  • Loading branch information
fcfang123 committed Apr 30, 2024
1 parent 95c190a commit c4184da
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/backend/ci/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ allprojects {
dependency("org.mybatis:mybatis:${Versions.MyBatis}")
dependency("commons-io:commons-io:${Versions.CommonIo}")
dependency("com.tencent.bk.sdk:crypto-java-sdk:${Versions.BkCrypto}")
dependency("org.testcontainers:testcontainers:${Versions.testcontainers}")
dependencySet("org.glassfish.jersey.containers:${Versions.Jersey}") {
entry("jersey-container-servlet-core")
entry("jersey-container-servlet")
Expand Down
2 changes: 2 additions & 0 deletions src/backend/ci/buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,6 @@ dependencies {
implementation("org.springframework.boot:spring-boot-gradle-plugin:2.6.13")
implementation("com.github.jk1:gradle-license-report:1.17") // 2.x need gradle-7.0
implementation("com.mysql:mysql-connector-j:8.0.33")
implementation("org.testcontainers:testcontainers:1.19.1")
implementation("org.testcontainers:mysql:1.19.1")
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,5 @@ object Versions {
const val MysqlDriver = "8.0.33"
const val swagger = "2.2.16"
const val jakarta = "2.1.2"
const val testcontainers="1.19.1"
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,15 @@ import java.util.Properties

tasks.register<BootRun>("multiBootRun") {
doFirst {
val sqlFilePath = joinPath(
rootDir.absolutePath.replace("${File.separator}src${File.separator}backend${File.separator}ci", ""),
"support-files",
"i18n"
)
systemProperty("devops.multi.from", localRunMultiServices)
systemProperty("spring.datasource.url", System.getProperty("mysqlURL"))
systemProperty("spring.datasource.username", System.getProperty("mysqlUser"))
systemProperty("spring.datasource.password", System.getProperty("mysqlPasswd"))
systemProperty("spring.datasource.password", System.getProperty("mysqlPasswd"))
systemProperty("spring.main.allow-circular-references", "true")
systemProperty("spring.cloud.config.enabled", "false")
systemProperty("spring.cloud.config.fail-fast", "true")
Expand All @@ -46,6 +51,8 @@ tasks.register<BootRun>("multiBootRun") {
systemProperty("server.port", "8081")
systemProperty("local.run", "true")
systemProperty("service.log.dir", joinPath(projectDir.absolutePath, "log"))
systemProperty("workspace.dir", rootProject.projectDir)
systemProperty("sql.file.dir", sqlFilePath)
}
dependsOn("multiBootJar")
val bootJarTask = tasks.getByName<BootJar>("bootJar")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package utils

import org.testcontainers.containers.GenericContainer
import org.testcontainers.images.builder.ImageFromDockerfile
import java.nio.file.Paths

class MysqlContainerInit {
fun initMysqlContainer() {
val path = Paths.get("C:\\Users\\bk-ci-2\\support-files\\Dockerfile")
val mysqlContainer = GenericContainer<GenericContainer<*>>(
ImageFromDockerfile().withDockerfile(path)
).withExposedPorts(3306)
.withEnv("MYSQL_ROOT_PASSWORD", "blueking")
mysqlContainer.start()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ dependencies {
api("mysql:mysql-connector-java")
api("com.tencent.devops.leaf:leaf-boot-starter")
implementation(kotlin("stdlib"))
api("org.testcontainers:testcontainers")
}
plugins {
`task-render-template`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ 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
import org.testcontainers.containers.FixedHostPortGenericContainer

@MicroService
@ComponentScan(
Expand All @@ -45,5 +46,31 @@ import org.springframework.context.annotation.FilterType
class MultijarApplication

fun main(args: Array<String>) {
val redis = FixedHostPortGenericContainer("redis:5.0.3-alpine")
.withFixedExposedPort(30002, 6379)
redis.start()
// 创建Elasticsearch容器
val elasticsearchContainer = FixedHostPortGenericContainer(
"docker.elastic.co/elasticsearch/elasticsearch:7.14.0"
).withFixedExposedPort(30014, 9200)
.withFixedExposedPort(30015, 9300)
.withEnv("discovery.type", "single-node")
.withEnv("xpack.security.enabled", "false")
.withEnv("ELASTIC_PASSWORD", "blueking")
// 启动容器
elasticsearchContainer.start()
val influxDBContainer = FixedHostPortGenericContainer(
"docker.io/bitnami/influxdb:1.8.3-debian-10-r88"
).withFixedExposedPort(30006, 8086)
.withEnv("INFLUXDB_ADMIN_USER_PASSWORD", "blueking")
influxDBContainer.start()

val rabbitmq = FixedHostPortGenericContainer("heidiks/rabbitmq-delayed-message-exchange:3.13.0-management")
.withFixedExposedPort(30003, 5672)
.withFixedExposedPort(15672, 15672)
.withEnv("RABBITMQ_DEFAULT_USER", "admin")
.withEnv("RABBITMQ_DEFAULT_PASS", "blueking")
rabbitmq.start()

MicroServiceApplication.run(MultijarApplication::class, args)
}
5 changes: 5 additions & 0 deletions support-files/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM mysql:5.7.26
LABEL OG=felord.cn
RUN mkdir -p /data/sql
COPY ./sql/ /data/sql
RUN find /data/sql -type f -name "*.sql" | sort | xargs -I {} mv {} /docker-entrypoint-initdb.d

0 comments on commit c4184da

Please sign in to comment.