我对Chef部署很陌生,我尝试使用OpsWorks部署rails应用程序。麻烦在于资产预编译。
我有这个配方来执行预编译:
execute "rake assets:precompile" do
cwd release_path
command "bundle exec rake assets:precompile --trace"
environment "RAILS_ENV" => "production"
end
当我使用Chef部署时,出现以下错误:
ERROR: undefined method `release_path' for Chef::Resource::Execute
奇怪的是,我能找到的每个示例配方都使用release_path
帮助器。怎么可能不在这里定义?
答案 0 :(得分:0)
以下是我在opsworks上的rails应用程序上进行预编译的方法:
此代码放在您的应用程序部署文件夹中,名为" before_migrate.rb"在/approot/deploy/before_migrate.rb。
环境变量是在opsworks中定义的应用程序中创建的。
rails_env = new_resource.environment["RAILS_ENV"]
secret_key_base = new_resource.environment["SECRET_KEY_BASE"]
devise_secret_key = new_resource.environment["DEVISE_SECRET_KEY"]
Chef::Log.info("Precompiling assets for RAILS_ENV=#{rails_env}...")
Chef::Log.info("SECRET_KEY_BASE=#{secret_key_base}, DEVISE_SECRET_KEY=#{devise_secret_key}")
execute "rake assets:precompile" do
cwd release_path
command "RAILS_ENV=#{rails_env} bundle exec rake assets:precompile"
environment "RAILS_ENV" => rails_env
environment "SECRET_KEY_BASE" => secret_key_base
environment "DEVISE_SECRET_KEY" => devise_secret_key
end
答案 1 :(得分:0)
我使用node[:deploy]['appshortname'][:deploy_to]
修正了此问题。我的完整食谱如下:
node[:deploy].each do |application, deploy|
execute "rake assets:precompile" do
cwd "#{deploy[:deploy_to]}/current"
command "bundle exec rake assets:precompile --trace"
environment deploy[:environment_variables].merge(
"RAILS_ENV" => deploy[:rails_env]
)
end
end