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

bug:公共构建机的插件缓存目录挪到工作空间的上一级目录 #9640 #9641

Merged
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