Skip to content

Commit

Permalink
Merge pull request #11080 from yaoxuwan/issue_10693_new
Browse files Browse the repository at this point in the history
bug: 归档报告插件创建token没有实现 #10693
  • Loading branch information
mingshewhe authored Oct 16, 2024
2 parents 5b8e53d + 1af0bd7 commit d79bc64
Show file tree
Hide file tree
Showing 21 changed files with 127 additions and 170 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/agent.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
key: ${{ runner.os }}-go-${{ hashFiles('src/agent/agent/go.sum') }}
- run: make BUILD_OUT_TAG=out clean all
working-directory: src/agent/agent/
- uses: actions/upload-artifact@v3
- uses: actions/upload-artifact@v4
if: ${{ inputs.upload == 'true' }}
with:
name: agent
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/backend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ jobs:
run: |
./gradlew clean test build :core:worker:worker-agent:shadowJar \
-DmysqlURL=127.0.0.1:${{ job.services.mysql.ports['3306'] }} -DmysqlUser=root -DmysqlPasswd=root --no-daemon
- uses: actions/upload-artifact@v1
- uses: actions/upload-artifact@v4
if: ${{ inputs.upload == 'true' }}
with:
name: backend-jar
Expand Down Expand Up @@ -95,7 +95,7 @@ jobs:
run: |
./gradlew clean test build :core:worker:worker-agent:shadowJar -Ddevops.assemblyMode=KUBERNETES \
-DmysqlURL=127.0.0.1:${{ job.services.mysql.ports['3306'] }} -DmysqlUser=root -DmysqlPasswd=root --no-daemon
- uses: actions/upload-artifact@v1
- uses: actions/upload-artifact@v4
if: ${{ inputs.upload == 'true' }}
with:
name: backend-docker
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/frontend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
export NODE_OPTIONS=--openssl-legacy-provider
yarn public
working-directory: src/frontend
- uses: actions/upload-artifact@v3
- uses: actions/upload-artifact@v4
if: ${{ inputs.upload == 'true' }}
with:
name: frontend
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ jobs:
version="$(basename $GITHUB_REF)"
echo "version=$version" >> $GITHUB_OUTPUT
ci_ms_wip="sign,monitoring" ci_pkg_dir=/dev/shm/ci ./scripts/packager-ci.sh "$version" bkci-slim.tar.gz
- uses: actions/upload-artifact@v1
- uses: actions/upload-artifact@v4
with:
name: bkci-slim
path: bkci-slim.tar.gz
Expand Down Expand Up @@ -120,7 +120,7 @@ jobs:
version="$(basename $GITHUB_REF)"
helm package . --version $version --app-version $version
mv bk-ci-$version.tgz bk-ci-charts.tgz
- uses: actions/upload-artifact@v1
- uses: actions/upload-artifact@v4
with:
name: bkci-chart
path: helm-charts/core/ci/bk-ci-charts.tgz
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,5 @@ landun.gateway=##gateWay##
devops.parallel.task.count=4
landun.env=##landun.env##
agentCollectorOn=##agentCollectorOn##
repo.class.name=com.tencent.devops.agent.service.SampleRepoServiceImpl
devops.public.host.maxFileCacheSize=209715200
devops.public.third.maxFileCacheSize=2147483648
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ package com.tencent.devops.worker.common.api.archive

import com.fasterxml.jackson.module.kotlin.readValue
import com.google.gson.JsonParser
import com.tencent.bkrepo.repository.pojo.token.TokenType
import com.tencent.devops.artifactory.constant.REALM_LOCAL
import com.tencent.devops.artifactory.pojo.GetFileDownloadUrlsResponse
import com.tencent.devops.artifactory.pojo.enums.FileTypeEnum
Expand Down Expand Up @@ -207,4 +208,15 @@ class ArchiveResourceApi : AbstractBuildResourceApi(), ArchiveSDKApi {
val responseContent = request(request, "upload file:$fileName fail")
return objectMapper.readValue(responseContent)
}

