Skip to content
Browse files

refactor capistrano tasks

  • Loading branch information...
1 parent 766b5d8 commit 7cc1d4198215813184c214d0002dea8aa3bb27ef @flyerhzm flyerhzm committed
View
2 Capfile
@@ -3,6 +3,6 @@ load 'deploy' if respond_to?(:namespace) # cap2 differentiator
# Uncomment if you are using Rails' asset pipeline
load 'deploy/assets'
-Dir['vendor/gems/*/recipes/*.rb','vendor/plugins/*/recipes/*.rb'].each { |plugin| load(plugin) }
+Dir['vendor/gems/*/recipes/*.rb','vendor/plugins/*/recipes/*.rb', 'config/deploy/recipes/*.rb'].each { |plugin| load(plugin) }
load 'config/deploy' # remove this line to skip loading any of the default tasks
View
1 Gemfile
@@ -71,7 +71,6 @@ group :development do
# Deploy with Capistrano
gem 'capistrano'
gem 'capistrano_colors'
- gem 'capistrano-ext'
gem 'rvm-capistrano'
gem 'quiet_assets'
View
3 Gemfile.lock
@@ -91,8 +91,6 @@ GEM
net-sftp (>= 2.0.0)
net-ssh (>= 2.0.14)
net-ssh-gateway (>= 1.1.0)
- capistrano-ext (1.2.1)
- capistrano (>= 1.0.0)
capistrano_colors (0.5.5)
capybara (1.1.2)
mime-types (>= 1.16)
@@ -390,7 +388,6 @@ DEPENDENCIES
brakeman
cancan
capistrano
- capistrano-ext
capistrano_colors
capybara
cells
View
61 config/deploy.rb
@@ -1,13 +1,8 @@
-set :stages, %w(staging production)
-set :default_stage, "staging"
-require 'capistrano/ext/multistage'
require 'capistrano_colors'
require 'bundler/capistrano'
-require "delayed/recipes"
require 'rvm/capistrano'
set :rvm_ruby_string, 'ruby-1.9.3-p194@railsbp.com'
-set :rvm_type, :user
set :application, "railsbp.com"
set :repository, "git@github.com:railsbp/railsbp.com.git"
@@ -17,68 +12,22 @@
set :use_sudo, false
set :scm, :git
-
-set :rake, "bundle exec rake"
+set :git_shallow_clone, 1
role :web, "app.railsbp.com" # Your HTTP server, Apache/etc
role :app, "app.railsbp.com" # This may be the same as your `Web` server
role :db, "db.railsbp.com", :primary => true # This is where Rails migrations will run
-role :delayed_job, 'db.railsbp.com'
-set :delayed_job_server_role, :delayed_job
-
-before "deploy:assets:precompile", "config:init"
-before "deploy:assets:precompile", "assets:init"
-before "deploy:restart", "delayed_job:stop"
-after "deploy:restart", "delayed_job:start"
+before "deploy:assets:precompile", "symlinks:create"
-after "deploy:stop", "delayed_job:stop"
-after "deploy:start", "delayed_job:start"
-
-namespace :config do
- task :init do
- run "ln -nfs #{shared_path}/config/database.yml #{release_path}/config/database.yml"
- run "ln -nfs #{shared_path}/config/github.yml #{release_path}/config/github.yml"
- run "ln -nfs #{shared_path}/config/mailers.yml #{release_path}/config/mailers.yml"
+namespace :symlinks do
+ task :create do
+ run "ln -nfs #{shared_path}/config/*.yml #{release_path}/config/"
run "ln -nfs #{shared_path}/builds #{release_path}/builds"
run "cd #{release_path}; bundle exec rails_best_practices -g"
end
end
-namespace :assets do
- task :init, :roles => :app do
- run "cd #{release_path}; #{rake} RAILS_ENV=#{rails_env} css_sprite:build"
- end
-end
-
-set :assets_dependencies, %w(app/assets lib/assets vendor/assets Gemfile.lock config/routes.rb)
-
-namespace :deploy do
- namespace :assets do
-
- desc <<-DESC
- Run the asset precompilation rake task. You can specify the full path \
- to the rake executable by setting the rake variable. You can also \
- specify additional environment variables to pass to rake via the \
- asset_env variable. The defaults are:
-
- set :rake, "rake"
- set :rails_env, "production"
- set :asset_env, "RAILS_GROUPS=assets"
- set :assets_dependencies, fetch(:assets_dependencies) + %w(config/locales/js)
- DESC
- task :precompile, :roles => :web, :except => { :no_release => true } do
- from = source.next_revision(current_revision)
- if capture("cd #{latest_release} && #{source.local.log(from)} #{assets_dependencies.join ' '} | wc -l").to_i > 0
- run %Q{cd #{latest_release} && #{rake} RAILS_ENV=#{rails_env} #{asset_env} assets:precompile}
- else
- logger.info "Skipping asset pre-compilation because there were no asset changes"
- end
- end
-
- end
-end
-
# If you are using Passenger mod_rails uncomment this:
namespace :deploy do
task :start do ; end
View
26 config/deploy/recipes/asset_pipeline.rb
@@ -0,0 +1,26 @@
+set :assets_dependencies, %w(app/assets lib/assets vendor/assets Gemfile.lock config/routes.rb)
+
+namespace :deploy do
+ namespace :assets do
+ desc <<-DESC
+ Run the asset precompilation rake task. You can specify the full path \
+ to the rake executable by setting the rake variable. You can also \
+ specify additional environment variables to pass to rake via the \
+ asset_env variable. The defaults are:
+
+ set :rake, "rake"
+ set :rails_env, "production"
+ set :asset_env, "RAILS_GROUPS=assets"
+ set :assets_dependencies, fetch(:assets_dependencies) + %w(config/locales/js)
+ DESC
+ task :precompile, :roles => :web, :except => { :no_release => true } do
+ from = source.next_revision(current_revision)
+ if capture("cd #{latest_release} && #{source.local.log(from)} #{assets_dependencies.join ' '} | wc -l").to_i > 0
+ run %Q{cd #{latest_release} && #{rake} RAILS_ENV=#{rails_env} #{asset_env} assets:precompile}
+ else
+ logger.info "Skipping asset pre-compilation because there were no asset changes"
+ end
+ end
+
+ end
+end
View
3 config/deploy/production.rb → config/deploy/recipes/cron.rb
@@ -1,6 +1,3 @@
-set :rails_env, "production"
-set :deploy_to, "/home/huangzhi/sites/railsbp.com/production"
-
after "deploy:symlink", "deploy:update_crontab:db"
namespace :deploy do
View
7 config/deploy/recipes/css_sprite.rb
@@ -0,0 +1,7 @@
+before "deploy:assets:precompile", "css_sprite:build"
+
+namespace :css_sprite do
+ task :build, :roles => :app do
+ run "cd #{release_path}; #{rake} RAILS_ENV=#{rails_env} css_sprite:build"
+ end
+end
View
10 config/deploy/recipes/delayed_job.rb
@@ -0,0 +1,10 @@
+require "delayed/recipes"
+
+role :delayed_job, 'db.railsbp.com'
+set :delayed_job_server_role, :delayed_job
+
+before "deploy:restart", "delayed_job:stop"
+after "deploy:restart", "delayed_job:start"
+
+after "deploy:stop", "delayed_job:stop"
+after "deploy:start", "delayed_job:start"
View
2 config/deploy/staging.rb
@@ -1,2 +0,0 @@
-set :rails_env, "staging"
-set :deploy_to, "/home/huangzhi/sites/railsbp.com/staging"

0 comments on commit 7cc1d41

Please sign in to comment.
Something went wrong with that request. Please try again.