Chef with rails: handling asset precompilation during deployment
If you are using rails with Sprockets and Opscode Chef, how do you handle pre-compiling resources during deployment? I want to keep my git history clean, so I don't want them to pre-hop them locally and then push them to the repository.
The easiest way is to add them to the application cookie migration command, but that seems frustrating to me. Asset pre-compilation should be separate from data migration. Any other suggestions on how to handle this?
source to share
If you are using the deploy_revision resource, you can use the rake task to precompile the asset into a block before_restart
.
Here is the code snippet that is in my deploy_revision resource. Since I am using RVM I have installed Fletcher Nichol awesome RVM cookbook on awesomeness. You can replace this with a resource ruby-block
.
Check out a more complete example in my sense .
app = node[:rails][:app_name]
before_restart do
rvm_shell "assets precompile" do
ruby_string "#{app[:ruby_ver]}@#{app[:gemset]}"
cwd release_path
user app[:deploy_user]
group app[:deploy_user]
# TODO I could not set the environment via the builtin command. Does not look like it is getting passed to popen4
# So instead of `environment "RAILS_ENV" => app[:environment]` I have it in the code block
code %{
export RAILS_ENV=#{app[:environment]}
bundle exec rake assets:precompile
}
end
end
source to share