簡體   English   中英

Capistrano 3 在資產上失敗:預編譯

[英]Capistrano 3 fails on assets:precompile

我無法部署我的 Rails 4 應用程序,在 assets:precompile 上出現奇怪的錯誤。 似乎任務不能使用已安裝的寶石。 在本地機器上的開發和生產環境中一切正常。 部署日志的一部分:

INFO[286bfe45] Running ~/.rvm/bin/rvm 2.2.0@gemset do bundle install --binstubs /var/www/app/shared/bin --path /var/www/app/shared/bundle --without development test --deployment --quiet on app.com
DEBUG[286bfe45] Command: cd /var/www/app/releases/20150411140229 && ~/.rvm/bin/rvm 2.2.0@gemset do bundle install --binstubs /var/www/app/shared/bin --path /var/www/app/shared/bundle --without development test --deployment --quiet
INFO[286bfe45] Finished in 2.512 seconds with exit status 0 (successful).
DEBUG[6abacc25] Running /usr/bin/env if test ! -d /var/www/app/releases/20150411140229; then echo "Directory does not exist '/var/www/app/releases/20150411140229'" 1>&2; false; fi on app.com
DEBUG[6abacc25] Command: if test ! -d /var/www/app/releases/20150411140229; then echo "Directory does not exist '/var/www/app/releases/20150411140229'" 1>&2; false; fi
DEBUG[6abacc25] Finished in 0.252 seconds with exit status 0 (successful).
INFO[6a11bfd6] Finished in 1.650 seconds with exit status 0 (successful).
DEBUG[9a60b6ea] Running /usr/bin/env if test ! -d /var/www/app/releases/20150411140229; then echo "Directory does not exist '/var/www/app/releases/20150411140229'" 1>&2; false; fi on app.com
DEBUG[9a60b6ea] Command: if test ! -d /var/www/app/releases/20150411140229; then echo "Directory does not exist '/var/www/app/releases/20150411140229'" 1>&2; false; fi
DEBUG[9a60b6ea] Finished in 0.252 seconds with exit status 0 (successful).
INFO[926b14e1] Running ~/.rvm/bin/rvm 2.2.0@gemset do bundle exec rake assets:precompile on app.com
DEBUG[926b14e1] Command: cd /var/www/app/releases/20150411140229 && ( RAILS_ENV=production ~/.rvm/bin/rvm 2.2.0@gemset do bundle exec rake assets:precompile )
DEBUG[926b14e1]         I, [2015-04-11T14:02:51.203678 #18205]  INFO -- : Writing /var/www/app/releases/20150411140229/public/assets/apple-touch-icon-114x114-precomposed-305f00ea8c7d006b84bb4fae81f9560f.png
DEBUG[926b14e1]         I, [2015-04-11T14:02:51.230319 #18205]  INFO -- : Writing /var/www/app/releases/20150411140229/public/assets/projects/project-item-engine-rails-879f2b31347734136f7381f19bb9f6a3.png
DEBUG[926b14e1]         I, [2015-04-11T14:02:51.233698 #18205]  INFO -- : Writing /var/www/app/releases/20150411140229/public/assets/projects/projects-list-header-57d1dcc1cc60e2eb39438cb1845a9aa2.jpg
DEBUG[926b14e1]         I, [2015-04-11T14:02:51.236956 #18205]  INFO -- : Writing /var/www/app/releases/20150411140229/public/assets/rails-31b23f13156504238438fdd89afe6fd6.png
DEBUG[926b14e1]         I, [2015-04-11T14:02:51.237889 #18205]  INFO -- : Writing /var/www/app/releases/20150411140229/public/assets/sprites/blog-color-fd3e21aa29714c4881b34b34b4980ba9.png
DEBUG[926b14e1]         I, [2015-04-11T14:02:51.284081 #18205]  INFO -- : Writing /var/www/app/releases/20150411140229/public/assets/application-659c280b13b0f592813748b6abb50b74.js
DEBUG[926b14e1]         I, [2015-04-11T14:02:51.311349 #18205]  INFO -- : Writing /var/www/app/releases/20150411140229/public/assets/front-9b21c4b4182f885f99929c6f71639a44.js
DEBUG[926b14e1]         rake aborted!
DEBUG[926b14e1]         Sass::SyntaxError: Undefined mixin 'sprites-sprite'.
DEBUG[926b14e1]           (in /var/www/app/releases/20150411140229/app/assets/stylesheets/static.css.scss:96)
DEBUG[926b14e1]         /var/www/app/releases/20150411140229/app/assets/stylesheets/static.css.scss:96:in `sprites-sprite'
DEBUG[926b14e1]         /var/www/app/releases/20150411140229/app/assets/stylesheets/static.css.scss:96
DEBUG[926b14e1]         /var/www/app/shared/bundle/ruby/2.2.0/gems/sass-3.2.19/lib/sass/tree/visitors/perform.rb:253:in `visit_mixin'
DEBUG[926b14e1]         /var/www/app/shared/bundle/ruby/2.2.0/gems/sass-3.2.19/lib/sass/tree/visitors/base.rb:37:in `visit'

我認為問題在於放置寶石。 日志的第一行告訴我 /var/www/app/shared/bundle 中的所有 gems 是真的——它們真的就在那里。 但是,如果我運行rvm 2.2.0@gemset do gem list作為部署用戶,我在列表中看不到已安裝的 gem:

deployer@server:/var/www/app/current$ rvm 2.2.0@gemset do gem list

*** LOCAL GEMS ***

bigdecimal (1.2.6)
bundler (1.8.4)
bundler-unload (1.0.2)
executable-hooks (1.3.2)
gem-wrappers (1.2.7)
io-console (0.4.3)
json (1.8.1)
minitest (5.4.3)
power_assert (0.2.2)
psych (2.0.8)
rake (10.4.2)
rdoc (4.2.0)
rubygems-bundler (1.4.4)
rvm (1.11.3.9)
test-unit (3.0.8)

當我從應用程序的文件夾中運行bundle ,我可以看到已安裝 gem 的完整列表:

deployer@server:/var/www/app/current$ bundle
Using rake 10.4.2
Using sass 3.2.19
Using bootstrap-sass 3.1.1.1
Using compass 0.12.7
Using breakpoint 2.0.7
Using compass-rails 2.0.0
Using sprockets 2.11.0
Using sprockets-rails 2.2.2
/* removed some lines to save space */
Using rails 4.1.8
Using sass-rails 4.0.3
Using uglifier 2.5.0
Using unicorn 4.8.3
Bundle complete! 39 Gemfile dependencies, 87 gems now installed.
Gems in the groups development and test were not installed.
Bundled gems are installed into /var/www/app/shared/bundle.

我在單用戶模式下使用 rvm 進行開發和生產,我的一些文件在這里:

# deploy.rb
lock '3.2.1'

set :application, 'App'
set :repo_url, 'git@bitbucket.org:app/app.com.git'
set :deploy_to, '/var/www/app'

set :rvm_ruby_version, '2.2.0@gemset'
set :unicorn_env, 'production'
set :rails_env, :production
set :linked_files, %w{config/database.yml config/secrets.yml config/scp.yml}

set :linked_dirs, %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system}
namespace :deploy do

    desc 'Restart application'
    task :restart do
        invoke 'unicorn:restart'
    end

    after :restart, :clear_cache do
        on roles(:web), in: :groups, limit: 3, wait: 10 do
        end
    end

after :publishing, :restart
end

文件

# Capfile
require 'capistrano/setup'
require 'capistrano/deploy'
require 'capistrano3/unicorn'
require 'whenever/capistrano'
require 'capistrano/rvm'
require 'capistrano/bundler'
require 'capistrano/rails'

Dir.glob('lib/capistrano/tasks/*.rake').each { |r| import r }

Front.css.scss 在 application.rb 中設置為預編譯

# front.css.scss
@import "compass";
@import "compass/utilities/sprites";
@import "sprites/*.png";
@include all-sprites-sprites;
@import "breakpoint";
$breakpoint-tiny : 0 660px;

@import "static";

例如 static.css.scss:

/* static.css.scss */
.blog {
    @include sprites-sprite(blog-gray);
    &:hover {
        @include sprites-sprite(blog-color);
    }
}

如果我從 static.css.scss 中刪除所有 mixins,部署將成功完成。

我解決了這個問題,它與 capistrano 甚至 rvm 無關。 我為我的應用程序使用了兩種布局:front.html.slim 和 admin.html.slim,每個布局都有一個專用的樣式表: front.cssadmin.css

front.css.scss我使用了以下(sass)語法:

@import "compass";
@import "compass/utilities/sprites";

雖然admin.css.scss使用了 Sprocket 的語法:

/*
 *= require base
 *= require posts
 *= require projects

admin.css.scss更改為實際 sass 語法后, assets:precompile任務成功完成:

 @import "base";
 @import "posts";
 @import "projects";

感謝@RAJ 的建議。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM