magic_recipes 0.0.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.
Files changed (64) hide show
  1. data/MIT-LICENSE +20 -0
  2. data/README.markdown +47 -0
  3. data/Rakefile +27 -0
  4. data/bin/g_cap +45 -0
  5. data/bin/git_cap +35 -0
  6. data/lib/generators/magic_recipes/capify_generator.rb +40 -0
  7. data/lib/generators/magic_recipes/templates/Capfile.tt +7 -0
  8. data/lib/generators/magic_recipes/templates/deploy.rb.tt +68 -0
  9. data/lib/magic_recipes/assets.rb +98 -0
  10. data/lib/magic_recipes/db.rb +40 -0
  11. data/lib/magic_recipes/gems.rb +19 -0
  12. data/lib/magic_recipes/git.rb +31 -0
  13. data/lib/magic_recipes/nginx.rb +58 -0
  14. data/lib/magic_recipes/nodejs.rb +26 -0
  15. data/lib/magic_recipes/passenger.rb +25 -0
  16. data/lib/magic_recipes/postgresql.rb +51 -0
  17. data/lib/magic_recipes/private_pub.rb +77 -0
  18. data/lib/magic_recipes/rbenv.rb +46 -0
  19. data/lib/magic_recipes/rvm.rb +43 -0
  20. data/lib/magic_recipes/templates/nginx_passenger.erb +27 -0
  21. data/lib/magic_recipes/templates/nginx_private_pub.erb +13 -0
  22. data/lib/magic_recipes/templates/nginx_thin.erb +30 -0
  23. data/lib/magic_recipes/templates/nginx_unicorn.erb +30 -0
  24. data/lib/magic_recipes/templates/postgresql.yml.erb +8 -0
  25. data/lib/magic_recipes/templates/private_pub_yml.erb +10 -0
  26. data/lib/magic_recipes/templates/thin_app_yml.erb +18 -0
  27. data/lib/magic_recipes/templates/thin_private_pub_yml.erb +19 -0
  28. data/lib/magic_recipes/templates/unicorn.rb.erb +8 -0
  29. data/lib/magic_recipes/templates/unicorn_init.erb +84 -0
  30. data/lib/magic_recipes/thin.rb +44 -0
  31. data/lib/magic_recipes/unicorn.rb +44 -0
  32. data/lib/magic_recipes.rb +75 -0
  33. data/lib/tasks/magic_recipes_tasks.rake +4 -0
  34. data/spec/dummy/README.rdoc +261 -0
  35. data/spec/dummy/Rakefile +7 -0
  36. data/spec/dummy/app/assets/javascripts/application.js +15 -0
  37. data/spec/dummy/app/assets/stylesheets/application.css +13 -0
  38. data/spec/dummy/app/controllers/application_controller.rb +3 -0
  39. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  40. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  41. data/spec/dummy/config/application.rb +65 -0
  42. data/spec/dummy/config/boot.rb +10 -0
  43. data/spec/dummy/config/database.yml +25 -0
  44. data/spec/dummy/config/environment.rb +5 -0
  45. data/spec/dummy/config/environments/development.rb +37 -0
  46. data/spec/dummy/config/environments/production.rb +67 -0
  47. data/spec/dummy/config/environments/test.rb +37 -0
  48. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  49. data/spec/dummy/config/initializers/inflections.rb +15 -0
  50. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  51. data/spec/dummy/config/initializers/secret_token.rb +7 -0
  52. data/spec/dummy/config/initializers/session_store.rb +8 -0
  53. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  54. data/spec/dummy/config/locales/en.yml +5 -0
  55. data/spec/dummy/config/routes.rb +58 -0
  56. data/spec/dummy/config.ru +4 -0
  57. data/spec/dummy/log/development.log +0 -0
  58. data/spec/dummy/public/404.html +26 -0
  59. data/spec/dummy/public/422.html +26 -0
  60. data/spec/dummy/public/500.html +25 -0
  61. data/spec/dummy/public/favicon.ico +0 -0
  62. data/spec/dummy/script/rails +6 -0
  63. data/spec/spec_helper.rb +40 -0
  64. metadata +269 -0
