yyuu-capistrano-chef-solo 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,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in capistrano-chef-solo.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Yamashita Yuu
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,64 @@
1
+ # capistrano-chef-solo
2
+
3
+ a capistrano recipe to invoke `chef-solo`.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'capistrano-chef-solo'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install capistrano-chef-solo
18
+
19
+ ## Usage
20
+
21
+ This recipe will try to bootstrap your servers with `chef-solo`. Following processes will be invoked.
22
+
23
+ 1. Install ruby for `chef-solo` with [capistrano-rbenv](https://github.com/yyuu/capistrano-rbenv)
24
+ 2. Install `chef` with [bundler](http://gembundler.com)
25
+ 3. Checkout your cookbooks and configurations
26
+ 4. Invoke `chef-solo`
27
+
28
+ To setup your servers with `chef-solo`, add following in you `config/deploy.rb`.
29
+
30
+ # in "config/deploy.rb"
31
+ require 'capistrano-chef-solo'
32
+ set(:chef_solo_cookbook_repository, "git@example.com:foo/bar.git")
33
+
34
+ And then, now you can start `chef-solo` via capistrano.
35
+
36
+ $ cap chef-solo
37
+
38
+ Following options are available to manage your `chef-solo`.
39
+
40
+ * `:chef_solo_version` - the version of chef.
41
+ * `:chef_solo_user` - special user to invoke `chef-solo`. use `user` by default.
42
+ * `:chef_solo_ssh_options` - special ssh options for `chef_solo_user`. use `ssh_options` by default.
43
+ * `:chef_solo_ruby_version` - ruby version to launch `chef-solo`.
44
+ * `:chef_solo_cookbook_repository` - the URL of your cookbook repository.
45
+ * `:chef_solo_cookbook_revision` - the `branch` in the repository.
46
+ * `:chef_solo_attributes` - the `attributes` to apply to `chef-solo`.
47
+ * `:chef_solo_run_list` - the `run_list` to apply to `chef-solo`.
48
+
49
+ ## Contributing
50
+
51
+ 1. Fork it
52
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
53
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
54
+ 4. Push to the branch (`git push origin my-new-feature`)
55
+ 5. Create new Pull Request
56
+
57
+ ## Author
58
+
59
+ - YAMASHITA Yuu (https://github.com/yyuu)
60
+ - Geisha Tokyo Entertainment Inc. (http://www.geishatokyo.com/)
61
+
62
+ ## License
63
+
64
+ MIT
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/capistrano-chef-solo/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Yamashita Yuu"]
6
+ gem.email = ["yamashita@geishatokyo.com"]
7
+ gem.description = %q{a capistrano recipe to invoke chef-solo.}
8
+ gem.summary = %q{a capistrano recipe to invoke chef-solo.}
9
+ gem.homepage = "https://github.com/yyuu/capistrano-chef-solo"
10
+
11
+ gem.files = `git ls-files`.split($/)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ # gem.name = "capistrano-chef-solo"
15
+ gem.name = "yyuu-capistrano-chef-solo"
16
+ gem.require_paths = ["lib"]
17
+ gem.version = Capistrano::ChefSolo::VERSION
18
+
19
+ gem.add_dependency("capistrano")
20
+ gem.add_dependency("capistrano-rbenv", ">= 0.0.3")
21
+ end
@@ -0,0 +1,5 @@
1
+ module Capistrano
2
+ module ChefSolo
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,125 @@
1
+ require "capistrano-chef-solo/version"
2
+ require 'capistrano-rbenv'
3
+ require 'json'
4
+ require 'tmpdir'
5
+
6
+ module Capistrano
7
+ module ChefSolo
8
+ def self.extended(configuration)
9
+ configuration.load {
10
+ namespace(:"chef-solo") {
11
+ _cset(:chef_solo_home) {
12
+ capture('echo $HOME').strip
13
+ }
14
+ _cset(:chef_solo_version, '0.10.12')
15
+ _cset(:chef_solo_path) { File.join(chef_solo_home, 'chef') }
16
+ _cset(:chef_solo_path_children, %w(bundle cache config cookbooks))
17
+
18
+ desc("Run chef-solo.")
19
+ task(:default) {
20
+ # login as chef user if specified
21
+ set(:user, fetch(:chef_solo_user, user))
22
+ set(:ssh_options, fetch(:chef_solo_ssh_options, ssh_options))
23
+
24
+ transaction {
25
+ bootstrap
26
+ update
27
+ }
28
+ }
29
+
30
+ task(:bootstrap) {
31
+ install_ruby
32
+ install_chef
33
+ }
34
+
35
+ _cset(:chef_solo_ruby_version) {
36
+ rbenv_ruby_version
37
+ }
38
+ task(:install_ruby) {
39
+ set(:rbenv_ruby_version, chef_solo_ruby_version)
40
+ set(:rbenv_use_bundler, true)
41
+ find_and_execute_task('rbenv:setup')
42
+ }
43
+
44
+ _cset(:chef_solo_gemfile) {
45
+ (<<-EOS).gsub(/^\s*/, '')
46
+ source "https://rubygems.org"
47
+ gem "chef", #{chef_solo_version.to_s.dump}
48
+ EOS
49
+ }
50
+ task(:install_chef) {
51
+ dirs = chef_solo_path_children.map { |dir| File.join(chef_solo_path, dir) }
52
+ run("mkdir -p #{dirs.join(' ')}")
53
+ put(chef_solo_gemfile, "#{File.join(chef_solo_path, 'Gemfile')}")
54
+ run("cd #{chef_solo_path} && #{bundle_cmd} install --path=#{chef_solo_path}/bundle --quiet")
55
+ }
56
+
57
+ task(:update) {
58
+ update_cookbook
59
+ update_config
60
+ invoke
61
+ }
62
+
63
+ _cset(:chef_solo_cookbook_repository) {
64
+ abort("chef_solo_cookbook_repository not set")
65
+ }
66
+ _cset(:chef_solo_cookbook_revision, 'HEAD')
67
+ task(:update_cookbook) {
68
+ git = fetch(:chef_solo_git, 'git')
69
+ tar = fetch(:chef_solo_tar, 'tar')
70
+ copy_dir = Dir.mktmpdir()
71
+ destination = File.join(copy_dir, 'cookbooks')
72
+ filename = "#{destination}.tar.gz"
73
+ remote_destination = File.join(chef_solo_path, 'cookbooks')
74
+ remote_filename = File.join('/tmp', File.basename(filename))
75
+
76
+ begin
77
+ checkout = []
78
+ checkout << "#{git} clone -q #{chef_solo_cookbook_repository} #{destination}"
79
+ checkout << "cd #{destination} && #{git} checkout -q -b deploy #{chef_solo_cookbook_revision}"
80
+ run_locally(checkout.join(' && '))
81
+
82
+ copy = []
83
+ copy << "cd #{File.dirname(destination)} && #{tar} chzf #{filename} #{File.basename(destination)}"
84
+ run_locally(copy.join(' && '))
85
+
86
+ upload(filename, remote_filename)
87
+ run("cd #{File.dirname(remote_destination)} && #{tar} xzf #{remote_filename} && rm -f #{remote_filename}")
88
+ ensure
89
+ run_locally("rm -rf #{copy_dir}")
90
+ end
91
+ }
92
+
93
+ _cset(:chef_solo_config) {
94
+ (<<-EOS).gsub(/^\s*/, '')
95
+ file_cache_path #{File.join(chef_solo_path, 'cache').dump}
96
+ cookbook_path #{File.join(chef_solo_path, 'cookbooks').dump}
97
+ EOS
98
+ }
99
+ _cset(:chef_solo_attributes, {})
100
+ task(:update_config) {
101
+ put(chef_solo_config, File.join(chef_solo_path, 'config', 'solo.rb'))
102
+
103
+ attributes = chef_solo_attributes.merge('run_list' => fetch(:chef_solo_run_list, []))
104
+ put(attributes.to_json, File.join(chef_solo_path, 'config', 'solo.json'))
105
+ }
106
+
107
+ task(:invoke) {
108
+ execute = []
109
+ execute << "cd #{chef_solo_path}"
110
+ execute << "#{sudo} #{bundle_cmd} exec chef-solo " + \
111
+ "-c #{File.join(chef_solo_path, 'config', 'solo.rb')} " + \
112
+ "-j #{File.join(chef_solo_path, 'config', 'solo.json')}"
113
+ run(execute.join(' && '))
114
+ }
115
+ }
116
+ }
117
+ end
118
+ end
119
+ end
120
+
121
+ if Capistrano::Configuration.instance
122
+ Capistrano::Configuration.instance.extend(Capistrano::ChefSolo)
123
+ end
124
+
125
+ # vim:set ft=ruby ts=2 sw=2 :
metadata ADDED
@@ -0,0 +1,85 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: yyuu-capistrano-chef-solo
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Yamashita Yuu
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-09-21 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: capistrano
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: capistrano-rbenv
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: 0.0.3
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.0.3
46
+ description: a capistrano recipe to invoke chef-solo.
47
+ email:
48
+ - yamashita@geishatokyo.com
49
+ executables: []
50
+ extensions: []
51
+ extra_rdoc_files: []
52
+ files:
53
+ - .gitignore
54
+ - Gemfile
55
+ - LICENSE.txt
56
+ - README.md
57
+ - Rakefile
58
+ - capistrano-chef-solo.gemspec
59
+ - lib/capistrano-chef-solo.rb
60
+ - lib/capistrano-chef-solo/version.rb
61
+ homepage: https://github.com/yyuu/capistrano-chef-solo
62
+ licenses: []
63
+ post_install_message:
64
+ rdoc_options: []
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ none: false
69
+ requirements:
70
+ - - ! '>='
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ required_rubygems_version: !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ! '>='
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ requirements: []
80
+ rubyforge_project:
81
+ rubygems_version: 1.8.23
82
+ signing_key:
83
+ specification_version: 3
84
+ summary: a capistrano recipe to invoke chef-solo.
85
+ test_files: []