kraken 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -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,7 @@
1
+ source :rubygems
2
+
3
+ gemspec
4
+
5
+ group :development do
6
+ gem 'guard-rspec'
7
+ end
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Umang Chouhan
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.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # Kraken
2
+
3
+ Test driven configuration and deploys across multiple environments and servers.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'kraken'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install kraken
18
+
19
+ ## Usage
20
+
21
+ Inherit from Kraken and you shall receive all the power you need.
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 'Added some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require 'bundler/gem_tasks'
data/kraken.gemspec ADDED
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/kraken/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = [ 'Umang Chouhan' ]
6
+ gem.email = [ 'uchouhan@optimiscorp.com' ]
7
+ gem.description = 'Test driven configuration and deploys across multiple environments and servers.'
8
+ gem.summary = 'Use chefs knife to automate complicated deploys.'
9
+ gem.homepage = 'http://github.com/optimis/kraken'
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map { |file| File.basename(file) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = 'kraken'
15
+ gem.require_paths = [ 'lib' ]
16
+ gem.version = Kraken::VERSION
17
+
18
+ gem.add_dependency 'net-ssh'
19
+ gem.add_dependency 'chef'
20
+
21
+ gem.add_development_dependency 'rake'
22
+ gem.add_development_dependency 'rspec'
23
+ end
data/lib/kraken.rb ADDED
@@ -0,0 +1,74 @@
1
+ require 'kraken/version'
2
+ require 'net/ssh'
3
+ require 'net/ssh/multi'
4
+ require 'chef'
5
+ require 'chef/knife'
6
+
7
+ module Kraken
8
+ class Bestower < Chef::Knife
9
+ deps do
10
+ require 'chef/search/query'
11
+
12
+ Chef::Knife::Ssh.load_deps
13
+ end
14
+
15
+ option :environment, :short => '-e ENVIRONMENT', :long => '--environment', :description => 'The environment to slice.'
16
+
17
+ private
18
+ def environment
19
+ config[:environment] || 'RC'
20
+ end
21
+
22
+ def nodes(tag)
23
+ query = Chef::Search::Query.new
24
+
25
+ nodes = []
26
+ query.search 'node', "chef_environment:#{environment} AND tags:#{tag}" do |node|
27
+ nodes << node
28
+ end
29
+ nodes
30
+ end
31
+
32
+ def rc?
33
+ environment == 'RC'
34
+ end
35
+
36
+ def user
37
+ rc? ? 'ec2-user' : 'config'
38
+ end
39
+
40
+ def command
41
+ 'sudo chef-client'
42
+ end
43
+
44
+ def chef(node, recipe)
45
+ ssh = Chef::Knife::Ssh.new
46
+ ssh.config[:node_name] = node.name
47
+ ssh.config[:ssh_user] = user
48
+
49
+ if rc?
50
+ ssh.config[:attribute] = 'ec2.public_hostname'
51
+ ssh.config[:identity_file] = '~/.ssh/aws' if rc?
52
+ end
53
+
54
+ ssh.name_args = [ "name:#{node.name}", command ]
55
+ ssh.run
56
+
57
+ node.run_list.remove recipe
58
+ node.save
59
+
60
+ Chef::Log.debug "Kraken deployed #{recipe} on #{node.name}!"
61
+ end
62
+
63
+ def perform(application, recipe)
64
+ nodes(application).each do |node|
65
+ Chef::Log.debug "Adding #{recipe} to #{node.name}'s run list."
66
+ node.run_list << recipe
67
+ node.save
68
+
69
+ Chef::Log.debug "Running chef client on #{node.name}."
70
+ chef node, recipe
71
+ end
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,3 @@
1
+ module Kraken
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,5 @@
1
+ require 'spec_helper'
2
+
3
+ describe Kraken::Bestower, 'Knife' do
4
+ it { subject.should be_kind_of Chef::Knife }
5
+ end
@@ -0,0 +1,6 @@
1
+ require 'rspec'
2
+ require 'kraken'
3
+
4
+ RSpec.configure do
5
+
6
+ end
metadata ADDED
@@ -0,0 +1,108 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: kraken
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Umang Chouhan
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-03-29 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: net-ssh
16
+ requirement: &70240478378900 !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: *70240478378900
25
+ - !ruby/object:Gem::Dependency
26
+ name: chef
27
+ requirement: &70240478378480 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70240478378480
36
+ - !ruby/object:Gem::Dependency
37
+ name: rake
38
+ requirement: &70240478378060 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *70240478378060
47
+ - !ruby/object:Gem::Dependency
48
+ name: rspec
49
+ requirement: &70240478377640 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *70240478377640
58
+ description: Test driven configuration and deploys across multiple environments and
59
+ servers.
60
+ email:
61
+ - uchouhan@optimiscorp.com
62
+ executables: []
63
+ extensions: []
64
+ extra_rdoc_files: []
65
+ files:
66
+ - .gitignore
67
+ - Gemfile
68
+ - LICENSE
69
+ - README.md
70
+ - Rakefile
71
+ - kraken.gemspec
72
+ - lib/kraken.rb
73
+ - lib/kraken/version.rb
74
+ - spec/lib/kraken_spec.rb
75
+ - spec/spec_helper.rb
76
+ homepage: http://github.com/optimis/kraken
77
+ licenses: []
78
+ post_install_message:
79
+ rdoc_options: []
80
+ require_paths:
81
+ - lib
82
+ required_ruby_version: !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ! '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ segments:
89
+ - 0
90
+ hash: -609388482725713793
91
+ required_rubygems_version: !ruby/object:Gem::Requirement
92
+ none: false
93
+ requirements:
94
+ - - ! '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ segments:
98
+ - 0
99
+ hash: -609388482725713793
100
+ requirements: []
101
+ rubyforge_project:
102
+ rubygems_version: 1.8.11
103
+ signing_key:
104
+ specification_version: 3
105
+ summary: Use chefs knife to automate complicated deploys.
106
+ test_files:
107
+ - spec/lib/kraken_spec.rb
108
+ - spec/spec_helper.rb