Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: dockerhost的dockerRun日志统一写入到了StartVMTask,分离开来 #5738 #5739

Merged
merged 1 commit into from
Dec 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ import javax.ws.rs.GET
import javax.ws.rs.POST
import javax.ws.rs.Path
import javax.ws.rs.PathParam
import javax.ws.rs.QueryParam
import javax.ws.rs.Produces
import javax.ws.rs.QueryParam
import javax.ws.rs.core.Context
import javax.ws.rs.core.MediaType

Expand Down Expand Up @@ -129,6 +129,9 @@ interface ServiceDockerHostResource {
@ApiParam(value = "buildId", required = true)
@PathParam("buildId")
buildId: String,
@ApiParam("插件ID", required = false)
@QueryParam("taskId")
pipelineTaskId: String?,
@ApiParam("镜像名称", required = true)
dockerRunParam: DockerRunParam,
@Context request: HttpServletRequest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,13 @@ class ServiceDockerHostResourceImpl @Autowired constructor(
pipelineId: String,
vmSeqId: String,
buildId: String,
pipelineTaskId: String?,
dockerRunParam: DockerRunParam,
request: HttpServletRequest
): Result<DockerRunResponse> {
checkReq(request)
logger.info("[$buildId]|Enter ServiceDockerHostResourceImpl.dockerRun...")
return Result(dockerService.dockerRun(projectId, pipelineId, vmSeqId, buildId, dockerRunParam))
return Result(dockerService.dockerRun(projectId, pipelineId, vmSeqId, buildId, pipelineTaskId, dockerRunParam))
}

override fun getDockerRunLogs(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ class DockerService @Autowired constructor(
pipelineId: String,
vmSeqId: String,
buildId: String,
pipelineTaskId: String?,
dockerRunParam: DockerRunParam
): DockerRunResponse {
logger.info("$buildId|dockerRun|vmSeqId=$vmSeqId|image=${dockerRunParam.imageName}|${dockerRunParam.command}")
Expand Down Expand Up @@ -140,7 +141,8 @@ class DockerService @Autowired constructor(
registryUser = dockerRunParam.registryUser,
registryPwd = dockerRunParam.registryPwd,
dockerRunParam = dockerRunParam,
qpcUniquePath = qpcUniquePath
qpcUniquePath = qpcUniquePath,
pipelineTaskId = pipelineTaskId
)

containerPullImageHandler.setNextHandler(containerCustomizedRunHandler).handlerRequest(containerHandlerContext)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,16 @@

package com.tencent.devops.dockerhost.services

import com.tencent.devops.process.engine.common.VMUtils

open class HandlerContext(
open val projectId: String,
open val pipelineId: String,
open val buildId: String,
open val vmSeqId: Int,
open val poolNo: Int,
open val userName: String
)
open val userName: String,
open val pipelineTaskId: String? = VMUtils.genStartVMTaskId(vmSeqId.toString())
) {
fun taskId(): String = pipelineTaskId?.takeIf { it.isNotBlank() } ?: VMUtils.genStartVMTaskId(vmSeqId.toString())
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ import com.tencent.devops.dockerhost.services.generator.DockerEnvLoader
import com.tencent.devops.dockerhost.services.generator.DockerMountLoader
import com.tencent.devops.dockerhost.utils.CommonUtils
import com.tencent.devops.dockerhost.utils.RandomUtil
import com.tencent.devops.process.engine.common.VMUtils
import org.slf4j.LoggerFactory
import org.springframework.stereotype.Service

Expand Down Expand Up @@ -88,7 +87,7 @@ class ContainerCustomizedRunHandler(
.withWorkingDir(dockerHostConfig.volumeWorkspace)

if (!(dockerRunParam!!.command.isEmpty() || dockerRunParam.command.equals("[]"))) {
createContainerCmd.withCmd(dockerRunParam!!.command)
createContainerCmd.withCmd(dockerRunParam.command)
}

val container = createContainerCmd.exec()
Expand All @@ -107,7 +106,7 @@ class ContainerCustomizedRunHandler(
buildId = buildId,
red = true,
message = "启动构建环境失败,错误信息:${er.message}",
tag = VMUtils.genStartVMTaskId(vmSeqId.toString()),
tag = taskId(),
containerHashId = containerHashId
)
if (er is NotFoundException) {
Expand Down Expand Up @@ -155,7 +154,7 @@ class ContainerCustomizedRunHandler(
throw ContainerException(
errorCodeEnum = ErrorCodeEnum.NO_AVAILABLE_PORT_ERROR,
message = "No enough port to use in dockerRun. " +
"startPort: ${dockerHostConfig.dockerRunStartPort}"
"startPort: ${dockerHostConfig.dockerRunStartPort}"
)
}
val tcpContainerPort: ExposedPort = ExposedPort.tcp(it)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@ data class ContainerHandlerContext(
override val buildId: String,
override val vmSeqId: Int,
override val poolNo: Int,
override val userName: String
override val userName: String,
override val pipelineTaskId: String? = null
) : HandlerContext(
projectId = projectId,
pipelineId = pipelineId,
buildId = buildId,
vmSeqId = vmSeqId,
poolNo = poolNo,
userName = userName
userName = userName,
pipelineTaskId = pipelineTaskId
)
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import com.tencent.devops.dockerhost.exception.ContainerException
import com.tencent.devops.dockerhost.services.Handler
import com.tencent.devops.dockerhost.services.LocalImageCache
import com.tencent.devops.dockerhost.utils.CommonUtils
import com.tencent.devops.process.engine.common.VMUtils
import org.slf4j.LoggerFactory
import org.springframework.stereotype.Service

Expand All @@ -48,7 +47,7 @@ class ContainerPullImageHandler(
override fun handlerRequest(handlerContext: ContainerHandlerContext) {
with(handlerContext) {
formatImageName = CommonUtils.normalizeImageName(originImageName)
val taskId = VMUtils.genStartVMTaskId(vmSeqId.toString())
val taskId = taskId()

try {
LocalImageCache.saveOrUpdate(formatImageName!!)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ import com.tencent.devops.dockerhost.services.generator.DockerEnvLoader
import com.tencent.devops.dockerhost.services.generator.DockerMountLoader
import com.tencent.devops.dockerhost.utils.ENTRY_POINT_CMD
import com.tencent.devops.dockerhost.utils.RandomUtil
import com.tencent.devops.process.engine.common.VMUtils
import org.slf4j.LoggerFactory
import org.springframework.stereotype.Service

Expand Down Expand Up @@ -86,7 +85,7 @@ class ContainerRunHandler(
buildId = buildId,
red = true,
message = "启动构建环境失败,错误信息:${er.message}",
tag = VMUtils.genStartVMTaskId(vmSeqId.toString()),
tag = taskId(),
containerHashId = containerHashId
)
if (er is NotFoundException) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,21 @@ data class ImageHandlerContext(
val outer: Boolean, // 是否为外部请求创建镜像
val scanFlag: Boolean, // 镜像扫描开关
val dockerClient: DockerClient,
val pipelineTaskId: String?,
val dockerBuildParam: DockerBuildParam,
var imageTagSet: MutableSet<String> = mutableSetOf(),
override val projectId: String,
override val pipelineId: String,
override val buildId: String,
override val vmSeqId: Int,
override val poolNo: Int,
override val userName: String
override val userName: String,
override val pipelineTaskId: String?
) : HandlerContext(
projectId = projectId,
pipelineId = pipelineId,
buildId = buildId,
vmSeqId = vmSeqId,
poolNo = poolNo,
userName = userName
userName = userName,
pipelineTaskId = pipelineTaskId
)