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

Use shallow cloning to add pack registries #444

Merged
merged 3 commits into from
Oct 25, 2023

Conversation

attachmentgenie
Copy link
Contributor

@attachmentgenie attachmentgenie commented Oct 20, 2023

We use a mono repo to build out all of our platforms, as a down side of this our git history and .git directory are huge (think 10x the actual code size)which causes git clones to be quite slow.

This PR switches the git clone behaviour of nomad-pack registry add to use shallow clone instead. In our particular case it drops the length of the process from ~9s to 0.5s.

Reminders

  • Add CHANGELOG.md entry

@attachmentgenie attachmentgenie force-pushed the shallow_clone_registries branch from e2d6d78 to 80cb4ac Compare October 20, 2023 13:05
Copy link
Contributor

@pkazmierczak pkazmierczak left a comment

Choose a reason for hiding this comment

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

Thanks for the PR @attachmentgenie! This is good thinking, in many scenarios (big repo, using pack in CI) a shallow clone makes much more sense than a full clone. However, shallow clones affect what we can do with the repository, and that's why I'd prefer shallow-cloning to be a flag.

For example, if we were to support updating registries, we'd have to introduce special treatment for shallow-cloned repositories, and their updates would take much longer. Secondly, users might want to switch branches of their registries (granted, a niche use-case, but possible with current implementation and defaulting to shallow-clones would break it).

I don't have a strong opinion on whether this should be an opt-in or an opt-out flag, perhaps @angrycub has an opinion? But I think it should be a flag nonetheless.

@@ -154,6 +154,9 @@ func (c *Cache) cloneRemoteGitRegistry(opts *AddOpts) (string, error) {
// If ref is set, add query string variable
if !opts.IsLatest() {
url = fmt.Sprintf("%s?ref=%s", url, opts.Ref)
} else {
// Attempt to shallow clone the constructed url
url = fmt.Sprintf("%s?depth=1", url)
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd rather have the shallow clone be a a flag to the add command than handling it this way.

@attachmentgenie
Copy link
Contributor Author

I debated with myself about feature flagging it but ultimately (lazily) decided not to do it because as long as , this bit of code is in place, there are IMHO no benefits to keeping any history more that the commit your are looking for since nomad-pack cleans that up for you automatically after adding the registry

But i am more than happy to add the feature flag code if you are considering removing that code in the (near) future

@pkazmierczak
Copy link
Contributor

as long as , this bit of code is in place, there are IMHO no benefits to keeping any history more that the commit your are looking for since nomad-pack cleans that up for you automatically after adding the registry

Right! The team has been thinking about adding an update feature though, and I just thought fetching would be a natural way to do this.

The more I think about shallow clones, the more I think this could just be an opt-out feature, as in: we'd default to a shallow clone.

@attachmentgenie
Copy link
Contributor Author

The more I think about shallow clones, the more I think this could just be an opt-out feature, as in: we'd default to a shallow clone.

alright, will update to do just that

Copy link
Contributor

@pkazmierczak pkazmierczak left a comment

Choose a reason for hiding this comment

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

I've reconsidered, you're right. Shallow-clones are the way to go. Vide #447 (review)

@pkazmierczak pkazmierczak merged commit 07eaeb3 into hashicorp:main Oct 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants