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

added a oci function to support generic image #48

Merged
merged 6 commits into from
Oct 18, 2024

Conversation

7h3-3mp7y-m4n
Copy link
Contributor

The main purpose of this PR is to fix #45 by adding the OCI feature mentioned here

Description

Added a new case check for oci and implemented a function to retrieve the image.

What does this PR do?

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • New chore (expected functionality to be implemented)

Checklist:

  • My change requires a change to the documentation.
    • I have updated the documentation accordingly.
  • I've signed off with an email address that matches the commit author.

@7h3-3mp7y-m4n
Copy link
Contributor Author

I know the unit test is missing , I'll do it ASAP ...

@mathieu-benoit mathieu-benoit marked this pull request as ready for review October 15, 2024 15:12
Copy link
Contributor

@mathieu-benoit mathieu-benoit left a comment

Choose a reason for hiding this comment

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

LGTM on my end, but would love the review from @delca85 to have a second pair of eyes on this one.
Thanks for your contribution, @7h3-3mp7y-m4n!

Copy link
Contributor

@delca85 delca85 left a comment

Choose a reason for hiding this comment

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

Thank you for this work!
I left some comments as I think the implementation might be simplified using the oras-go library.

fmt.Println("failed to pull OCI image:", err)
return
}
fmt.Println(len(buff) > 0, err)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we print err here? It needs to be nil otherwise we would be in the other branch.

uriget/uriget.go Outdated
@@ -233,3 +239,38 @@ func (o *options) getGit(ctx context.Context, u *url.URL) ([]byte, error) {
o.logger.Printf("Read %d bytes from %s", len(buff), filepath.Join(td, subPath))
return buff, nil
}

func (o *options) getOci(ctx context.Context, u *url.URL) ([]byte, error) {
parts := strings.Split(u.Host+u.Path, "/")
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we can use ParseReference to parse the artifact url into a Reference.

ref, err := registry.ParseReference(u.Host + u.Path)
if err != nil {
  return nil, fmt.Errorf("can't parse artifact url in a valid reference: %w", err)
}
registry := ref.Registry
repo := ref.Repository
var tag = "latest"
if ref.Reference != "" {
  tag = ref.Reference
}

We might get rid of all the parsing stuff from line 244 to line 256.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

alright

uriget/uriget.go Outdated
if err != nil {
return nil, fmt.Errorf("failed to create OCI layout store: %w", err)
}
repoUrl := fmt.Sprintf("%s/%s", registry, repo)
Copy link
Contributor

Choose a reason for hiding this comment

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

If we convert the url into a Reference, we don't need to compose the repo url anymore, but we can leverage String method from it (registry and repo vars will not be needed anymore).

uriget/uriget.go Outdated
if err != nil {
return nil, fmt.Errorf("failed to connect to remote repository: %w", err)
}
if strings.HasPrefix(repoUrl, "localhost:") || strings.HasPrefix(repoUrl, "127.0.0.1:") {
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we really need this? Genuine question, I am not sure about it, it sounds weird to me that this is not handled by oras.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added it cause I was pulling a local image from my docker remote repo, Basically, the terminal kept complaining about the HTTP request so I had to filter it, to avoid the errors and to pull the image, Maybe it was no use , so I'll remove it

Copy link
Contributor

Choose a reason for hiding this comment

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

I wasn't able to find anything like that in all the examples from oras library (here some examples) but I'm not an expert here, as said, it's only a gut feeling that this might be not required :).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

And yes you are right :)

uriget/example_test.go Show resolved Hide resolved
@mathieu-benoit mathieu-benoit marked this pull request as draft October 17, 2024 13:05
@7h3-3mp7y-m4n 7h3-3mp7y-m4n marked this pull request as ready for review October 17, 2024 18:57
Copy link
Contributor

@delca85 delca85 left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks for incorporating the suggested changes.

@mathieu-benoit
Copy link
Contributor

Wow, really great job on this one, @7h3-3mp7y-m4n, much appreciated!

And thank you very much, @delca85, for the detailed review and suggestions, much appreciated too!

Copy link
Contributor

@mathieu-benoit mathieu-benoit left a comment

Choose a reason for hiding this comment

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

LGTM

@mathieu-benoit mathieu-benoit merged commit b5497ab into score-spec:main Oct 18, 2024
4 checks passed
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.

3 participants