caterer 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in caterer.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Tyler Flint
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,29 @@
1
+ # Caterer
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'caterer'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install caterer
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,35 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # TODO: find a way to conditionally trigger this if dev only
4
+ lib = File.expand_path('../../lib', __FILE__)
5
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
6
+
7
+ require 'log4r'
8
+ require 'caterer'
9
+ require 'vli'
10
+
11
+ $stdout.sync = true
12
+ $stderr.sync = true
13
+
14
+ logger = Log4r::Logger.new "caterer::bin::cater"
15
+ logger.info "`cater` invoked: #{ARGV.inspect}"
16
+
17
+ opts = {}
18
+
19
+ # Disable color if the proper argument was passed or if we're
20
+ # on Windows since the default Windows terminal doesn't support
21
+ # colors.
22
+ if ARGV.include?("--no-color") || !$stdout.tty? || !Vli::Util::Platform.terminal_supports_colors?
23
+ # Delete the argument from the list so that it doesn't cause any
24
+ # invalid arguments down the road.
25
+ ARGV.delete("--no-color")
26
+ opts[:ui_class] = Vli::UI::Basic
27
+ else
28
+ opts[:ui_class] = Vli::UI::Colored
29
+ end
30
+
31
+ env = Caterer::Environment.new(opts)
32
+
33
+ env.load!
34
+
35
+ exit env.cli(ARGV)
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'caterer/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "caterer"
8
+ gem.version = Caterer::VERSION
9
+ gem.authors = ["Tyler Flint"]
10
+ gem.email = ["tylerflint@gmail.com"]
11
+ gem.description = %q{Caterer is a server configuration tool that caters to your servers with a push model, with support for chef recipes}
12
+ gem.summary = %q{A server configuration tool that caters to your servers with a push model, with support for chef recipes}
13
+ gem.homepage = ""
14
+
15
+ gem.add_dependency 'log4r'
16
+ gem.add_dependency 'activesupport'
17
+ gem.add_dependency 'vli'
18
+
19
+ gem.files = `git ls-files`.split($/)
20
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
21
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
22
+ gem.require_paths = ["lib"]
23
+ end
@@ -0,0 +1,3 @@
1
+ Caterer.configure do |config|
2
+ # nothing to see here... yet
3
+ end
@@ -0,0 +1,25 @@
1
+ Caterer.configure do |config|
2
+
3
+ config.role :default do |node|
4
+
5
+ node.provision :chef_solo do |chef|
6
+ chef.add_recipe 'ruby'
7
+ chef.add_recipe 'mysql::server'
8
+ chef.add_recipe 'mysql::client'
9
+ chef.json = {
10
+ "ruby" => {
11
+ "gems" => ['args_parser', 'mysql2']
12
+ },
13
+ "mysql" => {
14
+ "server_root_password" => "root",
15
+ "bind_address" => '127.0.0.1',
16
+ "client" => {
17
+ "packages" => ["mysql-client", "libmysqlclient-dev"]
18
+ }
19
+ }
20
+ }
21
+ end
22
+
23
+ end
24
+
25
+ end
@@ -0,0 +1,27 @@
1
+ require 'vli'
2
+ require 'caterer/version'
3
+ require 'caterer/logger'
4
+
5
+ module Caterer
6
+ autoload :Cli, 'caterer/cli'
7
+ autoload :Command, 'caterer/command'
8
+ autoload :Config, 'caterer/config'
9
+ autoload :Environment, 'caterer/environment'
10
+
11
+ extend self
12
+
13
+ def commands
14
+ @commands ||= Vli::Registry.new
15
+ end
16
+
17
+ def config
18
+ @config ||= Config::Base.new
19
+ end
20
+
21
+ def configure
22
+ yield config if block_given?
23
+ end
24
+
25
+ end
26
+
27
+ require 'caterer/commands'
@@ -0,0 +1,71 @@
1
+ # Credit:
2
+ # special thanks to Vagrant project: https://github.com/mitchellh/vagrant
3
+ # where the source of this module was originally extracted.
4
+
5
+ require 'optparse'
6
+
7
+ module Caterer
8
+ class Cli < Vli::Command::Base
9
+ def initialize(argv, env)
10
+ super
11
+
12
+ @logger = Log4r::Logger.new("caterer::cli")
13
+ @main_args, @sub_command, @sub_args = split_main_and_subcommand(argv)
14
+
15
+ @logger.info("CLI: #{@main_args.inspect} #{@sub_command.inspect} #{@sub_args.inspect}")
16
+ end
17
+
18
+ def execute
19
+ if @main_args.include?("-v") || @main_args.include?("--version")
20
+ # Version short-circuits the whole thing. Just print
21
+ # the version and exit.
22
+ @env.ui.info "Caterer version #{Caterer::VERSION}", :prefix => false
23
+
24
+ return 0
25
+ elsif @main_args.include?("-h") || @main_args.include?("--help")
26
+ # Help is next in short-circuiting everything. Print
27
+ # the help and exit.
28
+ help
29
+ return 0
30
+ end
31
+
32
+ command_class = Caterer.commands.get(@sub_command.to_sym) if @sub_command
33
+ if !command_class || !@sub_command
34
+ help
35
+ return 0
36
+ end
37
+ @logger.debug("Invoking command class: #{command_class} #{@sub_args.inspect}")
38
+
39
+ # Initialize and execute the command class, returning the exit status.
40
+ result = command_class.new(@sub_args, @env).execute
41
+ result = 0 if !result.is_a?(Fixnum)
42
+ result
43
+ end
44
+
45
+ def help
46
+ opts = OptionParser.new do |opts|
47
+ opts.banner = "Usage: cater [-v] [-h] command [<args>]"
48
+ opts.separator ""
49
+ opts.on("-v", "--version", "Print the version and exit.")
50
+ opts.on("-h", "--help", "Print this help.")
51
+ opts.separator ""
52
+ opts.separator "Available subcommands:"
53
+
54
+ # Add the available subcommands as separators in order to print them
55
+ # out as well.
56
+ keys = []
57
+ Caterer.commands.each { |key, value| keys << key.to_s }
58
+
59
+ keys.sort.each do |key|
60
+ opts.separator " #{key}"
61
+ end
62
+
63
+ opts.separator ""
64
+ opts.separator "For help on any individual command run `cater COMMAND -h`"
65
+ end
66
+
67
+ @env.ui.info opts.help, :prefix => false
68
+ end
69
+
70
+ end
71
+ end
@@ -0,0 +1,5 @@
1
+ module Caterer
2
+ module Command
3
+ autoload :Test, 'caterer/command/test'
4
+ end
5
+ end
@@ -0,0 +1,12 @@
1
+ module Caterer
2
+ module Command
3
+ class Test < Vli::Command::Base
4
+
5
+ def execute
6
+ puts "testy testy!"
7
+ 0
8
+ end
9
+
10
+ end
11
+ end
12
+ end
@@ -0,0 +1 @@
1
+ Caterer.commands.register(:test) { Caterer::Command::Test }
@@ -0,0 +1,7 @@
1
+ module Caterer
2
+ module Config
3
+ autoload :Base, 'caterer/config/base'
4
+ autoload :Role, 'caterer/config/role'
5
+ autoload :Provision, 'caterer/config/provision'
6
+ end
7
+ end
@@ -0,0 +1,17 @@
1
+ module Caterer::Config
2
+
3
+ class Base
4
+ attr_accessor :roles
5
+
6
+ def initialize
7
+ @roles = []
8
+ end
9
+
10
+ def role(name)
11
+ role = Caterer::Config::Role.new(name)
12
+ yield role if block_given?
13
+ @roles << role
14
+ end
15
+ end
16
+
17
+ end
@@ -0,0 +1,5 @@
1
+ module Caterer::Config
2
+ module Provision
3
+ autoload :ChefSolo, 'caterer/config/provision/chef_solo'
4
+ end
5
+ end
@@ -0,0 +1,18 @@
1
+ module Caterer::Config::Provision
2
+
3
+ class ChefSolo
4
+
5
+ attr_accessor :recipes, :json
6
+
7
+ def initialize
8
+ @recipes = []
9
+ @json = {}
10
+ end
11
+
12
+ def add_recipe(recipe)
13
+ @recipes << recipe
14
+ end
15
+
16
+ end
17
+
18
+ end
@@ -0,0 +1,21 @@
1
+ require 'active_support/inflector'
2
+
3
+ module Caterer::Config
4
+
5
+ class Role
6
+
7
+ attr_reader :name
8
+
9
+ def initialize(name)
10
+ @name = name
11
+ end
12
+
13
+ def provision(type=nil)
14
+ return @provision if not type
15
+ @provision = "Caterer::Config::Provision::#{type.to_s.classify}".constantize.new
16
+ yield @provision if block_given?
17
+ end
18
+
19
+ end
20
+
21
+ end
@@ -0,0 +1,53 @@
1
+ require 'pathname'
2
+
3
+ module Caterer
4
+ class Environment
5
+
6
+ attr_reader :cwd, :caterfile_name, :ui
7
+
8
+ def initialize(opts={})
9
+ opts = {
10
+ :cwd => nil,
11
+ :caterfile_name => nil,
12
+ :ui_class => nil
13
+ }.merge(opts)
14
+
15
+ opts[:cwd] ||= ENV["CATERER_CWD"] if ENV.has_key?("CATERER_CWD")
16
+ opts[:cwd] ||= Dir.pwd
17
+ opts[:cwd] = Pathname.new(opts[:cwd])
18
+
19
+ opts[:caterfile_name] ||= []
20
+ opts[:caterfile_name] = [opts[:caterfile_name]] if !opts[:vagrantfile_name].is_a?(Array)
21
+ opts[:caterfile_name] += ["Caterfile"]
22
+
23
+ @cwd = opts[:cwd]
24
+ @caterfile_name = opts[:caterfile_name]
25
+
26
+ ui_class = opts[:ui_class] || Vli::UI::Silent
27
+ @ui = ui_class.new("cater")
28
+
29
+ end
30
+
31
+ def load!
32
+ load_default_config
33
+ load_custom_config
34
+ end
35
+
36
+ def load_default_config
37
+ # doesn't work yet
38
+ # require 'config/default'
39
+ end
40
+
41
+ def load_custom_config
42
+ @caterfile_name.each do |config_file|
43
+ file = "#{@cwd}/#{config_file}"
44
+ load file if File.exists? file
45
+ end
46
+ end
47
+
48
+ def cli(*args)
49
+ Cli.new(args.flatten, self).execute
50
+ end
51
+
52
+ end
53
+ end
@@ -0,0 +1,43 @@
1
+ require 'log4r'
2
+
3
+ # Enable logging if it is requested. We do this before
4
+ # anything else so that we can setup the output before
5
+ # any logging occurs.
6
+ if ENV["LOG_LEVEL"] && ENV["LOG_LEVEL"] != ""
7
+ # Require Log4r and define the levels we'll be using
8
+ require 'log4r/config'
9
+ Log4r.define_levels(*Log4r::Log4rConfig::LogLevels)
10
+
11
+ level = nil
12
+ begin
13
+ level = Log4r.const_get(ENV["LOG_LEVEL"].upcase)
14
+ rescue NameError
15
+ # This means that the logging constant wasn't found,
16
+ # which is fine. We just keep `level` as `nil`. But
17
+ # we tell the user.
18
+ level = nil
19
+ end
20
+
21
+ # Some constants, such as "true" resolve to booleans, so the
22
+ # above error checking doesn't catch it. This will check to make
23
+ # sure that the log level is an integer, as Log4r requires.
24
+ level = nil if !level.is_a?(Integer)
25
+
26
+ if !level
27
+ # We directly write to stderr here because the VagrantError system
28
+ # is not setup yet.
29
+ $stderr.puts "Invalid LOG_LEVEL: #{ENV["LOG_LEVEL"]}"
30
+ $stderr.puts ""
31
+ $stderr.puts "Please use one of the standard log levels: debug, info, warn, or error"
32
+ exit 1
33
+ end
34
+
35
+ # Set the logging level on all "caterer" namespaced
36
+ # logs as long as we have a valid level.
37
+ if level
38
+ logger = Log4r::Logger.new("caterer")
39
+ logger.outputters = Log4r::Outputter.stderr
40
+ logger.level = level
41
+ logger = nil
42
+ end
43
+ end
@@ -0,0 +1,3 @@
1
+ module Caterer
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,119 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: caterer
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Tyler Flint
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-12-05 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: log4r
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: activesupport
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: vli
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ description: Caterer is a server configuration tool that caters to your servers with
63
+ a push model, with support for chef recipes
64
+ email:
65
+ - tylerflint@gmail.com
66
+ executables:
67
+ - cater
68
+ extensions: []
69
+ extra_rdoc_files: []
70
+ files:
71
+ - .gitignore
72
+ - Gemfile
73
+ - LICENSE.txt
74
+ - README.md
75
+ - Rakefile
76
+ - bin/cater
77
+ - caterer.gemspec
78
+ - config/default.rb
79
+ - example/Caterfile
80
+ - lib/caterer.rb
81
+ - lib/caterer/cli.rb
82
+ - lib/caterer/command.rb
83
+ - lib/caterer/command/test.rb
84
+ - lib/caterer/commands.rb
85
+ - lib/caterer/config.rb
86
+ - lib/caterer/config/base.rb
87
+ - lib/caterer/config/provision.rb
88
+ - lib/caterer/config/provision/chef_solo.rb
89
+ - lib/caterer/config/role.rb
90
+ - lib/caterer/environment.rb
91
+ - lib/caterer/logger.rb
92
+ - lib/caterer/version.rb
93
+ homepage: ''
94
+ licenses: []
95
+ post_install_message:
96
+ rdoc_options: []
97
+ require_paths:
98
+ - lib
99
+ required_ruby_version: !ruby/object:Gem::Requirement
100
+ none: false
101
+ requirements:
102
+ - - ! '>='
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ required_rubygems_version: !ruby/object:Gem::Requirement
106
+ none: false
107
+ requirements:
108
+ - - ! '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ requirements: []
112
+ rubyforge_project:
113
+ rubygems_version: 1.8.24
114
+ signing_key:
115
+ specification_version: 3
116
+ summary: A server configuration tool that caters to your servers with a push model,
117
+ with support for chef recipes
118
+ test_files: []
119
+ has_rdoc: