A
A
Anton Misyagin2015-08-20 13:19:19
Nginx
Anton Misyagin, 2015-08-20 13:19:19

How to get rid of the assets:precompile error during deployment?

First time trying to deploy an application on my home server ubuntu server 14 installed in VirtualBox. Capistrano started palpating for the first time yesterday. Something even happened). But nevertheless, the deployment does not work. I take a pure rails application (on the local computer, rails s starts and shows welcome). I'm trying to deploy it. I see an assets:precompile error. In general, is it possible to disable it, is it needed, can it be done on a local computer, where you can read more about it about this asset: precompile. It also gives an error on the working project (I don’t remember which one), so I decided to take a clean project first, and then torment the working one. I'm posting the configs:

gemfile:

source 'https://rubygems.org'


gem 'rails', '4.2.1'
gem 'sass-rails', '~> 5.0'

group :development do
  gem 'sqlite3'
  gem 'capistrano', '~> 3.4.0'
  gem 'capistrano-rvm', '~> 0.1.1'
  gem 'capistrano-bundler', '~> 1.1.3'
  gem 'capistrano-rails', '~> 1.1.2'
end

group :production do
  gem 'pg', '0.15.1'
  gem 'passenger'
  gem 'rack', '~> 1.6.1'
end

gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]

capfile:

require 'capistrano/setup'
require 'capistrano/deploy'
require 'capistrano/rvm'
require 'capistrano/bundler'
require 'capistrano/rails'
Dir.glob('lib/capistrano/tasks/*.rb').each { |r| import r }

config/deploy.rb

lock '3.4.0'

set :application, 'myapp'
set :deploy_to, "/var/www/#{fetch(:application)}"

set :scm, :git
set :repo_url, 'ssh://[email protected]/var/www/myapp.git'
set :deploy_via, :remote_cache
set :branch, 'master'
set :rails_env, 'production'
set :rvm_custom_path, '/usr/share/rvm'
set :linked_files, %w{config/secrets.yml config/database.yml}
set :linked_dirs, %w{public/upload}

set :format, :pretty

set :pty, false

set :log_level, :info

set :rvm_ruby_string, :local        # use the same ruby as used locally for deployment

namespace :deploy do
  after :finishing, 'nginx:restart'
  after :finishing, :cleanup
end

config/deploy/production.rb

server '192.168.1.106', user: 'deployer', roles: %w{web app}

lib/capistrano/tasks/nginx.rb

namespace :nginx do
  
  desc 'Создание симлинка в /etc/nginx/conf.d на nginx.conf приложения'
  task :append_config do
    on roles :all do
      sudo :ln, "-fs #{shared_path}/config/nginx.conf /etc/nginx/conf.d/#{fetch(:application)}.conf"
    end
  end
  
  desc 'Релоад nginx'
  task :reload do
    on roles :all do
      sudo :service, :nginx, :reload
    end
  end
  
  desc 'Рестарт nginx'
  task :restart do
    on roles :all do
      sudo :service, :nginx, :restart
    end
  end
  
  after :append_config, :restart
  
end

lib/capistrano/tasks/setup.rb

namespace :setup do
  
  desc 'Загрузка конфигурационных файлов на удаленный сервер'
  task :upload_config do
    on roles :all do
      execute :mkdir, "-p #{shared_path}"
      ['shared/config'].each do |f|
        upload!(f, shared_path, recursive: true)
      end
    end
  end
  
  after :upload_config, 'nginx:append_config'
  
end

cap production deploy output:

......
/var/www/myapp/shared/bundle --without development test --deployment --quiet
 as [email protected]
INFO [bc0b956a] Finished in 15.350 seconds with exit status 0 (successful).
INFO [dd83e0ad] Running /usr/share/rvm/bin/rvm default do bundle exec rake asset
s:precompile as [email protected]
(Backtrace restricted to imported tasks)
cap aborted!

The error itself:
SSHKit::Runner::ExecuteError: Exception while executing as [email protected]
6: rake exit status: 1
rake stdout: Nothing written
rake stderr: rake aborted!
LoadError: cannot load such file -- nokogiri
/var/www/myapp/shared/bundle/ruby/2.1.0/gems/loofah-2.0.3/lib/loofah.rb:3:in
 `require'
/var/www/myapp/shared/bundle/ruby/2.1.0/gems/loofah-2.0.3/lib/loofah.rb:3:in
 `<top (required)>'
