chicken_soup 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. data/.gitignore +2 -0
  2. data/.rspec +1 -0
  3. data/.rvmrc +1 -0
  4. data/chicken_soup.gemspec +3 -1
  5. data/lib/chicken_soup/capabilities.rb +21 -6
  6. data/lib/chicken_soup/capabilities/apache/apache-checks.rb +19 -0
  7. data/lib/chicken_soup/capabilities/apache/apache-defaults.rb +30 -0
  8. data/lib/chicken_soup/capabilities/apache/apache-tasks.rb +85 -0
  9. data/lib/chicken_soup/capabilities/bundler/bundler-checks.rb +19 -0
  10. data/lib/chicken_soup/capabilities/bundler/bundler-defaults.rb +14 -0
  11. data/lib/chicken_soup/capabilities/bundler/bundler-tasks.rb +35 -0
  12. data/lib/chicken_soup/capabilities/checks.rb +1 -1
  13. data/lib/chicken_soup/capabilities/defaults.rb +22 -5
  14. data/lib/chicken_soup/capabilities/{git.rb → git/git-defaults.rb} +2 -13
  15. data/lib/chicken_soup/capabilities/heroku/heroku-checks.rb +22 -0
  16. data/lib/chicken_soup/capabilities/heroku/heroku-defaults.rb +16 -0
  17. data/lib/chicken_soup/capabilities/{heroku.rb → heroku/heroku-tasks.rb} +5 -45
  18. data/lib/chicken_soup/capabilities/{mysql.rb → mysql/mysql-tasks.rb} +0 -0
  19. data/lib/chicken_soup/capabilities/nginx/nginx-checks.rb +19 -0
  20. data/lib/chicken_soup/capabilities/nginx/nginx-defaults.rb +21 -0
  21. data/lib/chicken_soup/capabilities/nginx/nginx-tasks.rb +85 -0
  22. data/lib/chicken_soup/capabilities/{passenger.rb → passenger/passenger-tasks.rb} +1 -1
  23. data/lib/chicken_soup/capabilities/postgres/postgres-checks.rb +17 -0
  24. data/lib/chicken_soup/capabilities/postgres/postgres-defaults.rb +15 -0
  25. data/lib/chicken_soup/capabilities/{postgres.rb → postgres/postgres-tasks.rb} +1 -1
  26. data/lib/chicken_soup/capabilities/rvm/rvm-checks.rb +21 -0
  27. data/lib/chicken_soup/capabilities/rvm/rvm-defaults.rb +13 -0
  28. data/lib/chicken_soup/capabilities/rvm/rvm-tasks.rb +6 -0
  29. data/lib/chicken_soup/capabilities/shared/db-checks.rb +19 -0
  30. data/lib/chicken_soup/capabilities/shared/db-defaults.rb +13 -0
  31. data/lib/chicken_soup/capabilities/shared/{db.rb → db-tasks.rb} +24 -11
  32. data/lib/chicken_soup/capabilities/shared/web_server-tasks.rb +99 -0
  33. data/lib/chicken_soup/capabilities/{svn.rb → svn/svn-defaults.rb} +0 -13
  34. data/lib/chicken_soup/capabilities/svn/svn-tasks.rb +12 -0
  35. data/lib/chicken_soup/capabilities/tasks.rb +12 -0
  36. data/lib/chicken_soup/capabilities/unix/unix-checks.rb +33 -0
  37. data/lib/chicken_soup/capabilities/unix/unix-defaults.rb +42 -0
  38. data/lib/chicken_soup/capabilities/{unix.rb → unix/unix-tasks.rb} +4 -83
  39. data/lib/chicken_soup/deploy.rb +0 -5
  40. data/lib/chicken_soup/environment.rb +10 -0
  41. data/lib/chicken_soup/environment/checks.rb +17 -2
  42. data/lib/chicken_soup/environment/defaults.rb +25 -3
  43. data/lib/chicken_soup/environment/tasks.rb +12 -0
  44. data/lib/chicken_soup/global.rb +77 -2
  45. data/lib/chicken_soup/notifiers.rb +7 -4
  46. data/lib/chicken_soup/notifiers/checks.rb +1 -1
  47. data/lib/chicken_soup/notifiers/defaults.rb +1 -2
  48. data/lib/chicken_soup/notifiers/email/email-checks.rb +26 -0
  49. data/lib/chicken_soup/notifiers/email/email-defaults.rb +50 -0
  50. data/lib/chicken_soup/notifiers/email/email-tasks.rb +37 -0
  51. data/lib/chicken_soup/notifiers/email/presenter.rb +56 -0
  52. data/lib/chicken_soup/notifiers/{git.rb → git/git-tasks.rb} +0 -0
  53. data/lib/chicken_soup/notifiers/{hoptoad.rb → hoptoad/hoptoad-tasks.rb} +0 -0
  54. data/lib/chicken_soup/notifiers/tasks.rb +12 -0
  55. data/lib/chicken_soup/templates/client_email.html.erb +21 -0
  56. data/lib/chicken_soup/templates/internal_email.html.erb +19 -0
  57. data/lib/chicken_soup/version.rb +1 -1
  58. data/lib/chicken_stock.rb +3 -3
  59. data/spec/support/focused.rb +10 -0
  60. metadata +91 -35
  61. data/lib/chicken_soup/capabilities/apache.rb +0 -235
  62. data/lib/chicken_soup/capabilities/bundler.rb +0 -68
  63. data/lib/chicken_soup/capabilities/rvm.rb +0 -42
  64. data/lib/chicken_soup/notifiers/email.rb +0 -109
