Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reproducing and Fixing #2892 #2893

Merged
merged 13 commits into from
Dec 15, 2023
31 changes: 31 additions & 0 deletions integration/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"os"
"os/exec"
"path/filepath"
"runtime"
"strconv"
"strings"
"testing"
Expand Down Expand Up @@ -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") {
Expand Down
7 changes: 4 additions & 3 deletions pkg/cache/warm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
Loading