diff --git a/src/internal/packager/images/pull.go b/src/internal/packager/images/pull.go index 7d5baf8464..61210d43c1 100644 --- a/src/internal/packager/images/pull.go +++ b/src/internal/packager/images/pull.go @@ -188,7 +188,7 @@ func Pull(ctx context.Context, cfg PullConfig) (map[transform.Image]v1.Image, er if err != nil { return err } - if cacheImg { + if cacheImg && cfg.CacheDirectory != "" { img = cache.Image(img, cache.NewFilesystemCache(cfg.CacheDirectory)) } diff --git a/src/internal/packager/images/pull_test.go b/src/internal/packager/images/pull_test.go index ad38bb3aac..0bc7903997 100644 --- a/src/internal/packager/images/pull_test.go +++ b/src/internal/packager/images/pull_test.go @@ -10,6 +10,7 @@ import ( "fmt" "os" "path/filepath" + "strings" "testing" v1 "github.com/google/go-containerregistry/pkg/v1" @@ -84,6 +85,53 @@ func TestCheckForIndex(t *testing.T) { } func TestPull(t *testing.T) { + t.Parallel() + testCases := []struct { + name string + ref string + expectErr bool + }{ + { + name: "pull an image", + ref: "ghcr.io/zarf-dev/zarf/agent:v0.32.6@sha256:b3fabdc7d4ecd0f396016ef78da19002c39e3ace352ea0ae4baa2ce9d5958376", + }, + { + name: "error when pulling an image that doesn't exist", + ref: "ghcr.io/zarf-dev/zarf/imagethatdoesntexist:v1.1.1", + expectErr: true, + }, + } + + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + ref, err := transform.ParseImageRef(tc.ref) + require.NoError(t, err) + destDir := t.TempDir() + pullConfig := PullConfig{ + DestinationDirectory: destDir, + ImageList: []transform.Image{ + ref, + }, + } + + pulled, err := Pull(context.Background(), pullConfig) + if tc.expectErr { + require.Error(t, err, tc.expectErr) + return + } + require.NoError(t, err) + layers, err := pulled[ref].Layers() + require.NoError(t, err) + // Make sure all the layers of the image are pulled in + for _, layer := range layers { + digestHash, err := layer.Digest() + require.NoError(t, err) + digest, _ := strings.CutPrefix(digestHash.String(), "sha256:") + require.FileExists(t, filepath.Join(destDir, fmt.Sprintf("blobs/sha256/%s", digest))) + } + }) + } + t.Run("pulling a cosign image is successful and doesn't add anything to the cache", func(t *testing.T) { ref, err := transform.ParseImageRef("ghcr.io/stefanprodan/podinfo:sha256-57a654ace69ec02ba8973093b6a786faa15640575fbf0dbb603db55aca2ccec8.sig") require.NoError(t, err) diff --git a/src/test/e2e/00_use_cli_test.go b/src/test/e2e/00_use_cli_test.go index e5bc25cb4d..1704ce5ea0 100644 --- a/src/test/e2e/00_use_cli_test.go +++ b/src/test/e2e/00_use_cli_test.go @@ -116,16 +116,6 @@ func TestUseCLI(t *testing.T) { require.Contains(t, stdErr, expectedOutString, "The log level should be changed to 'debug'") }) - t.Run("zarf package to test bad remote images", func(t *testing.T) { - _, stdErr, err := e2e.Zarf(t, "package", "create", "src/test/packages/00-remote-pull-fail", "--confirm") - // expecting zarf to have an error and output to stderr - require.Error(t, err) - // Make sure we print the get request error (only look for GET since the actual error changes based on login status) - require.Contains(t, stdErr, "failed to find the manifest on a remote: GET") - // And the docker error - require.Contains(t, stdErr, "response from daemon: No such image") - }) - t.Run("zarf package to test archive path", func(t *testing.T) { t.Parallel() stdOut, stdErr, err := e2e.Zarf(t, "package", "create", "packages/distros/eks", "--confirm") diff --git a/src/test/packages/00-remote-pull-fail/zarf.yaml b/src/test/packages/00-remote-pull-fail/zarf.yaml deleted file mode 100644 index b2212b15d6..0000000000 --- a/src/test/packages/00-remote-pull-fail/zarf.yaml +++ /dev/null @@ -1,8 +0,0 @@ -kind: ZarfPackageConfig -metadata: - name: doesnotexist -components: - - name: doesnotexist-docker - required: true - images: - - ghcr.io/zarf-dev/doesnotexist:1.3.3.7