diff --git a/integration/integration_test.go b/integration/integration_test.go index ab59771652..653a1f91f0 100644 --- a/integration/integration_test.go +++ b/integration/integration_test.go @@ -28,6 +28,7 @@ import ( "os" "os/exec" "path/filepath" + "runtime" "strconv" "strings" "testing" @@ -636,6 +637,36 @@ func TestCache(t *testing.T) { } } +// Attempt to warm an image two times : first time should populate the cache, second time should find the image in the cache. +func TestWarmerTwice(t *testing.T) { + _, ex, _, _ := runtime.Caller(0) + cwd := filepath.Dir(ex) + "/tmpCache" + + // Start a sleeping warmer container + dockerRunFlags := []string{"run", "--net=host"} + dockerRunFlags = addServiceAccountFlags(dockerRunFlags, config.serviceAccount) + dockerRunFlags = append(dockerRunFlags, + "--memory=16m", + "-v", cwd+":/cache", + WarmerImage, + "--cache-dir=/cache", + "-i", "debian:trixie-slim") + + warmCmd := exec.Command("docker", dockerRunFlags...) + out, err := RunCommandWithoutTest(warmCmd) + if err != nil { + t.Fatalf("Unable to perform first warming: %s", err) + } + t.Logf("First warm output: %s", out) + + warmCmd = exec.Command("docker", dockerRunFlags...) + out, err = RunCommandWithoutTest(warmCmd) + if err != nil { + t.Fatalf("Unable to perform second warming: %s", err) + } + t.Logf("Second warm output: %s", out) +} + func verifyBuildWith(t *testing.T, cache, dockerfile string) { args := []string{} if strings.HasPrefix(dockerfile, "Dockerfile_test_cache_copy") { diff --git a/pkg/cache/warm.go b/pkg/cache/warm.go index 7b5e307e6a..589edcafa7 100644 --- a/pkg/cache/warm.go +++ b/pkg/cache/warm.go @@ -97,10 +97,11 @@ func warmToFile(cacheDir, img string, opts *config.WarmerOptions) error { digest, err := cw.Warm(img, opts) if err != nil { - if !IsAlreadyCached(err) { - logrus.Warnf("Error while trying to warm image: %v %v", img, err) + if IsAlreadyCached(err) { + logrus.Infof("Image already in cache: %v", img) + return nil } - + logrus.Warnf("Error while trying to warm image: %v %v", img, err) return err }