mirror of
https://github.com/capistrano/capistrano
synced 2023-03-27 23:21:18 -04:00
Rails 3.1 Asset Pipeline support
This commit is contained in:
parent
a5d2e4c98c
commit
f68fcae65d
3 changed files with 65 additions and 4 deletions
|
@ -38,6 +38,10 @@ end
|
||||||
files = {
|
files = {
|
||||||
"Capfile" => unindent(<<-FILE),
|
"Capfile" => unindent(<<-FILE),
|
||||||
load 'deploy' if respond_to?(:namespace) # cap2 differentiator
|
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'].each { |plugin| load(plugin) }
|
||||||
|
|
||||||
load 'config/deploy' # remove this line to skip loading any of the default tasks
|
load 'config/deploy' # remove this line to skip loading any of the default tasks
|
||||||
|
|
|
@ -28,7 +28,9 @@ _cset :deploy_via, :checkout
|
||||||
_cset(:deploy_to) { "/u/apps/#{application}" }
|
_cset(:deploy_to) { "/u/apps/#{application}" }
|
||||||
_cset(:revision) { source.head }
|
_cset(:revision) { source.head }
|
||||||
|
|
||||||
# Maintenance base filename
|
_cset :rails_env, "production"
|
||||||
|
_cset :rake, "rake"
|
||||||
|
|
||||||
_cset :maintenance_basename, "maintenance"
|
_cset :maintenance_basename, "maintenance"
|
||||||
|
|
||||||
# =========================================================================
|
# =========================================================================
|
||||||
|
@ -384,8 +386,6 @@ namespace :deploy do
|
||||||
set :migrate_target, :latest
|
set :migrate_target, :latest
|
||||||
DESC
|
DESC
|
||||||
task :migrate, :roles => :db, :only => { :primary => true } do
|
task :migrate, :roles => :db, :only => { :primary => true } do
|
||||||
rake = fetch(:rake, "rake")
|
|
||||||
rails_env = fetch(:rails_env, "production")
|
|
||||||
migrate_env = fetch(:migrate_env, "")
|
migrate_env = fetch(:migrate_env, "")
|
||||||
migrate_target = fetch(:migrate_target, :latest)
|
migrate_target = fetch(:migrate_target, :latest)
|
||||||
|
|
||||||
|
@ -395,7 +395,7 @@ namespace :deploy do
|
||||||
else raise ArgumentError, "unknown migration target #{migrate_target.inspect}"
|
else raise ArgumentError, "unknown migration target #{migrate_target.inspect}"
|
||||||
end
|
end
|
||||||
|
|
||||||
run "cd #{directory}; #{rake} RAILS_ENV=#{rails_env} #{migrate_env} db:migrate"
|
run "cd #{directory} && #{rake} RAILS_ENV=#{rails_env} #{migrate_env} db:migrate"
|
||||||
end
|
end
|
||||||
|
|
||||||
desc <<-DESC
|
desc <<-DESC
|
||||||
|
|
57
lib/capistrano/recipes/deploy/assets.rb
Normal file
57
lib/capistrano/recipes/deploy/assets.rb
Normal file
|
@ -0,0 +1,57 @@
|
||||||
|
load 'deploy' unless defined?(_cset)
|
||||||
|
|
||||||
|
_cset :asset_env, "RAILS_GROUPS=assets"
|
||||||
|
_cset :assets_prefix, "assets"
|
||||||
|
|
||||||
|
before 'deploy:finalize_update', 'deploy:assets:symlink'
|
||||||
|
after 'deploy:update_code', 'deploy:assets:precompile'
|
||||||
|
|
||||||
|
namespace :deploy do
|
||||||
|
namespace :assets do
|
||||||
|
desc <<-DESC
|
||||||
|
[internal] This task will set up a symlink to the shared directory \
|
||||||
|
for the assets directory. Assets are shared across deploys to avoid \
|
||||||
|
mid-deploy mismatches between old application html asking for assets \
|
||||||
|
and getting a 404 file not found error. The assets cache is shared \
|
||||||
|
for efficiency. If you cutomize the assets path prefix, override the \
|
||||||
|
:assets_prefix variable to match.
|
||||||
|
DESC
|
||||||
|
task :symlink, :roles => :web, :except => { :no_release => true } do
|
||||||
|
run <<-CMD
|
||||||
|
rm -rf #{latest_release}/public/#{assets_prefix} &&
|
||||||
|
mkdir -p #{latest_release}/public &&
|
||||||
|
mkdir -p #{shared_path}/assets &&
|
||||||
|
ln -s #{shared_path}/assets #{latest_release}/public/#{assets_prefix}
|
||||||
|
CMD
|
||||||
|
end
|
||||||
|
|
||||||
|
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"
|
||||||
|
DESC
|
||||||
|
task :precompile, :roles => :web, :except => { :no_release => true } do
|
||||||
|
run "cd #{latest_release} && #{rake} RAILS_ENV=#{rails_env} #{asset_env} assets:precompile"
|
||||||
|
end
|
||||||
|
|
||||||
|
desc <<-DESC
|
||||||
|
Run the asset clean rake task. Use with caution, this will delete \
|
||||||
|
all of your compiled assets. 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"
|
||||||
|
DESC
|
||||||
|
task :clean, :roles => :web, :except => { :no_release => true } do
|
||||||
|
run "cd #{latest_release} && #{rake} RAILS_ENV=#{rails_env} #{asset_env} assets:clean"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Add table
Add a link
Reference in a new issue