capigen 0.1.3 → 0.1.4

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 CHANGED
@@ -17,8 +17,8 @@ set :user, Proc.new { Capistrano::CLI.ui.ask('Bootstrap user: ') }
17
17
  # Roles
18
18
  role :base, Capistrano::CLI.ui.ask('Server: ')
19
19
 
20
- # Profile
21
- set :profile, Proc.new { load choose_profile }
20
+ # Choose a profile
21
+ set :profile, Proc.new { load profile.choose }
22
22
 
23
23
  # Reset the password var
24
24
  reset_password
data/History.txt CHANGED
@@ -1,3 +1,7 @@
1
+ == 0.1.4 2008-02-07
2
+
3
+ * Using capistrano's plugin architecture instead of hacking around
4
+
1
5
  == 0.1.3 2008-02-06
2
6
 
3
7
  * Fixing local recipes
data/Manifest.txt CHANGED
@@ -7,20 +7,19 @@ Rakefile
7
7
  config/hoe.rb
8
8
  config/requirements.rb
9
9
  lib/capigen.rb
10
- lib/capigen/cap_ext/configuration.rb
11
10
  lib/capigen/cap_ext/connections.rb
12
- lib/capigen/cap_ext/namespace.rb
11
+ lib/capigen/cap_ext/extension_proxy.rb
13
12
  lib/capigen/config.rb
14
- lib/capigen/helper.rb
15
- lib/capigen/helpers/gem_helper.rb
16
- lib/capigen/helpers/package_helper.rb
17
- lib/capigen/helpers/script_helper.rb
18
- lib/capigen/helpers/wget_helper.rb
19
- lib/capigen/packagers/yum.rb
20
- lib/capigen/profiles.rb
13
+ lib/capigen/plugins/base.rb
14
+ lib/capigen/plugins/gem.rb
15
+ lib/capigen/plugins/package.rb
16
+ lib/capigen/plugins/profiles.rb
17
+ lib/capigen/plugins/script.rb
18
+ lib/capigen/plugins/templates.rb
19
+ lib/capigen/plugins/wget.rb
20
+ lib/capigen/plugins/yum.rb
21
21
  lib/capigen/recipes.rb
22
22
  lib/capigen/recipes.yml
23
- lib/capigen/templates.rb
24
23
  lib/capigen/version.rb
25
24
  lib/profiles/centos-sick.rb
26
25
  lib/recipes/README
@@ -0,0 +1,10 @@
1
+ module Capistrano
2
+ class ExtensionProxy #:nodoc:
3
+
4
+ # Allow include modules in plugins
5
+ def include(mod)
6
+ self.class.send(:include, mod)
7
+ end
8
+
9
+ end
10
+ end
@@ -6,16 +6,8 @@ require 'yaml'
6
6
  # * Loads the configuration
7
7
  # * Generates files from templates
8
8
  #
9
- module Capigen::Helper
9
+ module Capigen::Plugins::Base
10
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
11
  # Project root (for rails)
20
12
  def root
21
13
  if respond_to?(:fetch)
@@ -49,3 +41,4 @@ module Capigen::Helper
49
41
 
50
42
  end
51
43
 
