0

I set up a t1.micro instance on AWS. I was able to successfully run: RAILS_ENV=staging rubber:create_staging to create the server, deploy the code, and run the app. I made some changes to the code and want to deploy to my staging server but when I run this command: RAILS_ENV=staging cap deploy I get the following error:

 * executing "cd -- /mnt/domain-staging/releases/20130321005928 && bundle exec rake RAILS_ENV=staging RAILS_GROUPS=assets assets:precompile && cp -- /mnt/domain-staging/shared/assets/manifest.yml /mnt/domain-staging/releases/20130321005928/assets_manifest.yml"
    servers: ["staging.domain.com"]
    [staging.domain.com] executing command
 * [out :: staging.domain.com] /usr/local/rubies/1.9.3-p385/bin/ruby /mnt/domain-staging/shared/bundle/ruby/1.9.1/bin/rake assets:precompile:nondigest RAILS_ENV=staging RAILS_GROUPS=assets
 * [out :: staging.domain.com]
 * [out :: staging.domain.com] rake aborted!
 * [out :: staging.domain.com] Command failed with status (): [/usr/local/rubies/1.9.3-p385/bin/ruby /mnt...]
 * [out :: staging.domain.com] /mnt/domain-staging/shared/bundle/ruby/1.9.1/gems/actionpack-3.1.3/lib/sprockets/assets.rake:9:in `ruby_rake_task'
 * [out :: staging.domain.com] /mnt/domain-staging/shared/bundle/ruby/1.9.1/gems/actionpack-3.1.3/lib/sprockets/assets.rake:62:in `block (3 levels) in <top (required)>'
 * [out :: staging.domain.com] /mnt/domain-staging/shared/bundle/ruby/1.9.1/gems/actionpack-3.1.3/lib/sprockets/assets.rake:19:in `invoke_or_reboot_rake_task'
 * [out :: staging.domain.com] /mnt/domain-staging/shared/bundle/ruby/1.9.1/gems/actionpack-3.1.3/lib/sprockets/assets.rake:25:in `block (2 levels) in <top (required)>'
 * [out :: staging.domain.com] Tasks: TOP => assets:precompile:all
 * [out :: staging.domain.com] (See full trace by running task with --trace)
    command finished in 223523ms
failed: "/bin/bash -l -c 'cd -- /mnt/domain-staging/releases/20130321005928 && bundle exec rake RAILS_ENV=staging RAILS_GROUPS=assets assets:precompile && cp -- /mnt/domain-staging/shared/assets/manifest.yml /mnt/domain-staging/releases/20130321005928/assets_manifest.yml'" on staging.domain.com

I haven't changed any of the default capistrano recipes and it the code was successfully deployed 1 time. I've been able to run "cap deploy" for my production site but not the staging site. I haven't been able to find anything in the Google group, any help would be appreciated.

K M Rakibul Islam
  • 33,760
  • 12
  • 89
  • 110
Kevin Bende
  • 157
  • 2
  • 9

2 Answers2

2

You need to adapt your application.rb to include this:

if defined?(Bundler)
  Bundler.require(*Rails.groups(:assets => %w(development test), :profiling => %w[staging development]))
end
Benjamin Bouchet
  • 12,971
  • 2
  • 41
  • 73
  • I added the code to my application.rb file and the first deploy was successful. Then I updated a js file and deployed to make sure it compiled successfully and updated assets correctly and it worked. But then the 3rd time I tried, it failed on the same error. Then I tried again and it deployed successfully. I wonder if it is taking too long to compile my assets on the t1.micro instance and it times out sometimes. I don't have too many images, styles or js code in there. It's a relatively new basic app. – Kevin Bende Mar 21 '13 at 18:24
  • So my solution worked cause you can compile your staging environment now. If you have another problem (compilation failing **sometimes**) you need to trip down this new problem and ask a new question – Benjamin Bouchet Mar 22 '13 at 02:50
2

This happens due to the high memory consumption while running "assets:precompile". Try to reboot your EC2 instance and run the deploy again, it will probably work. You can also change the instance type in order to enhance the memory of your instance and avoid this kinda issue.

Tiago G.
  • 119
  • 2
  • 3
  • Reboot solved my problem when assets:precompile barfed with the error "Cannot allocate memory" when attempting the touch of all asset files. Thanks! – naudster Jul 03 '13 at 05:28