@@ -0,0 +1,19 @@
1
+ ######################################################################
2
+ # NGINX CHECKS #
3
+ ######################################################################
4
+ Capistrano::Configuration.instance(:must_exist).load do
5
+ namespace :capabilities do
6
+ namespace :check do
7
+ desc <<-DESC
8
+ [internal] Checks to see if all necessary Nginx capabilities variables have been set up.
9
+ DESC
10
+ task :nginx do
11
+ required_variables = [
12
+ :web_server_control_script
13
+ ]
14
+
15
+ verify_variables(required_variables)
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,21 @@
1
+ ######################################################################
2
+ # NGINX DEFAULTS #
3
+ ######################################################################
4
+ Capistrano::Configuration.instance(:must_exist).load do
5
+ namespace :capabilities do
6
+ namespace :defaults do
7
+ desc "[internal] Checks to see what type of Nginx installation is running on the remote."
8
+ task :nginx do
9
+ find_web_server_control_script
10
+ end
11
+ end
12
+ end
13
+ end
14
+
15
+ def find_web_server_control_script
16
+ if remote_file_exists?("/etc/init.d/nginx")
17
+ set :web_server_control_script, "/etc/init.d/nginx"
18
+ end
19
+
20
+ abort "Couldn't figure out how to control your installation of Nginx" unless exists?(:web_server_control_script)
21
+ end
@@ -0,0 +1,85 @@
1
+ ######################################################################
2
+ # NGINX TASKS #
3
+ ######################################################################
4
+ Capistrano::Configuration.instance(:must_exist).load do
5
+ require 'chicken_soup/capabilities/shared/web_server-tasks'
6
+
7
+ namespace :website do
8
+ desc "Creates the site configuration for the files."
9
+ task :create do
10
+ abort "Sorry, auto-installing sites is not supported on your installation of Nginx." unless exists?(:nginx_disable_script)
11
+
12
+ passenger_friendly_error_messages = rails_env == :production ? "off" : "on"
13
+
14
+ virtual_host_config = <<-VHOST
15
+ server {
16
+ listen #{web_server_ip}:443;
17
+ server_name #{deploy_site_name} *.#{deploy_site_name};
18
+
19
+ passenger_enabled on;
20
+ passenger_friendly_error_pages #{passenger_friendly_error_pages};
21
+ passenger_min_instances 4;
22
+
23
+ rails_env #{rails_env};
24
+ rack_env #{rails_env};
25
+
26
+ ssl on;
27
+ ssl_certificate /etc/nginx/ssl/#{domain}.crt;
28
+ ssl_certificate_key /etc/nginx/ssl/#{domain}.key;
29
+
30
+ ssl_session_timeout 5m;
31
+
32
+ ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;
33
+ ssl_prefer_server_ciphers on;
34
+
35
+ root #{deploy_to}/current/public;
36
+
37
+ client_max_body_size 3M;
38
+
39
+ access_log /var/log/nginx/#{application}.access.log main;
40
+ error_log /var/log/nginx/#{application}.error.log warn;
41
+
42
+ error_page 500 501 504 505 506 507 508 509 /500.html;
43
+ error_page 400 401 403 404 405 406 407 409 410 413 415 416 417 /404.html;
44
+ error_page 422 444 /422.html;
45
+ error_page 502 503 /public/maintenance.html;
46
+
47
+ location / {
48
+ try_files /system/maintenance.html $request_uri;
49
+ }
50
+ }
51
+
52
+ server {
53
+ listen #{web_server_ip}:80;
54
+ server_name #{deploy_site_name} *.#{deploy_site_name};
55
+
56
+ location / {
57
+ rewrite ^ https://$http_host$request_uri? permanent
58
+ }
59
+ }
60
+ VHOST
61
+
62
+ put virtual_host_config, "#{user_home}/#{deploy_site_name}"
63
+ run "#{sudo} mv #{user_home}/#{deploy_site_name} /etc/nginx/sites-available"
64
+ web_server.reload
65
+ end
66
+
67
+ desc "Completely removes the site configuration from the server (but leaves the files.)"
68
+ task :remove do
69
+ abort "Sorry, auto-removing sites is not supported on your installation of Nginx." unless exists?(:nginx_disable_script)
70
+
71
+ run "#{sudo} rm /etc/nginx/sites-available/#{deploy_site_name}"
72
+ web_server.reload
73
+ end
74
+
75
+ desc "Enable Site"
76
+ task :enable do
77
+ abort "Sorry, auto-enabling sites is not supported on your installation of Nginx." unless exists?(:nginx_enable_script)
78
+ end
79
+
80
+ desc "Disable Site"
81
+ task :disable do
82
+ abort "Sorry, auto-disabling sites is not supported on your installation of Nginx." unless exists?(:nginx_disable_script)
83
+ end
84
+ end
85
+ end
@@ -25,7 +25,7 @@ Capistrano::Configuration.instance(:must_exist).load do
25
25
  changes, Passenger restarts the app.
