Skip to content

Commit

Permalink
Enable using cache registry for the first build
Browse files Browse the repository at this point in the history
Registry caching was disabled for the first build although it permits
to share cache between images. This will speed lot of first builds.
  • Loading branch information
mtparet authored Dec 6, 2024
1 parent ec5264c commit 0bea8d7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
2 changes: 2 additions & 0 deletions pkg/apis/build/v1alpha2/build_pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)}
Expand Down
8 changes: 4 additions & 4 deletions pkg/apis/build/v1alpha2/build_pod_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 0bea8d7

Please sign in to comment.