Skip to content

Commit

Permalink
Merge pull request #9641 from carlyin0801/issue_9640_atom_cache_dir_fix
Browse files Browse the repository at this point in the history
bug:公共构建机的插件缓存目录挪到工作空间的上一级目录 #9640
  • Loading branch information
bkci-bot authored Nov 13, 2023
2 parents 5848e29 + b90ebac commit 2cb1c3f
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ class BkDiskLruFileCache(
val snapshot = diskCache[ShaUtils.sha256(key)]
snapshot?.getInputStream(0)?.use { inputStream ->
// 将snapshot对象输出流写入输出文件
if (!outputFile.exists()) {
outputFile.parentFile.mkdirs()
}
FileOutputStream(outputFile).use { outputStream ->
val buffer = ByteArray(BUFFER_SIZE)
var bytesRead: Int
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,25 +115,12 @@ object AgentEnv {
}

fun getEnv(): Env {
if (env == null) {
synchronized(this) {
if (env == null) {
val landunEnv = System.getProperty(AGENT_ENV)
env = if (!landunEnv.isNullOrEmpty()) {
Env.parse(landunEnv)
} else {
// Get it from .agent.property
try {
Env.parse(PropertyUtil.getPropertyValue(AGENT_ENV, "/$AGENT_PROPERTIES_FILE_NAME"))
} catch (t: Throwable) {
logger.warn("Fail to get the agent env, use prod as default", t)
Env.PROD
}
}
}
}
return try {
Env.parse(PropertyUtil.getPropertyValue(AGENT_ENV, "/$AGENT_PROPERTIES_FILE_NAME"))
} catch (t: Throwable) {
logger.warn("Fail to get the agent env, use prod as default", t)
Env.PROD
}
return env!!
}

@Suppress("UNUSED")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,8 @@ open class MarketAtomTask : ITask() {
atomData = atomData,
atomTmpSpace = atomTmpSpace,
workspace = workspace,
projectId = projectId
projectId = projectId,
buildId = buildTask.buildId
)
// 检查插件包的完整性
checkSha1(atomExecuteFile, atomData.shaContent!!)
Expand Down Expand Up @@ -397,7 +398,8 @@ open class MarketAtomTask : ITask() {
atomData: AtomEnv,
atomTmpSpace: File,
workspace: File,
projectId: String
projectId: String,
buildId: String
): File {
// 取插件文件名
val atomFilePath = atomData.pkgPath!!
Expand All @@ -416,8 +418,9 @@ open class MarketAtomTask : ITask() {
// 如果是第三方构建机,插件包缓存放入构建机的公共区域
System.getProperty("user.dir")
} else {
// 如果是公共构建机,插件包缓存放入流水线的工作空间中
workspace.absolutePath
// 如果是公共构建机,插件包缓存放入流水线的工作空间上一级目录中
// 如果workspace路径是相对路径.,workspace.parentFile会为空,故需用file对象包装一下
File(workspace.parentFile, "").absolutePath
}
val fileCacheDir = "$cacheDirPrefix${File.separator}$atomExecuteFileDir"
// 获取构建机缓存文件区域大小
Expand Down Expand Up @@ -447,9 +450,10 @@ open class MarketAtomTask : ITask() {
AtomStatusEnum.TESTING.name,
AtomStatusEnum.CODECCING.name,
AtomStatusEnum.AUDITING.name
)
) && !fileCacheDir.contains(buildId)
) {
// 无需鉴权的插件包且插件包内容是完整的才放入缓存中(未发布的插件版本内容可能会变化故也不存入缓存)
// 无需鉴权的插件包且插件包内容是完整的才放入缓存中
// 未发布的插件版本内容可能会变化故也不存入缓存、工作空间如果以构建ID为维度没法实现资源复用故也不存入缓存
bkDiskLruFileCache.put(fileCacheKey, atomExecuteFile)
}
} else {
Expand Down

0 comments on commit 2cb1c3f

Please sign in to comment.