/var/www/myapp/shared/bundle/ruby/2.1.0/gems/rails-html-sanitizer-1.0.2/lib/
rails-html-sanitizer.rb:2:in `require'
/var/www/myapp/shared/bundle/ruby/2.1.0/gems/rails-html-sanitizer-1.0.2/lib/
rails-html-sanitizer.rb:2:in `<top (required)>'
/var/www/myapp/shared/bundle/ruby/2.1.0/gems/actionview-4.2.1/lib/action_vie
w/helpers/sanitize_helper.rb:3:in `require'
/var/www/myapp/shared/bundle/ruby/2.1.0/gems/actionview-4.2.1/lib/action_vie
w/helpers/sanitize_helper.rb:3:in `<top (required)>'
/var/www/myapp/shared/bundle/ruby/2.1.0/gems/actionview-4.2.1/lib/action_vie
w/helpers/text_helper.rb:32:in `<module:TextHelper>'
/var/www/myapp/shared/bundle/ruby/2.1.0/gems/actionview-4.2.1/lib/action_vie
w/helpers/text_helper.rb:29:in `<module:Helpers>'
/var/www/myapp/shared/bundle/ruby/2.1.0/gems/actionview-4.2.1/lib/action_vie
w/helpers/text_helper.rb:6:in `<module:ActionView>'
/var/www/myapp/shared/bundle/ruby/2.1.0/gems/actionview-4.2.1/lib/action_vie
w/helpers/text_helper.rb:4:in `<top (required)>'
/var/www/myapp/shared/bundle/ruby/2.1.0/gems/actionview-4.2.1/lib/action_vie
w/helpers/form_tag_helper.rb:18:in `<module:FormTagHelper>'
/var/www/myapp/shared/bundle/ruby/2.1.0/gems/actionview-4.2.1/lib/action_vie
w/helpers/form_tag_helper.rb:14:in `<module:Helpers>'
/var/www/myapp/shared/bundle/ruby/2.1.0/gems/actionview-4.2.1/lib/action_vie
w/helpers/form_tag_helper.rb:8:in `<module:ActionView>'
/var/www/myapp/shared/bundle/ruby/2.1.0/gems/actionview-4.2.1/lib/action_vie
w/helpers/form_tag_helper.rb:6:in `<top (required)>'
/var/www/myapp/shared/bundle/ruby/2.1.0/gems/actionview-4.2.1/lib/action_vie
w/helpers/form_helper.rb:4:in `require'
/var/www/myapp/shared/bundle/ruby/2.1.0/gems/actionview-4.2.1/lib/action_vie
w/helpers/form_helper.rb:4:in `<top (required)>'
/var/www/myapp/shared/bundle/ruby/2.1.0/gems/actionview-4.2.1/lib/action_vie
w/helpers.rb:50:in `<module:Helpers>'
/var/www/myapp/shared/bundle/ruby/2.1.0/gems/actionview-4.2.1/lib/action_vie
w/helpers.rb:4:in `<module:ActionView>'
/var/www/myapp/shared/bundle/ruby/2.1.0/gems/actionview-4.2.1/lib/action_vie
w/helpers.rb:3:in `<top (required)>'
/var/www/myapp/shared/bundle/ruby/2.1.0/gems/sprockets-rails-2.3.2/lib/sproc
kets/rails/legacy_asset_tag_helper.rb:7:in `<module:LegacyAssetTagHelper>'
/var/www/myapp/shared/bundle/ruby/2.1.0/gems/sprockets-rails-2.3.2/lib/sproc
kets/rails/legacy_asset_tag_helper.rb:6:in `<module:Rails>'
/var/www/myapp/shared/bundle/ruby/2.1.0/gems/sprockets-rails-2.3.2/lib/sproc
kets/rails/legacy_asset_tag_helper.rb:4:in `<module:Sprockets>'
/var/www/myapp/shared/bundle/ruby/2.1.0/gems/sprockets-rails-2.3.2/lib/sproc
kets/rails/legacy_asset_tag_helper.rb:3:in `<top (required)>'
/var/www/myapp/shared/bundle/ruby/2.1.0/gems/sprockets-rails-2.3.2/lib/sproc
kets/rails/helper.rb:45:in `require'
/var/www/myapp/shared/bundle/ruby/2.1.0/gems/sprockets-rails-2.3.2/lib/sproc
kets/rails/helper.rb:45:in `<module:Helper>'
/var/www/myapp/shared/bundle/ruby/2.1.0/gems/sprockets-rails-2.3.2/lib/sproc
kets/rails/helper.rb:7:in `<module:Rails>'
/var/www/myapp/shared/bundle/ruby/2.1.0/gems/sprockets-rails-2.3.2/lib/sproc
kets/rails/helper.rb:6:in `<module:Sprockets>'
/var/www/myapp/shared/bundle/ruby/2.1.0/gems/sprockets-rails-2.3.2/lib/sproc
kets/rails/helper.rb:5:in `<top (required)>'
/var/www/myapp/shared/bundle/ruby/2.1.0/gems/sprockets-rails-2.3.2/lib/sproc
kets/railtie.rb:6:in `require'
/var/www/myapp/shared/bundle/ruby/2.1.0/gems/sprockets-rails-2.3.2/lib/sproc
kets/railtie.rb:6:in `<top (required)>'
/var/www/myapp/shared/bundle/ruby/2.1.0/gems/sass-rails-5.0.3/lib/sass/rails
/railtie.rb:3:in `require'
/var/www/myapp/shared/bundle/ruby/2.1.0/gems/sass-rails-5.0.3/lib/sass/rails
/railtie.rb:3:in `<top (required)>'
/var/www/myapp/shared/bundle/ruby/2.1.0/gems/sass-rails-5.0.3/lib/sass/rails
.rb:11:in `require'
/var/www/myapp/shared/bundle/ruby/2.1.0/gems/sass-rails-5.0.3/lib/sass/rails
.rb:11:in `<top (required)>'
/var/www/myapp/shared/bundle/ruby/2.1.0/gems/sass-rails-5.0.3/lib/sass-rails
.rb:1:in `require'
/var/www/myapp/shared/bundle/ruby/2.1.0/gems/sass-rails-5.0.3/lib/sass-rails
.rb:1:in `<top (required)>'
/home/deployer/.rvm/gems/ruby-2.1.5/gems/bundler-1.10.6/lib/bundler/runtime.rb:7
6:in `require'
/home/deployer/.rvm/gems/ruby-2.1.5/gems/bundler-1.10.6/lib/bundler/runtime.rb:7
6:in `block (2 levels) in require'
/home/deployer/.rvm/gems/ruby-2.1.5/gems/bundler-1.10.6/lib/bundler/runtime.rb:7
2:in `each'
/home/deployer/.rvm/gems/ruby-2.1.5/gems/bundler-1.10.6/lib/bundler/runtime.rb:7
2:in `block in require'
/home/deployer/.rvm/gems/ruby-2.1.5/gems/bundler-1.10.6/lib/bundler/runtime.rb:6
1:in `each'
/home/deployer/.rvm/gems/ruby-2.1.5/gems/bundler-1.10.6/lib/bundler/runtime.rb:6
1:in `require'
/home/deployer/.rvm/gems/ruby-2.1.5/gems/bundler-1.10.6/lib/bundler.rb:134:in `r
equire'
/var/www/myapp/releases/20150820100116/config/application.rb:7:in `<top (req
uired)>'
/var/www/myapp/releases/20150820100116/Rakefile:4:in `require'
/var/www/myapp/releases/20150820100116/Rakefile:4:in `<top (required)>'
(See full trace by running task with --trace)

