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: pushing based on temporary file store path #996

Merged
merged 16 commits into from
Jul 4, 2023
22 changes: 13 additions & 9 deletions cmd/oras/root/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ import (
"oras.land/oras-go/v2"
"oras.land/oras-go/v2/content"
"oras.land/oras-go/v2/content/file"
"oras.land/oras-go/v2/content/memory"
"oras.land/oras/cmd/oras/internal/display"
"oras.land/oras/cmd/oras/internal/fileref"
"oras.land/oras/cmd/oras/internal/option"
"oras.land/oras/internal/cache"
)

type pushOptions struct {
Expand Down Expand Up @@ -139,6 +141,8 @@ func runPush(ctx context.Context, opts pushOptions) error {
return err
}
defer store.Close()
memStore := memory.New()
qweeah marked this conversation as resolved.
Show resolved Hide resolved
proxy := cache.New(store, memStore)
qweeah marked this conversation as resolved.
Show resolved Hide resolved
if opts.manifestConfigRef != "" {
path, cfgMediaType, err := fileref.Parse(opts.manifestConfigRef, oras.MediaTypeUnknownConfig)
if err != nil {
Expand All @@ -160,11 +164,11 @@ func runPush(ctx context.Context, opts pushOptions) error {
return err
}
pack := func() (ocispec.Descriptor, error) {
root, err := oras.Pack(ctx, store, opts.artifactType, descs, packOpts)
root, err := oras.Pack(ctx, memStore, opts.artifactType, descs, packOpts)
if err != nil {
return ocispec.Descriptor{}, err
}
if err = store.Tag(ctx, root, root.Digest.String()); err != nil {
if err = memStore.Tag(ctx, root, root.Digest.String()); err != nil {
return ocispec.Descriptor{}, err
}
return root, nil
Expand All @@ -177,12 +181,12 @@ func runPush(ctx context.Context, opts pushOptions) error {
}
copyOptions := oras.DefaultCopyOptions
copyOptions.Concurrency = opts.concurrency
updateDisplayOption(&copyOptions.CopyGraphOptions, store, opts.Verbose)
updateDisplayOption(&copyOptions.CopyGraphOptions, proxy, opts.Verbose)
copy := func(root ocispec.Descriptor) error {
if tag := opts.Reference; tag == "" {
err = oras.CopyGraph(ctx, store, dst, root, copyOptions.CopyGraphOptions)
err = oras.CopyGraph(ctx, proxy, dst, root, copyOptions.CopyGraphOptions)
} else {
_, err = oras.Copy(ctx, store, root.Digest.String(), dst, tag, copyOptions)
_, err = oras.Copy(ctx, proxy, root.Digest.String(), dst, tag, copyOptions)
}
return err
}
Expand All @@ -195,7 +199,7 @@ func runPush(ctx context.Context, opts pushOptions) error {
fmt.Println("Pushed", opts.AnnotatedReference())

if len(opts.extraRefs) != 0 {
contentBytes, err := content.FetchAll(ctx, store, root)
contentBytes, err := content.FetchAll(ctx, proxy, root)
qweeah marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
return err
}
Expand All @@ -209,10 +213,10 @@ func runPush(ctx context.Context, opts pushOptions) error {
fmt.Println("Digest:", root.Digest)

// Export manifest
return opts.ExportManifest(ctx, store, root)
return opts.ExportManifest(ctx, proxy, root)
qweeah marked this conversation as resolved.
Show resolved Hide resolved
}

func updateDisplayOption(opts *oras.CopyGraphOptions, store content.Fetcher, verbose bool) {
func updateDisplayOption(opts *oras.CopyGraphOptions, fetcher content.Fetcher, verbose bool) {
committed := &sync.Map{}
opts.PreCopy = display.StatusPrinter("Uploading", verbose)
opts.OnCopySkipped = func(ctx context.Context, desc ocispec.Descriptor) error {
Expand All @@ -221,7 +225,7 @@ func updateDisplayOption(opts *oras.CopyGraphOptions, store content.Fetcher, ver
}
opts.PostCopy = func(ctx context.Context, desc ocispec.Descriptor) error {
committed.Store(desc.Digest.String(), desc.Annotations[ocispec.AnnotationTitle])
if err := display.PrintSuccessorStatus(ctx, desc, "Skipped ", store, committed, verbose); err != nil {
if err := display.PrintSuccessorStatus(ctx, desc, "Skipped ", fetcher, committed, verbose); err != nil {
return err
}
return display.PrintStatus(desc, "Uploaded ", verbose)
Expand Down