Add management tasks to rakefile

update ini to use chris's remote
This commit is contained in:
Dan Bode
2012-10-23 17:22:34 -07:00
parent b42ee86fc3
commit 328875ce4b
2 changed files with 110 additions and 3 deletions

View File

@@ -25,4 +25,4 @@ mod 'puppetlabs/stdlib', :git => 'git://github.com/puppetlabs/puppetlabs-stdlib'
mod 'puppetlabs/apt', :git => 'git://github.com/puppetlabs/puppetlabs-apt'
mod 'ripienaar/concat', :git => 'git://github.com/ripienaar/puppet-concat'
mod 'duritong/sysctl', :git => 'git://github.com/duritong/puppet-sysctl.git'
mod 'cprice/inifile', :git => 'git://github.com/bodepd/puppetlabs-inifile'
mod 'cprice/inifile', :git => 'git://github.com/cprice/puppetlabs-inifile'

111
Rakefile
View File

@@ -1,8 +1,6 @@
require 'yaml'
require 'rubygems'
require 'vagrant'
env = Vagrant::Environment.new(:cwd => File.dirname(__FILE__), :ui_class => Vagrant::UI::Colored)
def cmd_system (cmd)
result = system cmd
@@ -42,6 +40,9 @@ namespace :openstack do
end
task 'destroy' do
require 'vagrant'
env = Vagrant::Environment.new(:cwd => File.dirname(__FILE__), :ui_class => Vagrant::UI::Colored)
puts "About to destroy all vms..."
env.cli('vagrant destroy -f')
puts "Destroyed all vms"
@@ -49,8 +50,114 @@ namespace :openstack do
desc 'deploys the entire environment'
task :deploy_two_node do
require 'vagrant'
env = Vagrant::Environment.new(:cwd => File.dirname(__FILE__), :ui_class => Vagrant::UI::Colored)
build(:openstack_controller, env)
build(:compute1, env)
end
end
remote_name = 'bodepd'
namespace :paven do
cwd = File.expand_path(File.dirname(__FILE__))
desc 'for all repos in the module directory, add a read/write remote'
task :dev_setup do
each_repo do |repo|
# need to handle more failure cases
remotes = repo.remote_names
if remotes.include?(remote_name)
puts "Did not have to add remote #{remote_name} to #{File.basename(repo.path)}"
elsif ! remotes.include?('origin')
raise(Exception, "The repo #{File.basename(repo.path)} does not have a remote called origin, failing")
else
url = repo.remote_push_url('origin').gsub(/(git|https?):\/\/(.+)\/(.+)?\/(.+)/) do
"git@#{$2}:#{remote_name}/#{$4}"
end
puts "Adding remote #{remote_name} as #{url}"
repo.add_remote(remote_name, url)
end
end
end
desc 'pull the latest version of all code'
task :pull_all do
each_repo do |repo|
puts "Pulling repo: #{File.basename(repo.path)}"
puts ' ' + repo.pull.join("\n ")
end
end
desc 'shows the current state of code that has not been commited'
task :status_all do
each_repo do |repo|
status = repo.status
if status.include?('nothing to commit (working directory clean)')
puts "Module #{File.basename(repo.path)} has not changed" if verbose
else
puts "Uncommitted changes for: #{File.basename(repo.path)}"
puts " #{repo.status.join("\n ")}"
end
end
end
desc 'make sure that the current version from the module file matches the last tagged version'
task :check_tags do
# I need to be able to return this as a data structure
# when I start to do more complicated things like
# automated releases, I will need this data
each_repo do |repo|
require 'puppet'
modulefile = File.join(repo.path, 'Modulefile')
if File.exists?(modulefile)
print File.basename(repo.path)
metadata = ::Puppet::ModuleTool::Metadata.new
::Puppet::ModuleTool::ModulefileReader.evaluate(metadata, modulefile)
print ':' + metadata.version
branch_output = repo.git_cmd('branch')
if branch_output.first =~ /\* (.+)/
puts ":#{$1}"
git_cmd = %W(log #{metadata.version}..HEAD --oneline)
puts ' ' + repo.git_cmd(git_cmd).join("\n ")
else
puts ' ' + branch_output.join("\n ")
end
else
puts "#{File.basename(repo.path)} does not have a Modulefile"
end
end
end
task :check_sha do
each_repo do |repo|
print File.basename(repo.path) + ':'
puts repo.current_commit_hash
end
end
end
def each_repo(&block)
require 'librarian/puppet'
require 'librarian/puppet/source/git'
# create a manifest
# TODO replace this to use librarian puppet
env = Librarian::Puppet::Environment.new()
# this is the lock file, so it assumes that install has been run
env.lock.manifests.each do |manifest|
# I only care about git sources
if manifest.source.is_a? Librarian::Puppet::Source::Git
module_name = manifest.name.split('/', 2)[1]
module_path = File.join(env.install_path,module_name)
yield Librarian::Source::Git::Repository.new(env, module_path)
else
puts "Found a non-git manifest: #{manifest.class}, ignoring"
end
end
end