Skip to content

Commit 48c6f49

Browse files
authoredFeb 8, 2025··
Merge pull request #11422 from tangruotian/issue_11421
第三方构建机Docker支持JDK17 #11421
2 parents 5effbbc + 0baac6a commit 48c6f49

File tree

1 file changed

+34
-7
lines changed

1 file changed

+34
-7
lines changed
 

‎src/agent/agent/src/pkg/job/build_docker.go

+34-7
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ package job
3030
import (
3131
"context"
3232
"fmt"
33+
"github.com/TencentBlueKing/bk-ci/agent/src/third_components"
3334
"github.com/pkg/errors"
3435
"io"
3536
"os"
@@ -460,17 +461,38 @@ func postLog(red bool, message string, buildInfo *api.ThirdPartyBuildInfo, logTy
460461
}
461462
}
462463

464+
const (
465+
targetJreDir = "/usr/local/jre"
466+
targetJre8Dir = "/usr/local/jre8"
467+
)
468+
463469
// parseContainerMounts 解析生成容器挂载内容
464470
func parseContainerMounts(buildInfo *api.ThirdPartyBuildInfo) ([]mount.Mount, error) {
465471
var mounts []mount.Mount
466472

467-
// 默认绑定本机的java用来执行worker
468-
mounts = append(mounts, mount.Mount{
469-
Type: mount.TypeBind,
470-
Source: config.GAgentConfig.JdkDirPath,
471-
Target: "/usr/local/jre",
472-
ReadOnly: true,
473-
})
473+
// 默认绑定本机的java用来执行worker,如果有jdk17优先用jdk17,否则用jdk8
474+
if third_components.Jdk.Jdk17.GetJavaOrNull() != "" {
475+
mounts = append(mounts, mount.Mount{
476+
Type: mount.TypeBind,
477+
Source: config.GAgentConfig.Jdk17DirPath,
478+
Target: targetJreDir,
479+
ReadOnly: true,
480+
})
481+
// 用jdk17的同时保存jdk8
482+
mounts = append(mounts, mount.Mount{
483+
Type: mount.TypeBind,
484+
Source: config.GAgentConfig.JdkDirPath,
485+
Target: targetJre8Dir,
486+
ReadOnly: true,
487+
})
488+
} else {
489+
mounts = append(mounts, mount.Mount{
490+
Type: mount.TypeBind,
491+
Source: config.GAgentConfig.JdkDirPath,
492+
Target: targetJreDir,
493+
ReadOnly: true,
494+
})
495+
}
474496

475497
// 默认绑定本机的 worker 用来执行
476498
mounts = append(mounts, mount.Mount{
@@ -534,6 +556,11 @@ func parseContainerEnv(dockerBuildInfo *api.ThirdPartyDockerBuildInfo) []string
534556
envs = append(envs, "devops_gateway="+config.GetGateWay())
535557
// 通过环境变量区分agent docker
536558
envs = append(envs, "agent_build_env=DOCKER")
559+
// JDK版本,只有jdk17的过渡期需要这个
560+
if third_components.Jdk.Jdk17.GetJavaOrNull() != "" {
561+
envs = append(envs, "DEVOPS_AGENT_JDK_8_PATH="+(targetJre8Dir+"/bin/java"))
562+
envs = append(envs, "DEVOPS_AGENT_JDK_17_PATH="+(targetJreDir+"/bin/java"))
563+
}
537564

538565
return envs
539566
}

0 commit comments

Comments
 (0)
Please sign in to comment.