44
+ Capistrano.plugin :capigen, Capigen::Plugins::Base
@@ -0,0 +1,25 @@
1
+ module Capigen::Plugins::Gem
2
+
3
+ # Installl a gem.
4
+ #
5
+ # ==== Options
6
+ # +gems+:: List of gem names, or a single gem
7
+ #
8
+ # ==== Examples
9
+ # install("raspell")
10
+ # install([ "raspell", "foo" ])
11
+ #
12
+ def install(gems)
13
+ # If a single object, wrap in array
14
+ gems = [ gems ] unless gems.is_a?(Array)
15
+
16
+ # Install one at a time because we may need to pass install args (e.g. mysql)
17
+ # TODO: Fix this
18
+ gems.each do |gem|
19
+ sudo "gem install --no-rdoc --no-ri --no-verbose #{gem}"
20
+ end
21
+ end
22
+
23
+ end
24
+
25
+ Capistrano.plugin :gemc, Capigen::Plugins::Gem
@@ -0,0 +1,19 @@
1
+ module Capigen::Plugins::Package
2
+
3
+ # Setup packager
4
+ #
5
+ # ==== Options
6
+ # +packager+:: Packager type (:yum)
7
+ #
8
+ def type=(packager_type)
9
+ case packager_type.to_sym
10
+ when :yum
11
+ include Capigen::Plugins::Yum
12
+ else
13
+ raise "Invalid packager type: #{packager_type}"
14
+ end
15
+ end
16
+
17
+ end
18
+
19
+ Capistrano.plugin :package, Capigen::Plugins::Package
@@ -0,0 +1,35 @@
1
+ module Capigen::Plugins::Profiles
2
+
3
+ ProfileDir = File.dirname(__FILE__) + "/../../profiles"
4
+
5
+ def recipes(prefix = "")
6
+ Dir[ProfileDir + "/#{prefix}*.rb"].collect { |file| File.basename(file).gsub(File.extname(file), "") }
7
+ end
8
+
9
+ def choose(prefix = "")
10
+ profile = HighLine.new.choose(*recipes(prefix)) do |menu|
11
+ menu.header = "Choose recipe profile"
12
+ end
13
+
14
+ "#{ProfileDir}/#{profile}.rb"
15
+ end
16
+
17
+ # More helpful fetch
18
+ def get(var)
19
+ begin
20
+ result = fetch(var.to_sym)
21
+ rescue
22
+ puts <<-EOS
23
+
24
+ Please set :#{var} variable in your Capfile or profile.
25
+
26
+ EOS
27
+ raise "Please set :#{var} in your Capfile or profile."
28
+ end
29
+ result
30
+ end
31
+
32
+ end
33
+
34
+
35
+ Capistrano.plugin :profile, Capigen::Plugins::Profiles
@@ -0,0 +1,39 @@
1
+ module Capigen::Plugins::Script
2
+
3
+ # Install (sh) script
4
+ #
5
+ # ==== Options
6
+ # +script+:: Name of file (relative to templates dir)
7
+ # +files_to_put+:: List of files to upload [ { :file => "foo/bar.txt", :dest "/tmp/bar.txt" }, ... ]
8
+ #
9
+ def install(script, files_to_put = [], override_binding = nil)
10
+
11
+ files_to_put = [ files_to_put ] if files_to_put.is_a?(Hash)
12
+
13
+ files_to_put.each do |file_info|
14
+ data = template.load(file_info[:file], override_binding || binding)
15
+ put data, file_info[:dest]
16
+ end
17
+
18
+ if File.extname(script) == ".erb"
19
+ name = script[0...script.length-4]
20
+ dest = "/tmp/#{name}"
21
+ run "mkdir -p #{File.dirname(dest)}"
22
+ put template.load(script, override_binding || binding), dest
23
+ else
24
+ name = script
25
+ dest = "/tmp/#{name}"
26
+ run "mkdir -p #{File.dirname(dest)}"
27
+ put template.load(script), dest
28
+ end
29
+
30
+ # If want verbose, -v
31
+ sudo "sh #{dest}"
32
+
33
+ # Cleanup
34
+ sudo "rm -rf #{File.dirname(dest)}"
35
+ end
36
+
37
+ end
38
+
39
+ Capistrano.plugin :script, Capigen::Plugins::Script
@@ -0,0 +1,70 @@
1
+ module Capigen::Plugins::Templates
2
+
3
+ # Root of templates path
4
+ def gem_templates_root
5
+ File.expand_path(File.dirname(__FILE__) + "/../../templates")
6
+ end
7
+
8
+ # Get full template path
9
+ def gem_template_path(template_path)
10
+ File.join(gem_templates_root, template_path)
11
+ end
12
+
13
+ # Load template. If extension is erb will be evaluated with binding.
14
+ #
15
+ # ==== Options
16
+ # +path+:: If starts with '/', absolute path, otherwise relative path to templates dir
17
+ # +binding+:: Binding
18
+ #
19
+ def load(path, override_binding = nil)
20
+ template_paths = [ path, gem_template_path(path) ]
21
+
22
+ template_paths = template_paths.select { |file| File.exist?(file) }
23
+
24
+ if template_paths.empty?
25
+ raise <<-EOS
26
+
27
+ Template not found: #{template_paths.join("\n\t")}
28
+
29
+ EOS
30
+ end
31
+
32
+ # Use first
33
+ template_path = template_paths.first
34
+
35
+ data = IO.read(template_path)
36
+
37
+ if File.extname(template_path) == ".erb"
38
+ template = ERB.new(data)
39
+ data = template.result(override_binding || binding)
40
+ end
41
+ data
42
+ end
43
+
44
+ # Load template from project
45
+ def project(path, override_binding = nil)
46
+ load(project_root + "/" + path, override_binding || binding)
47
+ end
48
+
49
+ # Write template at (relative path) with binding to LOCAL destination path.
50
+ #
51
+ # ==== Options
52
+ # +template_path+:: Path to template relative to templates path
53
+ #
54
+ def write(template_path, binding, dest_path, overwrite = false, verbose = true)
55
+ # This is gnarly!
56
+ relative_dest_path = Pathname.new(File.expand_path(dest_path)).relative_path_from(Pathname.new(File.expand_path(".")))
57
+
58
+ if !overwrite && File.exist?(dest_path)
59
+ puts "%10s %-40s (skipped)" % [ "create", relative_dest_path ] if verbose
60
+ return
61
+ end
62
+
63
+ puts "%10s %-40s" % [ "create", relative_dest_path ] if verbose
64
+
65
+ File.open(dest_path, "w") { |file| file.puts(load(template_path, binding)) }
66
+ end
67
+
68
+ end
69
+
70
+ Capistrano.plugin :template, Capigen::Plugins::Templates
@@ -1,10 +1,14 @@
1
1
  require 'open-uri'
