[go: up one dir, main page]

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

implement getting plugins from remote git sources #17827

Open
wants to merge 5 commits into
base: tg/new-plugin-source
Choose a base branch
from

Conversation

tgummerer
Copy link
Collaborator
@tgummerer tgummerer commented Nov 21, 2024

Allow users go get and run plugins from remote git sources. This should work with all currently supported sources, such as GitHub and GitLab (for the correct URL splitting).

This does not currently support direct links (e.g. just pasting https://github.com/pulumi/pulumi-tls-self-signed-cert/tree/mikhailshilkov/boilerplateless/lib), or just getting the latest version of a plugin (the version needs to always be specified). These can be implemented separately later.

Depends on #17798

Allow users go get and run plugins from remote git sources.  This
should work with all currently supported sources, such as GitHub and
GitLab (for the correct URL splitting).
@tgummerer tgummerer marked this pull request as ready for review November 22, 2024 08:32
@tgummerer tgummerer requested a review from a team as a code owner November 22, 2024 08:32
path string
}

func newGitSource(url *url.URL) (*gitSource, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

We could name that newGitHTTPSSource since it always forces https.

}

tw.Close()
zip.Close()
Copy link
Contributor

Choose a reason for hiding this comment

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

Should these be defered before the potential error return?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I wanted to do that, but we can't. From https://go.dev/ref/spec#Defer_statements:

deferred functions are executed after any result parameters are set by that return statement but before the function returns to its caller.

So this means that tarbuf.Len() would be calculated before we do tw.Close(), which in turn means that the length can be off.

This is probably worth a comment though.

@@ -1378,7 +1378,7 @@ func (host *nodeLanguageHost) RunPlugin(
return err
}

env := os.Environ()
env := req.Env
Copy link
Contributor

Choose a reason for hiding this comment

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

The changes in this file look to be unrelated

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, let me pull these out.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

tw.Close()
zip.Close()

return io.NopCloser(tarbuf), int64(tarbuf.Len()), nil
Copy link
Contributor

Choose a reason for hiding this comment

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

It's a bit of a shame this builds the tarbuf in memory and then returns a reader to it, but it's probably not that easy to make this stream straight from the temp dir.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, this is the best I found so far.

Copy link
Member

Choose a reason for hiding this comment

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

Kinda loosing the point of this being an io.Reader, it was like that so we could see the download happening and do a progress bar. This isn't going to show any progress till the whole clone is finished.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Progress bar is always going to be kinda tricky with Git Repos. I don't think go-git supports anything like that. Also the way git works it downloads the objects first, and can only then open the repo and splat the files somewhere, that's not possible during transport.

Even the GitHub API to download contents of the repo (e.g. https://github.com/pulumi/pulumi/archive/refs/heads/master.zip) won't give the length upfront, so that also wouldn't help us get a progress bar here.

@@ -2278,7 +2378,7 @@ func getCandidateExtensions() []string {
// pluginRegexp matches plugin directory names: pulumi-KIND-NAME-VERSION.
var pluginRegexp = regexp.MustCompile(
"^(?P<Kind>[a-z]+)-" + // KIND
"(?P<Name>[a-zA-Z0-9-]*[a-zA-Z0-9])-" + // NAME
"(?P<Name>[a-zA-Z0-9-_.]*[a-zA-Z0-9])-" + // NAME
Copy link
Member

Choose a reason for hiding this comment

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

We're allowing dots to start names now?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I meant to only allow it within the name for URLs. E.g. github.com/pulumi/provider-bla gets turned into github.com_pulumi_provider-bla. Not sure we should even allow - at the beginning of the name, but since we always did I guess it's fine.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Hrm expressing not allowing . at the start of the regex is pretty awkward now. [a-zA-Z0-9-][a-zA-Z0-9-_.]*[a-zA-Z0-9])- would force at least two character names which we didn't. Though maybe that's fine, I doubt any providers with just a single character name exist currently anyway.

@@ -1745,7 +1755,7 @@ func TestNewPluginSpec(t *testing.T) {
Name: "github.com_pulumi_pulumi-example",
Copy link
Member

Choose a reason for hiding this comment

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

Thinking about this more while looking at it. Why is the name the whole url? Shouldn't it just be pulumi/pulumi-example, or maybe even just pulumi-example?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

To be able to distinguish the plugin. If it's just pulumi-example, it could come from gitlab.com/tgummerer/pulumi-example, but have the same name as github.com/pulumi/pulumi-example when that's downloaded using the current mechanisms. Which would get very confusing, especially as we're using this name on the file system to find the plugin again.

Copy link
Member

Choose a reason for hiding this comment

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

this is going to end up with plugin names that don't match the package names they provide though. I think there's parts of the system that might depend on that.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, I think we'll have to fix those though, otherwise this is getting messy with disambiguating 🤔

tw.Close()
zip.Close()

return io.NopCloser(tarbuf), int64(tarbuf.Len()), nil
Copy link
Member

Choose a reason for hiding this comment

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

Kinda loosing the point of this being an io.Reader, it was like that so we could see the download happening and do a progress bar. This isn't going to show any progress till the whole clone is finished.

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