Skip to content

check for existing image before pushing to registry#1663

Merged
pkwarren merged 4 commits intomainfrom
pkw/BSR-1024-check-imageid-exists
Dec 9, 2022
Merged

check for existing image before pushing to registry#1663
pkwarren merged 4 commits intomainfrom
pkw/BSR-1024-check-imageid-exists

Conversation

@pkwarren
Copy link
Member

@pkwarren pkwarren commented Dec 9, 2022

Update buf alpha plugin push to first check if an existing image digest exists in the OCI registry. If found, we can re-use it instead of pushing a new tag of the same image.

This should also greatly improve the performance of pushing images when the image already exists remotely.

Update `buf alpha plugin push` to first check if an existing image
digest exists in the OCI registry. If found, we can re-use it instead of
pushing a new tag of the same image.

This should also greatly improve the performance of pushing images when
the image already exists remotely.
@pkwarren pkwarren requested a review from mfridman December 9, 2022 21:37
Name: plugin.Name,
Version: plugin.Version,
Revision: plugin.Revision,
ImageDigest: plugin.ContainerImageDigest,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added the image digest to the JSON printed representation (useful for debugging).

return bufprint.NewCuratedPluginPrinter(container.Stdout()).PrintCuratedPlugin(ctx, format, curatedPlugin)
}

func createCuratedPluginRequest(
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refactored this out to a helper method.

}, nil
}

func pushImage(
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refactored this out to a helper method.

// - For each tag:
// - Fetch image: GET /v2/{owner}/{plugin}/manifests/{tag}
// - If image manifest matches imageID, we can use the image digest for the image.
func findExistingDigestForImageID(ctx context.Context, plugin *bufpluginconfig.Config, imageID string) (string, error) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the new method which looks up an existing digest for an image ID.

if err != nil {
return nil, err
}
return &InspectResponse{ImageID: inspect.ID}, nil
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doing an inspect here allows us to check for an image ID in the OCI registry no matter if we pass a .zip file or an image with the -image flag.

@pkwarren pkwarren merged commit 7beb1e3 into main Dec 9, 2022
@pkwarren pkwarren deleted the pkw/BSR-1024-check-imageid-exists branch December 9, 2022 22:51
Monirul1 pushed a commit to Monirul1/buf that referenced this pull request Apr 30, 2023
Update `buf alpha plugin push` to first check if an existing image
digest exists in the OCI registry. If found, we can re-use it instead of
pushing a new tag of the same image.

This should also greatly improve the performance of pushing images when
the image already exists remotely.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants