From 6b5e7ac1bfce5200a0282db25e892cd8c23a3829 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E5=90=AF=E8=88=AA?= <101104760+ZhangSetSail@users.noreply.github.com> Date: Thu, 17 Oct 2024 17:13:37 +0800 Subject: [PATCH] perf: adjust the storage mounting of builder and runner components MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 张启航 <101104760+ZhangSetSail@users.noreply.github.com> --- builder/build/code_build.go | 22 +++++++++++++-- builder/build/dockerfile_build.go | 15 +++++++++- builder/sources/image.go | 47 ++++++++----------------------- 3 files changed, 45 insertions(+), 39 deletions(-) diff --git a/builder/build/code_build.go b/builder/build/code_build.go index 267859510..0db936297 100644 --- a/builder/build/code_build.go +++ b/builder/build/code_build.go @@ -188,14 +188,30 @@ func (s *slugBuild) stopPreBuildJob(re *Request) error { func (s *slugBuild) createVolumeAndMount(re *Request, sourceTarFileName string, buildNoCache bool) (volumes []corev1.Volume, volumeMounts []corev1.VolumeMount) { cacheSubPath := strings.TrimPrefix(re.CacheDir, "/cache/") hostPathType := corev1.HostPathDirectoryOrCreate - volumeMounts = []corev1.VolumeMount{} - volumes = []corev1.Volume{} + volumeMounts = []corev1.VolumeMount{ + { + Name: "slug", + MountPath: "/tmp/slug", + }, + } + volumes = []corev1.Volume{ + { + Name: "slug", + VolumeSource: corev1.VolumeSource{ + HostPath: &corev1.HostPathVolumeSource{ + Path: path.Join("/opt/rainbond/", re.TGZDir), + Type: &hostPathType, + }, + }, + }, + } + logrus.Infof("look ------- %v------%v", re.CachePath, cacheSubPath) if !buildNoCache { volumes = append(volumes, corev1.Volume{ Name: "cache", VolumeSource: corev1.VolumeSource{ HostPath: &corev1.HostPathVolumeSource{ - Path: path.Join(re.CachePath, cacheSubPath), + Path: path.Join("/opt/rainbond/", re.CacheDir), Type: &hostPathType, }, }, diff --git a/builder/build/dockerfile_build.go b/builder/build/dockerfile_build.go index e596d1d44..b06c42a51 100644 --- a/builder/build/dockerfile_build.go +++ b/builder/build/dockerfile_build.go @@ -209,7 +209,16 @@ func (d *dockerfileBuild) createVolumeAndMount(secretName string, buildKitTomlCM Name: "dockerfile-build", VolumeSource: corev1.VolumeSource{ HostPath: &corev1.HostPathVolumeSource{ - Path: "/cache", + Path: "/opt/rainbond/cache", + Type: &hostPathType, + }, + }, + }, + { + Name: "grdata", + VolumeSource: corev1.VolumeSource{ + HostPath: &corev1.HostPathVolumeSource{ + Path: "/opt/rainbond/grdata", Type: &hostPathType, }, }, @@ -253,6 +262,10 @@ func (d *dockerfileBuild) createVolumeAndMount(secretName string, buildKitTomlCM }, } volumeMounts = []corev1.VolumeMount{ + { + Name: "grdata", + MountPath: "/grdata", + }, { Name: "dockerfile-build", MountPath: "/cache", diff --git a/builder/sources/image.go b/builder/sources/image.go index 8e94383dd..24825c456 100644 --- a/builder/sources/image.go +++ b/builder/sources/image.go @@ -875,44 +875,21 @@ func CreateVolumeAndMounts(contextDir, buildType string, buildKitTomlCMName stri MountPath: "/etc/buildkit", }, } - if buildType == "plug-build" { - volume := corev1.Volume{ - Name: "plug-build", - VolumeSource: corev1.VolumeSource{ - HostPath: &corev1.HostPathVolumeSource{ - Path: contextDir, - Type: &hostPathType, - }, + volume := corev1.Volume{ + Name: "plug-build", + VolumeSource: corev1.VolumeSource{ + HostPath: &corev1.HostPathVolumeSource{ + Path: path.Join("/opt/rainbond", contextDir), + Type: &hostPathType, }, - } - volumes = append(volumes, volume) - volumeMount := corev1.VolumeMount{ - Name: "plug-build", - MountPath: "/workspace", - } - volumeMounts = append(volumeMounts, volumeMount) - } - if buildType == "nc-build" { - volume := corev1.Volume{ - Name: "nc-build", - VolumeSource: corev1.VolumeSource{ - HostPath: &corev1.HostPathVolumeSource{ - Path: "/cache", - Type: &hostPathType, - }, - }, - } - volumes = append(volumes, volume) - volumeMount := corev1.VolumeMount{ - Name: "nc-build", - MountPath: "/workspace", - SubPath: subPath, - } - volumeMounts = append(volumeMounts, volumeMount) + }, } - if buildType == "run-build" || buildType == "vm-build" { - logrus.Infof("look ------------ %v", subPath) + volumes = append(volumes, volume) + volumeMount := corev1.VolumeMount{ + Name: "plug-build", + MountPath: "/workspace", } + volumeMounts = append(volumeMounts, volumeMount) return volumes, volumeMounts }