crossroads_capistrano 1.3.61 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,7 +3,7 @@ $:.push File.expand_path("../lib", __FILE__)
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "crossroads_capistrano"
6
- s.version = "1.3.61"
6
+ s.version = "1.4.0"
7
7
  s.platform = Gem::Platform::RUBY
8
8
  s.authors = ["Steve Kenworthy", "Ben Tillman", "Nathan Broadbent"]
9
9
  s.email = ["it_dept@crossroads.org.hk"]
@@ -0,0 +1,27 @@
1
+ # These default recipes are always loaded unless otherwise specified
2
+
3
+ # Default recipes
4
+ # ---------------------------------------------------------
5
+ load File.join(File.dirname(__FILE__), "prompt.rb")
6
+
7
+
8
+ # Default settings
9
+ # ---------------------------------------------------------
10
+ set :default_stage, "preview"
11
+
12
+ set :scm, :git
13
+ set :deploy_via, :remote_cache
14
+ set :keep_releases, 3
15
+
16
+ set :bundle_without, [:cucumber, :development, :test]
17
+
18
+ set :httpd_user, "apache"
19
+ set :httpd_group, "apache"
20
+
21
+ default_run_options[:pty] = true
22
+
23
+
24
+ # Default hooks
25
+ # ---------------------------------------------------------
26
+ after "deploy:restart", "deploy:cleanup"
27
+
@@ -1,11 +1,11 @@
1
1
  # For apps that are deployed with user permissions.
2
2
  # ----------------------------------------------------------
3
3
 
4
- # Our developers use different users on their local machines.
5
- set :user, case sysuser = `echo $USER`.strip
6
- when 'warp' then 'bstillman'
7
- when 'steve' then 'swkenworthy'
8
- else sysuser
4
+ # Fetch user from ~/.netrc or $USER.
5
+ set :user, if File.exist?("~/.netrc")
6
+ File.open(`echo ~/.netrc`.strip, 'r').read[/login ([a-z_]+)/m, 1]
7
+ else
8
+ `echo $USER`.strip
9
9
  end
10
10
 
11
11
  namespace :deploy do
@@ -17,11 +17,17 @@ namespace :deploy do
17
17
  desc "Apache permissions (for passenger)"
18
18
  task :apache_permissions do
19
19
  unless $apache_permissions
20
- sudo "chown -R #{httpd_user}:#{httpd_grp} #{current_path}/"
21
- sudo "chown -R #{httpd_user}:#{httpd_grp} #{deploy_to}/shared/"
20
+ sudo "chown -R #{httpd_user}:#{httpd_group} #{current_path}/"
21
+ sudo "chown -R #{httpd_user}:#{httpd_group} #{deploy_to}/shared/"
22
22
  $apache_permissions = true
23
23
  end
24
24
  end
25
+
26
+ desc "Set permissions on releases directory so old releases can be removed"
27
+ task :release_permissions do
28
+ run "if [ -d #{release_path}/ ]; then #{sudo} chown -R #{httpd_user}:#{httpd_group} #{release_path}/; fi"
29
+ run "if [ -d #{release_path}/ ]; then #{sudo} chmod -R 755 #{release_path}/; fi"
30
+ end
25
31
  end
26
32
 
27
33
  # Set user permissions before running each task, and apache permission when tasks finish.
@@ -31,4 +37,5 @@ end
31
37
  end
32
38
 
33
39
  before "deploy:restart", "deploy:apache_permissions"
40
+ before "deploy:cleanup", "deploy:release_permissions"
34
41
 
@@ -4,31 +4,35 @@
4
4
  namespace :deploy do
5
5
  desc "Notify Hoptoad of the deployment"
6
6
  task :notify_hoptoad, :except => { :no_release => true } do