2
2
 
3
- # Wget capistrano helper
4
- module Capigen::Helpers::WgetHelper
3
+ module Capigen::Plugins::Wget
5
4
 
6
5
  # Download the uri, then upload it into the remote destination directory
7
- def wget(uri, remote_dest_dir = "/tmp")
6
+ #
7
+ # ==== Options
8
+ # +uri+:: URI to get
9
+ # +remote_dest_dir+:: Remote destination directory
10
+ #
11
+ def uri(uri, remote_dest_dir = "/tmp")
8
12
 
9
13
  uri = uri = URI.parse(uri)
10
14
  name = uri.path.split("/").last
@@ -14,4 +18,6 @@ module Capigen::Helpers::WgetHelper
14
18
  put open(uri).read, remote_dest_path
15
19
  end
16
20
 
17
- end
21
+ end
22
+
23
+ Capistrano.plugin :wget, Capigen::Plugins::Wget
@@ -1,18 +1,14 @@
1
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
2
+ module Capigen::Plugins::Yum
7
3
 
8
4
  # Update all installed packages
9
5
  def update(packages = [])
10
- @cap.sudo "yum -y update #{packages.join(" ")}"
6
+ sudo "yum -y update #{packages.join(" ")}"
11
7
  end
12
8
 
13
9
  # Remove via yum.
14
10
  def remove(packages)
15
- @cap.sudo "yum -y remove #{packages.join(" ")}"
11
+ sudo "yum -y remove #{packages.join(" ")}"
16
12
  end
17
13
 
18
14
  # Install via yum.
@@ -26,21 +22,23 @@ class Capigen::Packagers::Yum
26
22
 
27
23
  installed_packages = []
28
24
 
29
- @cap.sudo "yum -d 0 list installed #{packages.join(" ")}" do |channel, stream, data|
25
+ sudo "yum -d 0 list installed #{packages.join(" ")}" do |channel, stream, data|
30
26
  installed_packages += data.split("\n")[1..-1].collect { |line| line.split(".").first }
31
27
  end
32
28
 
33
29
  packages -= installed_packages
34
30
 
35
- @cap.sudo "yum -y update #{installed_packages.join(" ")}" unless installed_packages.blank?
31
+ sudo "yum -y update #{installed_packages.join(" ")}" unless installed_packages.blank?
36
32
  end
37
33
 
38
- @cap.sudo "yum -y install #{packages.join(" ")}" unless packages.blank?
34
+ sudo "yum -y install #{packages.join(" ")}" unless packages.blank?
39
35
  end
40
36
 
41
37
  # Clean yum
42
38
  def clean
43
- @cap.sudo "yum -y clean all"
39
+ sudo "yum -y clean all"
44
40
  end
45
41
 
46
- end
42
+ end
43
+
44
+ Capistrano.plugin :yum, Capigen::Plugins::Yum
@@ -2,7 +2,7 @@ module Capigen #:nodoc:
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
4
  MINOR = 1
5
- TINY = 3
5
+ TINY = 4
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
data/lib/capigen.rb CHANGED
@@ -7,28 +7,23 @@ HighLine.track_eof = false
7
7
  $:.unshift File.dirname(__FILE__)
8
8
 
9
9
  module Capigen
10
- module Helpers
10
+ module Plugins
11
11
  end
