diff --git a/acceptance/acceptance_test.go b/acceptance/acceptance_test.go index 2607180e6..f837988e0 100644 --- a/acceptance/acceptance_test.go +++ b/acceptance/acceptance_test.go @@ -38,6 +38,7 @@ import ( "github.com/buildpacks/pack/internal/style" "github.com/buildpacks/pack/pkg/archive" "github.com/buildpacks/pack/pkg/cache" + "github.com/buildpacks/pack/pkg/logging" h "github.com/buildpacks/pack/testhelpers" ) @@ -1162,8 +1163,9 @@ func testAcceptance( ref, err := name.ParseReference(repoName, name.WeakValidation) assert.Nil(err) cacheImage := cache.NewImageCache(ref, dockerCli) - buildCacheVolume := cache.NewVolumeCache(ref, cache.CacheInfo{}, "build", dockerCli) - launchCacheVolume := cache.NewVolumeCache(ref, cache.CacheInfo{}, "launch", dockerCli) + logger := logging.NewSimpleLogger(&bytes.Buffer{}) + buildCacheVolume, _ := cache.NewVolumeCache(ref, cache.CacheInfo{}, "build", dockerCli, logger) + launchCacheVolume, _ := cache.NewVolumeCache(ref, cache.CacheInfo{}, "launch", dockerCli, logger) cacheImage.Clear(context.TODO()) buildCacheVolume.Clear(context.TODO()) launchCacheVolume.Clear(context.TODO()) @@ -1282,8 +1284,9 @@ func testAcceptance( ref, err := name.ParseReference(repoName, name.WeakValidation) assert.Nil(err) cacheImage := cache.NewImageCache(ref, dockerCli) - buildCacheVolume := cache.NewVolumeCache(ref, cache.CacheInfo{}, "build", dockerCli) - launchCacheVolume := cache.NewVolumeCache(ref, cache.CacheInfo{}, "launch", dockerCli) + logger := logging.NewSimpleLogger(&bytes.Buffer{}) + buildCacheVolume, _ := cache.NewVolumeCache(ref, cache.CacheInfo{}, "build", dockerCli, logger) + launchCacheVolume, _ := cache.NewVolumeCache(ref, cache.CacheInfo{}, "launch", dockerCli, logger) cacheImage.Clear(context.TODO()) buildCacheVolume.Clear(context.TODO()) launchCacheVolume.Clear(context.TODO()) @@ -3168,8 +3171,9 @@ include = [ "*.jar", "media/mountain.jpg", "/media/person.png", ] imageManager.CleanupImages(origID, repoName, runBefore) ref, err := name.ParseReference(repoName, name.WeakValidation) assert.Nil(err) - buildCacheVolume := cache.NewVolumeCache(ref, cache.CacheInfo{}, "build", dockerCli) - launchCacheVolume := cache.NewVolumeCache(ref, cache.CacheInfo{}, "launch", dockerCli) + logger := logging.NewSimpleLogger(&bytes.Buffer{}) + buildCacheVolume, _ := cache.NewVolumeCache(ref, cache.CacheInfo{}, "build", dockerCli, logger) + launchCacheVolume, _ := cache.NewVolumeCache(ref, cache.CacheInfo{}, "launch", dockerCli, logger) assert.Succeeds(buildCacheVolume.Clear(context.TODO())) assert.Succeeds(launchCacheVolume.Clear(context.TODO())) }) diff --git a/internal/build/lifecycle_execution.go b/internal/build/lifecycle_execution.go index bac6a53b9..1911c0eed 100644 --- a/internal/build/lifecycle_execution.go +++ b/internal/build/lifecycle_execution.go @@ -181,7 +181,11 @@ func (l *LifecycleExecution) Run(ctx context.Context, phaseFactoryCreator PhaseF } else { switch l.opts.Cache.Build.Format { case cache.CacheVolume: - buildCache = cache.NewVolumeCache(l.opts.Image, l.opts.Cache.Build, "build", l.docker) + var err error + buildCache, err = cache.NewVolumeCache(l.opts.Image, l.opts.Cache.Build, "build", l.docker, l.logger) + if err != nil { + return err + } l.logger.Debugf("Using build cache volume %s", style.Symbol(buildCache.Name())) case cache.CacheBind: buildCache = cache.NewBindCache(l.opts.Cache.Build, l.docker) @@ -196,7 +200,10 @@ func (l *LifecycleExecution) Run(ctx context.Context, phaseFactoryCreator PhaseF l.logger.Debugf("Build cache %s cleared", style.Symbol(buildCache.Name())) } - launchCache := cache.NewVolumeCache(l.opts.Image, l.opts.Cache.Launch, "launch", l.docker) + launchCache, err := cache.NewVolumeCache(l.opts.Image, l.opts.Cache.Launch, "launch", l.docker, l.logger) + if err != nil { + return err + } if l.opts.Network == "" { // start an ephemeral bridge network @@ -249,7 +256,10 @@ func (l *LifecycleExecution) Run(ctx context.Context, phaseFactoryCreator PhaseF // lifecycle 0.17.0 (introduces support for Platform API 0.12) and above will ensure that // this volume is owned by the CNB user, // and hence the restorer (after dropping privileges) will be able to write to it. - kanikoCache = cache.NewVolumeCache(l.opts.Image, l.opts.Cache.Kaniko, "kaniko", l.docker) + kanikoCache, err = cache.NewVolumeCache(l.opts.Image, l.opts.Cache.Kaniko, "kaniko", l.docker, l.logger) + if err != nil { + return err + } } else { switch { case buildCache.Type() == cache.Volume: @@ -261,7 +271,10 @@ func (l *LifecycleExecution) Run(ctx context.Context, phaseFactoryCreator PhaseF return fmt.Errorf("build cache must be volume cache when building with extensions") default: // The kaniko cache is unused, so it doesn't matter that it's not usable. - kanikoCache = cache.NewVolumeCache(l.opts.Image, l.opts.Cache.Kaniko, "kaniko", l.docker) + kanikoCache, err = cache.NewVolumeCache(l.opts.Image, l.opts.Cache.Kaniko, "kaniko", l.docker, l.logger) + if err != nil { + return err + } } } diff --git a/internal/config/config.go b/internal/config/config.go index de370ef72..e15da68f0 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -25,6 +25,10 @@ type Config struct { LayoutRepositoryDir string `toml:"layout-repo-dir,omitempty"` } +type VolumeConfig struct { + VolumeKeys map[string]string `toml:"volume-keys,omitempty"` +} + type Registry struct { Name string `toml:"name"` Type string `toml:"type"` @@ -58,6 +62,14 @@ func DefaultConfigPath() (string, error) { return filepath.Join(home, "config.toml"), nil } +func DefaultVolumeKeysPath() (string, error) { + home, err := PackHome() + if err != nil { + return "", errors.Wrap(err, "getting pack home") + } + return filepath.Join(home, "volume-keys.toml"), nil +} + func PackHome() (string, error) { packHome := os.Getenv("PACK_HOME") if packHome == "" { @@ -79,7 +91,16 @@ func Read(path string) (Config, error) { return cfg, nil } -func Write(cfg Config, path string) error { +func ReadVolumeKeys(path string) (VolumeConfig, error) { + cfg := VolumeConfig{} + _, err := toml.DecodeFile(path, &cfg) + if err != nil && !os.IsNotExist(err) { + return VolumeConfig{}, errors.Wrapf(err, "failed to read config file at path %s", path) + } + return cfg, nil +} + +func Write(cfg interface{}, path string) error { if err := MkdirAll(filepath.Dir(path)); err != nil { return err } diff --git a/pkg/cache/volume_cache.go b/pkg/cache/volume_cache.go index b274d3d3f..f414bcd90 100644 --- a/pkg/cache/volume_cache.go +++ b/pkg/cache/volume_cache.go @@ -2,25 +2,36 @@ package cache import ( "context" + "crypto/rand" "crypto/sha256" "fmt" + "os" "strings" + "github.com/GoogleContainerTools/kaniko/pkg/util/proc" "github.com/docker/docker/client" "github.com/google/go-containerregistry/pkg/name" + "github.com/buildpacks/pack/internal/config" "github.com/buildpacks/pack/internal/paths" + "github.com/buildpacks/pack/pkg/logging" ) +const EnvVolumeKey = "PACK_VOLUME_KEY" + type VolumeCache struct { docker DockerClient volume string } -func NewVolumeCache(imageRef name.Reference, cacheType CacheInfo, suffix string, dockerClient DockerClient) *VolumeCache { +func NewVolumeCache(imageRef name.Reference, cacheType CacheInfo, suffix string, dockerClient DockerClient, logger logging.Logger) (*VolumeCache, error) { var volumeName string if cacheType.Source == "" { - sum := sha256.Sum256([]byte(imageRef.Name())) + volumeKey, err := getVolumeKey(imageRef, logger) + if err != nil { + return nil, err + } + sum := sha256.Sum256([]byte(imageRef.Name() + volumeKey)) vol := paths.FilterReservedNames(fmt.Sprintf("%s-%x", sanitizedRef(imageRef), sum[:6])) volumeName = fmt.Sprintf("pack-cache-%s.%s", vol, suffix) } else { @@ -30,7 +41,66 @@ func NewVolumeCache(imageRef name.Reference, cacheType CacheInfo, suffix string, return &VolumeCache{ volume: volumeName, docker: dockerClient, + }, nil +} + +func getVolumeKey(imageRef name.Reference, logger logging.Logger) (string, error) { + var foundKey string + + // first, look for key in env + + foundKey = os.Getenv(EnvVolumeKey) + if foundKey != "" { + return foundKey, nil + } + + // then, look for key in existing config + + volumeKeysPath, err := config.DefaultVolumeKeysPath() + if err != nil { + return "", err + } + cfg, err := config.ReadVolumeKeys(volumeKeysPath) + if err != nil { + return "", err + } + + foundKey = cfg.VolumeKeys[imageRef.Name()] + if foundKey != "" { + return foundKey, nil + } + + // finally, create new key and store it in config + + // if we're running in a container, we should log a warning + // so that we don't always re-create the cache + if RunningInContainer() { + logger.Warnf("%s is unset; set this environment variable to a secret value to avoid creating a new volume cache on every build", EnvVolumeKey) + } + + newKey := randString(20) + if cfg.VolumeKeys == nil { + cfg.VolumeKeys = make(map[string]string) + } + cfg.VolumeKeys[imageRef.Name()] = newKey + if err = config.Write(cfg, volumeKeysPath); err != nil { + return "", err + } + + return newKey, nil +} + +// Returns a string iwith lowercase a-z, of length n +func randString(n int) string { + b := make([]byte, n) + _, err := rand.Read(b) + if err != nil { + panic(err) } + for i := range b { + b[i] = 'a' + (b[i] % 26) + } + return string(b) } func (c *VolumeCache) Name() string { @@ -56,3 +126,7 @@ func sanitizedRef(ref name.Reference) string { result = strings.ReplaceAll(result, "/", "_") return fmt.Sprintf("%s_%s", result, ref.Identifier()) } + +var RunningInContainer = func() bool { + return proc.GetContainerRuntime(0, 0) != proc.RuntimeNotFound +} diff --git a/pkg/cache/volume_cache_test.go b/pkg/cache/volume_cache_test.go index 5ae1e14a9..685f34d2b 100644 --- a/pkg/cache/volume_cache_test.go +++ b/pkg/cache/volume_cache_test.go @@ -1,11 +1,16 @@ package cache_test import ( + "bytes" "context" + "os" + "path/filepath" "strings" "testing" + "github.com/buildpacks/pack/internal/config" "github.com/buildpacks/pack/pkg/cache" + "github.com/buildpacks/pack/pkg/logging" "github.com/docker/docker/api/types/filters" "github.com/docker/docker/api/types/volume" @@ -24,23 +29,29 @@ func TestVolumeCache(t *testing.T) { color.Disable(true) defer color.Disable(false) - spec.Run(t, "VolumeCache", testCache, spec.Parallel(), spec.Report(report.Terminal{})) + spec.Run(t, "VolumeCache", testCache, spec.Sequential(), spec.Report(report.Terminal{})) } func testCache(t *testing.T, when spec.G, it spec.S) { - var dockerClient client.CommonAPIClient + var ( + dockerClient client.CommonAPIClient + outBuf bytes.Buffer + logger logging.Logger + ) it.Before(func() { var err error dockerClient, err = client.NewClientWithOpts(client.FromEnv, client.WithVersion("1.38")) h.AssertNil(t, err) + logger = logging.NewSimpleLogger(&outBuf) }) + when("#NewVolumeCache", func() { when("volume cache name is empty", func() { it("adds suffix to calculated name", func() { ref, err := name.ParseReference("my/repo", name.WeakValidation) h.AssertNil(t, err) - subject := cache.NewVolumeCache(ref, cache.CacheInfo{}, "some-suffix", dockerClient) + subject, _ := cache.NewVolumeCache(ref, cache.CacheInfo{}, "some-suffix", dockerClient, logger) if !strings.HasSuffix(subject.Name(), ".some-suffix") { t.Fatalf("Calculated volume name '%s' should end with '.some-suffix'", subject.Name()) } @@ -50,8 +61,8 @@ func testCache(t *testing.T, when spec.G, it spec.S) { ref, err := name.ParseReference("my/repo", name.WeakValidation) h.AssertNil(t, err) - subject := cache.NewVolumeCache(ref, cache.CacheInfo{}, "some-suffix", dockerClient) - expected := cache.NewVolumeCache(ref, cache.CacheInfo{}, "some-suffix", dockerClient) + subject, _ := cache.NewVolumeCache(ref, cache.CacheInfo{}, "some-suffix", dockerClient, logger) + expected, _ := cache.NewVolumeCache(ref, cache.CacheInfo{}, "some-suffix", dockerClient, logger) if subject.Name() != expected.Name() { t.Fatalf("The same repo name should result in the same volume") } @@ -61,11 +72,11 @@ func testCache(t *testing.T, when spec.G, it spec.S) { ref, err := name.ParseReference("my/repo:other-tag", name.WeakValidation) h.AssertNil(t, err) - subject := cache.NewVolumeCache(ref, cache.CacheInfo{}, "some-suffix", dockerClient) + subject, _ := cache.NewVolumeCache(ref, cache.CacheInfo{}, "some-suffix", dockerClient, logger) ref, err = name.ParseReference("my/repo", name.WeakValidation) h.AssertNil(t, err) - notExpected := cache.NewVolumeCache(ref, cache.CacheInfo{}, "some-suffix", dockerClient) + notExpected, _ := cache.NewVolumeCache(ref, cache.CacheInfo{}, "some-suffix", dockerClient, logger) if subject.Name() == notExpected.Name() { t.Fatalf("Different image tags should result in different volumes") } @@ -75,11 +86,11 @@ func testCache(t *testing.T, when spec.G, it spec.S) { ref, err := name.ParseReference("registry.com/my/repo:other-tag", name.WeakValidation) h.AssertNil(t, err) - subject := cache.NewVolumeCache(ref, cache.CacheInfo{}, "some-suffix", dockerClient) + subject, _ := cache.NewVolumeCache(ref, cache.CacheInfo{}, "some-suffix", dockerClient, logger) ref, err = name.ParseReference("my/repo", name.WeakValidation) h.AssertNil(t, err) - notExpected := cache.NewVolumeCache(ref, cache.CacheInfo{}, "some-suffix", dockerClient) + notExpected, _ := cache.NewVolumeCache(ref, cache.CacheInfo{}, "some-suffix", dockerClient, logger) if subject.Name() == notExpected.Name() { t.Fatalf("Different image registries should result in different volumes") } @@ -89,11 +100,11 @@ func testCache(t *testing.T, when spec.G, it spec.S) { ref, err := name.ParseReference("my/repo:latest", name.WeakValidation) h.AssertNil(t, err) - subject := cache.NewVolumeCache(ref, cache.CacheInfo{}, "some-suffix", dockerClient) + subject, _ := cache.NewVolumeCache(ref, cache.CacheInfo{}, "some-suffix", dockerClient, logger) ref, err = name.ParseReference("my/repo", name.WeakValidation) h.AssertNil(t, err) - expected := cache.NewVolumeCache(ref, cache.CacheInfo{}, "some-suffix", dockerClient) + expected, _ := cache.NewVolumeCache(ref, cache.CacheInfo{}, "some-suffix", dockerClient, logger) h.AssertEq(t, subject.Name(), expected.Name()) }) @@ -101,11 +112,11 @@ func testCache(t *testing.T, when spec.G, it spec.S) { ref, err := name.ParseReference("index.docker.io/my/repo", name.WeakValidation) h.AssertNil(t, err) - subject := cache.NewVolumeCache(ref, cache.CacheInfo{}, "some-suffix", dockerClient) + subject, _ := cache.NewVolumeCache(ref, cache.CacheInfo{}, "some-suffix", dockerClient, logger) ref, err = name.ParseReference("my/repo", name.WeakValidation) h.AssertNil(t, err) - expected := cache.NewVolumeCache(ref, cache.CacheInfo{}, "some-suffix", dockerClient) + expected, _ := cache.NewVolumeCache(ref, cache.CacheInfo{}, "some-suffix", dockerClient, logger) h.AssertEq(t, subject.Name(), expected.Name()) }) @@ -113,11 +124,95 @@ func testCache(t *testing.T, when spec.G, it spec.S) { ref, err := name.ParseReference("myregistryhost:5000/fedora/httpd:version1.0", name.WeakValidation) h.AssertNil(t, err) - subject := cache.NewVolumeCache(ref, cache.CacheInfo{}, "some-suffix", dockerClient) + subject, _ := cache.NewVolumeCache(ref, cache.CacheInfo{}, "some-suffix", dockerClient, logger) h.AssertContains(t, subject.Name(), "fedora_httpd_version1.0") h.AssertTrue(t, names.RestrictedNamePattern.MatchString(subject.Name())) }) + + when("PACK_VOLUME_KEY", func() { + when("is set", func() { + it.After(func() { + h.AssertNil(t, os.Unsetenv("PACK_VOLUME_KEY")) + }) + + it("uses it to construct the volume name", func() { + ref, err := name.ParseReference("my/repo:some-tag", name.WeakValidation) + h.AssertNil(t, err) + + nameFromNewKey, _ := cache.NewVolumeCache(ref, cache.CacheInfo{}, "some-suffix", dockerClient, logger) // sources a new key + h.AssertNil(t, os.Setenv("PACK_VOLUME_KEY", "some-volume-key")) + nameFromEnvKey, _ := cache.NewVolumeCache(ref, cache.CacheInfo{}, "some-suffix", dockerClient, logger) // sources key from env + h.AssertNotEq(t, nameFromNewKey.Name(), nameFromEnvKey.Name()) + }) + }) + + when("is unset", func() { + var tmpPackHome string + + it.Before(func() { + var err error + tmpPackHome, err = os.MkdirTemp("", "") + h.AssertNil(t, err) + h.AssertNil(t, os.Setenv("PACK_HOME", tmpPackHome)) + }) + + it.After(func() { + h.AssertNil(t, os.RemoveAll(tmpPackHome)) + }) + + when("~/.pack/volume-keys.toml contains key for repo name", func() { + it("sources the key from ~/.pack/volume-keys.toml", func() { + ref, err := name.ParseReference("my/repo:some-tag", name.WeakValidation) + h.AssertNil(t, err) + + nameFromNewKey, _ := cache.NewVolumeCache(ref, cache.CacheInfo{}, "some-suffix", dockerClient, logger) // sources a new key + + cfgContents := ` +[volume-keys] +"index.docker.io/my/repo:some-tag" = "SOME_VOLUME_KEY" +` + h.AssertNil(t, os.WriteFile(filepath.Join(tmpPackHome, "volume-keys.toml"), []byte(cfgContents), 0755)) // overrides the key that was set + + nameFromConfigKey, _ := cache.NewVolumeCache(ref, cache.CacheInfo{}, "some-suffix", dockerClient, logger) // sources key from config + h.AssertNotEq(t, nameFromNewKey.Name(), nameFromConfigKey.Name()) + }) + }) + + when("~/.pack/volume-keys.toml missing key for repo name", func() { + it("generates a new key and saves it to ~/.pack/volume-keys.toml", func() { + ref, err := name.ParseReference("my/repo:some-tag", name.WeakValidation) + h.AssertNil(t, err) + + nameFromNewKey, _ := cache.NewVolumeCache(ref, cache.CacheInfo{}, "some-suffix", dockerClient, logger) // sources a new key + nameFromConfigKey, _ := cache.NewVolumeCache(ref, cache.CacheInfo{}, "some-suffix", dockerClient, logger) // sources same key from config + h.AssertEq(t, nameFromNewKey.Name(), nameFromConfigKey.Name()) + + cfg, err := config.ReadVolumeKeys(filepath.Join(tmpPackHome, "volume-keys.toml")) + h.AssertNil(t, err) + h.AssertNotNil(t, cfg.VolumeKeys["index.docker.io/my/repo:some-tag"]) + }) + + when("containerized pack", func() { + it.Before(func() { + cache.RunningInContainer = func() bool { + return true + } + }) + + it("logs a warning", func() { + ref, err := name.ParseReference("my/repo:some-tag", name.WeakValidation) + h.AssertNil(t, err) + + _, _ = cache.NewVolumeCache(ref, cache.CacheInfo{}, "some-suffix", dockerClient, logger) // sources a new key + _, _ = cache.NewVolumeCache(ref, cache.CacheInfo{}, "some-suffix", dockerClient, logger) // sources same key from config + h.AssertContains(t, outBuf.String(), "PACK_VOLUME_KEY is unset; set this environment variable to a secret value to avoid creating a new volume cache on every build") + h.AssertEq(t, strings.Count(outBuf.String(), "PACK_VOLUME_KEY is unset"), 1) // the second call to NewVolumeCache reads from the config + }) + }) + }) + }) + }) }) when("volume cache name is not empty", func() { @@ -131,7 +226,7 @@ func testCache(t *testing.T, when spec.G, it spec.S) { ref, err := name.ParseReference("my/repo", name.WeakValidation) h.AssertNil(t, err) - subject := cache.NewVolumeCache(ref, cacheInfo, "some-suffix", dockerClient) + subject, _ := cache.NewVolumeCache(ref, cacheInfo, "some-suffix", dockerClient, logger) if volumeName != subject.Name() { t.Fatalf("Volume name '%s' should be same as the name specified '%s'", subject.Name(), volumeName) @@ -142,9 +237,9 @@ func testCache(t *testing.T, when spec.G, it spec.S) { ref, err := name.ParseReference("my/repo", name.WeakValidation) h.AssertNil(t, err) - subject := cache.NewVolumeCache(ref, cacheInfo, "some-suffix", dockerClient) + subject, _ := cache.NewVolumeCache(ref, cacheInfo, "some-suffix", dockerClient, logger) - expected := cache.NewVolumeCache(ref, cacheInfo, "some-suffix", dockerClient) + expected, _ := cache.NewVolumeCache(ref, cacheInfo, "some-suffix", dockerClient, logger) if subject.Name() != expected.Name() { t.Fatalf("The same repo name should result in the same volume") } @@ -154,11 +249,11 @@ func testCache(t *testing.T, when spec.G, it spec.S) { ref, err := name.ParseReference("registry.com/my/repo:other-tag", name.WeakValidation) h.AssertNil(t, err) - subject := cache.NewVolumeCache(ref, cache.CacheInfo{}, "some-suffix", dockerClient) + subject, _ := cache.NewVolumeCache(ref, cache.CacheInfo{}, "some-suffix", dockerClient, logger) ref, err = name.ParseReference("my/repo", name.WeakValidation) h.AssertNil(t, err) - notExpected := cache.NewVolumeCache(ref, cache.CacheInfo{}, "some-suffix", dockerClient) + notExpected, _ := cache.NewVolumeCache(ref, cache.CacheInfo{}, "some-suffix", dockerClient, logger) if subject.Name() == notExpected.Name() { t.Fatalf("Different image registries should result in different volumes") } @@ -168,11 +263,11 @@ func testCache(t *testing.T, when spec.G, it spec.S) { ref, err := name.ParseReference("my/repo:latest", name.WeakValidation) h.AssertNil(t, err) - subject := cache.NewVolumeCache(ref, cache.CacheInfo{}, "some-suffix", dockerClient) + subject, _ := cache.NewVolumeCache(ref, cache.CacheInfo{}, "some-suffix", dockerClient, logger) ref, err = name.ParseReference("my/repo", name.WeakValidation) h.AssertNil(t, err) - expected := cache.NewVolumeCache(ref, cache.CacheInfo{}, "some-suffix", dockerClient) + expected, _ := cache.NewVolumeCache(ref, cache.CacheInfo{}, "some-suffix", dockerClient, logger) h.AssertEq(t, subject.Name(), expected.Name()) }) @@ -180,11 +275,11 @@ func testCache(t *testing.T, when spec.G, it spec.S) { ref, err := name.ParseReference("index.docker.io/my/repo", name.WeakValidation) h.AssertNil(t, err) - subject := cache.NewVolumeCache(ref, cache.CacheInfo{}, "some-suffix", dockerClient) + subject, _ := cache.NewVolumeCache(ref, cache.CacheInfo{}, "some-suffix", dockerClient, logger) ref, err = name.ParseReference("my/repo", name.WeakValidation) h.AssertNil(t, err) - expected := cache.NewVolumeCache(ref, cache.CacheInfo{}, "some-suffix", dockerClient) + expected, _ := cache.NewVolumeCache(ref, cache.CacheInfo{}, "some-suffix", dockerClient, logger) h.AssertEq(t, subject.Name(), expected.Name()) }) @@ -192,7 +287,7 @@ func testCache(t *testing.T, when spec.G, it spec.S) { ref, err := name.ParseReference("myregistryhost:5000/fedora/httpd:version1.0", name.WeakValidation) h.AssertNil(t, err) - subject := cache.NewVolumeCache(ref, cache.CacheInfo{}, "some-suffix", dockerClient) + subject, _ := cache.NewVolumeCache(ref, cache.CacheInfo{}, "some-suffix", dockerClient, logger) h.AssertContains(t, subject.Name(), "fedora_httpd_version1.0") h.AssertTrue(t, names.RestrictedNamePattern.MatchString(subject.Name())) @@ -217,7 +312,7 @@ func testCache(t *testing.T, when spec.G, it spec.S) { ref, err := name.ParseReference(h.RandString(10), name.WeakValidation) h.AssertNil(t, err) - subject = cache.NewVolumeCache(ref, cache.CacheInfo{}, "some-suffix", dockerClient) + subject, _ = cache.NewVolumeCache(ref, cache.CacheInfo{}, "some-suffix", dockerClient, logger) volumeName = subject.Name() }) @@ -255,7 +350,7 @@ func testCache(t *testing.T, when spec.G, it spec.S) { it("returns the cache type", func() { ref, err := name.ParseReference("my/repo", name.WeakValidation) h.AssertNil(t, err) - subject := cache.NewVolumeCache(ref, cache.CacheInfo{}, "some-suffix", dockerClient) + subject, _ := cache.NewVolumeCache(ref, cache.CacheInfo{}, "some-suffix", dockerClient, logger) expected := cache.Volume h.AssertEq(t, subject.Type(), expected) })