7
- begin
8
- require 'active_support/core_ext/string'
9
- rescue LoadError
10
- end
11
- require 'hoptoad_notifier'
12
- require File.join(rails_root,'config','initializers','hoptoad')
13
- require 'hoptoad_tasks'
7
+ if ARGV.include?("-n")
8
+ puts "\n ** Dry run, not notifying hoptoad.\n\n"
9
+ else
10
+ begin
11
+ require 'active_support/core_ext/string'
12
+ rescue LoadError
13
+ end
14
+ require 'hoptoad_notifier'
15
+ require File.join(rails_root,'config','initializers','hoptoad')
16
+ require 'hoptoad_tasks'
14
17
 
15
- # Format HoptoadTasks output nicely.
16
- HoptoadTasks.module_eval do; def self.puts(str); super " ** #{str}\n\n"; end; end
18
+ # Format HoptoadTasks output nicely.
19
+ HoptoadTasks.module_eval do; def self.puts(str); super " ** #{str}\n\n"; end; end
17
20
 
18
- rails_env = fetch(:hoptoad_env, fetch(:rails_env, "production"))
19
- local_user = ENV['USER'] || ENV['USERNAME']
21
+ rails_env = fetch(:hoptoad_env, fetch(:rails_env, "production"))
22
+ local_user = ENV['USER'] || ENV['USERNAME']
20
23
 