@@ -0,0 +1,77 @@
1
+ # encoding: utf-8
2
+ module MagicRecipes
3
+ module PrivatePub
4
+ def self.load_into(configuration)
5
+ configuration.load do
6
+
7
+ set_default :private_pub_domain, "0.0.0.0" # => private_pub domain
8
+ #set_default :private_pub_instances, 1 # => private_pub server instances .. for now only 1 !
9
+ set_default :private_pub_host, 9200 # => public port
10
+ set_default :private_pub_port, 9292 # => intern port
11
+ set_default(:private_pub_key, "882293e492b7e7a2fed266a5f38062420e12fb75eae5f145e256af60dc9681bc")
12
+
13
+ namespace :private_pub do
14
+
15
+ # needs nginx_tcp_proxy_module ... https://github.com/yaoweibin/nginx_tcp_proxy_module
16
+ desc "reconf private_pub .. "
17
+ task :reconf do
18
+ template "thin_private_pub_yml.erb", "#{current_path}/config/thin_pp.yml"
19
+ run "#{sudo} ln -sf #{current_path}/config/thin_pp.yml #{thin_path}/thin_#{app_name}_pp.yml"
20
+ end
21
+
22
+
23
+ desc "setup private_pub .. "
24
+ task :setup do
25
+ reconf
26
+ template "nginx_private_pub.erb", "/tmp/nginx_tcp_conf"
27
+ run "#{sudo} mv /tmp/nginx_tcp_conf #{tcp_enabled_path}/#{app_name}_private_pub.conf"
28
+ end
29
+
30
+
31
+ desc "write config/private_pup.yml"
32
+ task :yml_file do
33
+ template "private_pub_yml.erb", "#{current_path}/config/private_pub.yml"
34
+ end
35
+
36
+
37
+ desc "start private_pub server"
38
+ task :start, roles: :app do
39
+ # => run <<-CMD
40
+ # => source '/usr/local/rvm/scripts/rvm' &&
41
+ # => rvm use 1.9.3 &&
42
+ # => cd #{current_path} &&
43
+ # => RAILS_ENV=production bundle exec rackup private_pub.ru -s thin -E production -p #{private_pub_port} -o #{server_ip} -D
44
+ # => CMD
45
+ run "cd #{current_path} && RAILS_ENV=production bundle exec rackup private_pub.ru -s thin -E production -p #{private_pub_port} -o #{server_ip} -D"
46
+ end
47
+
48
+
49
+ desc "stop private_pub server"
50
+ task :stop, roles: :app do
51
+ run "if [ `lsof -t -i:#{private_pub_port}` ]; then #{sudo} kill $(#{sudo} lsof -t -i:#{private_pub_port}); fi"
52
+ end
53
+
54
+
55
+ desc "restart private_pub server"
56
+ task :restart, roles: :app do
57
+ stop
58
+ start
59
+ end
60
+
61
+
62
+ before "thin:start", "private_pub:yml_file"
63
+ after "thin:start", "private_pub:start"
64
+ after "thin:stop", "private_pub:stop"
65
+ after "nginx:setup", "private_pub:setup"
66
+ after "thin:reconf", "private_pub:reconf"
67
+
68
+
69
+ end
70
+
71
+ # eof
72
+
73
+ end
74
+ end
75
+ end
76
+ end
77
+
@@ -0,0 +1,46 @@
1
+ # encoding: utf-8
2
+ module MagicRecipes
3
+ module Rbenv
4
+ def self.load_into(configuration)
5
+ configuration.load do
6
+
7
+ # code is taken from railscast #337
8
+
9
+ set_default :ruby_version, "1.9.3-p125"
10
+ set_default :rbenv_bootstrap, "bootstrap-ubuntu-10-04"
11
+
12
+ namespace :rbenv do
13
+ desc "Install rbenv, Ruby, and the Bundler gem"
14
+ task :install, roles: :app do
15
+ run "#{sudo} apt-get -y install curl git-core"
16
+ run "curl -L https://raw.github.com/fesplugas/rbenv-installer/master/bin/rbenv-installer | bash"
17
+ bashrc = <<-BASHRC
18
+ if [ -d $HOME/.rbenv ]; then
19
+ export PATH="$HOME/.rbenv/bin:$PATH"
20
+ eval "$(rbenv init -)"
21
+ fi
22
+ BASHRC
23
+ put bashrc, "/tmp/rbenvrc"
24
+ run "cat /tmp/rbenvrc ~/.bashrc > ~/.bashrc.tmp"
25
+ run "mv ~/.bashrc.tmp ~/.bashrc"
26
+ run %q{export PATH="$HOME/.rbenv/bin:$PATH"}
27
+ run %q{eval "$(rbenv init -)"}
28
+ run "rbenv #{rbenv_bootstrap}"
29
+ run "rbenv install #{ruby_version}"
30
+ run "rbenv global #{ruby_version}"
31
+ run "gem install bundler --no-ri --no-rdoc"
32
+ run "rbenv rehash"
33
+ end
34
+ after "deploy:install", "rbenv:install"
35
+ end
36
+
37
+ # eof
38
+
39
+ end
40
+ end
41
+ end
42
+ end
43
+
44
+
45
+
46
+
@@ -0,0 +1,43 @@
1
+ # encoding: utf-8
2
+ module MagicRecipes
3
+ module Rvm
4
+ def self.load_into(configuration)
5
+ configuration.load do
6
+
7
+ # => http://stackoverflow.com/questions/7313232/rvm-capistrano-and-bundler-path-issues
8
+ $:.unshift(File.expand_path('./lib', ENV['rvm_path']))
9
+ require 'rvm/capistrano'
10
+
11
+ set_default :rails_env, 'production'
12
+ set_default :rvm_ruby, '1.9.3'
13
+ set_default :rvm_patch, 'p0'
14
+ set_default :rvm_gemset, 'global'
15
+ set_default :rvm_path, '/usr/local/rvm'
16
+ set :rvm_type, :system
17
+ set :rvm_ruby_string, "ruby-#{rvm_ruby}-#{rvm_patch}@#{rvm_gemset}"
18
+ set :rvm_path, "/usr/local/rvm"
19
+ set :rvm_bin_path, "#{rvm_path}/bin"
20
+ set :rvm_lib_path, "#{rvm_path}/lib"
21
+ set :remote_bin_path, "#{rvm_path}/gems/ruby-#{rvm_ruby}-#{rvm_patch}/bin/"
22
+
23
+ set :default_environment, {
24
+ 'PATH' => "#{rvm_path}/gems/ruby/1.9.1/bin:#{rvm_bin_path}/bin:$PATH",
25
+ 'RUBY_VERSION' => "#{rvm_ruby}",
26
+ 'GEM_HOME' => "#{rvm_path}/gems/#{rvm_ruby_string}",
27
+ 'GEM_PATH' => "#{rvm_path}/gems/#{rvm_ruby_string}",
28
+ 'BUNDLE_PATH' => "#{rvm_path}/gems/#{rvm_ruby_string}"
29
+ }
30
+
31
+ set :bundle_dir, "#{rvm_path}/gems/#{rvm_ruby_string}"
32
+ set :bundle_flags, "--deployment --verbose"
33
+
34
+ # eof
35
+
36
+ end
37
+ end
38
+ end
39
+ end
40
+
41
+
42
+
43
+
@@ -0,0 +1,27 @@
1
+ server {
2
+ listen 80<%= ' default deferred' if default_site %>;
3
+ server_name <%= domains.join("\n ") %>;
4
+
5
+ root <%= current_path %>/public;
6
+
7
+ passenger_enabled on;
8
+
9
+ # Keep x instances alive
10
+ passenger_min_instances <% app_instances.to_i %>;
11
+
12
+ # Rails environment
13
+ rails_env <%= rails_env %>;
14
+
15
+ # Cache and Gzip Assets
16
+ location ^~ /assets/ {
17
+ gzip on;
18
+ expires max;
19
+ add_header Cache-Control public;
20
+ }
21
+
22
+ error_page 500 502 503 504 /500.html;
23
+ client_max_body_size 4G;
24
+ }
25
+ <%= if pre_start %>
26
+ passenger_pre_start http://<%= domains.first %>/;
27
+ <% end %>
@@ -0,0 +1,13 @@
1
+ upstream <%= app_name %>_websockets {
2
+ # <%# private_pub_instances.to_i.times do |i| %>server unix:/tmp/thin.<%= app_name %>.pp.<%#= i %>.sock;<%# end %>
3
+ server <%= server_ip %>:<%= private_pub_port %>;
4
+ check interval=300 rise=2 fall=5 timeout=1000;
5
+ }
6
+
7
+ server {
8
+ listen <%= private_pub_host %>;
9
+ server_name <%= private_pub_domain %>;
10
+ tcp_nodelay on;
11
+ proxy_pass <%= app_name %>_websockets;
12
+ }
13
+
@@ -0,0 +1,30 @@
1
+ upstream thin_<%= app_name %>_cluster {
2
+ <% app_instances.to_i.times do |i| %>
3
+ server unix:/tmp/thin.<%= app_name %>.<%= i %>.sock;<% end %>
4
+
5
+ }
6
+
7
+ server {
8
+ listen 80<%= ' default deferred' if default_site %>;
9
+ server_name <%= domains.join("\n ") %>;
10
+
11
+ root <%= current_path %>/public;
12
+
13
+ try_files $uri/index.html $uri @thin_<%= app_name %>;
14
+ location @thin_<%= app_name %> {
15
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
16
+ proxy_set_header Host $http_host;
17
+ proxy_redirect off;
18
+ proxy_pass http://thin_<%= app_name %>_cluster;
19
+ }
20
+
21
+ location ^~ /assets/ {
22
+ gzip on;
23
+ expires max;
24
+ add_header Cache-Control public;
25
+ }
26
+
27
+ error_page 500 502 503 504 /500.html;
28
+ client_max_body_size 4G;
29
+ }
30
+
@@ -0,0 +1,30 @@
1
+ upstream unicorn {
2
+ server unix:/tmp/unicorn.<%= application %>.sock fail_timeout=0;
3
+ }
4
+
5
+ server {
6
+ listen 80<%= ' default deferred' if default_site %>;
7
+
8
+ server_name <%= domains.join("\n ") %>;
9
+
10
+ root <%= current_path %>/public;
11
+
12
+ location ^~ /assets/ {
13
+ gzip_static on;
14
+ expires max;
15
+ add_header Cache-Control public;
16
+ }
17
+
18
+ try_files $uri/index.html $uri @unicorn;
19
+ location @unicorn {
20
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
21
+ proxy_set_header Host $http_host;
22
+ proxy_redirect off;
23
+ proxy_pass http://unicorn;
24
+ }
25
+
26
+ error_page 500 502 503 504 /500.html;
27
+ client_max_body_size 4G;
28
+ keepalive_timeout 10;
29
+ }
30
+
@@ -0,0 +1,8 @@
1
+ production:
2
+ adapter: postgresql
3
+ encoding: unicode
4
+ database: <%= postgresql_database %>
5
+ pool: 5
6
+ username: <%= postgresql_user %>
7
+ password: <%= postgresql_password %>
8
+ host: <%= postgresql_host %>
@@ -0,0 +1,10 @@
1
+ development:
2
+ server: "http://localhost:9292/faye"
3
+ secret_token: "secret"
4
+ test:
5
+ server: "http://localhost:9292/faye"
6
+ secret_token: "secret"
7
+ production:
8
+ server: "http://<%= private_pub_domain %>:<%= private_pub_host %>/faye"
9
+ secret_token: "<%#= random_string( 64 ) %><%= private_pub_key %>"
10
+ signature_expiration: 7200 # two hours
@@ -0,0 +1,18 @@
1
+ ---
2
+ adapter: rails
3
+ chdir: <%= current_path %>
4
+ environment: <%= rails_env %>
5
+ rackup: <%= current_path %>/config.ru
6
+ timeout: 30
7
+ # address: 127.0.0.1
8
+ # port: 4000
9
+ log: <%= deploy_to %>/shared/log/thin_<%= app_name %>.log
10
+ pid: <%= deploy_to %>/shared/pids/thin_<%= app_name %>.pid
11
+ max_conns: 1024
12
+ max_persistent_conns: 512
13
+ require: []
14
+ wait: 90
15
+ servers: <%= app_instances %>
16
+ user: <%= user %>
17
+ socket: /tmp/thin.<%= app_name %>.sock
18
+ daemonize: true
@@ -0,0 +1,19 @@
1
+ ---
2
+ adapter: rack
3
+ chdir: <%= current_path %>
4
+ environment: <%= rails_env %>
5
+ rackup: <%= current_path %>/private_pub.ru
6
+ timeout: 30
7
+ # address: 127.0.0.1
8
+ # port: 9292
9
+ log: <%= deploy_to %>/shared/log/thin_<%= app_name %>_pp.log
10
+ pid: <%= deploy_to %>/shared/pids/thin_<%= app_name %>_pp.pid
11
+ max_conns: 1024
12
+ max_persistent_conns: 512
13
+ require: []
14
+ wait: 90
15
+ servers: 1<%#= private_pub_instances %>
16
+ user: <%= user %>
17
+ socket: /tmp/thin.<%= app_name %>.pp.sock
18
+ daemonize: true
19
+
@@ -0,0 +1,8 @@
1
+ working_directory "<%= current_path %>"
2
+ pid "<%= unicorn_pid %>"
3
+ stderr_path "<%= unicorn_log %>"
4
+ stdout_path "<%= unicorn_log %>"
5
+
6
+ listen "/tmp/unicorn.<%= application %>.sock"
7
+ worker_processes <%= unicorn_workers %>
8
+ timeout 30
@@ -0,0 +1,84 @@
1
+ #!/bin/sh
2
+ ### BEGIN INIT INFO
3
+ # Provides: unicorn
4
+ # Required-Start: $remote_fs $syslog
5
+ # Required-Stop: $remote_fs $syslog
6
+ # Default-Start: 2 3 4 5
7
+ # Default-Stop: 0 1 6
8
+ # Short-Description: Manage unicorn server
9
+ # Description: Start, stop, restart unicorn server for a specific application.
10
+ ### END INIT INFO
11
+ set -e
12
+
13
+ # Feel free to change any of the following variables for your app:
14
+ TIMEOUT=${TIMEOUT-60}
15
+ APP_ROOT=<%= current_path %>
16
+ PID=<%= unicorn_pid %>
17
+ CMD="cd <%= current_path %>; bundle exec unicorn -D -c <%= unicorn_config %> -E production"
18
+ AS_USER=<%= unicorn_user %>
19
+ set -u
20
+
21
+ OLD_PIN="$PID.oldbin"
22
+
23
+ sig () {
24
+ test -s "$PID" && kill -$1 `cat $PID`
25
+ }
26
+
27
+ oldsig () {
28
+ test -s $OLD_PIN && kill -$1 `cat $OLD_PIN`
29
+ }
30
+
31
+ run () {
32
+ if [ "$(id -un)" = "$AS_USER" ]; then
33
+ eval $1
34
+ else
35
+ su -c "$1" - $AS_USER
36
+ fi
37
+ }
38
+
39
+ case "$1" in
40
+ start)
41
+ sig 0 && echo >&2 "Already running" && exit 0
42
+ run "$CMD"
43
+ ;;
44
+ stop)
45
+ sig QUIT && exit 0
46
+ echo >&2 "Not running"
47
+ ;;
48
+ force-stop)
49
+ sig TERM && exit 0
50
+ echo >&2 "Not running"
51
+ ;;
52
+ restart|reload)
53
+ sig HUP && echo reloaded OK && exit 0
54
+ echo >&2 "Couldn't reload, starting '$CMD' instead"
55
+ run "$CMD"
56
+ ;;
57
+ upgrade)
58
+ if sig USR2 && sleep 2 && sig 0 && oldsig QUIT
59
+ then
60
+ n=$TIMEOUT
61
+ while test -s $OLD_PIN && test $n -ge 0
62
+ do
63
+ printf '.' && sleep 1 && n=$(( $n - 1 ))
64
+ done
65
+ echo
66
+
67
+ if test $n -lt 0 && test -s $OLD_PIN
68
+ then
69
+ echo >&2 "$OLD_PIN still exists after $TIMEOUT seconds"
70
+ exit 1
71
+ fi
72
+ exit 0
73
+ fi
74
+ echo >&2 "Couldn't upgrade, starting '$CMD' instead"
75
+ run "$CMD"
76
+ ;;
77
+ reopen-logs)
78
+ sig USR1
79
+ ;;
80
+ *)
81
+ echo >&2 "Usage: $0 <start|stop|restart|upgrade|force-stop|reopen-logs>"
82
+ exit 1
83
+ ;;
84
+ esac
@@ -0,0 +1,44 @@
1
+ # encoding: utf-8
2
+ module MagicRecipes
3
+ module Thin
4
+ def self.load_into(configuration)
5
+ configuration.load do
6
+
7
+ set_default :thin_path, '/etc/thin'
8
+
9
+ namespace :thin do
10
+
11
+ desc "rewrite thin-configurations"
12
+ task :reconf, roles: :app do
13
+ template "thin_app_yml.erb", "#{current_path}/config/thin_app.yml"
14
+ run "#{sudo} rm #{thin_path}/thin_#{app_name}*"
15
+ run "#{sudo} ln -sf #{current_path}/config/thin_app.yml #{thin_path}/thin_#{app_name}.yml"
16
+ end
17
+
18
+ # Start / Stop / Restart Thin
19
+ %w[start stop restart].each do |command|
20
+ desc "#{command} thin"
21
+ task command, roles: :app do
22
+ reconf
23
+ # => run <<-CMD
24
+ # => source '/usr/local/rvm/scripts/rvm' &&
25
+ # => rvm use 1.9.3 && cd #{current_path} &&
26
+ # => bundle exec thin #{command} -C config/thin_app.yml
27
+ # => CMD
28
+ run "bundle exec thin #{command} -C config/thin_app.yml"
29
+ end
30
+ # before "nginx:#{command}", "thin:#{command}"
31
+ end
32
+
33
+ before "nginx:start", "thin:start"
34
+ before "nginx:stop", "thin:stop"
35
+
36
+ end
37
+
38
+ # eof
39
+
40
+ end
41
+ end
42
+ end
43
+ end
44
+
@@ -0,0 +1,44 @@
1
+ # encoding: utf-8
2
+ module MagicRecipes
3
+ module Unicorn
4
+ def self.load_into(configuration)
5
+ configuration.load do
6
+
7
+ # code is taken from railscast #337
8
+
9
+ set_default(:unicorn_user) { user }
10
+ set_default(:unicorn_pid) { "#{current_path}/tmp/pids/unicorn.pid" }
11
+ set_default(:unicorn_config) { "#{shared_path}/config/unicorn.rb" }
12
+ set_default(:unicorn_log) { "#{shared_path}/log/unicorn.log" }
13
+ set_default(:unicorn_workers, 2)
14
+
15
+ namespace :unicorn do
16
+ desc "Setup Unicorn initializer and app configuration"
17
+ task :setup, roles: :app do
18
+ run "mkdir -p #{shared_path}/config"
19
+ template "unicorn.rb.erb", unicorn_config
20
+ template "unicorn_init.erb", "/tmp/unicorn_init"
21
+ run "chmod +x /tmp/unicorn_init"
22
+ run "#{sudo} mv /tmp/unicorn_init /etc/init.d/unicorn_#{application}"
23
+ run "#{sudo} update-rc.d -f unicorn_#{application} defaults"
24
+ end
25
+ after "deploy:setup", "unicorn:setup"
26
+
27
+ %w[start stop restart].each do |command|
28
+ desc "#{command} unicorn"
29
+ task command, roles: :app do
30
+ run "service unicorn_#{application} #{command}"
31
+ end
32
+ after "deploy:#{command}", "unicorn:#{command}"
33
+ end
34
+
35
+ end
36
+
37
+ # eof
38
+
39
+ end
40
+ end
41
+ end
42
+ end
43
+
44
+
@@ -0,0 +1,75 @@
1
+ require 'capistrano'
2
+
3
+ module MagicRecipes
4
+ def self.load_into(configuration)
5
+ configuration.load do
6
+
7
+ @magical_recipes = []
8
+
9
+ class << self
10
+ attr_reader :magical_recipes
11
+ end
12
+
13
+ # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
14
+ # Magic-Helper:
15
+ # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
16
+
17
+ require 'bundler/capistrano'
18
+
19
+ default_run_options[:pty] = true
20
+ ssh_options[:forward_agent] = true
21
+
22
+ def template(from, to)
23
+ erb = File.read(File.expand_path("../magic_recipes/templates/#{from}", __FILE__))
24
+ put ERB.new(erb).result(binding), to
25
+ end
26
+
27
+ def set_default(name, *args, &block)
28
+ set(name, *args, &block) unless exists?(name)
29
+ end
30
+
31
+ def random_string(length=42)
32
+ # chars = 'abcdefghjkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ23456789'
33
+ chars = 'abcdefghjkmnpqrstuvwxyz234567890'
34
+ password = ''
35
+ length.times { password << chars[rand(chars.size)] }
36
+ password
37
+ end
38
+
39
+ namespace :deploy do
40
+ desc "Install everything onto the server"
41
+ task :install do
42
+ run "#{sudo} apt-get -y update"
43
+ run "#{sudo} apt-get -y install python-software-properties"
44
+ end
45
+ end
46
+
47
+ # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
48
+ # Load-Helper:
49
+ # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
50
+
51
+ def use_recipe(recipe_name)
52
+ return if @magical_recipes.include?(recipe_name.to_sym)
53
+
54
+ begin
55
+ require "magic_recipes/#{recipe_name.to_s}"
56
+
57
+ recipe = ::MagicRecipes.const_get( recipe_name.to_s.capitalize.gsub(/_(\w)/) { $1.upcase } )
58
+ recipe.load_into(self)
59
+ @magical_recipes << recipe_name.to_sym
60
+ rescue LoadError
61
+ abort "There is no recipe called `#{recipe_name}`!"
62
+ end
63
+ end
64
+
65
+ def magic_recipes(*recipes)
66
+ recipes.map{ |recipe| use_recipe(recipe) }
67
+ end
68
+
69
+ end
70
+ end
71
+ end
72
+
73
+ if Capistrano::Configuration.instance
74
+ MagicRecipes.load_into(Capistrano::Configuration.instance)
75
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :magic_recipes do
3
+ # # Task goes here
4
+ # end