From 0f7bd07fcf82a8665350eecbd33567e65f8a2500 Mon Sep 17 00:00:00 2001 From: yaoxuwan Date: Fri, 19 Jul 2024 12:11:24 +0800 Subject: [PATCH 1/2] =?UTF-8?q?bug:=20=E5=BD=92=E6=A1=A3=E6=8A=A5=E5=91=8A?= =?UTF-8?q?=E6=8F=92=E4=BB=B6=E5=88=9B=E5=BB=BAtoken=E6=B2=A1=E6=9C=89?= =?UTF-8?q?=E5=AE=9E=E7=8E=B0=20#10693?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../agent/service/SampleRepoServiceImpl.kt | 46 --------------- .../src/main/resources/.agent.properties | 1 - .../common/api/archive/ArchiveResourceApi.kt | 12 ++++ .../api/archive/BkRepoArchiveResourceApi.kt | 26 +++++++++ .../api/report/BkRepoReportResourceApi.kt | 26 +++++++++ .../common/api/report/ReportResourceApi.kt | 12 ++++ .../task/archive/BuildArchiveGetTask.kt | 3 +- .../task/archive/CustomizeArchiveGetTask.kt | 3 +- .../worker/task/archive/ReportArchiveTask.kt | 5 +- .../task/archive/SingleFileArchiveTask.kt | 7 ++- .../common/api/archive/ArchiveSDKApi.kt | 13 +++++ .../worker/common/api/report/ReportSDKApi.kt | 13 +++++ .../worker/common/logger/LoggerService.kt | 5 +- .../worker/common/service/RepoService.kt | 45 --------------- .../common/service/RepoServiceFactory.kt | 57 ------------------- .../common/task/market/MarketAtomTask.kt | 6 +- .../worker/common/task/script/ScriptTask.kt | 5 +- 17 files changed, 121 insertions(+), 164 deletions(-) delete mode 100644 src/backend/ci/core/worker/worker-agent/src/main/kotlin/com/tencent/devops/agent/service/SampleRepoServiceImpl.kt delete mode 100644 src/backend/ci/core/worker/worker-common/src/main/kotlin/com/tencent/devops/worker/common/service/RepoService.kt delete mode 100644 src/backend/ci/core/worker/worker-common/src/main/kotlin/com/tencent/devops/worker/common/service/RepoServiceFactory.kt diff --git a/src/backend/ci/core/worker/worker-agent/src/main/kotlin/com/tencent/devops/agent/service/SampleRepoServiceImpl.kt b/src/backend/ci/core/worker/worker-agent/src/main/kotlin/com/tencent/devops/agent/service/SampleRepoServiceImpl.kt deleted file mode 100644 index 1ef3a6fdffc..00000000000 --- a/src/backend/ci/core/worker/worker-agent/src/main/kotlin/com/tencent/devops/agent/service/SampleRepoServiceImpl.kt +++ /dev/null @@ -1,46 +0,0 @@ -/* - * 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. - */ - -package com.tencent.devops.agent.service - -import com.tencent.bkrepo.repository.pojo.token.TokenType -import com.tencent.devops.worker.common.service.RepoService - -class SampleRepoServiceImpl : RepoService { - - override fun getRepoToken( - userId: String, - projectId: String, - repoName: String, - path: String, - type: TokenType, - expireSeconds: Long? - ): String? { - // 开源版暂不支持用token去上传或下载 - return null - } -} diff --git a/src/backend/ci/core/worker/worker-agent/src/main/resources/.agent.properties b/src/backend/ci/core/worker/worker-agent/src/main/resources/.agent.properties index 24343bffb64..7e156ac392d 100644 --- a/src/backend/ci/core/worker/worker-agent/src/main/resources/.agent.properties +++ b/src/backend/ci/core/worker/worker-agent/src/main/resources/.agent.properties @@ -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 diff --git a/src/backend/ci/core/worker/worker-api-sdk/src/main/kotlin/com/tencent/devops/worker/common/api/archive/ArchiveResourceApi.kt b/src/backend/ci/core/worker/worker-api-sdk/src/main/kotlin/com/tencent/devops/worker/common/api/archive/ArchiveResourceApi.kt index e43e22d865b..1d7320adb55 100644 --- a/src/backend/ci/core/worker/worker-api-sdk/src/main/kotlin/com/tencent/devops/worker/common/api/archive/ArchiveResourceApi.kt +++ b/src/backend/ci/core/worker/worker-api-sdk/src/main/kotlin/com/tencent/devops/worker/common/api/archive/ArchiveResourceApi.kt @@ -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 @@ -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 + } } diff --git a/src/backend/ci/core/worker/worker-api-sdk/src/main/kotlin/com/tencent/devops/worker/common/api/archive/BkRepoArchiveResourceApi.kt b/src/backend/ci/core/worker/worker-api-sdk/src/main/kotlin/com/tencent/devops/worker/common/api/archive/BkRepoArchiveResourceApi.kt index 4913a680f9a..6f8b3728618 100644 --- a/src/backend/ci/core/worker/worker-api-sdk/src/main/kotlin/com/tencent/devops/worker/common/api/archive/BkRepoArchiveResourceApi.kt +++ b/src/backend/ci/core/worker/worker-api-sdk/src/main/kotlin/com/tencent/devops/worker/common/api/archive/BkRepoArchiveResourceApi.kt @@ -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 @@ -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 @@ -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 + } + } } diff --git a/src/backend/ci/core/worker/worker-api-sdk/src/main/kotlin/com/tencent/devops/worker/common/api/report/BkRepoReportResourceApi.kt b/src/backend/ci/core/worker/worker-api-sdk/src/main/kotlin/com/tencent/devops/worker/common/api/report/BkRepoReportResourceApi.kt index d63bcc28774..4e794f8c5bf 100644 --- a/src/backend/ci/core/worker/worker-api-sdk/src/main/kotlin/com/tencent/devops/worker/common/api/report/BkRepoReportResourceApi.kt +++ b/src/backend/ci/core/worker/worker-api-sdk/src/main/kotlin/com/tencent/devops/worker/common/api/report/BkRepoReportResourceApi.kt @@ -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 @@ -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 + } + } } diff --git a/src/backend/ci/core/worker/worker-api-sdk/src/main/kotlin/com/tencent/devops/worker/common/api/report/ReportResourceApi.kt b/src/backend/ci/core/worker/worker-api-sdk/src/main/kotlin/com/tencent/devops/worker/common/api/report/ReportResourceApi.kt index e630cfc4967..eed76bb621a 100644 --- a/src/backend/ci/core/worker/worker-api-sdk/src/main/kotlin/com/tencent/devops/worker/common/api/report/ReportResourceApi.kt +++ b/src/backend/ci/core/worker/worker-api-sdk/src/main/kotlin/com/tencent/devops/worker/common/api/report/ReportResourceApi.kt @@ -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 @@ -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) } diff --git a/src/backend/ci/core/worker/worker-common/src/main/kotlin/com/tencent/devops/plugin/worker/task/archive/BuildArchiveGetTask.kt b/src/backend/ci/core/worker/worker-common/src/main/kotlin/com/tencent/devops/plugin/worker/task/archive/BuildArchiveGetTask.kt index 21789e2b2c2..53e20d56fc1 100644 --- a/src/backend/ci/core/worker/worker-common/src/main/kotlin/com/tencent/devops/plugin/worker/task/archive/BuildArchiveGetTask.kt +++ b/src/backend/ci/core/worker/worker-common/src/main/kotlin/com/tencent/devops/plugin/worker/task/archive/BuildArchiveGetTask.kt @@ -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 @@ -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", diff --git a/src/backend/ci/core/worker/worker-common/src/main/kotlin/com/tencent/devops/plugin/worker/task/archive/CustomizeArchiveGetTask.kt b/src/backend/ci/core/worker/worker-common/src/main/kotlin/com/tencent/devops/plugin/worker/task/archive/CustomizeArchiveGetTask.kt index a6bb7053d0c..79c14fc491d 100644 --- a/src/backend/ci/core/worker/worker-common/src/main/kotlin/com/tencent/devops/plugin/worker/task/archive/CustomizeArchiveGetTask.kt +++ b/src/backend/ci/core/worker/worker-common/src/main/kotlin/com/tencent/devops/plugin/worker/task/archive/CustomizeArchiveGetTask.kt @@ -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 @@ -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", diff --git a/src/backend/ci/core/worker/worker-common/src/main/kotlin/com/tencent/devops/plugin/worker/task/archive/ReportArchiveTask.kt b/src/backend/ci/core/worker/worker-common/src/main/kotlin/com/tencent/devops/plugin/worker/task/archive/ReportArchiveTask.kt index 8ca1d186a5c..591c304d499 100644 --- a/src/backend/ci/core/worker/worker-common/src/main/kotlin/com/tencent/devops/plugin/worker/task/archive/ReportArchiveTask.kt +++ b/src/backend/ci/core/worker/worker-common/src/main/kotlin/com/tencent/devops/plugin/worker/task/archive/ReportArchiveTask.kt @@ -50,10 +50,10 @@ 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 @@ -61,7 +61,6 @@ 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() { @@ -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", diff --git a/src/backend/ci/core/worker/worker-common/src/main/kotlin/com/tencent/devops/plugin/worker/task/archive/SingleFileArchiveTask.kt b/src/backend/ci/core/worker/worker-common/src/main/kotlin/com/tencent/devops/plugin/worker/task/archive/SingleFileArchiveTask.kt index e222f0e457c..6b2b6eda434 100644 --- a/src/backend/ci/core/worker/worker-common/src/main/kotlin/com/tencent/devops/plugin/worker/task/archive/SingleFileArchiveTask.kt +++ b/src/backend/ci/core/worker/worker-common/src/main/kotlin/com/tencent/devops/plugin/worker/task/archive/SingleFileArchiveTask.kt @@ -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 @@ -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", diff --git a/src/backend/ci/core/worker/worker-common/src/main/kotlin/com/tencent/devops/worker/common/api/archive/ArchiveSDKApi.kt b/src/backend/ci/core/worker/worker-common/src/main/kotlin/com/tencent/devops/worker/common/api/archive/ArchiveSDKApi.kt index e97a82dc0ab..7c1cf620f5e 100644 --- a/src/backend/ci/core/worker/worker-common/src/main/kotlin/com/tencent/devops/worker/common/api/archive/ArchiveSDKApi.kt +++ b/src/backend/ci/core/worker/worker-common/src/main/kotlin/com/tencent/devops/worker/common/api/archive/ArchiveSDKApi.kt @@ -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 @@ -134,4 +135,16 @@ interface ArchiveSDKApi : WorkerRestApiSDK { headers: Map? = emptyMap(), isVmBuildEnv: Boolean? = null ): Result + + /** + * 获取仓库token + */ + fun getRepoToken( + userId: String, + projectId: String, + repoName: String, + path: String, + type: TokenType, + expireSeconds: Long + ): String? } diff --git a/src/backend/ci/core/worker/worker-common/src/main/kotlin/com/tencent/devops/worker/common/api/report/ReportSDKApi.kt b/src/backend/ci/core/worker/worker-common/src/main/kotlin/com/tencent/devops/worker/common/api/report/ReportSDKApi.kt index be461a6db16..db63f1e4bc6 100644 --- a/src/backend/ci/core/worker/worker-common/src/main/kotlin/com/tencent/devops/worker/common/api/report/ReportSDKApi.kt +++ b/src/backend/ci/core/worker/worker-common/src/main/kotlin/com/tencent/devops/worker/common/api/report/ReportSDKApi.kt @@ -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 @@ -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? } diff --git a/src/backend/ci/core/worker/worker-common/src/main/kotlin/com/tencent/devops/worker/common/logger/LoggerService.kt b/src/backend/ci/core/worker/worker-common/src/main/kotlin/com/tencent/devops/worker/common/logger/LoggerService.kt index a7094dee87b..53f19da1188 100644 --- a/src/backend/ci/core/worker/worker-common/src/main/kotlin/com/tencent/devops/worker/common/logger/LoggerService.kt +++ b/src/backend/ci/core/worker/worker-common/src/main/kotlin/com/tencent/devops/worker/common/logger/LoggerService.kt @@ -46,9 +46,9 @@ import com.tencent.devops.worker.common.LOG_SUBTAG_FLAG import com.tencent.devops.worker.common.LOG_TASK_LINE_LIMIT import com.tencent.devops.worker.common.LOG_WARN_FLAG import com.tencent.devops.worker.common.api.ApiFactory +import com.tencent.devops.worker.common.api.archive.ArchiveSDKApi import com.tencent.devops.worker.common.api.log.LogSDKApi import com.tencent.devops.worker.common.env.AgentEnv -import com.tencent.devops.worker.common.service.RepoServiceFactory import com.tencent.devops.worker.common.service.SensitiveValueService import com.tencent.devops.worker.common.utils.ArchiveUtils import com.tencent.devops.worker.common.utils.FileUtils @@ -72,6 +72,7 @@ import java.util.concurrent.locks.ReentrantLock object LoggerService { private val logResourceApi = ApiFactory.create(LogSDKApi::class) + private val archiveApi = ApiFactory.create(ArchiveSDKApi::class) private val logger = LoggerFactory.getLogger(LoggerService::class.java) private var future: Future? = null private val running = AtomicBoolean(true) @@ -357,7 +358,7 @@ object LoggerService { logger.info("Start to archive log files with LogMode[${AgentEnv.getLogMode()}]") try { val expireSeconds = buildVariables!!.timeoutMills / 1000 - val token = RepoServiceFactory.getInstance().getRepoToken( + val token = archiveApi.getRepoToken( userId = buildVariables!!.variables[PIPELINE_START_USER_ID] ?: "", projectId = buildVariables!!.projectId, repoName = "log", diff --git a/src/backend/ci/core/worker/worker-common/src/main/kotlin/com/tencent/devops/worker/common/service/RepoService.kt b/src/backend/ci/core/worker/worker-common/src/main/kotlin/com/tencent/devops/worker/common/service/RepoService.kt deleted file mode 100644 index 1e0fa873f91..00000000000 --- a/src/backend/ci/core/worker/worker-common/src/main/kotlin/com/tencent/devops/worker/common/service/RepoService.kt +++ /dev/null @@ -1,45 +0,0 @@ -/* - * 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. - */ - -package com.tencent.devops.worker.common.service - -import com.tencent.bkrepo.repository.pojo.token.TokenType - -interface RepoService { - - /** - * 获取仓库token - */ - fun getRepoToken( - userId: String, - projectId: String, - repoName: String, - path: String, - type: TokenType, - expireSeconds: Long? - ): String? -} diff --git a/src/backend/ci/core/worker/worker-common/src/main/kotlin/com/tencent/devops/worker/common/service/RepoServiceFactory.kt b/src/backend/ci/core/worker/worker-common/src/main/kotlin/com/tencent/devops/worker/common/service/RepoServiceFactory.kt deleted file mode 100644 index bea24d3980c..00000000000 --- a/src/backend/ci/core/worker/worker-common/src/main/kotlin/com/tencent/devops/worker/common/service/RepoServiceFactory.kt +++ /dev/null @@ -1,57 +0,0 @@ -/* - * 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. - */ - -package com.tencent.devops.worker.common.service - -import com.tencent.devops.common.api.util.PropertyUtil -import java.util.concurrent.ConcurrentHashMap - -object RepoServiceFactory { - - private val repoServiceMap = ConcurrentHashMap() - - private const val REPO_CLASS_NAME = "repo.class.name" - - private const val AGENT_PROPERTIES_FILE_NAME = "/.agent.properties" - - /** - * 根据配置文件的类名获取实现RepoService的对象 - * @return 实现RepoService的对象 - */ - fun getInstance(): RepoService { - // 从配置文件读取类名 - val className = PropertyUtil.getPropertyValue(REPO_CLASS_NAME, AGENT_PROPERTIES_FILE_NAME) - // 根据类名从缓存中获取实现RepoService的对象 - var repoService = repoServiceMap[className] - if (repoService == null) { - // 通过反射生成对象并放入缓存中 - repoService = Class.forName(className).newInstance() as RepoService - repoServiceMap[className] = repoService - } - return repoService - } -} diff --git a/src/backend/ci/core/worker/worker-common/src/main/kotlin/com/tencent/devops/worker/common/task/market/MarketAtomTask.kt b/src/backend/ci/core/worker/worker-common/src/main/kotlin/com/tencent/devops/worker/common/task/market/MarketAtomTask.kt index 7ef895e6092..0e6a251b0bf 100644 --- a/src/backend/ci/core/worker/worker-common/src/main/kotlin/com/tencent/devops/worker/common/task/market/MarketAtomTask.kt +++ b/src/backend/ci/core/worker/worker-common/src/main/kotlin/com/tencent/devops/worker/common/task/market/MarketAtomTask.kt @@ -82,6 +82,7 @@ import com.tencent.devops.worker.common.PIPELINE_SCRIPT_ATOM_CODE import com.tencent.devops.worker.common.WORKSPACE_CONTEXT import com.tencent.devops.worker.common.WORKSPACE_ENV import com.tencent.devops.worker.common.api.ApiFactory +import com.tencent.devops.worker.common.api.archive.ArchiveSDKApi import com.tencent.devops.worker.common.api.archive.ArtifactoryBuildResourceApi import com.tencent.devops.worker.common.api.atom.AtomArchiveSDKApi import com.tencent.devops.worker.common.api.atom.StoreSdkApi @@ -95,7 +96,6 @@ import com.tencent.devops.worker.common.env.BuildType import com.tencent.devops.worker.common.expression.SpecialFunctions import com.tencent.devops.worker.common.logger.LoggerService import com.tencent.devops.worker.common.service.CIKeywordsService -import com.tencent.devops.worker.common.service.RepoServiceFactory import com.tencent.devops.worker.common.task.ITask import com.tencent.devops.worker.common.task.TaskFactory import com.tencent.devops.worker.common.utils.ArchiveUtils @@ -121,6 +121,8 @@ open class MarketAtomTask : ITask() { private val storeApi = ApiFactory.create(StoreSdkApi::class) + private val archiveApi = ApiFactory.create(ArchiveSDKApi::class) + private val outputFile = "output.json" private val inputFile = "input.json" @@ -878,7 +880,7 @@ open class MarketAtomTask : ITask() { var oneArtifact = "" val artifactoryType = (output[ARTIFACTORY_TYPE] as? String) ?: ArtifactoryType.PIPELINE.name val customFlag = artifactoryType == ArtifactoryType.CUSTOM_DIR.name - val token = RepoServiceFactory.getInstance().getRepoToken( + val token = archiveApi.getRepoToken( userId = buildVariables.variables[PIPELINE_START_USER_ID] ?: "", projectId = buildVariables.projectId, repoName = if (customFlag) "custom" else "pipeline", diff --git a/src/backend/ci/core/worker/worker-common/src/main/kotlin/com/tencent/devops/worker/common/task/script/ScriptTask.kt b/src/backend/ci/core/worker/worker-common/src/main/kotlin/com/tencent/devops/worker/common/task/script/ScriptTask.kt index 94658c1d05a..e24f5fe3c51 100644 --- a/src/backend/ci/core/worker/worker-common/src/main/kotlin/com/tencent/devops/worker/common/task/script/ScriptTask.kt +++ b/src/backend/ci/core/worker/worker-common/src/main/kotlin/com/tencent/devops/worker/common/task/script/ScriptTask.kt @@ -40,12 +40,12 @@ import com.tencent.devops.process.pojo.BuildVariables import com.tencent.devops.process.utils.PIPELINE_START_USER_ID import com.tencent.devops.store.pojo.app.BuildEnv import com.tencent.devops.worker.common.api.ApiFactory +import com.tencent.devops.worker.common.api.archive.ArchiveSDKApi import com.tencent.devops.worker.common.api.quality.QualityGatewaySDKApi import com.tencent.devops.worker.common.constants.WorkerMessageCode.BK_NO_FILES_TO_ARCHIVE import com.tencent.devops.worker.common.constants.WorkerMessageCode.SCRIPT_EXECUTION_FAIL 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.script.bat.WindowsScriptTask import com.tencent.devops.worker.common.utils.ArchiveUtils @@ -62,6 +62,7 @@ import java.net.URLDecoder open class ScriptTask : ITask() { private val gatewayResourceApi = ApiFactory.create(QualityGatewaySDKApi::class) + private val archiveApi = ApiFactory.create(ArchiveSDKApi::class) override fun execute(buildTask: BuildTask, buildVariables: BuildVariables, workspace: File) { val taskParams = buildTask.params ?: mapOf() @@ -130,7 +131,7 @@ open class ScriptTask : ITask() { arrayOf(archiveFileIfExecFail) ) ) - val token = RepoServiceFactory.getInstance().getRepoToken( + val token = archiveApi.getRepoToken( userId = buildVariables.variables[PIPELINE_START_USER_ID] ?: "", projectId = buildVariables.projectId, repoName = "pipeline", From 1af0bd7aac1112bd2868d30eb78d5f983330e679 Mon Sep 17 00:00:00 2001 From: irwinsun Date: Tue, 10 Sep 2024 16:52:21 +0800 Subject: [PATCH 2/2] build(deps): bump actions/upload-artifact in /.github/workflows https://github.blog/changelog/2024-02-13-deprecation-notice-v1-and-v2-of-the-artifact-actions/ (cherry picked from commit 29bd59b5f71f0b5961e9b6c8e83e26d68b35a353) --- .github/workflows/agent.yml | 2 +- .github/workflows/backend.yml | 4 ++-- .github/workflows/frontend.yml | 2 +- .github/workflows/release.yml | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/agent.yml b/.github/workflows/agent.yml index a4c00272fbe..db418975aff 100644 --- a/.github/workflows/agent.yml +++ b/.github/workflows/agent.yml @@ -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 diff --git a/.github/workflows/backend.yml b/.github/workflows/backend.yml index 69af7fdec74..91014b65291 100644 --- a/.github/workflows/backend.yml +++ b/.github/workflows/backend.yml @@ -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 @@ -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 diff --git a/.github/workflows/frontend.yml b/.github/workflows/frontend.yml index cdc0aa42843..6641641c8e3 100644 --- a/.github/workflows/frontend.yml +++ b/.github/workflows/frontend.yml @@ -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 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index db4b0eb2eeb..2c7751b7cb1 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -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 @@ -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