1

我正在尝试使用 Capistrano 部署我的 Rails 应用程序,但生成的 application.css 样式表为空。这发生在我的登台和生产环境中。以下内容与我的分期有关。

这是使用 Rails 3.1.1、Ruby 2.0.0p0 和 Capistrano 2.14.1

我将尝试提供尽可能多的细节(尽管如果细节过多,我很抱歉)。

日志

运行部署时,将以下内容添加到 `staging.log':

Compiled application.js  (0ms)  (pid 15434)
Compiled application.css  (0ms)  (pid 15434)
Compiled application.js  (1ms)  (pid 15428)
Compiled application.css  (0ms)  (pid 15428)

我不确定重复输入是否是一个线索?

以下是我运行时输出的一部分cap staging deploy

    command finished in 730ms
    triggering after callbacks for `deploy:update_code'
  * 2013-04-28 14:04:10 executing `deploy:assets:precompile'
    triggering before callbacks for `deploy:assets:precompile'
  * 2013-04-28 14:04:10 executing `deploy:assets:update_asset_mtimes'
  * executing "[ -e /home/somedomain.co.uk/staging/mkn/shared/assets/manifest.yml ] && cat /home/somedomain.co.uk/staging/mkn/shared/assets/manifest.yml || echo"
    servers: ["homer.somedomain.co.uk"]
    [homer.somedomain.co.uk] executing command
    command finished in 614ms
 ** Updating mtimes for ~20 assets...
    servers: ["homer.somedomain.co.uk"]
 ** sftp upload #<StringIO:0x007f945d8d6a28> -> /home/somedomain.co.uk/staging/mkn//TOUCH_ASSETS
    [homer.somedomain.co.uk] /home/somedomain.co.uk/staging/mkn//TOUCH_ASSETS
    [homer.somedomain.co.uk] done
  * sftp upload complete
  * executing "cat /home/somedomain.co.uk/staging/mkn//TOUCH_ASSETS | while read asset; do touch -cm -- \"$asset\"; done && rm -f -- /home/somedomain.co.uk/staging/mkn//TOUCH_ASSETS"
    servers: ["homer.somedomain.co.uk"]
    [homer.somedomain.co.uk] executing command
    command finished in 812ms
  * executing "ls -x /home/somedomain.co.uk/staging/mkn/releases"
    servers: ["homer.somedomain.co.uk"]
    [homer.somedomain.co.uk] executing command
    command finished in 438ms
  * executing "cd -- /home/somedomain.co.uk/staging/mkn/releases/20130428130343 && bundle exec rake RAILS_ENV=staging RAILS_GROUPS=assets assets:precompile && cp -- /home/somedomain.co.uk/staging/mkn/shared/assets/manifest.yml /home/somedomain.co.uk/staging/mkn/releases/20130428130343/assets_manifest.yml"
    servers: ["homer.somedomain.co.uk"]
    [homer.somedomain.co.uk] executing command
 ** [out :: homer.somedomain.co.uk] /home/greggannicott/.rvm/gems/ruby-2.0.0-p0/gems/bundler-1.3.5/lib/bundler/runtime.rb:216: warning: Insecure world writable dir /home/somedomain.co.uk/staging/mkn/shared in PATH, mode 040777
 ** [out :: homer.somedomain.co.uk] /home/greggannicott/.rvm/rubies/ruby-2.0.0-p0/bin/ruby /home/somedomain.co.uk/staging/mkn/shared/bundle/ruby/2.0.0/bin/rake assets:precompile:nondigest RAILS_ENV=staging RAILS_GROUPS=assets
 ** [out :: homer.somedomain.co.uk] /home/greggannicott/.rvm/gems/ruby-2.0.0-p0/gems/bundler-1.3.5/lib/bundler/runtime.rb:216: warning: Insecure world writable dir /home/somedomain.co.uk/staging/mkn/shared in PATH, mode 040777
    command finished in 13990ms
  * 2013-04-28 14:04:26 executing `deploy:create_symlink'
  * executing "rm -f /home/somedomain.co.uk/staging/mkn/current && ln -s /home/somedomain.co.uk/staging/mkn/releases/20130428130343 /home/somedomain.co.uk/staging/mkn/current"
    servers: ["homer.somedomain.co.uk"]
    [homer.somedomain.co.uk] executing command
    command finished in 581ms
 ** transaction: commit
  * 2013-04-28 14:04:26 executing `deploy:restart'
  * executing "touch /home/somedomain.co.uk/staging/mkn/current/tmp/restart.txt"
    servers: ["homer.somedomain.co.uk"]
    [homer.somedomain.co.uk] executing command
    command finished in 427ms

配置文件

我的Capfile

load 'deploy'
# Uncomment if you are using Rails' asset pipeline
load 'deploy/assets'
Dir['vendor/gems/*/recipes/*.rb','vendor/plugins/*/recipes/*.rb'].each { |plugin| load(plugin) }
load 'config/deploy' # remove this line to skip loading any of the default tasks

我的config/application.rb

require File.expand_path('../boot', __FILE__)

require 'rails/all'

if defined?(Bundler)
  # If you precompile assets before deploying to production, use this line
  #Bundler.require(*Rails.groups(:assets => %w(development test)))
  # If you want your assets lazily compiled in production, use this line
  # Bundler.require(:default, :assets, Rails.env)
end

module Nuggets
  class Application < Rails::Application
    # Settings in config/environments/* take precedence over those specified here.
    # Application configuration should go into files in config/initializers
    # -- all .rb files in that directory are automatically loaded.

    # Custom directories with classes and modules you want to be autoloadable.
    # config.autoload_paths += %W(#{config.root}/extras)

    # Only load the plugins named here, in the order given (default is alphabetical).
    # :all can be used as a placeholder for all plugins not explicitly named.
    # config.plugins = [ :exception_notification, :ssl_requirement, :all ]

    # Activate observers that should always be running.
    # config.active_record.observers = :cacher, :garbage_collector, :forum_observer

    # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
    # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
    # config.time_zone = 'Central Time (US & Canada)'

    # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
    # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
    # config.i18n.default_locale = :de

    # Configure the default encoding used in templates for Ruby 1.9.
    config.encoding = "utf-8"

    # Configure sensitive parameters which will be filtered from the log file.
    config.filter_parameters += [:password]

    # Enable the asset pipeline
    config.assets.enabled = true

    # Version of your assets, change this if you want to expire all your assets
    config.assets.version = '1.2'

    config.generators do |g|
      g.test_framework :rspec,
        :fixtures => true,
        :view_specs => false,
        :helper_specs => false,
        :routing_specs => false,
        :controller_specs => true,
        :request_specs => true
      g.fixture_replacement :factory_girl, :dir => "spec/factories"
    end
  end
end

我的config/environments/staging.rb

Nuggets::Application.configure do
  # Settings specified here will take precedence over those in config/application.rb

  # Code is not reloaded between requests
  config.cache_classes = true

  # Full error reports are disabled and caching is turned on
  config.consider_all_requests_local       = false
  config.action_controller.perform_caching = true

  # Disable Rails's static asset server (Apache or nginx will already do this)
  config.serve_static_assets = false

  # Compress JavaScripts and CSS
  config.assets.compress = true

  # Don't fallback to assets pipeline if a precompiled asset is missed
  config.assets.compile = false

  # Generate digests for assets URLs
  config.assets.digest = true

  # Defaults to Rails.root.join("public/assets")
  # config.assets.manifest = YOUR_PATH

  # Specifies the header that your server uses for sending files
  # config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache
  # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx

  # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
  # config.force_ssl = true

  # See everything in the log (default is :info)
  config.log_level = :debug

  # Use a different logger for distributed setups
  # config.logger = SyslogLogger.new

  # Use a different cache store in production
  # config.cache_store = :mem_cache_store

  # Enable serving of images, stylesheets, and JavaScripts from an asset server
  # config.action_controller.asset_host = "http://assets.example.com"

  # Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added)
  # config.assets.precompile += %w( search.js )

  # Disable delivery errors, bad email addresses will be ignored
  # config.action_mailer.raise_delivery_errors = false

  # Enable threaded mode
  # config.threadsafe!

  # Enable locale fallbacks for I18n (makes lookups for any locale fall back to
  # the I18n.default_locale when a translation can not be found)
  config.i18n.fallbacks = true

  # Send deprecation notices to registered listeners
  config.active_support.deprecation = :notify

  # Show full error reports in the browser
  config.consider_all_requests_local       = true

end

我的config/deploy.rb

require "rvm/capistrano"
require 'bundler/capistrano'
# Based on: http://guides.beanstalkapp.com/deployments/deploy-with-capistrano.html
set :application, "nuggets"
set :normalize_asset_timestamps, false

set :scm, :git
set :repository, "ssh://greggannicott@homer.somedomain.co.uk/home/git/nuggets.git"
set :scm_passphrase, "*******"
ssh_options[:forward_agent] = true

set :user, "greggannicott"

set :stages, %w{staging production}
set :default_stage, "staging"
require 'capistrano/ext/multistage'

# The following needs to be added to avoid a failure (http://discuss.joyent.com/viewtopic.php?id=27326)
default_run_options[:pty] = true

namespace :deploy do
  desc "Tell Passenger to restart the app."
  task :restart do
    run "touch #{current_path}/tmp/restart.txt"
  end
end

set :bundle_flags,    ""

我的Gemfile

source 'http://rubygems.org'

gem 'rails', '3.1.1'
gem 'therubyracer', :platforms => :ruby # I believe this is required to run on Ubuntu due to a lack of a Javascript runtime env..
gem 'rdiscount'
gem 'bcrypt-ruby'
gem 'will_paginate'
gem 'faker'
gem 'capistrano'
gem 'rvm-capistrano'
gem 'sqlite3'

# Bundle edge Rails instead:
# gem 'rails',     :git => 'git://github.com/rails/rails.git'


# Gems used only for assets and not required
# in production environments by default.
group :assets do
  gem 'sass-rails',   '~> 3.1.4'
  gem 'coffee-rails', '~> 3.1.1'
  gem 'uglifier', '>= 1.0.3'
end

gem 'jquery-rails'

group :development do
  gem 'better_errors'
  gem 'binding_of_caller'
  gem 'meta_request'
  gem 'rspec-rails'
  gem 'guard-rspec'
  gem 'guard-spork'
  gem 'spork'
end

# To use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0'

# Use unicorn as the web server
# gem 'unicorn'

# Deploy with Capistrano
# gem 'capistrano'

# To use debugger
# gem 'ruby-debug19', :require => 'ruby-debug'

group :test do
  # Pretty printed test output
  gem 'turn', :require => false
  gem 'rspec-rails'
  gem 'factory_girl_rails'
  gem 'capybara'
  gem 'guard-rspec'
  gem 'rb-fsevent', :require => false
  gem 'growl'
end

我的app/assets/stylesheets目录列表:

-rw-rw-r--  1 greggannicott  staff    350 27 Jan 13:28 application.css
-rw-rw-r--  1 greggannicott  staff  13622 27 Apr 23:35 global.css.scss
-rw-rw-r--  1 greggannicott  staff  33211 27 Jan 13:28 jquery-ui-1.8.17.custom.css
-rw-rw-r--  1 greggannicott  staff   2208 27 Jan 13:28 media-queries.css
-rw-rw-r--  1 greggannicott  staff    178 27 Jan 13:28 nuggets.css.scss
-rw-rw-r--  1 greggannicott  staff    176 27 Jan 13:28 pages.css.scss
-rw-rw-r--  1 greggannicott  staff    179 27 Jan 13:28 sessions.css.scss
-rw-rw-r--  1 greggannicott  staff    179 27 Jan 13:28 settings.css.scss
-rw-rw-r--  1 greggannicott  staff    175 27 Jan 13:28 tags.css.scss
-rw-rw-r--  1 greggannicott  staff    176 27 Jan 13:28 users.css.scss

最后,我的app/assets/stylesheets/application.css

/*
 * This is a manifest file that'll automatically include all the stylesheets available in this directory
 * and any sub-directories. You're free to add application-wide styles to this file and they'll appear at
 * the top of the compiled file, but it's generally better to create a new file per style scope.
 *= require_self
 *= require_tree .
*/
4

1 回答 1

3

我找到了答案(至少在高水平上)。

它似乎与 Ruby 2.0 有关。

当我在服务器上设置 RVM 以使用 Ruby 1.9.3 并进行另一次部署时,它起作用了**。

我是 RVM 的新手,所以我所做的可能有点矫枉过正:

rvm install 1.9.3
rvm use 1.9.3
rvm --default 1.9.3

** 我还在config/application.rb. 我之前曾将其注释掉,作为我尝试使其工作的一部分:

Bundler.require(*Rails.groups(:assets => %w(development test)))
于 2013-04-28T17:27:20.107 回答