26
26
  DESC
27
27
  task :restart, :except => { :no_release => true } do
28
- run "touch #{File.join(current_path,'tmp','restart.txt')}"
28
+ run "touch #{File.join( current_path, 'tmp', 'restart.txt' )}"
29
29
  end
30
30
  end
31
31
  end
@@ -0,0 +1,17 @@
1
+ ######################################################################
2
+ # POSTGRES CHECKS #
3
+ ######################################################################
4
+ Capistrano::Configuration.instance(:must_exist).load do
5
+ require 'chicken_soup/capabilities/shared/db-checks'
6
+
7
+ namespace :capabilities do
8
+ namespace :check do
9
+ desc <<-DESC
10
+ [internal] Checks to see if all necessary Postgres capabilities variables have been set up.
11
+ DESC
12
+ task :postgres do
13
+ capabilities.check.db
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,15 @@
1
+ ######################################################################
2
+ # POSTGRES DEFAULTS #
3
+ ######################################################################
4
+ Capistrano::Configuration.instance(:must_exist).load do
5
+ require 'chicken_soup/capabilities/shared/db-defaults'
6
+
7
+ namespace :capabilities do
8
+ namespace :defaults do
9
+ desc "[internal] Sets intelligent defaults for Postgres deployments."
10
+ task :postgres do
11
+ capabilities.defaults.db
12
+ end
13
+ end
14
+ end
15
+ end
@@ -2,5 +2,5 @@
2
2
  # POSTGRES TASKS #
3
3
  ######################################################################
4
4
  Capistrano::Configuration.instance(:must_exist).load do
5
- require 'chicken_soup/capabilities/shared/db'
5
+ require 'chicken_soup/capabilities/shared/db-tasks'
6
6
  end
@@ -0,0 +1,21 @@
1
+ ######################################################################
2
+ # RVM CHECKS #
3
+ ######################################################################
4
+ Capistrano::Configuration.instance(:must_exist).load do
5
+ namespace :capabilities do
6
+ namespace :check do
7
+ desc <<-DESC
8
+ [internal] Checks to see if all necessary RVM variables have been set up.
9
+ DESC
10
+ task :rvm do
11
+ required_variables = [
12
+ :ruby_version,
13
+ :ruby_gemset,
14
+ :rvm_ruby_string,
15
+ ]
16
+
17
+ verify_variables(required_variables)
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,13 @@
1
+ ######################################################################
2
+ # RVM DEFAULTS #
3
+ ######################################################################
4
+ Capistrano::Configuration.instance(:must_exist).load do
5
+ namespace :capabilities do
6
+ namespace :defaults do
7
+ _cset :ruby_version, ENV["rvm_ruby_string"]
8
+ _cset :ruby_gemset, ENV["GEM_HOME"].split('@')[1]
9
+
10
+ _cset(:rvm_ruby_string) {ruby_gemset ? "#{ruby_version}@#{ruby_gemset}" : ruby_version}
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,6 @@
1
+ ######################################################################
2
+ # RVM TASKS #
3
+ ######################################################################
4
+ def run_with_rvm(ruby_env_string, command)
5
+ run("rvm use #{ruby_env_string} && #{command}")
6
+ end
@@ -0,0 +1,19 @@
1
+ ######################################################################
2
+ # DB CHECKS #
3
+ ######################################################################
4
+ Capistrano::Configuration.instance(:must_exist).load do
5
+ namespace :capabilities do
6
+ namespace :check do
7
+ desc <<-DESC
8
+ [internal] Checks to see if all necessary DB capabilities variables have been set up.
9
+ DESC
10
+ task :db do
11
+ required_variables = [
12
+ :skip_backup_before_migration
13
+ ]
14
+
15
+ verify_variables(required_variables)
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,13 @@
1
+ ######################################################################
2
+ # DB DEFAULTS #
3
+ ######################################################################
4
+ Capistrano::Configuration.instance(:must_exist).load do
5
+ namespace :capabilities do
6
+ namespace :defaults do
7
+ desc "[internal] Sets intelligent defaults for DB deployments."
8
+ task :db do
9
+ _cset :skip_backup_before_migration, false
10
+ end
11
+ end
12
+ end
13
+ end
@@ -5,8 +5,12 @@ Capistrano::Configuration.instance(:must_exist).load do
5
5
  _cset(:db_root_password) {Capistrano::CLI.password_prompt("Root Password For DB: ")}
