Capistrano 3.1 compile_assets_locally

mar*_*cks 5 capistrano ruby-on-rails

我正在尝试使用此模板部署rails 4.1.0应用程序https://github.com/TalkingQuickly/capistrano-3-rails-template/blob/master/Capfile.我跑的时候

cap production deploy:setup_config
Run Code Online (Sandbox Code Playgroud)

我收到错误消息

cap aborted!
Don't know how to build task 'deploy:compile_assets_locally'
Run Code Online (Sandbox Code Playgroud)

Capfile

require 'capistrano/setup'
require 'capistrano/deploy'
require 'capistrano/rbenv'
require 'capistrano/rails/migrations'
# Loads custom tasks from `lib/capistrano/tasks' if you have any defined.
Dir.glob('lib/capistrano/tasks/*.cap').each { |r| import r }
Dir.glob('lib/capistrano/**/*.rb').each { |r| import r }
Run Code Online (Sandbox Code Playgroud)

deploy.rb

set :application, 'myapp'

set :deploy_user, 'deployer'

set :scm, :git

set :repo_url, 'deployer@mysite.com:~/.git/myapp.git'

set :rbenv_type, :system
set :rbenv_ruby, '2.1.1'
set :rbenv_prefix, "RBENV_ROOT=#{fetch(:rbenv_path)} RBENV_VERSION=#{fetch(:rbenv_ruby)} #{fetch(:rbenv_path)}/bin/rbenv exec"
set :rbenv_map_bins, %w{rake gem bundle ruby rails}

set :keep_releases, 5

set :linked_files, %w{config/database.yml}

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

set :tests, []

set(:config_files, %w(
  nginx.conf
  database.example.yml
  log_rotation
  monit
  unicorn.rb
  unicorn_init.sh
))

set(:executable_config_files, %w(
  unicorn_init.sh
))

set(:symlinks, [
  {
    source: "nginx.conf",
    link: "/etc/nginx/sites-enabled/{{full_app_name}}"
  },
  {
    source: "unicorn_init.sh",
    link: "/etc/init.d/unicorn_{{full_app_name}}"
  },
  {
    source: "log_rotation",
    link: "/etc/logrotate.d/{{full_app_name}}"
  }
])

namespace :deploy do

  before :deploy, "deploy:check_revision"
  before :deploy, "deploy:run_tests"
  after 'deploy:symlink:shared', 'deploy:compile_assets_locally'
  after :finishing, 'deploy:cleanup'
  before 'deploy:setup_config', 'nginx:remove_default_vhost'
  after 'deploy:setup_config', 'nginx:reload'
  after 'deploy:setup_config', 'monit:restart'
  after 'deploy:publishing', 'deploy:restart'
end
Run Code Online (Sandbox Code Playgroud)

小智 1

错误消息表明您没有定义“compile_assets_locally”任务。

看来您已经包含了 capistrano-rails gem,所以我认为第二种方法可以轻松解决您的问题

  • 第一种方法:定义compile_assets_locally任务。复制模板并将其放在 lib/capistrano/tasks 目录下(确保扩展名是 .cap)。

  • 第二种方法:使用 capistrano-rails gem

    • 配置/部署.rb set :assets_roles, [:app]

      消除after 'deploy:symlink:shared', 'deploy:compile_assets_locally'

    • 卡菲勒 require 'capistrano/rails/assets'