12
-
13
- module Packagers
14
- end
15
12
  end
16
13
 
17
- require "capigen/packagers/yum"
18
-
19
- require "capigen/helpers/package_helper"
20
- require "capigen/helpers/wget_helper"
21
- require "capigen/helpers/script_helper"
22
- require "capigen/helpers/gem_helper"
23
- require "capigen/templates"
24
- require "capigen/profiles"
25
- require "capigen/helper"
14
+ require 'capigen/plugins/base'
15
+ require 'capigen/plugins/gem'
16
+ require 'capigen/plugins/package'
17
+ require 'capigen/plugins/profiles'
18
+ require 'capigen/plugins/script'
19
+ require 'capigen/plugins/templates'
20
+ require 'capigen/plugins/wget'
21
+ require 'capigen/plugins/yum'
26
22
 
27
23
  require "capigen/config"
28
24
 
29
- require "capigen/cap_ext/configuration"
30
- require "capigen/cap_ext/namespace"
31
25
  require "capigen/cap_ext/connections"
26
+ require "capigen/cap_ext/extension_proxy"
32
27
 
33
28
 
34
29
 
@@ -1,8 +1,31 @@
1
1
  set :namespace, "centos"
2
2
  set :description, "Install based on default centos 5.1 image"
3
- set :packager_type, "yum"
4
- set :packages_to_remove, [ "openoffice.org-*", "ImageMagick" ]
5
- set :packages_to_add, [
3
+
4
+ set :recipes, [
5
+ # "centos:setup",
6
+ # "packages:install",
7
+ # "ruby:install",
8
+ # "nginx:install",
9
+ # "nginx:install_monit",
10
+ # "mysql:install",
11
+ # "mysql:install_monit",
12
+ # "sphinx:install",
13
+ # "monit:install",
14
+ # "imagemagick:install",
15
+ # "memcached:install",
16
+ # "memcached:install_monit",
17
+ # "gems:install",
18
+ "centos:cleanup"
19
+ ]
20
+
21
+ #
22
+ # Settings for recipes
23
+ #
24
+
25
+ set :packages, {
26
+ :type => "yum",
27
+ :remove => [ "openoffice.org-*", "ImageMagick" ],
28
+ :add => [
6
29
  "gcc", "kernel-devel", "libevent-devel", "libxml2-devel",
7
30
  "openssl", "openssl-devel",
8
31
  "aspell", "aspell-devel", "aspell-en", "aspell-es",
@@ -13,34 +36,22 @@ set :packages_to_add, [
13
36
  "flex", "byacc",
14
37
  "libjpeg-devel", "libpng-devel", "glib2-devel", "fontconfig-devel", "libwmf-devel", "freetype-devel",
15
38
  "libtiff-devel"
16
- ]
39
+ ]
40
+ }
17
41
 
18
- set :install_tasks, [
19
- "centos:setup",
20
- "packages:install",
21
- "ruby:install",
22
- "nginx:install",
23
- "nginx:install_monit",
24
- "mysql:install",
25
- "mysql:install_monit",
26
- "sphinx:install",
27
- "monit:install",
28
- "imagemagick:install",
29
- "memcached:install",
30
- "memcached:install_monit",
31
- "gems:install",
32
- "centos:cleanup"
33
- ]
34
-
35
42
  set :gem_list, [
36
43
  "rake",
37
44
  "mysql -- --with-mysql-include=/usr/include/mysql --with-mysql-lib=/usr/lib/mysql --with-mysql-config",
38
- "raspell", "rmagick", "mongrel", "mongrel_cluster"
45
+ "raspell",
46
+ "rmagick",
47
+ "mongrel",
48
+ "mongrel_cluster",
49
+ "json"
39
50
  ]
40
51
 
41
52
  # Monit
42
53
  set :monit_port, 2812 # Capistrano::CLI.ui.ask('Monit port: ')
43
- set :monit_password, Capistrano::CLI.ui.ask('Monit admin password (to set): ')
54
+ set :monit_password, Proc.new { Capistrano::CLI.ui.ask('Monit admin password (to set): ') }
44
55
 
45
56
  # For nginx
46
57
  set :nginx_bin_path, "/sbin/nginx"
@@ -49,7 +60,7 @@ set :nginx_pid_path, "/var/run/nginx.pid"
49
60
  set :nginx_prefix_path, "/var/nginx"
50
61
 
51
62
  # Mysql
52
- set :mysql_admin_password, Capistrano::CLI.ui.ask('Mysql admin password (to set): ')
63
+ set :mysql_admin_password, Proc.new { Capistrano::CLI.ui.ask('Mysql admin password (to set): ') }
53
64
  set :mysql_pid_path, "/var/run/mysqld/mysqld.pid"
54
65
  set :db_port, 3306 # Capistrano::CLI.ui.ask('Mysql port: ')
55
66
 
@@ -3,14 +3,12 @@ namespace :centos do
3
3
 
4
4
  desc "Setup centos"
5
5
  task :setup do
6
- put load_file("centos/sudoers"), "/tmp/sudoers"
7
- script_install("centos/setup.sh")
8
- end
9
-
6
+ script.install("centos/setup.sh", :file => "centos/sudoers", :dest => "/tmp/sudoers")
7
+ end
10
8
 
11
9
  desc "Cleanup"
12
10
  task :cleanup do
13
- package_clean
11
+ yum.clean
14
12
  end
15
13
 
16
14
  # Add user for an application
data/lib/recipes/gems.rb CHANGED
@@ -1,8 +1,10 @@
1
1
  namespace :gems do
2
2
 
3
3
  desc "Install gems"
4
- task :install do
5
- gem_install(gem_list) if gem_list
4
+ task :install do
5
+ gem_list = profile.get(:gem_list)
6
+
7
+ gemc.install(gem_list)
6
8
  end
7
9
 
8
10
  end
@@ -3,7 +3,8 @@ namespace :imagemagick do
3
3
  task :install do
4
4
  # Dependencies: "libjpeg-devel", "libpng-devel", "glib2-devel", "fontconfig-devel", "zlib-devel",
5
5
  # "libwmf-devel", "freetype-devel", "libtiff-devel"
6
- script_install("imagemagick/install.sh")
6
+
7
+ script.install("imagemagick/install.sh")
7
8
  end
8
9
 
9
10
  end
@@ -5,7 +5,7 @@ namespace :install do
5
5
  fetch(:profile)
6
6
 
7
7
  # These run after install task and install all the apps
8
- install_tasks.each do |task_name|
8
+ recipes.each do |task_name|
9
9
  after "install", task_name
10
10
  end
11
11
  end
@@ -2,14 +2,13 @@ namespace :memcached do
2
2
 
3
3
  desc "Install memcached"
4
4
  task :install do
5
- put load_template("memcached/memcached.initd.centos.erb", binding), "/tmp/memcached.initd"
6
- script_install("memcached/install.sh")
5
+ script.install("memcached/install.sh", :file => "memcached/memcached.initd.centos.erb", :dest => "/tmp/memcached.initd")
7
6
  end
8
7
 
9
8
  desc "Install memcached monit hooks"
10
9
  task :install_monit do
11
- put load_template("memcached/memcached.monitrc.erb", binding), "/tmp/memcached.monitrc"
12
- script_install("memcached/install_monit.sh")
10
+ put template.load("memcached/memcached.monitrc.erb", binding), "/tmp/memcached.monitrc"
11
+ sudo "install -o root /tmp/memcached.monitrc /etc/monit/memcached.monitrc"
13
12
  end
14
13
 
15
14
  end
@@ -13,8 +13,8 @@ namespace :mongrel_cluster do
13
13
 
14
14
  pid_path = "#{shared_path}/pids"
15
15
 
16
- put load_template("mongrel/mongrel_cluster.initd.erb", binding), "/tmp/mongrel_cluster_#{application}.initd"
17
- put load_template("mongrel/mongrel_cluster.yml.erb", binding), "#{mongrel_config_path}/mongrel_cluster.yml"
16
+ put template.load("mongrel/mongrel_cluster.initd.erb", binding), "/tmp/mongrel_cluster_#{application}.initd"
17
+ put template.load("mongrel/mongrel_cluster.yml.erb", binding), "#{mongrel_config_path}/mongrel_cluster.yml"
18
18
 
19
19
  # Setup the mongrel_cluster init script
20
20
  sudo "install -o root /tmp/mongrel_cluster_#{application}.initd /etc/init.d/mongrel_cluster_#{application}"
@@ -41,7 +41,7 @@ namespace :mongrel_cluster do
41
41
  processes << { :port => port, :start_options => start_options, :stop_options => stop_options, :name => "/usr/bin/mongrel_rails", :pid_path => pid_path }
42
42
  end
43
43
 
44
- put load_template("mongrel/mongrel_cluster.monitrc.erb", binding), "/tmp/mongrel_cluster_#{application}.monitrc"
44
+ put template.load("mongrel/mongrel_cluster.monitrc.erb", binding), "/tmp/mongrel_cluster_#{application}.monitrc"
45
45
 
46
46
  sudo "install -o root /tmp/mongrel_cluster_#{application}.monitrc /etc/monit/mongrel_cluster_#{application}.monitrc"
47
47
  end
data/lib/recipes/monit.rb CHANGED
@@ -4,13 +4,16 @@ namespace :monit do
4
4
  task :install do
5
5
  # Dependencies: "flex", "byacc"
6
6
 
7
- put load_template("monit/monit.initd.centos.erb", binding), "/tmp/monit.initd"
8
- put load_template("monit/monitrc.erb", binding), "/tmp/monitrc"
9
- put load_file("monit/monit.cnf"), "/tmp/monit.cnf"
7
+ install_files = [
8
+ { :file => "monit/monit.initd.centos.erb", :dest => "/tmp/monit.initd" },
9
+ { :file => "monit/monitrc.erb", :dest => "/tmp/monitrc" }
10
+ ]
10
11
 
11
- script_install("monit/install.sh")
12
- script_install("monit/patch_inittab.sh")
13
- script_install("monit/cert.sh")
12
+ script.install("monit/install.sh", install_files)
13
+
14
+ script.install("monit/patch_inittab.sh")
15
+
16
+ script.install("monit/cert.sh", :file => "monit/monit.cnf", :dest => "/tmp/monit.cnf")
14
17
  end
15
18
 
16
19
  end
data/lib/recipes/mysql.rb CHANGED
@@ -3,13 +3,13 @@ namespace :mysql do
3
3
 
4
4
  desc "Install mysql"
5
5
  task :install do
6
- script_install("mysql/install.sh.erb")
6
+ script.install("mysql/install.sh.erb")
7
7
  end
8
8
 
9
9
  desc "Install mysql monit hooks"
10
10
  task :install_monit do
11
- put load_template("mysql/mysql.monitrc.erb", binding), "/tmp/mysql.monitrc"
12
- script_install("mysql/install_monit.sh")
11
+ put template.load("mysql/mysql.monitrc.erb", binding), "/tmp/mysql.monitrc"
12
+ sudo "install -o root /tmp/mysql.monitrc /etc/monit/mysql.monitrc"
13
13
  end
14
14
 
15
15
  desc "Create database user, and database with appropriate permissions"
@@ -17,7 +17,7 @@ namespace :mysql do
17
17
  # Add localhost to grant locations
18
18
  locations_for_grant = [ "localhost", web_host ]
19
19
 
20
- put load_template("mysql/install_db.sql.erb", binding), "/tmp/install_db_#{application}.sql"
20
+ put template.load("mysql/install_db.sql.erb", binding), "/tmp/install_db_#{application}.sql"
21
21
  run "mysql -u root -p#{mysql_admin_password} < /tmp/install_db_#{application}.sql"
22
22
  end
23
23
 
data/lib/recipes/nginx.rb CHANGED
@@ -8,19 +8,20 @@ namespace :nginx do
8
8
  task :install do
9
9
  # Dependencies: "pcre-devel", "openssl", "openssl-devel"
10
10
 
11
- put(load_template("nginx/nginx.initd.erb", binding), "/tmp/nginx.initd")
12
- put(load_template("nginx/nginx.conf.erb", binding), "/tmp/nginx.conf")
11
+ files = [
12
+ { :file => "nginx/nginx.initd.erb", :dest => "/tmp/nginx.initd" },
13
+ { :file => "nginx/nginx.conf.erb", :dest => "/tmp/nginx.conf" }
14
+ ]
13
15
 
14
- script_install("nginx/install.sh.erb")
16
+ script.install("nginx/install.sh.erb", files, binding)
15
17
  end
16
18
 
17
19
  desc "Install nginx monit hooks"
18
20
  task :install_monit do
19
- put load_template("nginx/nginx.monitrc.erb", binding), "/tmp/nginx.monitrc"
20
- script_install("nginx/install_monit.sh")
21
+ put template.load("nginx/nginx.monitrc.erb", binding), "/tmp/nginx.monitrc"
22
+ sudo "install -o root /tmp/nginx.monitrc /etc/monit/nginx.monitrc"
21
23
  end
22
-
23
-
24
+
24
25
  desc "Create and update the nginx vhost include"
25
26
  task :setup do
26
27
 
@@ -28,7 +29,7 @@ namespace :nginx do
28
29
  public_path = current_path + "/public"
29
30
 
30
31
  run "mkdir -p #{shared_path}/config"
31
- put load_template("nginx/nginx_vhost.conf.erb", binding), "/tmp/nginx_#{application}.conf"
32
+ put template.load("nginx/nginx_vhost.conf.erb", binding), "/tmp/nginx_#{application}.conf"
32
33
 
33
34
  sudo "install -o root /tmp/nginx_#{application}.conf /etc/nginx/vhosts/#{application}.conf"
34
35
  end
@@ -2,18 +2,23 @@ namespace :packages do
2
2
 
3
3
  task :install do
4
4
 
5
- # Setup packager
6
- setup_packager(packager_type)
5
+ # Settings
6
+ packages = profile.get(:packages)
7
+
8
+ packages_to_remove = packages[:remove]
9
+ packages_to_add = packages[:add]
10
+
11
+ # Set package type
12
+ package.type = packages[:type]
7
13
 
8
14
  # Remove packages
9
- package_remove(packages_to_remove)
15
+ package.remove(packages_to_remove) unless packages_to_remove.blank?
10
16
 
11
17
  # Update all existing packages
12
- package_update
18
+ package.update
13
19
 
14
20
  # Install packages
15
- package_install(packages_to_add)
16
-
21
+ package.install(packages_to_add) unless packages_to_add.blank?
17
22
  end
18
23
 
19
24
  end
data/lib/recipes/rails.rb CHANGED
@@ -4,7 +4,7 @@ namespace :rails do
4
4
  desc "Create database yaml in shared path"
5
5
  task :setup do
6
6
  run "mkdir -p #{shared_path}/config"
7
- put load_template("rails/database.yml.erb", binding), "#{shared_path}/config/database.yml"
7
+ put template.load("rails/database.yml.erb", binding), "#{shared_path}/config/database.yml"
8
8
  end
9
9
 
10
10
  desc "Make symlink for database yaml"
data/lib/recipes/ruby.rb CHANGED
@@ -5,10 +5,10 @@ namespace :ruby do
5
5
  # Dependencies: zlib, zlib-devel
6
6
 
7
7
  # Install ruby 1.8.6
8
- script_install("ruby/ruby_install.sh")
8
+ script.install("ruby/ruby_install.sh")
9
9
 
10
10
  # Install rubygems
11
- script_install("ruby/rubygems_install.sh")
11
+ script.install("ruby/rubygems_install.sh")
12
12
  end
13
13
 
14
14
  end
@@ -6,7 +6,7 @@ namespace :sphinx do
6
6
  desc "Install sphinx"
7
7
  task :install do
8
8
  # Dependencies: gcc-c++
9
- script_install("sphinx/install.sh.erb")
9
+ script.install("sphinx/install.sh.erb")
10
10
  end
11
11
 
12
12
  desc "Setup sphinx for application"
@@ -16,7 +16,7 @@ namespace :sphinx do
16
16
  sphinx_conf_path = "#{shared_path}/config/sphinx.conf"
17
17
  sphinx_pid_path = "#{shared_path}/pids/searchd.pid"
18
18
 
19
- put load_template("sphinx/sphinx_app.initd.centos.erb", binding), "/tmp/sphinx.initd"
19
+ put template.load("sphinx/sphinx_app.initd.centos.erb"), "/tmp/sphinx.initd"
20
20
 
21
21
  sudo "install -o root /tmp/sphinx.initd /etc/init.d/sphinx_#{application}"
22
22
 
@@ -28,7 +28,7 @@ namespace :sphinx do
28
28
  desc "Create monit configuration for sphinx"
29
29
  task :setup_monit do
30
30
  sphinx_pid_path = "#{shared_path}/pids/searchd.pid"
31
- put load_template("sphinx/sphinx.monitrc.erb", binding), "/tmp/sphinx_#{application}.monitrc"
31
+ put template.load("sphinx/sphinx.monitrc.erb"), "/tmp/sphinx_#{application}.monitrc"
32
32
 
33
33
  sudo "install -o root /tmp/sphinx_#{application}.monitrc /etc/monit/sphinx_#{application}.monitrc"
34
34
  end
@@ -36,12 +36,12 @@ namespace :sphinx do
36
36
  desc "Update sphinx for application"
37
37
  task :update_code do
38
38
 
39
- rails_root = current_path
40
- index_root = "#{shared_path}/var/index";
41
- log_root = "#{shared_path}/log"
42
- pid_root = "#{shared_path}/pids"
39
+ set :rails_root, current_path
40
+ set :index_root, "#{shared_path}/var/index";
41
+ set :log_root, "#{shared_path}/log"
42
+ set :pid_root, "#{shared_path}/pids"
43
43
 
44
- put load_project_template("config/templates/sphinx.conf.erb", binding), "#{shared_path}/config/sphinx.conf"
44
+ put template.project("config/templates/sphinx.conf.erb"), "#{shared_path}/config/sphinx.conf"
45
45
  end
46
46
 
47
47
  desc "Rotate sphinx index for application"
@@ -4,7 +4,8 @@ set -e
4
4
  trap ERROR ERR
5
5
 
6
6
  cd /usr/src
7
- #wget -nv ftp://ftp.ruby-lang.org/pub/ruby/1.8/ruby-1.8.6-p110.tar.gz
7
+ wget -nv http://capigen.s3.amazonaws.com/ruby-1.8.6-p110.tar.gz
8
+ # ftp://ftp.ruby-lang.org/pub/ruby/1.8/ruby-1.8.6-p110.tar.gz
8
9
  tar xzf ruby-1.8.6-p110.tar.gz
9
10
  cd ruby-1.8.6-p110
10
11
  echo "Configuring ruby..."
data/website/index.html CHANGED
@@ -33,7 +33,7 @@
33
33
  <h1>capigen</h1>
34
34
  <div id="version" class="clickable" onclick='document.location = "http://rubyforge.org/projects/capigen"; return false'>
35
35
  <p>Get Version</p>
36
- <a href="http://rubyforge.org/projects/capigen" class="numbers">0.1.3</a>
36
+ <a href="http://rubyforge.org/projects/capigen" class="numbers">0.1.4</a>
37
37
  </div>
38
38
  <h1>&#x2192; &#8216;capigen&#8217;</h1>
39
39
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capigen
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ""
6
6
  authors:
7
7
  - Gabriel Handford
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-02-06 00:00:00 -05:00
12
+ date: 2008-02-07 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -36,20 +36,19 @@ files:
36
36
  - config/hoe.rb
37
37
  - config/requirements.rb
38
38
  - lib/capigen.rb
39
- - lib/capigen/cap_ext/configuration.rb
40
39
  - lib/capigen/cap_ext/connections.rb
41
- - lib/capigen/cap_ext/namespace.rb
40
+ - lib/capigen/cap_ext/extension_proxy.rb
42
41
  - lib/capigen/config.rb
43
- - lib/capigen/helper.rb
44
- - lib/capigen/helpers/gem_helper.rb
45
- - lib/capigen/helpers/package_helper.rb
46
- - lib/capigen/helpers/script_helper.rb
47
- - lib/capigen/helpers/wget_helper.rb
48
- - lib/capigen/packagers/yum.rb
49
- - lib/capigen/profiles.rb
42
+ - lib/capigen/plugins/base.rb
43
+ - lib/capigen/plugins/gem.rb
44
+ - lib/capigen/plugins/package.rb
45
+ - lib/capigen/plugins/profiles.rb
46
+ - lib/capigen/plugins/script.rb
47
+ - lib/capigen/plugins/templates.rb
48
+ - lib/capigen/plugins/wget.rb
49
+ - lib/capigen/plugins/yum.rb
50
50
  - lib/capigen/recipes.rb
51
51
  - lib/capigen/recipes.yml
52
- - lib/capigen/templates.rb
53
52
  - lib/capigen/version.rb
54
53
  - lib/profiles/centos-sick.rb
55
54
  - lib/recipes/README
@@ -1,5 +0,0 @@
1
- class Capistrano::Configuration
2
- # Load config helper for use within Capfile
3
- include Capigen::Helper
4
-
5
- end
@@ -1,6 +0,0 @@
1
- class Capistrano::Configuration::Namespaces::Namespace
2
-
3
- # Load config helper for use within recipes
4
- include Capigen::Helper
5
-
6
- end
@@ -1,15 +0,0 @@
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
@@ -1,40 +0,0 @@
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
@@ -1,30 +0,0 @@
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
@@ -1,19 +0,0 @@
1
- module Capigen::Profiles
2
-
3
- ProfileDir = File.dirname(__FILE__) + "/../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
-
@@ -1,65 +0,0 @@
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