Skip to content

Commit

Permalink
perf: adjust the storage mounting of builder and runner components
Browse files Browse the repository at this point in the history
Signed-off-by: 张启航 <[email protected]>
  • Loading branch information
ZhangSetSail committed Oct 17, 2024
1 parent ab5ab13 commit 952a9d9
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 41 deletions.
22 changes: 19 additions & 3 deletions builder/build/code_build.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
},
Expand Down
15 changes: 14 additions & 1 deletion builder/build/dockerfile_build.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
},
Expand Down Expand Up @@ -253,6 +262,10 @@ func (d *dockerfileBuild) createVolumeAndMount(secretName string, buildKitTomlCM
},
}
volumeMounts = []corev1.VolumeMount{
{
Name: "grdata",
MountPath: "/grdata",
},
{
Name: "dockerfile-build",
MountPath: "/cache",
Expand Down
49 changes: 12 additions & 37 deletions builder/sources/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -817,8 +817,6 @@ func PrepareBuildKitTomlCM(ctx context.Context, kubeClient kubernetes.Interface,

// CreateVolumeAndMounts -
func CreateVolumeAndMounts(contextDir, buildType string, buildKitTomlCMName string) (volumes []corev1.Volume, volumeMounts []corev1.VolumeMount) {
pathSplit := strings.Split(contextDir, "/")
subPath := strings.Join(pathSplit[2:], "/")
hostPathType := corev1.HostPathDirectoryOrCreate
hostsFilePathType := corev1.HostPathFile
// buildkit volumes volumeMounts config
Expand Down Expand Up @@ -875,44 +873,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
}

Expand Down

0 comments on commit 952a9d9

Please sign in to comment.