I read and did according to this subject
. From the differences: instead of unicorn - passenger and instead of github - my own server, where in the next folder with the site there is a repository that I push from a local computer.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
_
_ _, 2015-08-20
@AMar4enko

Ну пишет же, что у вас гем nokogiri не установлен, который используется для работы с html в процессе санитизации html.
Почему не установлен nokogiri, легко выяснить, зайдя на целевую машину по ssh и запустив gem install nokogiri.
Предполагаю, что ему нужен какой-нибудь libxml установленный через apt-get.

Андрей, 2016-03-27
@heart

Долго искал решение этой проблемы. У меня было что я с Windows делал деплой на Ubuntu. Обратите внимание на ваш. Gemfile.lock. Возможно там закрались строчки подобные этой:
nokogiri (1.6.6.2-x86-mingw32)
уберите вручную (или попытайтесь избавиться от -x86....) закомитте и запуште (не забудте). Следующий деплой пройдет без проблем!
Дело в том, что Unix сервер просто игнорирует данные джемы для установки т.к. не находит соответствия(что естественно), но не ругается. Как по хорошему решать проблему - пока не знаю - думаю.

D
disa1985, 2015-08-20
@disa1985

bundle install?

A
Anton Misyagin, 2015-08-20
@sunnmas

Found something interesting:

There are several reasons why you might want to compile resources locally. Here are some of them:
You do not have write access to the production filesystem.
You are hosted on more than one server and want to avoid duplication of work.
You often do deployments that don't involve resource changes.
Local compilation allows you to commit compiled files in version control and deploy as normal.
However, there are three caveats:
You must not run the Capistrano task that compiles the resources.
You must make sure that all the necessary compressors or minifires are present in your development system.
You must change the following application configuration setting:
In config/environments/development.rb put the following line:
config.assets.prefix = "/dev-assets"
Changing the prefix allows Sprockets to use a different URL to serve resources in development mode and pass all requests to Sprockets. The prefix remained set to /assets in production mode. Without this change, the app will be served with precompiled assets from /assets in development, and you won't see any local changes until you compile the assets again.
In practice, this will allow you to precompile locally, keep these files in the working branch, and commit to version control if necessary. development mode will work as expected

I managed to compile them locally. As it is now
You must not run the Capistrano task that compiles the resources
?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question