capigen 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Capfile +22 -0
- data/History.txt +3 -0
- data/License.txt +20 -0
- data/Manifest.txt +83 -0
- data/README.txt +35 -0
- data/Rakefile +4 -0
- data/config/hoe.rb +70 -0
- data/config/requirements.rb +17 -0
- data/init.rb +3 -0
- data/lib/capigen/config.rb +84 -0
- data/lib/capigen/helper.rb +51 -0
- data/lib/capigen/helpers/gem_helper.rb +15 -0
- data/lib/capigen/helpers/package_helper.rb +40 -0
- data/lib/capigen/helpers/script_helper.rb +30 -0
- data/lib/capigen/helpers/wget_helper.rb +17 -0
- data/lib/capigen/packagers/yum.rb +46 -0
- data/lib/capigen/profiles.rb +19 -0
- data/lib/capigen/recipes.yml +14 -0
- data/lib/capigen/templates.rb +65 -0
- data/lib/capigen/version.rb +9 -0
- data/lib/capigen.rb +26 -0
- data/recipes/README +12 -0
- data/recipes/bootstrap/patch.rb +87 -0
- data/recipes/centos.rb +40 -0
- data/recipes/deploy.rb +17 -0
- data/recipes/gems.rb +8 -0
- data/recipes/imagemagick.rb +9 -0
- data/recipes/install.rb +13 -0
- data/recipes/memcached.rb +15 -0
- data/recipes/mongrel_cluster.rb +49 -0
- data/recipes/monit.rb +16 -0
- data/recipes/mysql.rb +24 -0
- data/recipes/nginx.rb +42 -0
- data/recipes/profiles/centos-sick.rb +65 -0
- data/recipes/rails.rb +14 -0
- data/recipes/ruby.rb +14 -0
- data/recipes/sphinx.rb +62 -0
- data/script/destroy +14 -0
- data/script/generate +14 -0
- data/script/txt2html +74 -0
- data/setup.rb +1585 -0
- data/tasks/capigen.rake +13 -0
- data/tasks/deployment.rake +34 -0
- data/tasks/environment.rake +7 -0
- data/tasks/website.rake +17 -0
- data/templates/capistrano/Capfile +22 -0
- data/templates/capistrano/deploy.rb.erb +61 -0
- data/templates/centos/setup.sh +17 -0
- data/templates/centos/sudoers +95 -0
- data/templates/imagemagick/install.sh +20 -0
- data/templates/memcached/install.sh +27 -0
- data/templates/memcached/memcached.initd.centos.erb +70 -0
- data/templates/memcached/memcached.monitrc.erb +4 -0
- data/templates/mongrel/mongrel_cluster.initd.erb +61 -0
- data/templates/mongrel/mongrel_cluster.monitrc.erb +15 -0
- data/templates/mongrel/mongrel_cluster.yml.erb +10 -0
- data/templates/monit/cert.sh +14 -0
- data/templates/monit/install.sh +29 -0
- data/templates/monit/monit.cnf +34 -0
- data/templates/monit/monit.initd.centos.erb +68 -0
- data/templates/monit/monitrc.erb +28 -0
- data/templates/monit/patch_inittab.sh +15 -0
- data/templates/mysql/install.sh.erb +10 -0
- data/templates/mysql/install_db.sql.erb +5 -0
- data/templates/mysql/mysql.monitrc.erb +6 -0
- data/templates/nginx/install.sh.erb +42 -0
- data/templates/nginx/nginx.conf.erb +76 -0
- data/templates/nginx/nginx.initd.erb +62 -0
- data/templates/nginx/nginx.monitrc.erb +4 -0
- data/templates/nginx/nginx_vhost.conf.erb +94 -0
- data/templates/rails/database.yml.erb +42 -0
- data/templates/ruby/ruby_install.sh +26 -0
- data/templates/ruby/rubygems_install.sh +13 -0
- data/templates/sphinx/install.sh.erb +22 -0
- data/templates/sphinx/sphinx.conf.erb +496 -0
- data/templates/sphinx/sphinx.monitrc.erb +4 -0
- data/templates/sphinx/sphinx_app.initd.centos.erb +67 -0
- data/templates/sphinx/sphinx_app.initd.erb +57 -0
- data/website/index.html +93 -0
- data/website/index.txt +39 -0
- data/website/javascripts/rounded_corners_lite.inc.js +285 -0
- data/website/stylesheets/screen.css +138 -0
- data/website/template.rhtml +48 -0
- metadata +141 -0
data/Capfile
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Capfile for running base install recipe
|
|
3
|
+
#
|
|
4
|
+
|
|
5
|
+
load 'deploy' if respond_to?(:namespace) # cap2 differentiator
|
|
6
|
+
|
|
7
|
+
# Patches for capistrano
|
|
8
|
+
load "recipes/bootstrap/patch.rb"
|
|
9
|
+
|
|
10
|
+
# Load recipes
|
|
11
|
+
Dir['recipes/*.rb'].each { |plugin| load(plugin) }
|
|
12
|
+
|
|
13
|
+
require 'erb'
|
|
14
|
+
|
|
15
|
+
# This should be overriden by project specific Capfile
|
|
16
|
+
set :user, Proc.new { Capistrano::CLI.ui.ask('Bootstrap user: ') }
|
|
17
|
+
|
|
18
|
+
# Roles
|
|
19
|
+
role :base, Capistrano::CLI.ui.ask('Server: ')
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
set :profile, Proc.new { load choose_profile }
|
data/History.txt
ADDED
data/License.txt
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
Copyright (c) 2008 Gabriel Handford
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
4
|
+
a copy of this software and associated documentation files (the
|
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
9
|
+
the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be
|
|
12
|
+
included in all copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Manifest.txt
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
Capfile
|
|
2
|
+
History.txt
|
|
3
|
+
License.txt
|
|
4
|
+
Manifest.txt
|
|
5
|
+
README.txt
|
|
6
|
+
Rakefile
|
|
7
|
+
config/hoe.rb
|
|
8
|
+
config/requirements.rb
|
|
9
|
+
init.rb
|
|
10
|
+
lib/capigen.rb
|
|
11
|
+
lib/capigen/config.rb
|
|
12
|
+
lib/capigen/helper.rb
|
|
13
|
+
lib/capigen/helpers/gem_helper.rb
|
|
14
|
+
lib/capigen/helpers/package_helper.rb
|
|
15
|
+
lib/capigen/helpers/script_helper.rb
|
|
16
|
+
lib/capigen/helpers/wget_helper.rb
|
|
17
|
+
lib/capigen/packagers/yum.rb
|
|
18
|
+
lib/capigen/profiles.rb
|
|
19
|
+
lib/capigen/recipes.yml
|
|
20
|
+
lib/capigen/templates.rb
|
|
21
|
+
lib/capigen/version.rb
|
|
22
|
+
recipes/README
|
|
23
|
+
recipes/bootstrap/patch.rb
|
|
24
|
+
recipes/centos.rb
|
|
25
|
+
recipes/deploy.rb
|
|
26
|
+
recipes/gems.rb
|
|
27
|
+
recipes/imagemagick.rb
|
|
28
|
+
recipes/install.rb
|
|
29
|
+
recipes/memcached.rb
|
|
30
|
+
recipes/mongrel_cluster.rb
|
|
31
|
+
recipes/monit.rb
|
|
32
|
+
recipes/mysql.rb
|
|
33
|
+
recipes/nginx.rb
|
|
34
|
+
recipes/profiles/centos-sick.rb
|
|
35
|
+
recipes/rails.rb
|
|
36
|
+
recipes/ruby.rb
|
|
37
|
+
recipes/sphinx.rb
|
|
38
|
+
script/destroy
|
|
39
|
+
script/generate
|
|
40
|
+
script/txt2html
|
|
41
|
+
setup.rb
|
|
42
|
+
tasks/capigen.rake
|
|
43
|
+
tasks/deployment.rake
|
|
44
|
+
tasks/environment.rake
|
|
45
|
+
tasks/website.rake
|
|
46
|
+
templates/capistrano/Capfile
|
|
47
|
+
templates/capistrano/deploy.rb.erb
|
|
48
|
+
templates/centos/setup.sh
|
|
49
|
+
templates/centos/sudoers
|
|
50
|
+
templates/imagemagick/install.sh
|
|
51
|
+
templates/memcached/install.sh
|
|
52
|
+
templates/memcached/memcached.initd.centos.erb
|
|
53
|
+
templates/memcached/memcached.monitrc.erb
|
|
54
|
+
templates/mongrel/mongrel_cluster.initd.erb
|
|
55
|
+
templates/mongrel/mongrel_cluster.monitrc.erb
|
|
56
|
+
templates/mongrel/mongrel_cluster.yml.erb
|
|
57
|
+
templates/monit/cert.sh
|
|
58
|
+
templates/monit/install.sh
|
|
59
|
+
templates/monit/monit.cnf
|
|
60
|
+
templates/monit/monit.initd.centos.erb
|
|
61
|
+
templates/monit/monitrc.erb
|
|
62
|
+
templates/monit/patch_inittab.sh
|
|
63
|
+
templates/mysql/install.sh.erb
|
|
64
|
+
templates/mysql/install_db.sql.erb
|
|
65
|
+
templates/mysql/mysql.monitrc.erb
|
|
66
|
+
templates/nginx/install.sh.erb
|
|
67
|
+
templates/nginx/nginx.conf.erb
|
|
68
|
+
templates/nginx/nginx.initd.erb
|
|
69
|
+
templates/nginx/nginx.monitrc.erb
|
|
70
|
+
templates/nginx/nginx_vhost.conf.erb
|
|
71
|
+
templates/rails/database.yml.erb
|
|
72
|
+
templates/ruby/ruby_install.sh
|
|
73
|
+
templates/ruby/rubygems_install.sh
|
|
74
|
+
templates/sphinx/install.sh.erb
|
|
75
|
+
templates/sphinx/sphinx.conf.erb
|
|
76
|
+
templates/sphinx/sphinx.monitrc.erb
|
|
77
|
+
templates/sphinx/sphinx_app.initd.centos.erb
|
|
78
|
+
templates/sphinx/sphinx_app.initd.erb
|
|
79
|
+
website/index.html
|
|
80
|
+
website/index.txt
|
|
81
|
+
website/javascripts/rounded_corners_lite.inc.js
|
|
82
|
+
website/stylesheets/screen.css
|
|
83
|
+
website/template.rhtml
|
data/README.txt
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
= Capigen
|
|
2
|
+
|
|
3
|
+
Capistrano recipes and templates.
|
|
4
|
+
|
|
5
|
+
== Install recipes
|
|
6
|
+
|
|
7
|
+
To install an application, use the install recipes; cap nginx:install
|
|
8
|
+
|
|
9
|
+
To install a group of applications based on a "profile":
|
|
10
|
+
|
|
11
|
+
cap install
|
|
12
|
+
|
|
13
|
+
_You may need to comment out "Defaults requiretty" in /etc/sudoders on the image before capistrano recipes will work._
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
== Generating a Capfile
|
|
17
|
+
|
|
18
|
+
From a rails project:
|
|
19
|
+
|
|
20
|
+
rake capigen
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
== Deploying (application)
|
|
24
|
+
|
|
25
|
+
If this is the first time you've deployed you'll need to run:
|
|
26
|
+
|
|
27
|
+
cap deploy:setup
|
|
28
|
+
|
|
29
|
+
Otherwise, your deploy options:
|
|
30
|
+
|
|
31
|
+
cap deploy
|
|
32
|
+
|
|
33
|
+
cap deploy:migrations (deploys and does migration)
|
|
34
|
+
|
|
35
|
+
cap deploy:migrate (only does migration on existing deployment)
|
data/Rakefile
ADDED
data/config/hoe.rb
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
require 'capigen/version'
|
|
2
|
+
|
|
3
|
+
AUTHOR = 'Gabriel Handford' # can also be an array of Authors
|
|
4
|
+
EMAIL = "gabrielh@gmail.com"
|
|
5
|
+
DESCRIPTION = "Capistrano recipe library for all types of remote tasks."
|
|
6
|
+
GEM_NAME = 'capigen' # what ppl will type to install your gem
|
|
7
|
+
RUBYFORGE_PROJECT = 'capigen' # The unix name for your project
|
|
8
|
+
HOMEPATH = "http://#{RUBYFORGE_PROJECT}.rubyforge.org"
|
|
9
|
+
DOWNLOAD_PATH = "http://rubyforge.org/projects/#{RUBYFORGE_PROJECT}"
|
|
10
|
+
|
|
11
|
+
@config_file = "~/.rubyforge/user-config.yml"
|
|
12
|
+
@config = nil
|
|
13
|
+
RUBYFORGE_USERNAME = "gabe"
|
|
14
|
+
def rubyforge_username
|
|
15
|
+
unless @config
|
|
16
|
+
begin
|
|
17
|
+
@config = YAML.load(File.read(File.expand_path(@config_file)))
|
|
18
|
+
rescue
|
|
19
|
+
puts <<-EOS
|
|
20
|
+
ERROR: No rubyforge config file found: #{@config_file}
|
|
21
|
+
Run 'rubyforge setup' to prepare your env for access to Rubyforge
|
|
22
|
+
- See http://newgem.rubyforge.org/rubyforge.html for more details
|
|
23
|
+
EOS
|
|
24
|
+
exit
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
RUBYFORGE_USERNAME.replace @config["username"]
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
REV = nil
|
|
32
|
+
# UNCOMMENT IF REQUIRED:
|
|
33
|
+
# REV = `svn info`.each {|line| if line =~ /^Revision:/ then k,v = line.split(': '); break v.chomp; else next; end} rescue nil
|
|
34
|
+
VERS = Capigen::VERSION::STRING + (REV ? ".#{REV}" : "")
|
|
35
|
+
RDOC_OPTS = ['--quiet', '--title', 'capigen documentation',
|
|
36
|
+
"--opname", "index.html",
|
|
37
|
+
"--line-numbers",
|
|
38
|
+
"--main", "README",
|
|
39
|
+
"--inline-source"]
|
|
40
|
+
|
|
41
|
+
class Hoe
|
|
42
|
+
def extra_deps
|
|
43
|
+
@extra_deps.reject! { |x| Array(x).first == 'hoe' }
|
|
44
|
+
@extra_deps
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
# Generate all the Rake tasks
|
|
49
|
+
# Run 'rake -T' to see list of generated tasks (from gem root directory)
|
|
50
|
+
hoe = Hoe.new(GEM_NAME, VERS) do |p|
|
|
51
|
+
p.developer(AUTHOR, EMAIL)
|
|
52
|
+
p.description = DESCRIPTION
|
|
53
|
+
p.summary = DESCRIPTION
|
|
54
|
+
p.url = HOMEPATH
|
|
55
|
+
p.rubyforge_name = RUBYFORGE_PROJECT if RUBYFORGE_PROJECT
|
|
56
|
+
p.test_globs = ["test/**/test_*.rb"]
|
|
57
|
+
p.clean_globs |= ['**/.*.sw?', '*.gem', '.config', '**/.DS_Store'] #An array of file patterns to delete on clean.
|
|
58
|
+
|
|
59
|
+
# == Optional
|
|
60
|
+
p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
|
|
61
|
+
#p.extra_deps = [] # An array of rubygem dependencies [name, version], e.g. [ ['active_support', '>= 1.3.1'] ]
|
|
62
|
+
|
|
63
|
+
#p.spec_extras = {} # A hash of extra values to set in the gemspec.
|
|
64
|
+
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
CHANGES = hoe.paragraphs_of('History.txt', 0..1).join("\\n\\n")
|
|
68
|
+
PATH = (RUBYFORGE_PROJECT == GEM_NAME) ? RUBYFORGE_PROJECT : "#{RUBYFORGE_PROJECT}/#{GEM_NAME}"
|
|
69
|
+
hoe.remote_rdoc_dir = File.join(PATH.gsub(/^#{RUBYFORGE_PROJECT}\/?/,''), 'rdoc')
|
|
70
|
+
hoe.rsync_args = '-av --delete --ignore-errors'
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
require 'fileutils'
|
|
2
|
+
include FileUtils
|
|
3
|
+
|
|
4
|
+
require 'rubygems'
|
|
5
|
+
%w[rake hoe newgem rubigen].each do |req_gem|
|
|
6
|
+
begin
|
|
7
|
+
require req_gem
|
|
8
|
+
rescue LoadError
|
|
9
|
+
puts "This Rakefile requires the '#{req_gem}' RubyGem."
|
|
10
|
+
puts "Installation: gem install #{req_gem} -y"
|
|
11
|
+
exit
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
$:.unshift(File.join(File.dirname(__FILE__), %w[.. lib]))
|
|
16
|
+
|
|
17
|
+
require 'capigen'
|
data/init.rb
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
require 'yaml'
|
|
2
|
+
require 'highline'
|
|
3
|
+
|
|
4
|
+
# Configuration
|
|
5
|
+
class Capigen::Config
|
|
6
|
+
|
|
7
|
+
attr_accessor :application, :user, :deploy_to, :web_host
|
|
8
|
+
attr_accessor :db_host, :db_user, :db_pass, :db_name, :db_port
|
|
9
|
+
attr_accessor :sphinx_port, :sphinx_host
|
|
10
|
+
attr_accessor :repository, :recipes
|
|
11
|
+
attr_accessor :mongrel_port, :mongrel_size
|
|
12
|
+
attr_accessor :domain_name
|
|
13
|
+
|
|
14
|
+
def initialize
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
# Expose the binding
|
|
18
|
+
def get_binding
|
|
19
|
+
binding
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def ask(message, property, options = {}, &block)
|
|
23
|
+
# Options
|
|
24
|
+
default = options[:default] || nil
|
|
25
|
+
answer_type = options[:answer_type] || String
|
|
26
|
+
auto_apply = options[:auto_apply]
|
|
27
|
+
|
|
28
|
+
# Default to existing or default if set
|
|
29
|
+
existing = send(property.to_sym)
|
|
30
|
+
default = existing || default
|
|
31
|
+
|
|
32
|
+
unless auto_apply and !existing.blank?
|
|
33
|
+
result = HighLine.new.ask(message, answer_type) { |q|
|
|
34
|
+
q.default = default unless default.blank?
|
|
35
|
+
yield q if block_given?
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
send("#{property}=", result)
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def set_default(property, value)
|
|
43
|
+
v = send(property.to_sym)
|
|
44
|
+
send("#{property}=", value) if v.blank?
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def save(path)
|
|
48
|
+
File.open(path, "w") { |f| f.puts self.to_yaml }
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
# Build config from asking
|
|
52
|
+
def ask_all(auto_apply = false)
|
|
53
|
+
|
|
54
|
+
options = { :auto_apply => auto_apply }
|
|
55
|
+
|
|
56
|
+
ask("Application name: ", "application", options)
|
|
57
|
+
ask("User (to run application as): ", "user", options.merge({ :default => application }))
|
|
58
|
+
|
|
59
|
+
ask("Deploy to: ", "deploy_to", options.merge({ :default => "/var/www/apps/#{application}" }))
|
|
60
|
+
ask("Web host: ", "web_host", options)
|
|
61
|
+
|
|
62
|
+
ask("Database host: ", "db_host", options.merge({ :default => web_host }))
|
|
63
|
+
ask("Database user: ", "db_user", options.merge({ :default => user }))
|
|
64
|
+
ask("Database password: ", "db_pass", options)
|
|
65
|
+
ask("Database name: ", "db_name", options.merge({ :default => application }))
|
|
66
|
+
|
|
67
|
+
ask("Database port: ", "db_port", options.merge({ :default => 3306, :answer_type => Integer }))
|
|
68
|
+
|
|
69
|
+
ask("Sphinx host: ", "sphinx_host", options.merge({ :default => "127.0.0.1" }))
|
|
70
|
+
ask("Sphinx port: ", "sphinx_port", options.merge({ :default => 3312, :answer_type => Integer }))
|
|
71
|
+
|
|
72
|
+
default_repos = YAML.load(`svn info`)["URL"] rescue nil
|
|
73
|
+
ask("Repository uri: ", "repository", options.merge({ :default => default_repos }))
|
|
74
|
+
|
|
75
|
+
ask("Mongrel starting port: ", "mongrel_port", options.merge({ :answer_type => Integer }))
|
|
76
|
+
ask("Number of mongrels: ", "mongrel_size", options.merge({ :answer_type => Integer }))
|
|
77
|
+
|
|
78
|
+
ask("Domain name (for nginx vhost; no www prefix): ", "domain_name", options)
|
|
79
|
+
|
|
80
|
+
# Load default recipes if not set
|
|
81
|
+
set_default("recipes", YAML.load_file(File.dirname(__FILE__) + "/recipes.yml"))
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
end
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
require 'erb'
|
|
2
|
+
require 'yaml'
|
|
3
|
+
|
|
4
|
+
# == Recipe helpers
|
|
5
|
+
#
|
|
6
|
+
# * Loads the configuration
|
|
7
|
+
# * Generates files from templates
|
|
8
|
+
#
|
|
9
|
+
module Capigen::Helper
|
|
10
|
+
|
|
11
|
+
include Capigen::Templates
|
|
12
|
+
include Capigen::Profiles
|
|
13
|
+
|
|
14
|
+
include Capigen::Helpers::PackageHelper
|
|
15
|
+
include Capigen::Helpers::WgetHelper
|
|
16
|
+
include Capigen::Helpers::ScriptHelper
|
|
17
|
+
include Capigen::Helpers::GemHelper
|
|
18
|
+
|
|
19
|
+
# Project root (for rails)
|
|
20
|
+
def root
|
|
21
|
+
if respond_to?(:fetch)
|
|
22
|
+
return fetch(:project_root)
|
|
23
|
+
else
|
|
24
|
+
RAILS_ROOT
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
# Path relative to project root
|
|
29
|
+
def relative_to_root(path = nil, check_exist = false)
|
|
30
|
+
if path
|
|
31
|
+
root_path = File.join(root, path)
|
|
32
|
+
else
|
|
33
|
+
root_path = root
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
# Check for file existance
|
|
37
|
+
if check_exist and !File.exist?(root_path)
|
|
38
|
+
raise <<-EOS
|
|
39
|
+
|
|
40
|
+
File not found: #{File.expand_path(root_path)}
|
|
41
|
+
|
|
42
|
+
This is loaded for the capigen plugin. View the README in:
|
|
43
|
+
#{File.expand_path(File.dirname(__FILE__) + "/../doc/README")}
|
|
44
|
+
EOS
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
root_path
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
end
|
|
51
|
+
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# Gem capistrano helpers
|
|
2
|
+
module Capigen::Helpers::GemHelper
|
|
3
|
+
|
|
4
|
+
# gem_install("raspell") or gem_install([ "raspell", "foo" ])
|
|
5
|
+
def gem_install(gems)
|
|
6
|
+
# If a single object, wrap in array
|
|
7
|
+
gems = [ gems ] unless gems.is_a?(Array)
|
|
8
|
+
|
|
9
|
+
# Install one at a time because we may need to pass install args (e.g. mysql)
|
|
10
|
+
gems.each do |gem|
|
|
11
|
+
sudo "gem install --no-rdoc --no-ri --no-verbose #{gem}"
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
end
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# Package, Yum capistrano helpers
|
|
2
|
+
module Capigen::Helpers::PackageHelper
|
|
3
|
+
|
|
4
|
+
def setup_packager(packager)
|
|
5
|
+
@packager = case packager.to_sym
|
|
6
|
+
when :yum then Capigen::Packagers::Yum.new(self)
|
|
7
|
+
end
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def ensure_packager
|
|
11
|
+
unless @packager
|
|
12
|
+
logger.important "No packager defined, defaulting to yum."
|
|
13
|
+
|
|
14
|
+
# Currently only have 1 packager, so
|
|
15
|
+
setup_packager(:yum)
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def package_install(packages)
|
|
20
|
+
ensure_packager
|
|
21
|
+
@packager.install(packages)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def package_update(packages = [])
|
|
25
|
+
ensure_packager
|
|
26
|
+
@packager.update(packages)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def package_clean
|
|
30
|
+
ensure_packager
|
|
31
|
+
@packager.clean
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def package_remove(packages)
|
|
35
|
+
ensure_packager
|
|
36
|
+
@packager.remove(packages)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
end
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# Installer capistrano helper
|
|
2
|
+
module Capigen::Helpers::ScriptHelper
|
|
3
|
+
|
|
4
|
+
def script_install(script, files_to_put = {})
|
|
5
|
+
|
|
6
|
+
files_to_put.each do |file, dest|
|
|
7
|
+
put load_file(file), dest
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
if File.extname(script) == ".erb"
|
|
11
|
+
name = script[0...script.length-4]
|
|
12
|
+
dest = "/tmp/#{name}"
|
|
13
|
+
run "mkdir -p #{File.dirname(dest)}"
|
|
14
|
+
put load_template(script, binding), dest
|
|
15
|
+
|
|
16
|
+
else
|
|
17
|
+
name = script
|
|
18
|
+
dest = "/tmp/#{name}"
|
|
19
|
+
run "mkdir -p #{File.dirname(dest)}"
|
|
20
|
+
put load_file(name), dest
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
# If want verbose, -v
|
|
24
|
+
sudo "sh #{dest}"
|
|
25
|
+
|
|
26
|
+
# Cleanup
|
|
27
|
+
sudo "rm -rf #{File.dirname(dest)}"
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
require 'open-uri'
|
|
2
|
+
|
|
3
|
+
# Wget capistrano helper
|
|
4
|
+
module Capigen::Helpers::WgetHelper
|
|
5
|
+
|
|
6
|
+
# Download the uri, then upload it into the remote destination directory
|
|
7
|
+
def wget(uri, remote_dest_dir = "/tmp")
|
|
8
|
+
|
|
9
|
+
uri = uri = URI.parse(uri)
|
|
10
|
+
name = uri.path.split("/").last
|
|
11
|
+
remote_dest_path = File.join(remote_dest_dir, name)
|
|
12
|
+
|
|
13
|
+
logger.info "Downloading #{name} from #{uri}..."
|
|
14
|
+
put open(uri).read, remote_dest_path
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
end
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# Packages must respond to update, remove, install and clean
|
|
2
|
+
class Capigen::Packagers::Yum
|
|
3
|
+
|
|
4
|
+
def initialize(cap)
|
|
5
|
+
@cap = cap
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
# Update all installed packages
|
|
9
|
+
def update(packages = [])
|
|
10
|
+
@cap.sudo "yum -y update #{packages.join(" ")}"
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
# Remove via yum.
|
|
14
|
+
def remove(packages)
|
|
15
|
+
@cap.sudo "yum -y remove #{packages.join(" ")}"
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
# Install via yum.
|
|
19
|
+
# If package already exists, it will be updated (unless update_existing = false).
|
|
20
|
+
def install(packages, update_existing = true)
|
|
21
|
+
|
|
22
|
+
# If a single object, wrap in array
|
|
23
|
+
packages = [ packages ] unless packages.is_a?(Array)
|
|
24
|
+
|
|
25
|
+
if update_existing
|
|
26
|
+
|
|
27
|
+
installed_packages = []
|
|
28
|
+
|
|
29
|
+
@cap.sudo "yum -d 0 list installed #{packages.join(" ")}" do |channel, stream, data|
|
|
30
|
+
installed_packages += data.split("\n")[1..-1].collect { |line| line.split(".").first }
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
packages -= installed_packages
|
|
34
|
+
|
|
35
|
+
@cap.sudo "yum -y update #{installed_packages.join(" ")}" unless installed_packages.blank?
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
@cap.sudo "yum -y install #{packages.join(" ")}" unless packages.blank?
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
# Clean yum
|
|
42
|
+
def clean
|
|
43
|
+
@cap.sudo "yum -y clean all"
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
module Capigen::Profiles
|
|
2
|
+
|
|
3
|
+
ProfileDir = File.dirname(__FILE__) + "/../../recipes/profiles"
|
|
4
|
+
|
|
5
|
+
def recipe_profiles(prefix = "")
|
|
6
|
+
Dir[ProfileDir + "/#{prefix}*.rb"].collect { |file| File.basename(file)[0...-3] }
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def choose_profile(prefix = "")
|
|
10
|
+
profile = HighLine.new.choose(*recipe_profiles(prefix)) do |menu|
|
|
11
|
+
menu.header = "Choose recipe profile"
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
"#{ProfileDir}/#{profile}.rb"
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
module Capigen::Templates
|
|
2
|
+
|
|
3
|
+
# Root of templates path
|
|
4
|
+
def template_root
|
|
5
|
+
@template_root ||= File.expand_path(File.dirname(__FILE__) + "/../../templates")
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
# Get full template path
|
|
9
|
+
def full_template_path(template_path)
|
|
10
|
+
File.join(template_root, template_path)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
# Load template at (full) path with binding.
|
|
14
|
+
# If options[:project] is true will load template relative to project root.
|
|
15
|
+
def load_template(path, binding, options = {})
|
|
16
|
+
template_path = options[:project] ? "#{root}/#{path}" : full_template_path(path)
|
|
17
|
+
|
|
18
|
+
unless File.exist?(template_path)
|
|
19
|
+
raise <<-EOS
|
|
20
|
+
|
|
21
|
+
Template not found: #{template_path}
|
|
22
|
+
|
|
23
|
+
EOS
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
template = ERB.new(IO.read(template_path))
|
|
27
|
+
template.result(binding)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def load_project_template(path, binding)
|
|
31
|
+
load_template(path, binding, { :project => true })
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def load_file(path)
|
|
35
|
+
template_path = full_template_path(path)
|
|
36
|
+
IO.read(template_path)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
# Write template at (relative path) with binding to destination path.
|
|
40
|
+
#
|
|
41
|
+
# template_path is relative <tt>"capistrano/deploy.rb.erb"</tt>
|
|
42
|
+
def write_template(template_path, binding, dest_path, overwrite = false, verbose = true)
|
|
43
|
+
# This is gnarly!
|
|
44
|
+
relative_dest_path = Pathname.new(File.expand_path(dest_path)).relative_path_from(Pathname.new(File.expand_path(".")))
|
|
45
|
+
|
|
46
|
+
if !overwrite && File.exist?(dest_path)
|
|
47
|
+
puts "%10s %-40s (skipped)" % [ "create", relative_dest_path ] if verbose
|
|
48
|
+
return
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
puts "%10s %-40s" % [ "create", relative_dest_path ] if verbose
|
|
52
|
+
|
|
53
|
+
File.open(dest_path, "w") { |file| file.puts(load_template(template_path, binding)) }
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
# Remove files from root
|
|
57
|
+
def clean(files, verbose = true)
|
|
58
|
+
rm_files = files.collect { |f| File.join(root, f) }
|
|
59
|
+
rm_files.each do |rm_file|
|
|
60
|
+
puts "%10s %-40s" % [ "delete", rm_file ] if verbose
|
|
61
|
+
FileUtils.rm_rf(rm_file)
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
end
|