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

add a github downloader #947

Merged
merged 2 commits into from Dec 9, 2013
Merged

add a github downloader #947

merged 2 commits into from Dec 9, 2013

Conversation

punkle
Copy link
Contributor

@punkle punkle commented Dec 8, 2013

This is to support downloading cookbooks from a github location type by the berkshelf-api provided by Issue https://github.com/berkshelf/berkshelf-api/issues/27

@sethvargo
Copy link
Contributor

I don't really think this belongs in berkshelf core - is there a reason this isn't part of the API server?

@reset
Copy link
Contributor

reset commented Dec 8, 2013

@sethvargo @punkle is right, Berkshelf needs to know how to download each location_type for the API server. Currently there are only two types, "opscode" and "chef-server", but with his addition of the Github cache builder this would be the third.

@punkle this looks really solid, my comments are inline

@@ -65,6 +70,24 @@ def try_download(source, name, version)
# https://github.com/opscode/test-kitchen/blob/master/lib/kitchen.rb#L99
Celluloid.logger = nil unless ENV["DEBUG_CELLULOID"]
Ridley.open(credentials) { |r| r.cookbook.download(name, version) }
when :github
tmp_dir = "/tmp/#{name}/#{version}"
url = URI("https://codeload.github.com/#{remote_cookbook.location_path}/legacy.tar.gz/v#{version}")
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not just use the standard archive link (ie. https://github.com/punkle/berkshelf/archive/v2.0.10.tar.gz)? I admittedly don't even know what this legacy one is.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hey, I can't remember exactly where I found that url but I imagine I had followed a resource href in the github api somewhere. The url you are suggesting is much cleaner. With your url the root of the tar.gz contains the actual repository. This is not the case with the codeload url. Hence the complicated fname.include?("-#{name}-") malarkey. I can improve on this, in the morning (GMT).

@reset
Copy link
Contributor

reset commented Dec 8, 2013

@sethvargo also, the downloading logic should be moved into the berkshelf-api-client gem in the near future. That should clean stuff up a bit.

@@ -65,6 +70,24 @@ def try_download(source, name, version)
# https://github.com/opscode/test-kitchen/blob/master/lib/kitchen.rb#L99
Celluloid.logger = nil unless ENV["DEBUG_CELLULOID"]
Ridley.open(credentials) { |r| r.cookbook.download(name, version) }
when :github
tmp_dir = "/tmp/#{name}/#{version}"
Copy link
Contributor

Choose a reason for hiding this comment

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

Temp directories should be created with Dir.mktmpdir. Don't forget to cleanup afterwards! :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Where should this tmp dir be cleaned up? The try_download function returns a path to the tmp directory. If I delete the tmp directory at that point, won't it fail?

- better github download url
- using Dir.mktmpdir
- removes include Archive::Tar
@reset
Copy link
Contributor

reset commented Dec 9, 2013

@punkle thanks for doing both ends of this

reset added a commit that referenced this pull request Dec 9, 2013
@reset reset merged commit 0bdbcc6 into berkshelf:master Dec 9, 2013
@rteabeault
Copy link
Contributor

The berkshelf-api's github downloader uses an oauth token to communicate with github. This implies that you would be able to index private repositories. But after looking at the downloader code here I am thinking that it would not be able to download private repositories. Is that true?

@reset
Copy link
Contributor

reset commented Dec 17, 2013

@rteabeault good catch, we'll need to refactor this downloader a bit before 3.0 comes out.

@punkle punkle deleted the githubdownloader branch January 12, 2014 01:15
@berkshelf berkshelf locked and limited conversation to collaborators Jun 16, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants