Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

adding utility files: Rakefile, chefignore, .watchrs

  • Loading branch information...
commit 1032a697b30130a3bdd8ef5056b1f9929ae92773 1 parent a135a73
Philip (flip) Kromer authored
View
3  .rspec
@@ -0,0 +1,3 @@
+--color
+--format documentation
+--drb
View
29 Gemfile
@@ -0,0 +1,29 @@
+source "http://rubygems.org"
+
+gem 'chef', "~> 0.10.4"
+gem 'right_aws', "~> 2.1.0"
+#
+gem 'highline', "~> 1.6.2"
+gem 'fog', "~> 1.1.1"
+gem 'extlib', "~> 0.9.15"
+#
+gem 'formatador', "~> 0.2.1"
+gem 'choice', "~> 0.1.4"
+gem 'gorillib', "~> 0.1.7"
+
+# Add dependencies to develop your gem here.
+# Include everything needed to run rake, tests, features, etc.
+group :development do
+ gem 'bundler', "~> 1"
+ gem 'yard', "~> 0.6.7"
+ gem 'jeweler', "~> 1.6.4"
+ gem 'rspec', "~> 2.7.0"
+ gem 'spork', "~> 0.9.0.rc5"
+ gem 'watchr', "~> 0.7"
+ gem 'configliere', "~> 0.4.8"
+end
+
+group :vagrant do
+ gem 'vagrant'
+ gem 'veewee'
+end
View
137 Rakefile
@@ -1,9 +1,9 @@
#
# Rakefile for Chef Server Repository
#
-# Author:: Adam Jacob (<adam@opscode.com>)
+# Author:: Adam Jacob (<adam@opscode.com>)
# Copyright:: Copyright (c) 2008 Opscode, Inc.
-# License:: Apache License, Version 2.0
+# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -18,42 +18,58 @@
# limitations under the License.
#
-require 'rubygems'
+require 'rubygems' unless defined?(Gem)
+require 'bundler'
+begin
+ Bundler.setup(:default, :development)
+rescue Bundler::BundlerError => e
+ $stderr.puts e.message
+ $stderr.puts "Run `bundle install` to install missing gems"
+ exit e.status_code
+end
require 'chef'
require 'json'
+require 'jeweler'
+require 'rspec/core'
+require 'rspec/core/rake_task'
+require 'yard'
# Load constants from rake config file.
require File.join(File.dirname(__FILE__), 'config', 'rake')
-# Detect the version control system and assign to $vcs. Used by the update
-# task in chef_repo.rake (below). The install task calls update, so this
-# is run whenever the repo is installed.
+# ---------------------------------------------------------------------------
+#
+# Chef tasks
#
-# Comment out these lines to skip the update.
-
-if File.directory?(File.join(TOPDIR, ".svn"))
- $vcs = :svn
-elsif File.directory?(File.join(TOPDIR, ".git"))
- $vcs = :git
-end
-
# Load common, useful tasks from Chef.
# rake -T to see the tasks this loads.
+#
+
+# # Detect the version control system and assign to $vcs. Used by the update
+# # task in chef_repo.rake (below). The install task calls update, so this
+# # is run whenever the repo is installed.
+# #
+# # Comment out these lines to skip the update.
+# if File.directory?(File.join(TOPDIR, ".svn"))
+# $vcs = :svn
+# elsif File.directory?(File.join(TOPDIR, ".git"))
+# $vcs = :git
+# end
load 'chef/tasks/chef_repo.rake'
desc "Bundle a single cookbook for distribution"
task :bundle_cookbook => [ :metadata ]
task :bundle_cookbook, :cookbook do |t, args|
- tarball_name = "#{args.cookbook}.tar.gz"
- temp_dir = File.join(Dir.tmpdir, "chef-upload-cookbooks")
+ tarball_name = "#{args.cookbook}.tar.gz"
+ temp_dir = File.join(Dir.tmpdir, "chef-upload-cookbooks")
temp_cookbook_dir = File.join(temp_dir, args.cookbook)
- tarball_dir = File.join(TOPDIR, "pkgs")
+ tarball_dir = File.join(TOPDIR, "pkgs")
FileUtils.mkdir_p(tarball_dir)
FileUtils.mkdir(temp_dir)
FileUtils.mkdir(temp_cookbook_dir)
- child_folders = [ "cookbooks/#{args.cookbook}", "site-cookbooks/#{args.cookbook}" ]
+ child_folders = Dir[ "cookbooks/#{args.cookbook}", "*-cookbooks/#{args.cookbook}" ]
child_folders.each do |folder|
file_path = File.join(TOPDIR, folder, ".")
FileUtils.cp_r(file_path, temp_cookbook_dir) if File.directory?(file_path)
@@ -63,3 +79,88 @@ task :bundle_cookbook, :cookbook do |t, args|
FileUtils.rm_rf temp_dir
end
+
+
+desc "create a simple runit service template"
+task :create_runit, :cookbook, :template_name do |t, args|
+ cookbook = args.cookbook
+ template_name = args.template_name || cookbook
+ cookbook_roots = Dir[ "cookbooks", "*-cookbooks" ]
+ cookbook_dir = cookbook_roots.map{|r| Dir[ "#{r}/#{args.cookbook}"] }.flatten.compact.last
+ raise "Can't find cookbooks in #{cookbook_roots}" unless cookbook_dir
+ #
+ template_dir = File.join(cookbook_dir, 'templates', 'default')
+ sv_run_script_file = File.join(template_dir, "sv-#{template_name}-run.erb")
+ sv_log_script_file = File.join(template_dir, "sv-#{template_name}-log-run.erb")
+ #
+ sv_log_script_text = %Q{\#!/bin/sh\nexec svlogd -tt <%= @options[:log_dir] %>}
+ sv_run_script_text = %Q{#!/bin/bash
+exec 2>&1
+cd <%= @options[:pid_dir] %>
+exec chpst -u <%= @options[:user] %> /usr/sbin/#{template_name}
+}
+ FileUtils.mkdir_p(template_dir)
+ if File.exists?(sv_run_script_file) || File.exists?(sv_log_script_file)
+ warn "Files #{sv_run_script_file} and/or #{sv_log_script_file} exist -- remove them first"
+ exit
+ else
+ File.open(sv_run_script_file, "w"){|f| f.puts sv_run_script_text }
+ File.open(sv_log_script_file, "w"){|f| f.puts sv_log_script_text }
+ puts "Created runit scripts #{sv_run_script_file} and #{sv_log_script_file}"
+ puts "I bet you'll want to edit the run script, especially the path at the end of the last line"
+ end
+end
+
+
+# ---------------------------------------------------------------------------
+#
+# Jeweler -- release cluster_chef as a gem
+#
+Jeweler::Tasks.new do |gem|
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
+ gem.name = "cluster_chef"
+ gem.homepage = "http://infochimps.com/labs"
+ gem.license = NEW_COOKBOOK_LICENSE.to_s
+ gem.summary = %Q{cluster_chef allows you to orchestrate not just systems but clusters of machines. It includes a powerful layer on top of knife and a collection of cloud cookbooks.}
+ gem.description = %Q{cluster_chef allows you to orchestrate not just systems but clusters of machines. It includes a powerful layer on top of knife and a collection of cloud cookbooks.}
+ gem.email = SSL_EMAIL_ADDRESS
+ gem.authors = ["Infochimps"]
+
+ gem.add_development_dependency 'bundler', "~> 1.0.12"
+ gem.add_development_dependency 'jeweler', "~> 1.5.2"
+
+ ignores = File.readlines(".gitignore").grep(/^[^#]\S+/).map{|s| s.chomp }
+ dotfiles = [".gemtest", ".gitignore", ".rspec", ".yardopts"]
+ gem.files = dotfiles + Dir["**/*"].
+ reject{|f| f =~ %r{^(cookbooks|site-cookbooks|meta-cookbooks|integration-cookbooks)} }.
+ reject{|f| f =~ %r{^(certificates|clusters|config|data_bags|environments|roles|chefignore|deprecated|tasks)/} }.
+ reject{|f| File.directory?(f) }.
+ reject{|f| ignores.any?{|i| File.fnmatch(i, f) || File.fnmatch(i+'/**/*', f) } }
+ gem.test_files = gem.files.grep(/^spec\//)
+ gem.require_paths = ['lib']
+end
+Jeweler::RubygemsDotOrgTasks.new
+
+# ---------------------------------------------------------------------------
+#
+# RSpec -- testing
+#
+RSpec::Core::RakeTask.new(:spec) do |spec|
+ spec.pattern = FileList['spec/**/*_spec.rb']
+end
+
+RSpec::Core::RakeTask.new(:rcov) do |spec|
+ spec.pattern = 'spec/**/*_spec.rb'
+ spec.rcov = true
+ spec.rcov_opts = %w[ --exclude .rvm --no-comments --text-summary]
+end
+
+# ---------------------------------------------------------------------------
+#
+# Yard -- documentation
+#
+YARD::Rake::YardocTask.new
+
+# ---------------------------------------------------------------------------
+
+task :default => :spec
View
38 chefignore
@@ -1,11 +1,41 @@
# Put files/directories that should be ignored in this file.
# Lines that start with '# ' are comments.
-# emacs
-*~
+## OS
+.DS_Store
+Icon?
+nohup.out
-# vim
+## EDITORS
+\#*
+.#*
+*~
*.sw[a-z]
+*.bak
+REVISION
+TAGS*
+tmtags
+*_flymake.*
+*_flymake
+*.tmproj
+.project
+.settings
+mkmf.log
+
+## COMPILED
+a.out
+*.o
+*.pyc
+*.so
-# subversion
+## OTHER SCM
+*/.bzr/*
+*/.hg/*
*/.svn/*
+
+## Don't send rspecs up in cookbook
+.watchr
+.rspec
+spec/*
+spec/fixtures/*
+
View
32 knifer.watchr
@@ -0,0 +1,32 @@
+# -*- ruby -*-
+
+COOKBOOK_PATHS = %w[cookbooks meta-cookbooks site-cookbooks] unless defined?(COOKBOOK_PATHS)
+ROLES_PATH = 'roles' unless defined?(ROLES_PATH)
+
+def upload_cookbook(cookbook)
+ Watchr.debug "uploading cookbook #{cookbook}"
+ system "knife cookbook upload '#{cookbook}'"
+ puts
+end
+
+def upload_role(role)
+ Watchr.debug "uploading role file #{role}"
+ system "knife role from file '#{role}'"
+end
+
+COOKBOOK_PATHS.each do |cookbook_path|
+ watch("#{cookbook_path}/(.+?)/.*") do |match|
+ unless File.directory?(match[0])
+ Watchr.debug "cookbook file #{match[0]} changed"
+ upload_cookbook(match[1])
+ end
+ end
+end
+
+watch("#{ROLES_PATH}/.*\.rb") do |match|
+ upload_role(match[0])
+end
+
+# p Dir["#{ROLES_PATH}/*.rb"]
+# p Dir["#{COOKBOOK_PATHS.first}/*"]
+Watchr.debug "watchr #{__FILE__} loaded"
View
29 rspec.watchr
@@ -0,0 +1,29 @@
+# -*- ruby -*-
+
+def run_spec(file)
+ unless File.exist?(file)
+ puts "#{file} does not exist"
+ return
+ end
+
+ puts "Running #{file}"
+ system "rspec #{file}"
+ puts
+end
+
+watch("spec/.*/*_spec\.rb") do |match|
+ run_spec match[0]
+end
+
+watch("lib/(.*)\.rb") do |match|
+ file = %{spec/#{match[1]}_spec.rb}
+ run_spec file if File.exists?(file)
+end
+
+# watch('lib/cluster_chef/cookbook_munger\.rb') do |match|
+# system match[0]
+# end
+#
+# watch('lib/cluster_chef/cookbook_munger/.*\.erb') do |match|
+# system 'lib/cluster_chef/cookbook_munger.rb'
+# end
Please sign in to comment.
Something went wrong with that request. Please try again.