Question

I am new to Capistrano and trying to precompile the assets. after entering command cap production deploy my code is successfully deployed on the server,but my assets are not compiled.below is my deploy.rb file.

       #SSHKit.config.command_map[:rake] = "bundle exec rake"
# config valid only for Capistrano 3.1
lock '3.1.0'

set :application, 'woi'
set :repo_url, 'git@github.com:sanjay-salunkhe/cap.git'
set :branch, "master"
set :deploy_via, :remote_cache
set :stages, ["production"]

# Default branch is :master
# ask :branch, proc { `git rev-parse --abbrev-ref HEAD`.chomp }

# Default deploy_to directory is /var/www/my_app
 set :deploy_to, '/home/webuser/apps/cap/'

# Default value for :scm is :git
# set :scm, :git

# Default value for :format is :pretty
# set :format, :pretty

# Default value for :log_level is :debug
# set :log_level, :debug

# Default value for :pty is false
# set :pty, true

# Default value for :linked_files is []
# set :linked_files, %w{config/database.yml}

# Default value for linked_dirs is []
# set :linked_dirs, %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system}

# Default value for default_env is {}
# set :default_env, { path: "/opt/ruby/bin:$PATH" }

# Default value for keep_releases is 5
 set :keep_releases, 5

namespace :deploy do

  desc 'Restart application'
  task :restart do
    on roles(:app), in: :sequence, wait: 5 do
      # Your restart mechanism here, for example:
       execute :touch, release_path.join('tmp/restart.txt')
    end
  end

  after :publishing, :restart

  after :restart, :clear_cache do
    on roles(:web), in: :groups, limit: 3, wait: 10 do
      # Here we can do anything such as:
      # within release_path do
      #   execute :rake, 'cache:clear'
      # end
    end
  end


  desc 'precompiling assets..............'
  task :composer_install do
    on roles(:web) do
      within release_path do
        execute :rake, "assets:precompile RAILS_ENV=production"
      end
    end
  end

  after :publishing, 'deploy:composer_install'



end

Below are my logs

   DEBUG [cf204b99]     /usr/bin/env: 
DEBUG [cf204b99]    rake
DEBUG [cf204b99]    : No such file or directory
DEBUG [cf204b99]    
cap aborted!
SSHKit::Command::Failed: rake stdout: Nothing written
rake stderr: Nothing written
/var/lib/gems/1.9.1/gems/sshkit-1.3.0/lib/sshkit/command.rb:94:in `exit_status='
/var/lib/gems/1.9.1/gems/sshkit-1.3.0/lib/sshkit/backends/netssh.rb:142:in `block (4 levels) in _exe

also if possible then please send me the good documentation link for Capistrano 3.1.

Thanks,

Was it helpful?

Solution 2

Finally i manged to deploy my app using capastrano 3.Actually i had not included below two lines in my capfile.

 require 'capistrano/rvm'
require 'capistrano/rails'

After including these two lines my issue has been resolved.

OTHER TIPS

You need to change directory and compile assets in one command. I'm using this:
execute "cd #{release_path}/ && RAILS_ENV=production bundle exec rake assets:precompile"

Sometimes (it depends on server configuration) capistrano can raise an error that it can't find 'bundle', then You have to find where bundle is located on the server by using:
which bundle
And add the full path to above line, in my configuration it was required to provide full path:
execute "cd #{release_path}/ && RAILS_ENV=production /usr/local/bin/bundle exec rake assets:precompile"

I had to update node and install yarn on my server to get rake assets:precompile to work. The frustrating part is that it was not producing any error or feedback. I only discovered this was the problem when I did rake assets:clobber

For Rails 4 and Capistrano 3, I find it unnecessary to write a Capistrano recipe to precompile assets for production.

Instead before I

cap production deploy

I just run

rake assets:precompile RAILS_ENV=production

from my local machine and then go on and deploy.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top