Skip to content

Commit df488da

Browse files
authored
Reproducing and Fixing #2892 (#2893)
* Add an integration test to reproduce #2892 * Fix go compilation * Fix docker run cmd * Fixing entrypoint * Test warmer with cache in a volume. * Add missing comma * Fix imports * Fix dir * Add logs * fix * Use test framework to log * Fix warmer failing if image already in cache. * Fix format.
1 parent 60aa11e commit df488da

File tree

2 files changed

+35
-3
lines changed

2 files changed

+35
-3
lines changed

Diff for: integration/integration_test.go

+31
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
"os"
2929
"os/exec"
3030
"path/filepath"
31+
"runtime"
3132
"strconv"
3233
"strings"
3334
"testing"
@@ -636,6 +637,36 @@ func TestCache(t *testing.T) {
636637
}
637638
}
638639

640+
// Attempt to warm an image two times : first time should populate the cache, second time should find the image in the cache.
641+
func TestWarmerTwice(t *testing.T) {
642+
_, ex, _, _ := runtime.Caller(0)
643+
cwd := filepath.Dir(ex) + "/tmpCache"
644+
645+
// Start a sleeping warmer container
646+
dockerRunFlags := []string{"run", "--net=host"}
647+
dockerRunFlags = addServiceAccountFlags(dockerRunFlags, config.serviceAccount)
648+
dockerRunFlags = append(dockerRunFlags,
649+
"--memory=16m",
650+
"-v", cwd+":/cache",
651+
WarmerImage,
652+
"--cache-dir=/cache",
653+
"-i", "debian:trixie-slim")
654+
655+
warmCmd := exec.Command("docker", dockerRunFlags...)
656+
out, err := RunCommandWithoutTest(warmCmd)
657+
if err != nil {
658+
t.Fatalf("Unable to perform first warming: %s", err)
659+
}
660+
t.Logf("First warm output: %s", out)
661+
662+
warmCmd = exec.Command("docker", dockerRunFlags...)
663+
out, err = RunCommandWithoutTest(warmCmd)
664+
if err != nil {
665+
t.Fatalf("Unable to perform second warming: %s", err)
666+
}
667+
t.Logf("Second warm output: %s", out)
668+
}
669+
639670
func verifyBuildWith(t *testing.T, cache, dockerfile string) {
640671
args := []string{}
641672
if strings.HasPrefix(dockerfile, "Dockerfile_test_cache_copy") {

Diff for: pkg/cache/warm.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,11 @@ func warmToFile(cacheDir, img string, opts *config.WarmerOptions) error {
9797

9898
digest, err := cw.Warm(img, opts)
9999
if err != nil {
100-
if !IsAlreadyCached(err) {
101-
logrus.Warnf("Error while trying to warm image: %v %v", img, err)
100+
if IsAlreadyCached(err) {
101+
logrus.Infof("Image already in cache: %v", img)
102+
return nil
102103
}
103-
104+
logrus.Warnf("Error while trying to warm image: %v %v", img, err)
104105
return err
105106
}
106107

0 commit comments

Comments
 (0)