Capistrano - rake assets:precompile - 应用程序已经初始化
Posted
技术标签:
【中文标题】Capistrano - rake assets:precompile - 应用程序已经初始化【英文标题】:Capistrano - rake assets:precompile - Application has been already initialized 【发布时间】:2013-09-09 18:40:36 【问题描述】:我正在尝试使用 Capistrano 部署我的 Rails 3.2.13 应用程序。
我正在使用资产管道,因此尝试在部署期间预编译资产。
我收到以下错误:“应用程序已被初始化。”在 rake assets:precompile 阶段。
这是堆栈跟踪:
执行“cd -- /sites/beta.myapp.com/releases/20130905192243 && RAILS_ENV=beta RAILS_GROUPS=assets bundle exec rake assets:precompile" 执行命令 rake 中止!已经申请了 初始化。 /sites/beta.myapp.com/shared/bundle/ruby/1.9.1/gems/railties-3.2.13/lib/rails/application.rb:135:in
initialize!' /sites/beta.myapp.com/shared/bundle/ruby/1.9.1/gems/actionpack-3.2.13/lib/sprockets/assets.rake:95:in
block (2 级) in '任务:TOP => assets:precompile:primary => assets:environment
有什么想法吗?
这是我的 deploy.rb:
require "bundler/capistrano"
require 'capistrano/ext/multistage'
require "whenever/capistrano"
require './config/boot'
require 'airbrake/capistrano'
set :stages, %w(beta production)
set :application, "myapp...."
set :whenever_environment, defer stage
set :whenever_command, "bundle exec whenever"
set :user, "myuser...."
set :deploy_via, :remote_cache
set :use_sudo, false
set :scm, "git"
set :repository, "myrepo....."
set :branch, $1 if `git branch` =~ /\* (\S+)\s/m
namespace :deploy do
task :cold do # Overriding the default deploy:cold
update
load_schema # My own step, replacing migrations.
start
end
task :load_schema, :roles => :app do
run "cd #current_path; rake db:schema:load RAILS_ENV=#stage"
end
desc "Tell Passenger to restart and restart workers."
task :restart, :roles => :web do
run "touch #deploy_to/current/tmp/restart.txt"
end
desc "Do nothing on startup so we don't get a script/spin error."
task :start do
puts "You may need to restart Apache."
end
desc "Symlink extra configs and folders."
task :symlink_extras do
run "ln -nfs #shared_path/config/database.yml #latest_release/config/database.yml"
run "ln -nfs #shared_path/assets #latest_release/public/assets"
end
desc "Setup shared directory."
task :setup_shared do
run "mkdir #shared_path/assets"
run "mkdir #shared_path/config"
run "mkdir #shared_path/tmp"
run "mkdir #shared_path/db"
put File.read("config/examples/database.yml"), "#shared_path/config/database.yml"
puts "Now edit the config files and fill assets folder in #shared_path."
end
desc "Seed the db with shipping options and a product"
task :seed do
run "cd #current_path; rake db:seed"
end
desc "Make sure there is something to deploy"
task :check_revision, :roles => :web do
unless `git rev-parse HEAD` == `git rev-parse origin/#branch`
puts "WARNING: HEAD is not the same as origin/master"
puts "Run `git push` to sync changes."
exit
end
end
desc "Stop resque Workers."
task :stop_workers, :on_error => :continue do
run "cd #current_path && rake resque:stop_workers RAILS_ENV=#stage"
end
end
before "deploy", "deploy:check_revision"
after "deploy", "deploy:cleanup"
after "deploy:setup", "deploy:setup_shared"
before "deploy:assets:precompile", "deploy:symlink_extras"
after "deploy:update_code", "deploy:stop_workers"
【问题讨论】:
你能给我们看看你的 deploy.rb 吗?否则我们所能做的就是给出一个疯狂的猜测 @fontanus --- 我刚刚按要求添加了我的 deploy.rb。谢谢。 【参考方案1】:我最终解决了这个问题:
在 config/application.rb 中,我不得不注释掉以下行:
config.assets.initialize_on_precompile = true
我曾尝试将 config.assets.initialize_on_precompile 设置为 false 和 true...在这两种情况下,我都收到“应用程序已初始化”错误。
但是,一旦我完全注释掉这行代码,我就可以部署我的应用了。
【讨论】:
我很悲观,但它确实奏效了......知道为什么将其设置为 false 不够好?以上是关于Capistrano - rake assets:precompile - 应用程序已经初始化的主要内容,如果未能解决你的问题,请参考以下文章
Capistrano在部署时失败:资产:使用SSHKit预编译:: Command :: Failed:rake退出状态:1
为啥 rake assets:precompile 需要永远?