【问题标题】:RAILS_ENV=staging cap deploy fails on rake precompile assetsRAILS_ENV=staging cap deploy 在 rake 预编译资产上失败
【发布时间】:2013-03-10 09:41:03
【问题描述】:

我在 AWS 上设置了一个 t1.micro 实例。我能够成功运行: RAILS_ENV=staging rubber:create_staging 创建服务器、部署代码和运行应用程序。我对代码进行了一些更改,并希望部署到我的登台服务器,但是当我运行此命令时: RAILS_ENV=staging cap deploy 我收到以下错误:

 * 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

我没有更改任何默认的 capistrano 配方,并且代码已成功部署 1 次。我已经能够为我的生产站点而不是暂存站点运行“cap deploy”。我无法在 Google 群组中找到任何内容,我们将不胜感激。

【问题讨论】:

    标签: ruby-on-rails deployment amazon-ec2 capistrano rubber


    【解决方案1】:

    您需要调整您的 application.rb 以包含以下内容:

    if defined?(Bundler)
      Bundler.require(*Rails.groups(:assets => %w(development test), :profiling => %w[staging development]))
    end
    

    【讨论】:

    • 我将代码添加到我的 application.rb 文件中,第一次部署成功。然后我更新了一个 js 文件并进行了部署,以确保它编译成功并正确更新了资产并且它工作正常。但后来我第三次尝试,同样的错误失败了。然后我再次尝试并成功部署。我想知道在 t1.micro 实例上编译我的资产是否花费了太长时间,并且有时会超时。我那里没有太多的图像、样式或 js 代码。这是一个相对较新的基本应用程序。
    • 所以我的解决方案有效,因为您现在可以编译您的暂存环境。如果您还有其他问题(编译失败有时),您需要解决这个新问题并提出一个新问题
    【解决方案2】:

    这是由于运行“assets:precompile”时内存消耗量大。尝试重新启动您的 EC2 实例并再次运行部署,它可能会工作。您还可以更改实例类型以增强实例的内存并避免此类问题。

    【讨论】:

    • 当 assets:precompile 在尝试触摸所有资产文件时出现错误“无法分配内存”时,重新启动解决了我的问题。谢谢!
    猜你喜欢
    • 2013-03-15
    • 1970-01-01
    • 1970-01-01
    • 2014-06-29
    • 2016-03-31
    • 1970-01-01
    • 1970-01-01
    • 2015-08-12
    • 1970-01-01
    相关资源
    最近更新 更多