21
- puts %Q{
22
- * \033[0;32m== Notifying Hoptoad of Deploy\033[0m
23
- - \033[0;33mUser:\033[0m #{local_user}
24
- - \033[0;33mRails Environment:\033[0m #{rails_env}
25
- - \033[0;33mRevision:\033[1;37m #{current_revision[0,7]}\033[0m
26
- - \033[0;33mRepository:\033[0m #{repository}\n\n}
24
+ puts %Q{
25
+ * \033[0;32m== Notifying Hoptoad of Deploy\033[0m
26
+ - \033[0;33mUser:\033[0m #{local_user}
27
+ - \033[0;33mRails Environment:\033[0m #{rails_env}
28
+ - \033[0;33mRevision:\033[1;37m #{current_revision[0,7]}\033[0m
29
+ - \033[0;33mRepository:\033[0m #{repository}\n\n}
27
30
 
28
- HoptoadTasks.deploy(:rails_env => rails_env,
29
- :scm_revision => current_revision,
30
- :scm_repository => repository,
31
- :local_username => local_user)
31
+ HoptoadTasks.deploy(:rails_env => rails_env,
32
+ :scm_revision => current_revision,
33
+ :scm_repository => repository,
34
+ :local_username => local_user)
35
+ end
32
36
  end
33
37
  end
34
38
 
@@ -30,5 +30,15 @@ namespace :log do
30
30
  puts "File can be accessed at /tmp/production.log"
31
31
  end
32
32
  end
33
+
34
+ desc "Symlink shared logs to /var/log/rails/<application>-<stage>"
35
+ task :symlink_shared do
36
+ # Creates /var/log/rails/<application>-<stage> and migrates any existing logs.
37
+ run "if ! [ -d /var/log/rails/#{application}-#{stage} ]; then #{sudo} mkdir -p /var/log/rails/#{application}-#{stage} && #{sudo} mv #{shared_path}/log/* /var/log/rails/#{application}-#{stage}/; fi"
38
+ sudo "rm -rf #{shared_path}/log && ln -fs /var/log/rails/#{application}-#{stage} #{shared_path}/log"
39
+ sudo "chown -R #{httpd_user}:#{httpd_group} /var/log/rails/#{application}-#{stage}/"
40
+ end
33
41
  end
34
42
 
43
+ after "stack", "log:symlink_shared"
44
+
@@ -36,8 +36,14 @@ namespace :passenger do
36
36
 
37
37
  desc "Apache config files: uses special variables @DEPLOY_TO@ @IP_ADDR@ @SERVER_NAME@ @PASSENGER_ROOT@ @RUBY_ROOT@"
38
38
  task :config, :roles => :web do
39
- sudo "cp -f #{release_path}/config/httpd-rails.conf /etc/httpd/sites-enabled/010-#{application}-#{stage}.conf"
40
- sudo "sed -i -e 's%@DEPLOY_TO@%#{deploy_to}%g' -e 's%@IP_ADDR@%#{ip_address}%g' -e 's%@SERVER_NAME@%#{site_domain_name}%g' /etc/httpd/sites-enabled/010-#{application}-#{stage}.conf"
39
+ # You can set the following paths from your deploy.rb file, if needed.
40
+ unless defined?(httpd_site_conf_path)
41
+ httpd_site_conf_path = "/etc/httpd/sites-enabled/010-#{application}-#{stage}.conf"
42
+ end
43
+ unless defined?(passenger_conf_path)
44
+ passenger_conf_path = "/etc/httpd/mods-enabled/passenger.conf"
45
+ end
46
+
41
47
  if respond_to?(:rvm_ruby_string) # Deploying with RVM
42
48
  ruby_root = "/usr/local/rvm/wrappers/#{rvm_ruby_string}/ruby"
43
49
  passenger_root = "/usr/local/rvm/gems/#{rvm_ruby_string}/gems/passenger-#{passenger_version}"
@@ -46,8 +52,12 @@ namespace :passenger do
46
52
  passenger_root = capture("pass_path=`gem which phusion_passenger` && echo ${pass_path%/lib/phusion_passenger.rb}")
47
53
  end
48
54
  sed_args = "-e 's%@PASSENGER_ROOT@%#{passenger_root.strip}%g' -e 's%@RUBY_ROOT@%#{ruby_root.strip}%g'"
49
- sudo "cp -f #{release_path}/config/passenger.conf /etc/httpd/mods-enabled/passenger.conf"
50
- sudo "sed -i #{sed_args} /etc/httpd/mods-enabled/passenger.conf"
55
+ # httpd conf
56
+ sudo "cp -f #{release_path}/config/httpd-rails.conf #{httpd_site_conf_path}"
57
+ sudo "sed -i -e 's%@DEPLOY_TO@%#{deploy_to}%g' -e 's%@IP_ADDR@%#{ip_address}%g' -e 's%@SERVER_NAME@%#{site_domain_name}%g' #{httpd_site_conf_path}"
58
+ # passenger conf
59
+ sudo "cp -f #{release_path}/config/passenger.conf #{passenger_conf_path}"
60
+ sudo "sed -i #{sed_args} #{passenger_conf_path}"
51
61
  end
52
62
  end
53
63
 
@@ -1,7 +1,7 @@
1
1
  namespace :deploy do
2
2
  desc "Show currently deployed revision on server."
3
3
  task :revisions, :roles => :app do
4
- current, previous, latest = current_revision[0,7], previous_revision[0,7], real_revision[0,7]
4
+ current, previous, latest = current_revision.to_s[0,7], previous_revision.to_s[0,7], real_revision.to_s[0,7]
5
5
  # Following line 'right-aligns' the branch string.
6
6
  branch_indent = " "*(i=10-branch.size;i<0 ? 0 : i) << branch.capitalize
7
7
  current_is_deployed = current == latest
@@ -5,8 +5,8 @@ namespace :rvm do
5
5
  desc "Install rvm"
6
6
  task :install, :roles => :web do
7
7
  install_deps
8
- run "if ! (which rvm); then bash < <( curl http://rvm.beginrescueend.com/releases/rvm-install-head ); fi", :shell => 'sh'
9
- run "if ! (rvm list | grep #{rvm_ruby_string}); then rvm install #{rvm_ruby_string}; fi", :shell => 'sh'
8
+ sudo "if ! (which rvm); then bash < <( curl http://rvm.beginrescueend.com/releases/rvm-install-head ); fi", :shell => 'sh'
9
+ sudo "if ! (rvm list | grep #{rvm_ruby_string}); then rvm install #{rvm_ruby_string}; fi", :shell => 'sh'
10
10
  end
11
11
 
12
12
  task :install_deps, :roles => :web do
@@ -15,5 +15,5 @@ namespace :rvm do
15
15
 
16
16
  end
17
17
 
18
- before "deploy:cold", "rvm:install"
18
+ before "stack", "rvm:install"
19
19
 
@@ -0,0 +1,9 @@
1
+ namespace :deploy do
2
+ desc "Symlink Shared config files into release path."
3
+ task :symlink_config do
4
+ run "ln -sf #{shared_path}/config/*.yml #{release_path}/config/"
5
+ end
6
+ end
7
+
8
+ before "deploy:symlink", "deploy:symlink_config"
9
+
@@ -1,58 +1,46 @@
1
1
  require File.expand_path('../yum', __FILE__)
2
2
 
3
- #
4
- # Capistrano recipes for cold deployments
5
- #
6
- # Usage (add the following to your deploy.rb):
7
- #
8
- # load 'recipes/stack'
9
- # set :gems_for_project, ""
10
- # ...
11
- #
12
- # Then just run "cap deploy:cold" and this stack will hook into it
13
- #
3
+ # Installs minimal system software stack. Runs before "cap deploy:cold"
14
4
 
15
5
  namespace :stack do
16
-
17
- # Override this if you don't want particular stack items
18
6
  desc "Setup operating system and rails environment"
19
7
  task :default do
20
8
  yum.update
21
- yum.install( {:base => packages_for_project}, :stable ) if packages_for_project
22
-
23
- gems
24
-
9
+ yum.install( {:base => packages_for_project}, :stable ) if defined?(packages_for_project)
10
+ install.bundler
25
11
  deploy.setup
26
12
  shared.setup
13
+ shared.permissions
27
14
  end
28
-
29
- desc "Install required gems"
30
- task :gems do
31
- run "gem install #{gems_for_project} --no-rdoc --no-ri"
15
+ namespace :install do
16
+ desc "Install Bundler"
17
+ task :bundler do
18
+ run "gem install bundler --no-rdoc --no-ri"
19
+ end
32
20
  end
33
-
34
21
  end
35
22
 
36
23
  namespace 'shared' do
37
-
24
+ # This task can be extended by the application via an :after hook.
38
25
  desc "Setup shared directory"
39
26
  task :setup do
40
27
  sudo "mkdir -p #{deploy_to}/shared/config"
41
28
  end
42
29
 
43
- desc "Setting proper permissions on shared directory"
30
+ desc "Set permissions on shared directory"
44
31
  task :permissions do
45
- run "chown -R apache:apache #{deploy_to}/shared/"
46
- #~ run "chmod -R 755 #{deploy_to}/shared/"
47
- # during deployments
48
- run "if [ -d #{release_path}/ ]; then chown -R apache:apache #{release_path}/; fi"
49
- run "if [ -d #{release_path}/ ]; then chmod -R 755 #{release_path}/; fi"
32
+ sudo "chown -R #{httpd_user}:#{httpd_group} #{deploy_to}/shared/"
33
+ sudo "chmod -R 755 #{deploy_to}/shared/"
50
34
  end
35
+ end
51
36
 
37
+ namespace :deploy do
38
+ desc "Check for project dependencies"
39
+ task :check_dependencies, :roles => :db, :only => { :primary => true } do
40
+ sudo "cd #{current_path} && RAILS_ENV=production rake check_dependencies"
41
+ end
52
42
  end
53
43
 
54
- #
55
- # Hooks
56
- #
57
- before "deploy:cold", "stack"
58
- before "deploy:symlink", "shared:permissions"
44
+ before "deploy:cold", "stack"
45
+ after "deploy:check", "deploy:check_dependencies"
46
+
@@ -19,7 +19,7 @@ namespace :ts do
19
19
  desc "Start sphinx"
20
20
  task :start do
21
21
  run "cd #{current_path} && RAILS_ENV=production rake ts:start"
22
- run "chown apache:apache #{deploy_to}/shared/log/searchd.production.pid"
22
+ run "chown #{httpd_user}:#{httpd_group} #{deploy_to}/shared/log/searchd.production.pid"
23
23
  end
24
24
 
25
25
  desc "Restart sphinx"
@@ -8,6 +8,11 @@ if defined?(Capistrano::Configuration) && Capistrano::Configuration.instance
8
8
  Capistrano::Configuration.instance(:must_exist).load do
9
9
  set :rails_root, Dir.pwd # For tasks that need the root directory
10
10
 
11
+ # Load defaults unless explicitly told not to.
12
+ unless $no_default
13
+ load File.join(File.dirname(__FILE__), "crossroads_capistrano/recipes/defaults.rb")
14
+ end
15
+
11
16
  def load_crossroads_recipes(recipes)
12
17
  if recipes == :all
13
18
  # Load all available crossroads_recipes.
metadata CHANGED
@@ -1,36 +1,26 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: crossroads_capistrano
3
- version: !ruby/object:Gem::Version
4
- hash: 97
5
- prerelease: false
6
- segments:
7
- - 1
8
- - 3
9
- - 61
10
- version: 1.3.61
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.4.0
5
+ prerelease:
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Steve Kenworthy
14
9
  - Ben Tillman
15
10
  - Nathan Broadbent
16
11
  autorequire:
17
12
  bindir: bin
18
13
  cert_chain: []
19
-
20
- date: 2011-05-20 00:00:00 +08:00
14
+ date: 2011-05-20 00:00:00.000000000 +08:00
21
15
  default_executable:
22
16
  dependencies: []
23
-
24
17
  description: A Crossroads Foundation collection of generic capistrano recipes.
25
- email:
18
+ email:
26
19
  - it_dept@crossroads.org.hk
27
20
  executables: []
28
-
29
21
  extensions: []
30
-
31
22
  extra_rdoc_files: []
32
-
33
- files:
23
+ files:
34
24
  - .gitignore
35
25
  - Gemfile
36
26
  - README.textile
@@ -38,6 +28,7 @@ files:
38
28
  - crossroads_capistrano.gemspec
39
29
  - lib/crossroads_capistrano.rb
40
30
  - lib/crossroads_capistrano/recipes/cache.rb
31
+ - lib/crossroads_capistrano/recipes/defaults.rb
41
32
  - lib/crossroads_capistrano/recipes/delayed_job.rb
42
33
  - lib/crossroads_capistrano/recipes/deploy_permissions.rb
43
34
  - lib/crossroads_capistrano/recipes/hoptoad.rb
@@ -49,6 +40,7 @@ files:
49
40
  - lib/crossroads_capistrano/recipes/prompt.rb
50
41
  - lib/crossroads_capistrano/recipes/revisions.rb
51
42
  - lib/crossroads_capistrano/recipes/rvm.rb
43
+ - lib/crossroads_capistrano/recipes/shared_config.rb
52
44
  - lib/crossroads_capistrano/recipes/stack.rb
53
45
  - lib/crossroads_capistrano/recipes/thinking_sphinx.rb
54
46
  - lib/crossroads_capistrano/recipes/whenever.rb
@@ -56,36 +48,26 @@ files:
56
48
  has_rdoc: true
57
49
  homepage: http://www.crossroads.org.hk
58
50
  licenses: []
59
-
60
51
  post_install_message:
61
52
  rdoc_options: []
62
-
63
- require_paths:
53
+ require_paths:
64
54
  - lib
65
- required_ruby_version: !ruby/object:Gem::Requirement
55
+ required_ruby_version: !ruby/object:Gem::Requirement
66
56
  none: false
67
- requirements:
68
- - - ">="
69
- - !ruby/object:Gem::Version
70
- hash: 3
71
- segments:
72
- - 0
73
- version: "0"
74
- required_rubygems_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ! '>='
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ required_rubygems_version: !ruby/object:Gem::Requirement
75
62
  none: false
76
- requirements:
77
- - - ">="
78
- - !ruby/object:Gem::Version
79
- hash: 3
80
- segments:
81
- - 0
82
- version: "0"
63
+ requirements:
64
+ - - ! '>='
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
83
67
  requirements: []
84
-
85
68
  rubyforge_project: crossroads_capistrano
86
- rubygems_version: 1.3.7
69
+ rubygems_version: 1.6.2
87
70
  signing_key:
88
71
  specification_version: 3
89
72
  summary: Crossroads capistrano recipes
90
73
  test_files: []
91
-