由于使用了 UPYUN 做资源存储,替换资源方便不少,在 production.rb 中已经进行了如下设置:
config.action_controller.asset_host = Settings.upyun_url
但每次发布后,都需要重新 FTP 发布资源,在寻求自动化方法的路上,我找到了 gem 'rails-assets-for-upyun', '>= 0.0.9'
,可以用命令上传方便多了,但仍然没有解决自动化部署,于是考虑在 mina 的 deploy.rb 中写一段自动部署脚本,于是就解决了。
# => Deploy task
# ===========================================================================================
desc "Deploys the current version to the server."
task :deploy => :environment do
deploy do
# Put things that will set up an empty directory into a fully set-up
# instance of your project.
invoke :'git:clone'
invoke :'deploy:link_shared_paths'
invoke :'bundle:install'
invoke :'rails:db_migrate'
invoke :'rails:assets_precompile'
invoke :'rails:assets_publish_assets_upyun'
invoke :'deploy:cleanup'
to :launch do
invoke :'unicorn:restart'
end
end
end
namespace :rails do
set :publish_upyun, %{
cd #{app_path}
bundle exec rake assets:publish_assets_upyun RAILS_ENV=production
}
task :assets_publish_assets_upyun do
queue 'echo "-----> Assets To UPYUN"'
queue! publish_upyun
end
end
Rakefile
...
namespace :assets do
task :publish_assets_upyun do
RailsAssetsForUpyun.publish 'bucket', 'username', 'password'
end
end