capistrano-local-precompile: Seems like it doesn't upload the assets after copmilation

My gemfile

group :development do
  # Access an IRB console on exception pages or by using <%= console %> anywhere in the code.
  gem 'web-console', '>= 3.3.0'
  gem 'listen', '>= 3.0.5', '< 3.2'
  # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
  # gem 'spring'
  # gem 'spring-watcher-listen', '~> 2.0.0'
  gem 'capistrano',         require: false
  gem 'capistrano-rvm',     require: false
  gem 'capistrano-rails',   require: false
  gem 'capistrano-sidekiq', require: false
  gem 'capistrano-rails-db', require: false
  gem 'capistrano-bundler', require: false
  gem 'capistrano-local-precompile', '~> 1.0.0', require: false
  gem 'capistrano-secrets-yml', require: false
  gem 'capistrano3-puma',   require: false
  gem 'capistrano-rails-console', require: false
end

capfile

# Load DSL and Setup Up Stages
require 'capistrano/setup'
require 'capistrano/deploy'
require 'capistrano/bundler'
require 'capistrano/rails'
require 'capistrano/secrets_yml'
require 'capistrano/local_precompile'
require 'capistrano/rvm'
require 'capistrano/puma'
require 'capistrano/sidekiq'
require 'capistrano/rails/console'
install_plugin Capistrano::Puma

# Loads custom tasks from `lib/capistrano/tasks' if you have any defined.
Dir.glob('lib/capistrano/tasks/*.rake').each { |r| import r }

deploy.rb

set :assets_roles, [:web, :app]

## Defaults:
set :scm,           :git
# set :branch,        :master
# set :format,        :pretty
set :log_level,     :debug
set :keep_releases, 5

## Linked Files & Directories (Default None):
# set :linked_files, %w{config/database.yml}
set :linked_dirs,  %w{log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system}

namespace :puma do
  desc 'Create Directories for Puma Pids and Socket'
  task :make_dirs do
    on roles(:app) do
      execute "mkdir #{shared_path}/tmp/sockets -p"
      execute "mkdir #{shared_path}/tmp/pids -p"
    end
  end

  before :start, :make_dirs
end

namespace :deploy do
  desc "Make sure local git is in sync with remote."
  task :check_revision do
    on roles(:app) do
      unless `git rev-parse HEAD` == `git rev-parse origin/master`
        puts "WARNING: HEAD is not the same as origin/master"
        puts "Run `git push` to sync changes."
        exit
      end
    end
  end

  desc 'Initial Deploy'
  task :initial do
    on roles(:app) do
      before 'deploy:restart'
      invoke 'deploy'
    end
  end

  desc 'Restart application'
  task :start do
    on roles(:app), in: :sequence, wait: 5 do
      invoke 'puma:start'
    end
  end

  before :starting,     :check_revision
  after  :finishing,    :cleanup
  after  :finishing,    :start
  after :restart, 'sidekiq:restart'
end

I use rails 5, and capistrano 3.

The deploy log looks good, but in the end it doesn’t takes any effects in production.

Any suggestions?

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 15

Most upvoted comments

@eriknygren I couldn’t get the gem to rsync even when pulling the latest from master. I ended up writing my own by following the gem source to get the job done in a pinch:

# Load DSL and set up stages
require "capistrano/setup"

# Include default deployment tasks
require "capistrano/deploy"

require "capistrano/scm/git"
install_plugin Capistrano::SCM::Git

# Include tasks from other gems included in your Gemfile
require 'capistrano/rails'
require 'capistrano/rbenv'
require 'capistrano/passenger'
require 'capistrano/npm'
require 'capistrano/sidekiq'
require 'capistrano/clockwork'

# Load custom tasks from `lib/capistrano/tasks` if you have any defined
Dir.glob("lib/capistrano/tasks/*.rake").each { |r| import r }

namespace :load do
  task :defaults do
    set :precompile_env,   fetch(:rails_env) || 'production'
    set :assets_dir,       "public/assets"
    set :rsync_cmd,        "rsync -av --delete"

    after "bundler:install", "deploy:assets:prepare"
  end
end

# Precompile files locally for _much_ faster deployment.
namespace :deploy do
  # Clear existing task so we can replace it rather than "add" to it.
  Rake::Task["deploy:compile_assets"].clear

  namespace :assets do
    desc "Precompile the assets locally and rsync to the server"
    task :prepare do
      run_locally do
        with rails_env: fetch(:precompile_env) do
          execute "rake assets:clobber"
          execute "rm -rf node_modules && npm install"
          execute "rake assets:precompile"
          info "Sending precompiled files to the server."
          execute "#{fetch(:rsync_cmd)} ./#{fetch(:assets_dir)}/ #{fetch(:user)}@#{fetch(:server)}:#{shared_path}/#{fetch(:assets_dir)}/"
        end
      end
    end   
  end
end