6
6
  _cset(:db_app_password) {Capistrano::CLI.password_prompt("App Password For DB: ")}
7
7
 
8
- run_task "db:create", :as => "manager"
9
- run_task "db:drop", :as => "manager"
8
+ run_task "db:create", :as => manager_username
9
+ run_task "db:drop", :as => manager_username
10
+
11
+ before "deploy:migrate", "db:backup" unless skip_backup_before_migration
12
+
13
+ before 'db:backup', 'db:backup:check'
10
14
 
11
15
  namespace :db do
12
16
  desc <<-DESC
@@ -17,9 +21,18 @@ Capistrano::Configuration.instance(:must_exist).load do
17
21
  * The filenames are formatted with the timestamp of the backup.
18
22
  * After export, each file is zipped up using a bzip2 compression format.
19
23
  DESC
20
- task :backup do
21
- run "if [ ! -d #{shared_path}/db_backups ]; then mkdir #{shared_path}/db_backups; fi"
22
- run "cd #{current_path} && bundle exec rake BACKUP_DIRECTORY=#{shared_path}/db_backups RAILS_ENV=#{rails_env} db:backup"
24
+ namespace :backup do
25
+ task :default do
26
+ run "cd #{current_path} && BACKUP_DIRECTORY=#{shared_path}/db_backups #{rake} db:backup"
27
+ end
28
+
29
+ desc "[internal] Used to check to see if the db:backup task exists on the server."
30
+ task :check do
31
+ backup_task_exists = capture("cd #{current_path} && #{rake} -T | grep db:backup | wc -l").chomp
32
+ abort("There must be a task named db:backup in order to deploy. If you do not want to backup your DB during deployments, set the skip_backup_before_migration variable to true in your deploy.rb.") if backup_task_exists == '0'
33
+
34
+ run "if [ ! -d #{shared_path}/db_backups ]; then mkdir #{shared_path}/db_backups; fi"
35
+ end
23
36
  end
24
37
 
25
38
  desc <<-DESC
@@ -30,12 +43,12 @@ Capistrano::Configuration.instance(:must_exist).load do
30
43
 
31
44
  Warning: This task cannot be called in production mode. If you truely wish
32
45
  to run this in production, you'll need to log into the server and
33
- run the rake task manually.
46
+ run the rake task manually or use Capistrano's `console` task.
34
47
  DESC
35
48
  task :reset_and_seed do
36
- raise "I'm sorry Dave, but I can't let you do that. I have full control over production." if rails_env == 'production'
49
+ abort "I'm sorry Dave, but I can't let you do that. I have full control over production." if rails_env == 'production'
37
50
  db.backup
38
- run "cd #{current_path} && rake RAILS_ENV=#{rails_env} db:reset_and_seed"
51
+ run "cd #{current_path} && #{rake} db:reset_and_seed"
39
52
  end
40
53
 
41
54
  desc <<-DESC
@@ -47,12 +60,12 @@ Capistrano::Configuration.instance(:must_exist).load do
47
60
 
48
61
  Warning: This task cannot be called in production mode. If you truely wish
49
62
  to run this in production, you'll need to log into the server and
50
- run the rake task manually.
63
+ run the rake task manually or use Capistrano's `console` task.
51
64
  DESC
52
65
  task :seed do
53
- raise "I'm sorry Dave, but I can't let you do that. I have full control over production." if rails_env == 'production'
66
+ abort "I'm sorry Dave, but I can't let you do that. I have full control over production." if rails_env == 'production'
54
67
  db.backup
