资产预编译与厨师食谱的问题

时间:2014-12-03 09:33:01

标签: ruby-on-rails chef assets chef-recipe cookbook

我遇到通过大厨食谱预编译的资产问题。

我的食谱块包含

execute "rake assets:precompile" do   
cwd current_release_directory    
command "bundle exec rake assets:precompile  --trace"    
environment "RAILS_ENV" => "production"    
end

和database.yml文件包含,

production:    
  adapter: mysql2    
  encoding: utf8    
  reconnect: true    
  database: <%= ENV['production_db'] %>     
  pool: 25     
  username: <%= ENV['production_username'] %>    
  password: <%= ENV['production_password'] %>    
  socket: /var/run/mysqld/mysqld.sock    
  host: <%= ENV['production_host'] %>       

当我运行食谱时,我收到以下错误。

  Compiled Resource:    
  ------------------    
  # Declared in /var/chef/cache/cookbooks/env_setup/recipes/default.rb:255:in `from_file'     

  execute("rake assets:precompile") do     
    action "run"    
    retries 0     
    retry_delay 2    
    guard_interpreter :default     
    command "bundle exec rake assets:precompile  --trace"    
    backup 5    
    cwd "/home/ubuntu/apps/new_spree_st/current"    
    environment {"RAILS_ENV"=>"production"}    
    returns 0    
    cookbook_name "env_setup"    
    recipe_name "default"    
  end    


Running handlers:    
[2014-12-03T18:38:04+05:30] ERROR: Running exception handlers    
Running handlers complete    
[2014-12-03T18:38:04+05:30] ERROR: Exception handlers complete    
[2014-12-03T18:38:04+05:30] FATAL: Stacktrace dumped to /var/chef/cache/chef-stacktrace.out    
Chef Client failed. 16 resources updated in 139.571723545 seconds    
[2014-12-03T18:38:04+05:30] ERROR: execute[rake assets:precompile] (env_setup::default line     255) had an error: Mixlib::ShellOut::ShellCommandFailed: Expected process to exit with [0], but received '1'    
---- Begin output of bundle exec rake assets:precompile  --trace ----    
STDOUT: Your Gemfile lists the gem hiredis (~> 0.4.5) more than once.    
You should probably keep only one of them.    
While it's not a problem now, it could cause errors if you change the version of just one of them later.    
STDERR: ** Invoke assets:precompile (first_time)    
** Execute assets:precompile    
/opt/chef/embedded/bin/ruby /usr/local/rvm/gems/ruby-2.0.0-p481/bundle/ruby/1.9.1/bin/rake   assets:precompile:all RAILS_ENV=production RAILS_GROUPS=assets --trace    
** Invoke assets:precompile:all (first_time)    
** Invoke assets:cache:clean (first_time)    
** Invoke assets:environment (first_time)    
** Execute assets:environment    
** Invoke environment (first_time)    
** Execute environment    
rake aborted!    
Psych::SyntaxError: (<unknown>): could not find expected ':' while scanning a simple key at line 11 column 3    

可能是什么问题?

2 个答案:

答案 0 :(得分:1)

您必须添加到环境production_usernameproduction_passwordproduction_host,因为当您运行bundle exec rake命令时,database.yml会填充您环境中的值。

基本上你得到了这个错误,因为你的database.yml对于那些值是空的。

答案 1 :(得分:0)

一个简单的解决方法是向您的database.yml

添加回退
<%= ENV['production_db'] || '""' %>