override fun getRepoToken(
userId: String,
projectId: String,
repoName: String,
path: String,
type: TokenType,
expireSeconds: Long
): String? {
return null
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ package com.tencent.devops.worker.common.api.archive

import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
import com.fasterxml.jackson.module.kotlin.readValue
import com.tencent.bkrepo.repository.pojo.token.TokenType
import com.tencent.devops.artifactory.constant.REALM_BK_REPO
import com.tencent.devops.artifactory.pojo.enums.FileTypeEnum
import com.tencent.devops.common.api.exception.RemoteServiceException
Expand All @@ -37,6 +38,7 @@ import com.tencent.devops.common.api.pojo.ErrorCode
import com.tencent.devops.common.api.pojo.ErrorType
import com.tencent.devops.common.api.pojo.Result
import com.tencent.devops.common.api.util.MessageUtil
import com.tencent.devops.common.util.HttpRetryUtils
import com.tencent.devops.process.pojo.BuildVariables
import com.tencent.devops.worker.common.api.AbstractBuildResourceApi
import com.tencent.devops.worker.common.api.ApiPriority
Expand Down Expand Up @@ -308,4 +310,28 @@ class BkRepoArchiveResourceApi : AbstractBuildResourceApi(), ArchiveSDKApi {
val responseContent = request(request, "upload file[$fileName] failed")
return objectMapper.readValue(responseContent)
}

override fun getRepoToken(
userId: String,
projectId: String,
repoName: String,
path: String,
type: TokenType,
expireSeconds: Long
): String? {
return if (bkrepoResourceApi.tokenAccess()) {
HttpRetryUtils.retry(retryTime = 3, retryPeriodMills = 1000) {
bkrepoResourceApi.createBkRepoTemporaryToken(
userId = userId,
projectId = projectId,
repoName = repoName,
path = path,
type = type,
expireSeconds = expireSeconds
)
}
} else {
null
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@
package com.tencent.devops.worker.common.api.report

import com.fasterxml.jackson.module.kotlin.readValue
import com.tencent.bkrepo.repository.pojo.token.TokenType
import com.tencent.devops.artifactory.constant.REALM_BK_REPO
import com.tencent.devops.common.api.exception.RemoteServiceException
import com.tencent.devops.common.api.pojo.Result
import com.tencent.devops.common.api.util.MessageUtil
import com.tencent.devops.common.util.HttpRetryUtils
import com.tencent.devops.process.pojo.BuildVariables
import com.tencent.devops.process.pojo.report.ReportEmail
import com.tencent.devops.process.pojo.report.enums.ReportTypeEnum
Expand Down Expand Up @@ -197,4 +199,28 @@ class BkRepoReportResourceApi : AbstractBuildResourceApi(), ReportSDKApi {
}
bkrepoResourceApi.setPipelineMetadata("report", buildVariables)
}

override fun getRepoToken(
userId: String,
projectId: String,
repoName: String,
path: String,
type: TokenType,
expireSeconds: Long
): String? {
return if (bkrepoResourceApi.tokenAccess()) {
HttpRetryUtils.retry(retryTime = 3, retryPeriodMills = 1000) {
bkrepoResourceApi.createBkRepoTemporaryToken(
userId = userId,
projectId = projectId,
repoName = repoName,
path = path,
type = type,
expireSeconds = expireSeconds
)
}
} else {
null
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ package com.tencent.devops.worker.common.api.report

import com.fasterxml.jackson.module.kotlin.readValue
import com.google.gson.JsonParser
import com.tencent.bkrepo.repository.pojo.token.TokenType
import com.tencent.devops.artifactory.constant.REALM_LOCAL
import com.tencent.devops.artifactory.pojo.enums.FileTypeEnum
import com.tencent.devops.common.api.exception.RemoteServiceException
Expand Down Expand Up @@ -134,6 +135,17 @@ class ReportResourceApi : AbstractBuildResourceApi(), ReportSDKApi {
return objectMapper.readValue(responseContent)
}

override fun getRepoToken(
userId: String,
projectId: String,
repoName: String,
path: String,
type: TokenType,
expireSeconds: Long
): String? {
return null
}

companion object {
private val logger = LoggerFactory.getLogger(ReportResourceApi::class.java)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ import com.tencent.devops.worker.common.api.ArtifactApiFactory
import com.tencent.devops.worker.common.api.archive.ArchiveSDKApi
import com.tencent.devops.worker.common.api.process.BuildSDKApi
import com.tencent.devops.worker.common.logger.LoggerService
import com.tencent.devops.worker.common.service.RepoServiceFactory
import com.tencent.devops.worker.common.task.ITask
import com.tencent.devops.worker.common.task.TaskClassType
import com.tencent.devops.worker.common.utils.TaskUtil
Expand Down Expand Up @@ -104,7 +103,7 @@ class BuildArchiveGetTask : ITask() {
count = files.size
LoggerService.addNormalLine("total $count file(s) found")
files.forEachIndexed { index, (fileUrl, file) ->
val token = RepoServiceFactory.getInstance().getRepoToken(
val token = archiveGetResourceApi.getRepoToken(
userId = buildVariables.variables[PIPELINE_START_USER_ID] ?: "",
projectId = buildVariables.projectId,
repoName = "pipeline",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ import com.tencent.devops.process.utils.PIPELINE_START_USER_ID
import com.tencent.devops.worker.common.api.ArtifactApiFactory
import com.tencent.devops.worker.common.api.archive.ArchiveSDKApi
import com.tencent.devops.worker.common.logger.LoggerService
import com.tencent.devops.worker.common.service.RepoServiceFactory
import com.tencent.devops.worker.common.task.ITask
import com.tencent.devops.worker.common.task.TaskClassType
import com.tencent.devops.worker.common.utils.TaskUtil
Expand Down Expand Up @@ -92,7 +91,7 @@ class CustomizeArchiveGetTask : ITask() {
count = files.size
LoggerService.addNormalLine("total $count file(s) found")
files.forEachIndexed { index, (fileUrl, file) ->
val token = RepoServiceFactory.getInstance().getRepoToken(
val token = archiveGetResourceApi.getRepoToken(
userId = buildVariables.variables[PIPELINE_START_USER_ID] ?: "",
projectId = buildVariables.projectId,
repoName = "custom",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,17 @@ import com.tencent.devops.worker.common.constants.WorkerMessageCode.FOLDER_NOT_E
import com.tencent.devops.worker.common.constants.WorkerMessageCode.UPLOAD_CUSTOM_OUTPUT_SUCCESS
import com.tencent.devops.worker.common.env.AgentEnv
import com.tencent.devops.worker.common.logger.LoggerService
import com.tencent.devops.worker.common.service.RepoServiceFactory
import com.tencent.devops.worker.common.task.ITask
import com.tencent.devops.worker.common.task.TaskClassType
import com.tencent.devops.worker.common.utils.TaskUtil
import org.slf4j.LoggerFactory
import java.io.File
import java.nio.file.Path
import java.nio.file.Paths
import java.util.concurrent.Executors
import java.util.concurrent.TimeUnit
import java.util.concurrent.TimeoutException
import java.util.regex.Pattern
import org.slf4j.LoggerFactory

@TaskClassType(classTypes = [ReportArchiveElement.classType])
class ReportArchiveTask : ITask() {
Expand All @@ -81,7 +80,7 @@ class ReportArchiveTask : ITask() {
val reportType = taskParams["reportType"] ?: ReportTypeEnum.INTERNAL.name
val indexFileParam: String
var indexFileContent: String
val token = RepoServiceFactory.getInstance().getRepoToken(
val token = api.getRepoToken(
userId = buildVariables.variables[PIPELINE_START_USER_ID] ?: "",
projectId = buildVariables.projectId,
repoName = "report",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,10 @@ import com.tencent.devops.common.archive.element.SingleArchiveElement
import com.tencent.devops.process.pojo.BuildTask
import com.tencent.devops.process.pojo.BuildVariables
import com.tencent.devops.process.utils.PIPELINE_START_USER_ID
import com.tencent.devops.worker.common.api.ArtifactApiFactory
import com.tencent.devops.worker.common.api.archive.ArchiveSDKApi
import com.tencent.devops.worker.common.constants.WorkerMessageCode.NO_MATCHING_ARCHIVE_FILE
import com.tencent.devops.worker.common.env.AgentEnv
import com.tencent.devops.worker.common.service.RepoServiceFactory
import com.tencent.devops.worker.common.task.ITask
import com.tencent.devops.worker.common.task.TaskClassType
import com.tencent.devops.worker.common.utils.ArchiveUtils.archiveCustomFiles
Expand All @@ -50,12 +51,14 @@ import java.io.File
@TaskClassType(classTypes = [SingleArchiveElement.classType])
class SingleFileArchiveTask : ITask() {

private val api = ArtifactApiFactory.create(ArchiveSDKApi::class)

override fun execute(buildTask: BuildTask, buildVariables: BuildVariables, workspace: File) {
val taskParams = buildTask.params ?: mapOf()
val filePath = taskParams["filePath"] ?: throw ParamBlankException("param [filePath] is empty")
val isCustomize = taskParams["customize"] ?: throw ParamBlankException("param [isCustomize] is empty")
TaskUtil.setTaskId(buildTask.taskId ?: "")
val token = RepoServiceFactory.getInstance().getRepoToken(
val token = api.getRepoToken(
userId = buildVariables.variables[PIPELINE_START_USER_ID] ?: "",
projectId = buildVariables.projectId,
repoName = if (isCustomize.toBoolean()) "custom" else "pipeline",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

package com.tencent.devops.worker.common.api.archive

import com.tencent.bkrepo.repository.pojo.token.TokenType
import com.tencent.devops.artifactory.pojo.enums.FileTypeEnum
import com.tencent.devops.common.api.pojo.Result
import com.tencent.devops.process.pojo.BuildVariables
Expand Down Expand Up @@ -134,4 +135,16 @@ interface ArchiveSDKApi : WorkerRestApiSDK {
headers: Map<String, String>? = emptyMap(),
isVmBuildEnv: Boolean? = null
): Result<Boolean>

/**
* 获取仓库token
*/
fun getRepoToken(
userId: String,
projectId: String,
repoName: String,
path: String,
type: TokenType,
expireSeconds: Long
): String?
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

package com.tencent.devops.worker.common.api.report

import com.tencent.bkrepo.repository.pojo.token.TokenType
import com.tencent.devops.common.api.pojo.Result
import com.tencent.devops.process.pojo.BuildVariables
import com.tencent.devops.process.pojo.report.ReportEmail
Expand Down Expand Up @@ -75,4 +76,16 @@ interface ReportSDKApi : WorkerRestApiSDK {
buildVariables: BuildVariables,
token: String? = null
)

/**
* 获取仓库token
*/
fun getRepoToken(
userId: String,
projectId: String,
repoName: String,
path: String,
type: TokenType,
expireSeconds: Long
): String?
}
Loading

0 comments on commit d79bc64

Please sign in to comment.