Add script/sync-puppet helper

This commit is contained in:
John Barnette
2012-10-03 20:51:35 -07:00
parent bb56d27ab1
commit bd92c872d3
3 changed files with 64 additions and 0 deletions

2
.gitignore vendored
View File

@@ -1,5 +1,7 @@
/.bundle
/.env.local.rb
/.rbenv-version
/Gemfile.lock
/bin
/boxen-*.gem
/puppet

View File

@@ -5,3 +5,24 @@ Manage development boxes with love (and Puppet).
## Contributing
Use the OS X system Ruby (1.8.7). Run `script/tests` often. Open PR's.
### Managing Boxen's Puppet Modules
There are roughly nine million puppet modules under the
[Boxen GitHub organization][boxen]. To clone them all into a central
location, run `script/sync-puppet`. This script will make sure every
`boxen/puppet-*` repo is cloned under the `./puppet`, which is ignored
by Git.
[boxen]: https://github.com/boxen
Because it uses the GitHub API, `script/sync-puppet` requires the
`GITHUB_LOGIN` and `GITHUB_PASSWORD` environment variables to be set.
If you don't want to provide them every time, you can set them in
`.env.local.rb`, which is also ignored by Git. For example, your
`.env.local.rb` might look like this:
```ruby
ENV["GITHUB_LOGIN"] = "jbarnette"
ENV["GITHUB_PASSWORD"] = "adventures"
```

41
script/sync-puppet Executable file
View File

@@ -0,0 +1,41 @@
#!/usr/bin/env ruby
# Make sure all boxen/puppet-* repos are cloned under ./puppet.
require "fileutils"
require "pathname"
# Put us where we belong, in the root dir of boxen.
Dir.chdir Pathname.new(__FILE__).realpath + "../.."
# Load the local env in case creds are set there.
load ".env.local.rb" if File.file? ".env.local.rb"
# Make sure we're up to date.
abort "Bootstrap failed." unless system "script/bootstrap"
require "bundler/setup"
require "octokit"
unless ENV["GITHUB_LOGIN"] && ENV["GITHUB_PASSWORD"]
abort "Please set the GITHUB_LOGIN and GITHUB_PASSWORD env vars."
end
api = Octokit::Client.new \
:login => ENV["GITHUB_LOGIN"], :password => ENV["GITHUB_PASSWORD"]
# Gotta have a ./puppet dir.
FileUtils.mkdir_p "puppet"
# Clone boxen/puppet-* unless we have it already.
api.organization_repositories("boxen").each do |repo|
next unless /^puppet-/ =~ repo.name
unless File.directory? dest = "puppet/#{repo.name}"
system "git", "clone", repo.clone_url, dest
end
end