Skip to content

Commit

Permalink
Reproducing and Fixing #2892 (#2893)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
mxbossard authored Dec 15, 2023
1 parent 60aa11e commit df488da
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
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

0 comments on commit df488da

Please sign in to comment.