Skip to content

Commit

Permalink
Merge pull request #4549 from sawyersong2/issue_4521
Browse files Browse the repository at this point in the history
feat: 优化无编译构建环境镜像选择逻辑 #4521
  • Loading branch information
irwinsun authored Jun 29, 2021
2 parents 0c66770 + 750cf09 commit 15c8be1
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 32 deletions.
8 changes: 8 additions & 0 deletions scripts/bkenv.properties
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,14 @@ BK_CI_REDIS_SENTINEL_MASTER_NAME=
##########
# 3-微服务配置
##########
# BK_CI_AGENTLESS_IMAGE_NAME默认为bkci/ci:alpine. 按需修改. 镜像的路径名称及TAG, 私有REGISTRY需配置BK_CI_AGENTLESS_IMAGE_REGISTRY_URL
BK_CI_AGENTLESS_IMAGE_NAME=bkci/ci:alpine
# BK_CI_AGENTLESS_IMAGE_REGISTRY_PASSWORD无默认值. 按需修改. 私有registry用户名对应的密码, 为空则无认证.
BK_CI_AGENTLESS_IMAGE_REGISTRY_PASSWORD=
# BK_CI_AGENTLESS_IMAGE_REGISTRY_URL无默认值. 按需修改. 私有registry的地址及端口, 为空则使用docker hub.
BK_CI_AGENTLESS_IMAGE_REGISTRY_URL=
# BK_CI_AGENTLESS_IMAGE_REGISTRY_USER无默认值. 按需修改. 私有registry的用户名, 为空则无认证.
BK_CI_AGENTLESS_IMAGE_REGISTRY_USER=
# BK_CI_CODEOA_API_KEY无默认值. 废弃. 待清理配置文件及相关代码.
BK_CI_CODEOA_API_KEY=
# BK_CI_CODEOA_API_URL无默认值. 废弃. 待清理配置文件及相关代码.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,9 @@ package com.tencent.devops.common.pipeline.enums
enum class DockerVersion(val value: String) {
TLINUX1_2("tlinux1.2"),
TLINUX2_2("tlinux2.2"),
CENTOS7_2("centos7.2")

/**
* 用户自定义配置无编译环境镜像
*/
CUSTOMIZE("customize")
}
Original file line number Diff line number Diff line change
Expand Up @@ -229,19 +229,19 @@ class DockerHostClient @Autowired constructor(
LOG.info("[${event.buildId}]|BUILD_LESS| agentId: $agentId")
val dispatchType = event.dispatchType as DockerDispatchType
val dockerImage = when (dispatchType.dockerBuildVersion) {
DockerVersion.TLINUX1_2.value -> {
defaultImageConfig.getBuildLessTLinux1_2CompleteUri()
DockerVersion.CUSTOMIZE.value -> {
defaultImageConfig.getAgentLessCompleteUri()
}
DockerVersion.TLINUX2_2.value -> {
defaultImageConfig.getBuildLessTLinux2_2CompleteUri()
defaultImageConfig.getAgentLessCompleteUri()
}
else -> {
defaultImageConfig.getBuildLessCompleteUriByImageName(dispatchType.dockerBuildVersion)
defaultImageConfig.getAgentLessCompleteUriByImageName(dispatchType.dockerBuildVersion)
}
}
LOG.info("[${event.buildId}]|BUILD_LESS| Docker images is: $dockerImage")

var userName: String? = null
/* var userName: String? = null
var password: String? = null
if (dispatchType.imageType == ImageType.THIRD) {
if (!dispatchType.credentialId.isNullOrBlank()) {
Expand All @@ -254,7 +254,7 @@ class DockerHostClient @Autowired constructor(
userName = ticketsMap["v1"] as String
password = ticketsMap["v2"] as String
}
}
}*/

val requestBody = DockerHostBuildInfo(
projectId = event.projectId,
Expand All @@ -268,9 +268,9 @@ class DockerHostClient @Autowired constructor(
containerId = "",
wsInHost = true,
poolNo = 0,
registryUser = userName ?: "",
registryPwd = password ?: "",
imageType = dispatchType.imageType?.type,
registryUser = defaultImageConfig.agentLessRegistryUserName ?: "",
registryPwd = defaultImageConfig.agentLessRegistryPassword ?: "",
imageType = ImageType.THIRD.type,
imagePublicFlag = dispatchType.imagePublicFlag,
imageRDType = if (dispatchType.imageRDType == null) {
null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,37 +43,35 @@ class DefaultImageConfig {
@Value("\${dispatch.imageTLinux2_2:bkci/ci:latest}")
val imageTLinux2_2: String? = null

// 无编译环境,末尾需含bkdevops
@Value("\${dispatch.dockerBuildLessImagePrefix:#{null}}")
var dockerBuildLessImagePrefix: String? = null
// 无编译环境镜像仓库
@Value("\${dispatch.agentLessRegistryUrl:#{null}}")
var agentLessRegistryUrl: String? = null

@Value("\${dispatch.imageBuildLessTLinux1_2:bkci/ci:alpine}")
val imageBuildLessTLinux1_2: String? = null
// 无编译环境镜像路径
@Value("\${dispatch.agentLessImageName:bkci/ci:alpine}")
val agentLessImageName: String? = null

@Value("\${dispatch.imageBuildLessTLinux2_2:bkci/ci:alpine}")
val imageBuildLessTLinux2_2: String? = null
// 无编译环境镜像仓库登录信息
@Value("\${dispatch.agentLessRegistryUserName:#{null}}")
val agentLessRegistryUserName: String? = null

fun getBuildLessTLinux1_2CompleteUri(): String {
return if (dockerBuildLessImagePrefix.isNullOrBlank()) {
imageBuildLessTLinux1_2?.trim()?.removePrefix("/")
} else {
dockerBuildLessImagePrefix + imageBuildLessTLinux1_2?.trim()
} ?: ""
}
// 无编译环境镜像仓库登录信息
@Value("\${dispatch.agentLessRegistryPassword:#{null}}")
val agentLessRegistryPassword: String? = null

fun getBuildLessTLinux2_2CompleteUri(): String {
return if (dockerBuildLessImagePrefix.isNullOrBlank()) {
imageBuildLessTLinux2_2?.trim()?.removePrefix("/")
fun getAgentLessCompleteUri(): String {
return if (agentLessRegistryUrl.isNullOrBlank()) {
agentLessImageName?.trim()?.removePrefix("/")
} else {
dockerBuildLessImagePrefix + imageBuildLessTLinux2_2?.trim()
agentLessRegistryUrl + agentLessImageName?.trim()
} ?: ""
}

fun getBuildLessCompleteUriByImageName(imageName: String?): String {
return if (dockerBuildLessImagePrefix.isNullOrBlank()) {
fun getAgentLessCompleteUriByImageName(imageName: String?): String {
return if (agentLessRegistryUrl.isNullOrBlank()) {
imageName?.trim()?.removePrefix("/")
} else {
"$dockerBuildLessImagePrefix/${imageName?.trim()}"
"$agentLessRegistryUrl/${imageName?.trim()}"
} ?: ""
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ class DispatchBuildLessDockerStartupTaskAtom @Autowired constructor(
os = VMBaseOS.LINUX.name,
startTime = System.currentTimeMillis(),
channelCode = pipelineInfo.channelCode.name,
dispatchType = DockerDispatchType(DockerVersion.TLINUX2_2.value),
dispatchType = DockerDispatchType(DockerVersion.CUSTOMIZE.value),
zone = getBuildZone(container),
atoms = atoms,
executeCount = task.executeCount
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ dispatch:
#defaultImageUrl: __BK_CI_DOCKER_IMAGE_PREFIX__/paas/bkdevops/centos7.2:v1
#defaultImageName: centos7.2
#dockerhostPort: __BK_CI_DOCKERHOST_API_PORT__
agentLessRegistryUrl: __BK_CI_AGENTLESS_IMAGE_REGISTRY_URL__
agentLessImageName: __BK_CI_AGENTLESS_IMAGE_NAME__
agentLessRegistryUserName: __BK_CI_AGENTLESS_IMAGE_REGISTRY_USER__
agentLessRegistryPassword: __BK_CI_AGENTLESS_IMAGE_REGISTRY_PASSWORD__
jobQuota:
systemAlertReceiver:
enable: false
Expand Down

0 comments on commit 15c8be1

Please sign in to comment.