From 0bea8d7c1f566643dcc5c613cb6785617d7f0656 Mon Sep 17 00:00:00 2001 From: Matthieu Paret Date: Fri, 6 Dec 2024 09:43:12 +0000 Subject: [PATCH] Enable using cache registry for the first build Registry caching was disabled for the first build although it permits to share cache between images. This will speed lot of first builds. --- pkg/apis/build/v1alpha2/build_pod.go | 2 ++ pkg/apis/build/v1alpha2/build_pod_test.go | 8 ++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/pkg/apis/build/v1alpha2/build_pod.go b/pkg/apis/build/v1alpha2/build_pod.go index 0d525daa6..0263c9bca 100644 --- a/pkg/apis/build/v1alpha2/build_pod.go +++ b/pkg/apis/build/v1alpha2/build_pod.go @@ -269,6 +269,8 @@ func (b *Build) BuildPod(images BuildPodImages, buildContext BuildContext) (*cor useCacheFromLastBuild := b.Spec.LastBuild != nil && b.Spec.LastBuild.Cache.Image != "" if useCacheFromLastBuild { genericCacheArgs = []string{fmt.Sprintf("-cache-image=%s", b.Spec.LastBuild.Cache.Image)} + } else { + genericCacheArgs = []string{fmt.Sprintf("-cache-image=%s", b.Spec.Cache.Registry.Tag)} } analyzerCacheArgs = genericCacheArgs exporterCacheArgs = []string{fmt.Sprintf("-cache-image=%s", b.Spec.Cache.Registry.Tag)} diff --git a/pkg/apis/build/v1alpha2/build_pod_test.go b/pkg/apis/build/v1alpha2/build_pod_test.go index 7ade6f4e1..cdc8bf47c 100644 --- a/pkg/apis/build/v1alpha2/build_pod_test.go +++ b/pkg/apis/build/v1alpha2/build_pod_test.go @@ -1053,19 +1053,19 @@ func testBuildPod(t *testing.T, when spec.G, it spec.S) { assert.Len(t, podWithImageCache.Spec.Volumes, len(podWithVolumeCache.Spec.Volumes)-1) }) - it("does not add the cache to analyze container", func() { + it("does add the cache to analyze container", func() { podWithImageCache, err := build.BuildPod(config, buildContext) require.NoError(t, err) analyzeContainer := podWithImageCache.Spec.InitContainers[2] - assert.NotContains(t, analyzeContainer.Args, "-cache-image=test-cache-image") + assert.Contains(t, analyzeContainer.Args, "-cache-image=test-cache-image") }) - it("does not add the cache to restore container", func() { + it("does add cache to restore container", func() { podWithImageCache, err := build.BuildPod(config, buildContext) require.NoError(t, err) restoreContainer := podWithImageCache.Spec.InitContainers[3] - assert.NotContains(t, restoreContainer.Args, "-cache-image=test-cache-image") + assert.Contains(t, restoreContainer.Args, "-cache-image=test-cache-image") }) it("adds the cache to export container", func() { podWithImageCache, err := build.BuildPod(config, buildContext)