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

fix: reference in the formatted output of oras pull is invalid #1496

Merged
merged 6 commits into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 4 additions & 18 deletions cmd/oras/internal/option/target.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ func (opts *Target) Parse(cmd *cobra.Command) error {
}
} else {
opts.Reference = ref.Reference
ref.Reference = ""
opts.Path = ref.String()
}
return opts.Remote.Parse(cmd)
}
Expand Down Expand Up @@ -145,15 +147,7 @@ func (opts *Target) newOCIStore() (*oci.Store, error) {
}

func (opts *Target) newRepository(common Common, logger logrus.FieldLogger) (*remote.Repository, error) {
repo, err := opts.NewRepository(opts.RawReference, common, logger)
if err != nil {
return nil, err
}
tmp := repo.Reference
tmp.Reference = ""
opts.Path = tmp.String()
opts.Reference = repo.Reference.Reference
return repo, nil
return opts.NewRepository(opts.RawReference, common, logger)
}

// NewTarget generates a new target based on opts.
Expand Down Expand Up @@ -232,15 +226,7 @@ func (opts *Target) NewReadonlyTarget(ctx context.Context, common Common, logger
}
return store, nil
case TargetTypeRemote:
repo, err := opts.NewRepository(opts.RawReference, common, logger)
if err != nil {
return nil, err
}
tmp := repo.Reference
tmp.Reference = ""
opts.Path = tmp.String()
opts.Reference = repo.Reference.Reference
return repo, nil
return opts.NewRepository(opts.RawReference, common, logger)
}
return nil, fmt.Errorf("unknown target type: %q", opts.Type)
}
Expand Down
7 changes: 7 additions & 0 deletions test/e2e/suite/command/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,13 @@ var _ = Describe("OCI spec 1.1 registry users:", func() {
Expect(err).ShouldNot(HaveOccurred())
})

It("should show correct reference", func() {
tempDir := PrepareTempFiles()
ref := RegistryRef(ZOTHost, ArtifactRepo, foobar.Tag)
out := ORAS("pull", ref, "--format", "go-template={{.reference}}").WithWorkDir(tempDir).Exec().Out.Contents()
Expect(out).To(Equal([]byte("localhost:7000/command/artifacts@sha256:fd6ed2f36b5465244d5dc86cb4e7df0ab8a9d24adc57825099f522fe009a22bb")))
})

It("should pull specific platform", func() {
ORAS("pull", RegistryRef(ZOTHost, ImageRepo, "multi"), "--platform", "linux/amd64", "-v", "-o", GinkgoT().TempDir()).
MatchStatus(multi_arch.LinuxAMD64StateKeys, true, len(multi_arch.LinuxAMD64StateKeys)).Exec()
Expand Down
Loading