55
- run "cd #{current_path} && rake RAILS_ENV=#{rails_env} db:seed"
68
+ run "cd #{current_path} && #{rake} db:seed"
56
69
  end
57
70
  end
58
71
  end
@@ -0,0 +1,99 @@
1
+ ######################################################################
2
+ # COMMON WEB SERVER TASKS #
3
+ ######################################################################
4
+ Capistrano::Configuration.instance(:must_exist).load do
5
+ run_task 'web_server:stop', :as => manager_username
6
+ run_task 'web_server:start', :as => manager_username
7
+ run_task 'web_server:restart', :as => manager_username
8
+ run_task 'web_server:reload', :as => manager_username
9
+
10
+ run_task 'website:install', :as => manager_username
11
+ run_task 'website:remove', :as => manager_username
12
+ run_task 'website:enable', :as => manager_username
13
+ run_task 'website:disable', :as => manager_username
14
+
15
+ before 'deploy', 'deploy:web:disable'
16
+ after 'deploy', 'deploy:web:enable'
17
+
18
+ namespace :deploy do
19
+ namespace :web do
20
+ desc <<-DESC
21
+ Enables the website's application by removing the maintenance page.
22
+ DESC
23
+ task :enable do
24
+ website.maintenance_mode.disable
25
+ end
26
+
27
+ desc <<-DESC
28
+ Disables the website's application by installing the maintenance page.
29
+ DESC
30
+ task :disable do
31
+ website.maintenance_mode.enable
32
+ end
33
+ end
34
+ end
35
+
36
+ namespace :website do
37
+ namespace :maintenance_mode do
38
+ desc <<-DESC
39
+ Makes the application web-accessible again. Removes the \
40
+ "maintenance.html" page generated by deploy:web:disable, which (if your \
41
+ web servers are configured correctly) will make your application \
42
+ web-accessible again.
43
+ DESC
44
+ task :disable, :except => { :no_release => true } do
45
+ run "rm #{shared_path}/system/maintenance.html"
46
+ end
47
+
48
+ desc <<-DESC
49
+ Present a maintenance page to visitors. Disables your application's web \
50
+ interface by writing a "maintenance.html" file to each web server. The \
51
+ servers must be configured to detect the presence of this file, and if \
52
+ it is present, always display it instead of performing the request.
53
+
54
+ By default, the maintenance page will just say the site is down for \
55
+ "maintenance", and will be back "shortly", but you can customize the \
56
+ page by specifying the REASON and UNTIL environment variables:
57
+
58
+ $ cap deploy:web:disable \\
59
+ REASON="hardware upgrade" \\
60
+ UNTIL="12pm Central Time"
61
+
62
+ Further customization will require that you write your own task.
63
+ DESC
64
+ task :enable, :except => { :no_release => true } do
65
+ on_rollback { rm "#{shared_path}/system/maintenance.html" }
66
+
67
+ require 'erb'
68
+ deadline, reason = ENV['UNTIL'], ENV['REASON']
69
+
70
+ template = File.read("./public/maintenance.html.erb")
71
+ maintenance_page = ERB.new(template).result(binding)
72
+
73
+ put maintenance_page, "#{shared_path}/system/maintenance.html", :mode => 0644
74
+ end
75
+ end
76
+ end
77
+
78
+ namespace :web_server do
79
+ desc "Stop the web server"
80
+ task :stop do
81
+ run "#{sudo} #{web_server_control_script} stop"
82
+ end
83
+
84
+ desc "Start the web server"
85
+ task :start do
86
+ run "#{sudo} #{web_server_control_script} start"
87
+ end
88
+
89
+ desc "Restart the web server"
90
+ task :restart do
91
+ run "#{sudo} #{web_server_control_script} restart"
92
+ end
93
+
94
+ desc "Reloads the web server configuration"
95
+ task :reload do
96
+ run "#{sudo} #{web_server_control_script} reload"
97
+ end
98
+ end
99
+ end
@@ -1,16 +1,3 @@
1
- ######################################################################
2
- # SUBVERSION TASKS #
3
- ######################################################################
4
- Capistrano::Configuration.instance(:must_exist).load do
5
- namespace :vc do
6
- desc <<-DESC
7
- DESC
8
- task :log do
9
- set :vc_log, `svn log -r #{previous_revision.to_i + 1}:#{current_revision}`
10
- end
11
- end
12
- end
13
-
14
1
  ######################################################################
15
2
  # SUBVERSION DEFAULTS #
16
3
  ######################################################################